fix(junction): reject overlapping exclusion cores

This commit is contained in:
que01 committed 2026-09-09 10:00:32 +08:00
1 parent 75bdfbe607
commit 3bf2edaf99
2 files changed
+34 -1

No files matched your search

+25 -1
View File
@@ -126,6 +126,30 @@ function pointInRing(point, ring) {
}, false);
}
function segmentsIntersect(first, second, third, fourth) {
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);
const thirdSide = cross(third, fourth, first);
const fourthSide = cross(third, fourth, second);
return (
((firstSide >= 0 && secondSide <= 0) || (firstSide <= 0 && secondSide >= 0)) &&
((thirdSide >= 0 && fourthSide <= 0) || (thirdSide <= 0 && fourthSide >= 0))
);
}
function ringsOverlap(first, second) {
return (
first.slice(0, -1).some((point) => pointInRing(point, second)) ||
second.slice(0, -1).some((point) => pointInRing(point, first)) ||
first
.slice(1)
.some((point, index) =>
second.slice(1).some((other, otherIndex) => segmentsIntersect(first[index], point, second[otherIndex], other)),
)
);
}
// A central paved region is safe to infer only when every arm has exactly one
// source carriageway. Its shared entry seams are the sections' `inner` edges;
// every remaining edge is an explicit closure between adjacent arms.
@@ -157,7 +181,7 @@ function buildCoreClosure(topology, graph, center) {
});
if (ring.length < 7 || !paired || Math.abs(signedArea(ring)) < 1e-14 || ringSelfIntersects(ring))
return { status: 'unsupported', reason: 'core-closure-invalid' };
if (graph.exclusionRegions.some((region) => region.ring.some((point) => pointInRing(point, ring))))
if (graph.exclusionRegions.some((region) => ringsOverlap(region.ring, ring)))
return { status: 'unsupported', reason: 'known-exclusion-region' };
return {
status: 'supported',