MCPcopy Create free account
hub / github.com/Andreaswt/figma-clone / findIntersectionLayersWithRectangle

Function findIntersectionLayersWithRectangle

src/utils.ts:134–166  ·  view source on GitHub ↗
(
  layerIds: readonly string[],
  layers: ReadonlyMap<string, Layer>,
  a: Point,
  b: Point,
)

Source from the content-addressed store, hash-verified

132};
133
134export function findIntersectionLayersWithRectangle(
135 layerIds: readonly string[],
136 layers: ReadonlyMap<string, Layer>,
137 a: Point,
138 b: Point,
139) {
140 const rect = {
141 x: Math.min(a.x, b.x),
142 y: Math.min(a.y, b.y),
143 width: Math.abs(a.x - b.x),
144 height: Math.abs(a.y - b.y),
145 };
146
147 const ids = [];
148
149 for (const layerId of layerIds) {
150 const layer = layers.get(layerId);
151
152 if (layer == null) continue;
153
154 const { x, y, height, width } = layer;
155 if (
156 rect.x + rect.width > x &&
157 rect.x < x + width &&
158 rect.y + rect.height > y &&
159 rect.y < y + height
160 ) {
161 ids.push(layerId);
162 }
163 }
164
165 return ids;
166}

Callers 1

CanvasFunction · 0.90

Calls

no outgoing calls

Tested by

no test coverage detected