fix: coordinate crosswalk landings across all four islands

This commit is contained in:
que01 committed 2026-09-14 09:43:12 +08:00
1 parent 1b91e280bc
commit 695bf21a84
6 files changed
+121 -25

No files matched your search

@@ -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²、中心铺装缺口仍待解决;不能声称严格共享边界或整体验收完成。前序“六点数量通过即完整接触完成”的说法不成立。
Binary file not shown.

After

Width:  |  Height:  |  Size: 154 KiB

@@ -0,0 +1 @@
<svg xmlns="http://www.w3.org/2000/svg" width="1000" height="1000" viewBox="-36.08719395540545 -36.08719395540545 72.1743879108109 72.1743879108109"><rect x="-36.08719395540545" y="-36.08719395540545" width="72.1743879108109" height="72.1743879108109" fill="#dce3df"/><g transform="scale(1,-1)"><path d="M-182.72631252387666,-102.1254779457577L-33.00576846735486,-19.702587331817085L-28.30378794160006,-28.24386623474055L-178.02433199812185,-110.66675684868116L-182.72631252387666,-102.1254779457577Z" fill="#344352"/><path d="M-13.877401061909028,35.83996618690307L-32.60097145071207,71.07898612677815L-161.74997668598377,307.7601702851575L-153.19122065898344,312.43036411201814L-24.035529937824496,75.7369070787422L-5.267299635186701,40.41480768260513L-13.877401061909028,35.83996618690307Z" fill="#344352"/><path d="M-169.01463130553654,303.2055773836122L-43.950508628821844,67.09405910058749L-23.02876457095017,30.732235013365L-31.480275695757523,25.87029876582065L-52.54496135333369,62.489498105253034L-177.6308895210455,298.6419478217193L-169.01463130553654,303.2055773836122Z" fill="#344352"/><path d="M227.89329146984065,-415.97013570007834L216.2973298218892,-386.63581315828185L52.601558673307466,-85.6251049921157L28.66176037225708,-43.50461866020552L21.656629977431322,-31.17675199865701L30.13323351541536,-26.35967778008009L37.13805004474461,-38.686992133814755L61.15567230865561,-80.94706580242772L224.90986798852398,-382.066237636286L236.95678034543502,-412.3771710938688L227.89329146984065,-415.97013570007834Z" fill="#344352"/><path d="M-34.90012262525051,-15.773328815598546L-85.9687356197671,-44.46171225077663L-183.29816268315759,-101.35414802585004L-188.21843339596572,-92.93670276831634L-90.83958152603056,-36.015570543775226L-39.675436564727946,-7.27280951919866L-34.90012262525051,-15.773328815598546Z" fill="#344352"/><path d="M14.487867939045346,-35.1143224160154L43.06213857618463,-90.99741176058245L208.05265473251958,-380.1064956216152L236.03985796447984,-410.9027824842917L228.81021385079586,-417.4445243096554L199.70524974312679,-385.1446351729646L34.55910884461189,-95.76820703344168L5.807165522069592,-39.553622662553494L14.487867939045346,-35.1143224160154Z" fill="#344352"/><path d="M35.97666266680469,11.928837813092201L99.27241954235028,44.21004944984773L107.22220535738948,48.26093672582374L243.9846680723037,124.43157018532702L455.510081483468,240.26866166835205L527.5118120727817,279.3797563671248L532.1657079866715,270.81215558769344L460.1858011875623,231.71295153723705L248.69183824237126,115.89312302060819L111.94923577452634,39.73346847966127L103.70211764688071,35.52441175560986L40.4063884383186,3.2432142290782906L35.97666266680469,11.928837813092201Z" fill="#344352"/><path d="M524.4852868960485,287.1272811170911L453.90409544962495,247.28311397322443L96.16102153715367,53.88725207466905L32.57094869790052,20.375806013470168L28.02516156424126,29.001316422333474L91.53776264174262,62.471489130865336L449.2411057296136,255.84583523250643L519.6919605940101,295.61773208885285L524.4852868960485,287.1272811170911Z" fill="#344352"/><path d="M-5.267301987357549,40.41481210969877L7.19145597908364,16.966896881429534L-1.4186221277396471,12.392046531540188L-13.87739870973818,35.83996175980943L-5.267301987357549,40.41481210969877Z" fill="#344352"/><path d="M32.576226528848196,20.378616826004645L9.936314014707545,8.44764971968658L5.390735592917476,17.07320856793075L28.030643108183735,29.004175674248813L32.576226528848196,20.378616826004645Z" fill="#344352"/><path d="M21.65533265089493,-31.174733991428383L8.83172652160411,-8.607331372620877L17.308727370561304,-3.7903951627757237L30.132315857888972,-26.35779778158323L21.65533265089493,-31.174733991428383Z" fill="#344352"/><path d="M40.406387662443116,3.243213833194716L15.952162468129686,-6.714401549583897L12.81716073391365,2.5178387161778915L35.97666344268018,11.928838208975776L40.406387662443116,3.243213833194716Z" fill="#344352"/><path d="M-23.029565476260696,30.733442482788433L-9.745785547033872,7.643493719473469L-18.19700835160192,2.781456926201855L-31.480806274594837,25.87140568951682L-23.029565476260696,30.733442482788433Z" fill="#344352"/><path d="M-39.67543890599017,-7.272810834196548L-17.18469783808538,5.361780903661071L-12.409373652688094,-3.138735762743039L-34.90012028398828,-15.773327500600658L-39.67543890599017,-7.272810834196548Z" fill="#344352"/><path d="M5.8071632026246,-39.553618127096115L-5.955117169320215,-16.553263765692634L2.7256082975662728,-12.113972590069295L14.48787025849034,-35.114326951472776L5.8071632026246,-39.553618127096115Z" fill="#344352"/><path d="M-33.004774561312836,-19.702030337864898L-10.85947931753688,-7.510787799941454L-6.157425483139099,-16.052048931212255L-28.302726014867837,-28.2432914691357L-33.004774561312836,-19.702030337864898Z" fill="#344352"/><path d="M30.898332217283116,-1.639110287941321L28.960168413725203,-2.3917021397042504L27.284427538434166,-3.2440767015880567L25.871109591410008,-4.196233976361157L24.720214575379885,-5.248173Line truncated

After

Width:  |  Height:  |  Size: 43 KiB

+62 -18
View File
@@ -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;
+4 -2
View File
@@ -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) => {
+48 -5
View File
@@ -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);
}