feat: establish junction region geometry baseline

This commit is contained in:
que01 committed 2026-09-11 15:27:53 +08:00
1 parent de97600fe8
commit 76f81d024a
14 files changed
+287 -11

No files matched your search

+22
View File
@@ -0,0 +1,22 @@
'use strict';
const assert = require('assert/strict');
const { buildPedestrianIsland, validateFacilityComposition } = require('../src/compile/junction-facility-composition');
const ring = [
[0, 0],
[4, 0],
[4, 2],
[0, 2],
[0, 0],
];
const crossings = [1, 2, 3].map((id) => ({
key: `crossing:${id}`,
fromBoundary: `walk:${id}`,
toBoundary: 'island:1',
}));
const island = buildPedestrianIsland({ key: 'island:1', ring, crossingKeys: crossings.map((item) => item.key) });
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');
+26
View File
@@ -0,0 +1,26 @@
'use strict';
const assert = require('assert/strict');
const { difference, intersection, union, intersectsOrTouches } = require('../src/compile/junction-polygon-ops');
const square = (x, y, size) => [
[
[x, y],
[x + size, y],
[x + size, y + size],
[x, y + size],
[x, y],
],
];
const shell = square(0, 0, 10);
const hole = square(2, 2, 6);
assert.equal(difference(shell, hole)[0].length, 2);
assert.equal(intersection(shell, hole).length, 1);
assert.equal(union(shell, square(10, 0, 5)).length, 1);
assert.deepEqual(difference(shell), [shell]);
assert.equal(intersectsOrTouches(shell, hole), true);
assert.equal(
intersectsOrTouches(shell, square(20, 0, 2), () => true),
true,
);
console.log('junction polygon operation tests passed');
+25
View File
@@ -0,0 +1,25 @@
'use strict';
const assert = require('assert/strict');
const { solvePavedRegion, solveCornerFeasibleRegion } = require('../src/compile/junction-region-solver');
const shell = [
[0, 0],
[10, 0],
[10, 10],
[0, 10],
[0, 0],
];
const hole = [
[2, 2],
[8, 2],
[8, 8],
[2, 8],
[2, 2],
];
const result = solvePavedRegion(shell, [hole]);
assert.equal(result.length, 1);
assert.equal(result[0].length, 2);
assert.deepEqual(solvePavedRegion(shell), [[shell]]);
assert.equal(solveCornerFeasibleRegion(shell, hole).length, 1);
console.log('junction region solver tests passed');