Crossing — selected if any part of the geometry overlaps the rectangle.
The check has two stages:
first, any vertex inside the rectangle is an immediate hit;
second, every geometry edge is tested against each of the four rectangle edges
using a 2D segment-intersection routine:
private anyCrossingHit(pts, edges, minX, minY, maxX, maxY): boolean {
// 1) any vertex inside rect
for (const p of pts) {
if (p.x >= minX && p.x <= maxX && p.y >= minY && p.y <= maxY) return true;
}
// 2) any geometry edge crosses rect boundary
const rectEdges = [
[minX, minY, maxX, minY],
[maxX, minY, maxX, maxY],
[maxX, maxY, minX, maxY],
[minX, maxY, minX, minY],
];
for (const [ai, bi] of edges) {
const pa = pts[ai], pb = pts[bi];
for (const [ex1, ey1, ex2, ey2] of rectEdges) {
if (segmentsIntersect(pa.x, pa.y, pb.x, pb.y, ex1, ey1, ex2, ey2)) return true;
}
}
return false;
}