fix: respect finite extents in junction region overlap
This commit is contained in:
1 parent
101bcb3792
commit
c003edaf51
2 files changed
+34
-1
No files matched your search
@@ -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);
|
||||
|
||||
@@ -4,11 +4,35 @@
|
||||
|
||||
const assert = require('assert/strict');
|
||||
const { resolveJunctionBuildPlan, stationAtDistanceFrom } = require('../src/compile/junction-build-plan');
|
||||
const { buildJunctionBoundaryGraph, buildCoreClosure } = require('../src/compile/junction-boundary-graph');
|
||||
const {
|
||||
buildJunctionBoundaryGraph,
|
||||
buildCoreClosure,
|
||||
ringsOverlap,
|
||||
} = require('../src/compile/junction-boundary-graph');
|
||||
const { classifyJunctionShape } = require('../src/compile/complex-junction');
|
||||
|
||||
const metersPerDegree = 111320;
|
||||
const point = (east, north) => [east / metersPerDegree, north / metersPerDegree];
|
||||
const square = (x, y, size = 2) =>
|
||||
[
|
||||
[x, y],
|
||||
[x + size, y],
|
||||
[x + size, y + size],
|
||||
[x, y + size],
|
||||
[x, y],
|
||||
].map(([east, north]) => point(east, north));
|
||||
for (const [other, expected] of [
|
||||
[square(10, 0), false],
|
||||
[square(0, 10), false],
|
||||
[square(2, 0), true],
|
||||
[square(2, 2), true],
|
||||
[square(1, 1), true],
|
||||
[square(0.5, 0.5, 0.5), true],
|
||||
]) {
|
||||
assert.equal(ringsOverlap(square(0, 0), other), expected);
|
||||
assert.equal(ringsOverlap(other, square(0, 0)), expected);
|
||||
assert.equal(ringsOverlap(square(0, 0).reverse(), other.slice().reverse()), expected);
|
||||
}
|
||||
|
||||
function heading(line) {
|
||||
const [from, to] = line;
|
||||
|
||||
Reference in new issue
Block a user