fix: align junction crossings and round pedestrian islands
This commit is contained in:
1 parent
76f81d024a
commit
7a7912f302
18 files changed
+491
-96
No files matched your search
@@ -20,3 +20,88 @@ assert.equal(validateFacilityComposition(island, crossings).valid, true);
|
||||
assert.equal(buildPedestrianIsland({ key: 'bad', ring, crossingKeys: ['a', 'b'] }), null);
|
||||
assert.equal(validateFacilityComposition(island, crossings.slice(0, 2)).reason, 'crossing-reference-missing');
|
||||
console.log('junction facility composition tests passed');
|
||||
|
||||
// User's sketch: a horizontal crossing to the right, a vertical crossing down,
|
||||
// and the island in the upper-left quadrant, bounded by doubled short edges.
|
||||
const { buildIslandFromCrossingEdges } = require('../src/compile/junction-facility-composition');
|
||||
const clipping = require('polygon-clipping');
|
||||
const sketchIsland = buildIslandFromCrossingEdges([0, 0], [0, 6.8], [-6.8, 0]);
|
||||
assert.deepEqual(sketchIsland[0], sketchIsland.at(-1));
|
||||
assert.ok(sketchIsland.every(([x, y]) => x <= 0 && y >= 0));
|
||||
const arcMiddle = sketchIsland[7];
|
||||
assert.ok(arcMiddle[1] - arcMiddle[0] < 6.8, 'hypotenuse bends toward the right-angle vertex');
|
||||
for (const crossing of [
|
||||
[
|
||||
[0, 0],
|
||||
[12, 0],
|
||||
[12, 3.4],
|
||||
[0, 3.4],
|
||||
[0, 0],
|
||||
],
|
||||
[
|
||||
[0, 0],
|
||||
[0, -12],
|
||||
[-3.4, -12],
|
||||
[-3.4, 0],
|
||||
[0, 0],
|
||||
],
|
||||
])
|
||||
assert.deepEqual(clipping.intersection([sketchIsland], [crossing]), [], 'short-edge attachment has no area overlap');
|
||||
const rotate = ([x, y]) => [-y + 20, x - 10];
|
||||
const rotatedIsland = buildIslandFromCrossingEdges(
|
||||
...[
|
||||
[0, 0],
|
||||
[0, 6.8],
|
||||
[-6.8, 0],
|
||||
].map(rotate),
|
||||
);
|
||||
rotatedIsland.forEach((p, i) =>
|
||||
assert.ok(
|
||||
Math.hypot(...p.map((v, j) => v - rotate(sketchIsland[i])[j])) < 1e-10,
|
||||
'composition is independent of world orientation',
|
||||
),
|
||||
);
|
||||
|
||||
const { stripeLayout, orthogonalCrossingHeadings } = require('../src/compile/junction-facility-composition');
|
||||
for (const span of [3.4, 8.123, 31.7]) {
|
||||
const layout = stripeLayout(span);
|
||||
for (let i = 1; i < layout.centers.length; i++)
|
||||
assert.ok(Math.abs(layout.centers[i] - layout.centers[i - 1] - layout.width - layout.gap) < 1e-10);
|
||||
assert.ok(layout.centers[0] >= layout.width / 2);
|
||||
assert.ok(layout.centers.at(-1) + layout.width / 2 <= span + 1e-10);
|
||||
}
|
||||
const fitted = orthogonalCrossingHeadings([62.2, 150.4, 240.7, 332]);
|
||||
for (let i = 1; i < 4; i++) assert.ok(Math.abs(fitted[i] - fitted[i - 1] - 90) < 1e-10);
|
||||
assert.deepEqual(orthogonalCrossingHeadings([0, 120, 240]), [0, 120, 240]);
|
||||
assert.deepEqual(orthogonalCrossingHeadings([0, 40, 180, 270]), [0, 40, 180, 270]);
|
||||
|
||||
const { crossingArcSupport } = require('../src/compile/junction-facility-composition');
|
||||
assert.ok(!sketchIsland.some(([x, y]) => x === 0 && y === 0), 'right-angle vertex is rounded');
|
||||
assert.ok(!sketchIsland.some(([x, y]) => x === 0 && y === 6.8), 'first arc/leg vertex is rounded');
|
||||
assert.ok(!sketchIsland.some(([x, y]) => x === -6.8 && y === 0), 'second arc/leg vertex is rounded');
|
||||
// Curve support must consider the ends of a finite-width bar, not only its centre.
|
||||
const curved = [
|
||||
[-3, 2],
|
||||
[-1, 0],
|
||||
[1, 0],
|
||||
[3, 2],
|
||||
[3, -2],
|
||||
[-3, -2],
|
||||
[-3, 2],
|
||||
];
|
||||
assert.equal(crossingArcSupport(curved, 2), 1);
|
||||
assert.deepEqual(
|
||||
clipping.intersection(
|
||||
[curved],
|
||||
[
|
||||
[
|
||||
[-2, 1],
|
||||
[2, 1],
|
||||
[2, 1.42],
|
||||
[-2, 1.42],
|
||||
[-2, 1],
|
||||
],
|
||||
],
|
||||
),
|
||||
[],
|
||||
);
|
||||
Reference in new issue
Block a user