From 234dd46f59e5f68dd7333a36c7aa7f8c5f294384 Mon Sep 17 00:00:00 2001 From: que01 Date: Wed, 9 Sep 2026 11:34:56 +0800 Subject: [PATCH] test(junction): cover six-arm rotation stability --- test/junction-build-plan-counterexamples.js | 33 +++++++++++++++++++++ 1 file changed, 33 insertions(+) diff --git a/test/junction-build-plan-counterexamples.js b/test/junction-build-plan-counterexamples.js index 99c3d55..df29bbe 100644 --- a/test/junction-build-plan-counterexamples.js +++ b/test/junction-build-plan-counterexamples.js @@ -195,4 +195,37 @@ const curvedBoundaryStation = stationAtDistanceFrom(curvedBoundaryLine, point(0, }); assert.ok(Math.abs(distance(pointAtStation(curvedBoundaryLine, curvedBoundaryStation), point(0, 0)) - 9) < 0.01); +// Six-arm clusters remain within the supported matrix and keep semantic keys +// stable when the source geometry is rotated. Geometry may change with the +// transform, but identity and arm count must not depend on input orientation. +const sixArmEntries = [0, 60, 120, 180, 240, 300].map((angle) => ({ + widthMeters: 6, + line: [point(0, 0), point(Math.sin((angle * Math.PI) / 180) * 45, Math.cos((angle * Math.PI) / 180) * 45)], +})); +const sixArm = topology('six-arm', sixArmEntries); +assert.equal(sixArm.topology.arms.length, 6); +assert.equal(classifyJunctionShape(sixArm.topology.arms, point(0, 0), sixArm.helpers).kind, 'multi-arm'); +const sixArmGraph = buildJunctionBoundaryGraph( + sixArm.topology, + point(0, 0), + { outerRadiusFor: () => 30, innerRadiusFor: () => 10 }, + sixArm.helpers, +); +assert.equal(buildCoreClosure(sixArm.topology, sixArmGraph, point(0, 0)).status, 'supported'); +const rotate = (coordinate, degrees) => { + const radians = (degrees * Math.PI) / 180; + return point( + coordinate[0] * metersPerDegree * Math.cos(radians) - coordinate[1] * metersPerDegree * Math.sin(radians), + coordinate[0] * metersPerDegree * Math.sin(radians) + coordinate[1] * metersPerDegree * Math.cos(radians), + ); +}; +const rotatedSixArmEntries = sixArmEntries.map((entry) => ({ + ...entry, + line: entry.line.map((coordinate) => rotate(coordinate, 37)), +})); +const rotatedSixArm = fixture('six-arm', rotatedSixArmEntries); +const rotatedTopology = resolveJunctionBuildPlan(rotatedSixArm.model, rotatedSixArm.cluster, rotatedSixArm.helpers); +assert.deepEqual(rotatedTopology.arms.map((arm) => arm.key).sort(), sixArm.topology.arms.map((arm) => arm.key).sort()); +assert.equal(rotatedTopology.arms.length, sixArm.topology.arms.length); + console.log('junction build-plan counterexample tests passed');