2dbi
Home/Figma/Hit Testing / Rectangle Overlap on Canvas
FFigma·DSAProduct EngOnsite – Coding 1

Hit Testing / Rectangle Overlap on Canvas

Problem

Given shapes on a canvas and a point (or selection rectangle), return which shapes are hit/selected, respecting z-order.

Example

point -> topmost shape under it; rect -> shapes inside

Constraints

  • Many shapes; consider performance

Approach

Reverse z-order scan, or a spatial index (quadtree) for large scenes.

added 6 days ago
LeadersAccount