fix(junction): align complex boundary trims
This commit is contained in:
1 parent
a12e2ac823
commit
4de971ce68
5 files changed
+125
-24
No files matched your search
@@ -3,7 +3,7 @@
|
||||
// Source-independent counterexamples for the JunctionBuildPlan contract.
|
||||
|
||||
const assert = require('assert/strict');
|
||||
const { resolveJunctionBuildPlan } = require('../src/compile/junction-build-plan');
|
||||
const { resolveJunctionBuildPlan, stationAtDistanceFrom } = require('../src/compile/junction-build-plan');
|
||||
const { classifyJunctionShape } = require('../src/compile/complex-junction');
|
||||
|
||||
const metersPerDegree = 111320;
|
||||
@@ -22,6 +22,22 @@ function length(line) {
|
||||
return line.slice(1).reduce((total, item, index) => total + distance(line[index], item), 0);
|
||||
}
|
||||
|
||||
function pointAtStation(line, station) {
|
||||
let remaining = station;
|
||||
for (let index = 1; index < line.length; index += 1) {
|
||||
const segmentLength = distance(line[index - 1], line[index]);
|
||||
if (remaining <= segmentLength) {
|
||||
const ratio = remaining / segmentLength;
|
||||
return [
|
||||
line[index - 1][0] + (line[index][0] - line[index - 1][0]) * ratio,
|
||||
line[index - 1][1] + (line[index][1] - line[index - 1][1]) * ratio,
|
||||
];
|
||||
}
|
||||
remaining -= segmentLength;
|
||||
}
|
||||
return line.at(-1);
|
||||
}
|
||||
|
||||
function fixture(name, entries) {
|
||||
const nodeId = `${name}:node`;
|
||||
const approaches = entries.map((entry, index) => ({
|
||||
@@ -120,4 +136,10 @@ assert.notEqual(
|
||||
curvedShort.topology.carriageways[0].entrySection.farTangent,
|
||||
);
|
||||
|
||||
const curvedBoundaryLine = [point(0, 0), point(0, 5), point(10, 10)];
|
||||
const curvedBoundaryStation = stationAtDistanceFrom(curvedBoundaryLine, point(0, 0), 9, {
|
||||
distanceMeters: distance,
|
||||
});
|
||||
assert.ok(Math.abs(distance(pointAtStation(curvedBoundaryLine, curvedBoundaryStation), point(0, 0)) - 9) < 0.01);
|
||||
|
||||
console.log('junction build-plan counterexample tests passed');
|
||||
Reference in new issue
Block a user