fix: respect finite extents in junction region overlap

This commit is contained in:
que01 committed 2026-09-10 09:47:07 +08:00
1 parent 101bcb3792
commit c003edaf51
2 files changed
+34 -1

No files matched your search

+9
View File
@@ -161,6 +161,15 @@ function pointInRing(point, ring) {
}
function segmentsIntersect(first, second, third, fourth) {
// Orientation alone treats all collinear segments as intersecting, even
// when their finite extents are disjoint.
if (
Math.max(first[0], second[0]) < Math.min(third[0], fourth[0]) ||
Math.max(third[0], fourth[0]) < Math.min(first[0], second[0]) ||
Math.max(first[1], second[1]) < Math.min(third[1], fourth[1]) ||
Math.max(third[1], fourth[1]) < Math.min(first[1], second[1])
)
return false;
const cross = (a, b, c) => (b[0] - a[0]) * (c[1] - a[1]) - (b[1] - a[1]) * (c[0] - a[0]);
const firstSide = cross(first, second, third);
const secondSide = cross(first, second, fourth);