diff --git a/.trellis/tasks/09-08-junction-reference-fidelity/implement.md b/.trellis/tasks/09-08-junction-reference-fidelity/implement.md index c448fcd..1de7809 100644 --- a/.trellis/tasks/09-08-junction-reference-fidelity/implement.md +++ b/.trellis/tasks/09-08-junction-reference-fidelity/implement.md @@ -162,3 +162,9 @@ complex-junction.js / native-road.js:构建与全部消费者;direct-edit-so ## 完整接触求解实现(工作区,待提交) 新增 `solveIslandContacts`,复杂路口现在消费同一结果生成动态直角边、圆滑外轮廓和六点 `greenRing`;第三组斑马线中心也由该结果定位。前端以 `kind=island-green` 显示绿色六边形。真实 OSM 输出 4 个岛且每个都有 6 个接触点,相关重叠检查为 0。新增纯几何回归覆盖端点数量和动态腿长。尚未提交。 + +## 2026-09-14 四角协调与实际工作台配置复现(未提交) + +实际最新导入工作区 import-fE8XI7 使用四节点、coreRadius=21;此前验证脚本硬编码五节点、24,漏掉真实失败。已复现两个 contact-crosses-corner 导致两岛省略。四臂过街现在在发布前共同检查相邻接触短边;必要时对称缩短所有过街跨度,以完整白条节距进行裁减,保留白条长度/宽度/间隔。找不到满足最小过街跨度的方案时不应用试探裁减,保留不可行诊断。未改保存配置或用户编辑。 + +实际配置现在发布四岛、四绿色六边形,各六个唯一点,面积约 19.49–28.70m²。新增真实 OSM 四节点 21m 回归检查四角对象、六点及岛体引用。references/four-islands-coordinated.png 为编译几何整图(黄色停止线用于辨识),非浏览器截图。接触交集约 4.2e-5m²、中心铺装缺口仍待解决;不能声称严格共享边界或整体验收完成。前序“六点数量通过即完整接触完成”的说法不成立。 diff --git a/.trellis/tasks/09-08-junction-reference-fidelity/references/four-islands-coordinated.png b/.trellis/tasks/09-08-junction-reference-fidelity/references/four-islands-coordinated.png new file mode 100644 index 0000000..bab8531 Binary files /dev/null and b/.trellis/tasks/09-08-junction-reference-fidelity/references/four-islands-coordinated.png differ diff --git a/.trellis/tasks/09-08-junction-reference-fidelity/references/four-islands-coordinated.svg b/.trellis/tasks/09-08-junction-reference-fidelity/references/four-islands-coordinated.svg new file mode 100644 index 0000000..4880a36 --- /dev/null +++ b/.trellis/tasks/09-08-junction-reference-fidelity/references/four-islands-coordinated.svg @@ -0,0 +1 @@ + \ No newline at end of file diff --git a/src/compile/complex-junction.js b/src/compile/complex-junction.js index e9cbb99..1ca67d9 100644 --- a/src/compile/complex-junction.js +++ b/src/compile/complex-junction.js @@ -274,13 +274,57 @@ function buildComplexJunctionGeometry(model, cluster, helpers) { arm.crosswalkFrame.supportHeading = normalizeHeading(crossingHeadings[index] + 90); } }); + // Coordinate all four landing pairs before publishing stripes. Trim whole + // stripe pitches symmetrically so stripe size and spacing stay unchanged. + let crossingSpanTrim = 0; + if (arms.length === 4 && arms.every((arm) => arm.crosswalkFrame)) { + for (let attempt = 0; attempt < 12; attempt++) { + const trialTrim = attempt * 1.64; + const candidates = arms.map((arm) => { + const f = arm.crosswalkFrame; + const span = f.envelopeWidthMeters - 0.7 - trialTrim; + if (span < f.groupDepth) return null; + const shifted = helpers.offsetCoordinate(f.center, f.heading, f.groupDepth); + const layout = stripeLayout(span); + const half = span / 2 - (layout.centers[0] - layout.width / 2); + return [-1, 1].map((sign) => helpers.offsetCoordinate(shifted, f.heading + 90, sign * half)); + }); + if (candidates.some((candidate) => !candidate)) break; + const valid = arms.every((arm, i) => { + const j = (i + 1) % arms.length; + const pair = candidates[i] + .flatMap((a) => candidates[j].map((b) => ({ a, b, distance: helpers.distanceMeters(a, b) }))) + .sort((a, b) => a.distance - b.distance)[0]; + const origin = rayIntersection( + { point: pair.a, heading: arm.crosswalkFrame.heading }, + { point: pair.b, heading: arms[j].crosswalkFrame.heading }, + center, + ); + return ( + origin && + [ + [arm, pair.a], + [arms[j], pair.b], + ].every( + ([side, point]) => + directionalProjectionMeters(origin, point, side.crosswalkFrame.heading) > + side.crosswalkFrame.groupDepth / 2 + 0.2, + ) + ); + }); + if (valid) { + crossingSpanTrim = trialTrim; + break; + } + } + } for (let index = 0; index < arms.length; index += 1) { const arm = arms[index]; if (!arm.crosswalkFrame) continue; const item = arm.representative; const crossingHeading = arm.crosswalkFrame.heading; const roadEdgeInset = 0.35; - const usableSpan = Math.max(0.42, arm.crosswalkFrame.envelopeWidthMeters - roadEdgeInset * 2); + const usableSpan = Math.max(0.42, arm.crosswalkFrame.envelopeWidthMeters - roadEdgeInset * 2 - crossingSpanTrim); const groupDepth = arm.crosswalkFrame.groupDepth; arm.crosswalkFrame.center = helpers.offsetCoordinate(arm.crosswalkFrame.center, crossingHeading, groupDepth); arm.crosswalkRadius += groupDepth; @@ -477,21 +521,30 @@ function buildComplexJunctionGeometry(model, cluster, helpers) { const outerFirst = helpers.offsetCoordinate( crossingCorner, first.crosswalkFrame.heading, - first.crosswalkFrame.groupDepth * 2, + first.crosswalkFrame.groupDepth, ); const outerSecond = helpers.offsetCoordinate( crossingCorner, second.crosswalkFrame.heading, - second.crosswalkFrame.groupDepth * 2, + second.crosswalkFrame.groupDepth, ); const lonScale = 111320 * Math.cos((crossingCorner[1] * Math.PI) / 180); const toLocal = (point) => [(point[0] - crossingCorner[0]) * lonScale, (point[1] - crossingCorner[1]) * 111320]; const fromLocal = (point) => [crossingCorner[0] + point[0] / lonScale, crossingCorner[1] + point[1] / 111320]; + const landing = (arm, endpoint) => { + const frame = arm.crosswalkFrame; + const layout = stripeLayout(frame.spanMeters); + const margin = layout.centers[0] - layout.width / 2; + const edgeCenter = helpers.offsetCoordinate(endpoint, bearing(endpoint, frame.center), margin); + return [-1, 1].map((sign) => + toLocal(helpers.offsetCoordinate(edgeCenter, frame.heading, (sign * frame.groupDepth) / 2)), + ); + }; const contactSolution = solveIslandContacts( - [[0, 0], toLocal(outerFirst)], - [[0, 0], toLocal(outerSecond)], + landing(first, pair.a), + landing(second, pair.b), COMPLEX_CROSSWALK_DEPTH_METERS, - { maxLegLength: Math.max(outerRadius * 2, COMPLEX_CROSSWALK_DEPTH_METERS * 4) }, + { maxLegLength: outerRadius }, ); if (contactSolution.status !== 'solved') { cornerDiagnostics.push( @@ -549,18 +602,9 @@ function buildComplexJunctionGeometry(model, cluster, helpers) { // not required for the default visual treatment. const outerMidpoint = fromLocal(contactSolution.thirdCenter); const diagonalDepth = COMPLEX_CROSSWALK_DEPTH_METERS; - const diagonalHeading = bearing(outerFirst, outerSecond) - 90; - const outwardHeading = bearing(crossingCorner, outerMidpoint); - const theta = (outwardHeading * Math.PI) / 180; - const diagonalLonScale = 111320 * Math.cos((outerMidpoint[1] * Math.PI) / 180); - const projectedIsland = publishedIslandRing.map((p) => { - const east = (p[0] - outerMidpoint[0]) * diagonalLonScale; - const north = (p[1] - outerMidpoint[1]) * 111320; - return [east * Math.cos(theta) - north * Math.sin(theta), east * Math.sin(theta) + north * Math.cos(theta)]; - }); - const support = crossingArcSupport(projectedIsland, COMPLEX_CROSSWALK_DEPTH_METERS / 2); - if (support === null) continue; - const diagonalCenter = helpers.offsetCoordinate(outerMidpoint, outwardHeading, support + diagonalDepth / 2); + const outwardHeading = (Math.atan2(contactSolution.outward[0], contactSolution.outward[1]) * 180) / Math.PI; + const diagonalHeading = outwardHeading; + const diagonalCenter = helpers.offsetCoordinate(outerMidpoint, outwardHeading, diagonalDepth / 2); const diagonalSpan = COMPLEX_CROSSWALK_DEPTH_METERS; const layout = stripeLayout(diagonalDepth); const stripeCount = layout.centers.length; diff --git a/src/compile/junction-facility-composition.js b/src/compile/junction-facility-composition.js index 3fdcf9c..2fcd567 100644 --- a/src/compile/junction-facility-composition.js +++ b/src/compile/junction-facility-composition.js @@ -134,8 +134,8 @@ function solveIslandContacts(firstSegment, secondSegment, thirdWidth, options = second = ordered(secondSegment); const u = unit(sub(first[1], corner)), v = unit(sub(second[1], corner)); - // A short edge may begin exactly at the supporting-line intersection; this - // is the intended right-angle landing and is still a complete contact. + if (dot(sub(first[0], corner), u) <= 1e-8 || dot(sub(second[0], corner), v) <= 1e-8) + return fail('contact-crosses-corner'); const a = length(sub(first[1], corner)), b = length(sub(second[1], corner)); const chord = sub(second[1], first[1]), @@ -157,6 +157,8 @@ function solveIslandContacts(firstSegment, secondSegment, thirdWidth, options = if (dot(outward, sub(thirdCenter, corner)) < 0) outward = outward.map((value) => -value); const contacts = [first, thirdContact, [second[1], second[0]]]; const vertices = contacts.flat(); + if (vertices.some((p, i) => vertices.slice(i + 1).some((q) => length(sub(p, q)) < 1e-8))) + return fail('duplicate-contact-endpoints'); const hexArea = Math.abs( vertices.reduce((sum, point, i) => { diff --git a/test/junction-facility-composition.js b/test/junction-facility-composition.js index de92069..6a4ab5e 100644 --- a/test/junction-facility-composition.js +++ b/test/junction-facility-composition.js @@ -108,12 +108,12 @@ assert.deepEqual( const solvedContacts = solveIslandContacts( [ - [0, 0], - [0, 6.8], + [0, 1.7], + [0, 5.1], ], [ - [0, 0], - [-6.8, 0], + [-1.7, 0], + [-5.1, 0], ], 3.4, { maxLegLength: 20 }, @@ -122,4 +122,47 @@ assert.equal(solvedContacts.status, 'solved'); assert.equal(solvedContacts.contacts.length, 3); assert.equal(solvedContacts.greenRing.length, 7); assert.equal(solvedContacts.legLengths.length, 2); -assert.ok(solvedContacts.legLengths.every((value) => value > 6.8)); +assert.ok(solvedContacts.legLengths.every((value) => value > 5.1)); + +assert.equal(new Set(solvedContacts.greenRing.slice(0, -1).map((p) => p.join(','))).size, 6); + +// Regression: the saved four-node, 21m cluster previously lost two islands. +{ + const fs = require('fs'); + const path = require('path'); + const compiler = require('../src'); + const model = compiler.nativeRoad.compileRoadModel( + fs.readFileSync(path.join(__dirname, '../inputs/osm/枫树二路.osm'), 'utf8'), + { overrides: [] }, + ); + const geometry = compiler.nativeRoad.compileGeometry( + model, + { overrides: [] }, + { + edgeLines: false, + junctionTemplates: { + enabled: true, + clusters: [ + { + id: 'four-node-contact-regression', + template: 'complex-junction-v1', + coreRadiusMeters: 21, + nodeIds: ['8005332807', '8024512135', '8024512145', '8024512147'], + }, + ], + }, + }, + ); + const outer = geometry.sidewalkSurface.features.filter((f) => f.properties.kind === 'island'); + const green = geometry.sidewalkSurface.features.filter((f) => f.properties.kind === 'island-green'); + assert.equal(outer.length, 4, 'all four corners must publish islands'); + assert.equal(green.length, 4, 'all four islands must publish green contact polygons'); + assert.equal(new Set(green.map((f) => f.properties.corner_key)).size, 4); + for (const feature of green) { + const points = feature.geometry.coordinates[0].slice(0, -1); + assert.equal(new Set(points.map((p) => p.join(','))).size, 6); + const island = outer.find((f) => f.properties.corner_key === feature.properties.corner_key); + assert.deepEqual(points, island.properties.contact_points); + } + assert.equal(geometry.diagnostics.filter((d) => d.rule === 'complex-junction-island-infeasible').length, 0); +}