| 132 | }; |
| 133 | |
| 134 | export 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 | } |