feat: solve complete junction island contacts
This commit is contained in:
1 parent
7a7912f302
commit
1b91e280bc
5 files changed
+164
-7
No files matched your search
@@ -158,3 +158,7 @@ complex-junction.js / native-road.js:构建与全部消费者;direct-edit-so
|
|||||||
## 2026-09-11 基线提交与新增完整接触规则
|
## 2026-09-11 基线提交与新增完整接触规则
|
||||||
|
|
||||||
用户要求先提交当前视觉基线,已执行。随后补充的五条规则已写入 PRD、design 与 backend/junction-island-contact.md。此次补充为待实现契约,不声称已有代码满足完整短边接触或绿色六边形。下一实现单元:三段完整接触的共享求解 + 六点绿色区域 + 动态腿长,一起验证后交付;不得拆成独立挪动第三条斑马线、独立画绿色六边形的中间态。
|
用户要求先提交当前视觉基线,已执行。随后补充的五条规则已写入 PRD、design 与 backend/junction-island-contact.md。此次补充为待实现契约,不声称已有代码满足完整短边接触或绿色六边形。下一实现单元:三段完整接触的共享求解 + 六点绿色区域 + 动态腿长,一起验证后交付;不得拆成独立挪动第三条斑马线、独立画绿色六边形的中间态。
|
||||||
|
|
||||||
|
## 完整接触求解实现(工作区,待提交)
|
||||||
|
|
||||||
|
新增 `solveIslandContacts`,复杂路口现在消费同一结果生成动态直角边、圆滑外轮廓和六点 `greenRing`;第三组斑马线中心也由该结果定位。前端以 `kind=island-green` 显示绿色六边形。真实 OSM 输出 4 个岛且每个都有 6 个接触点,相关重叠检查为 0。新增纯几何回归覆盖端点数量和动态腿长。尚未提交。
|
||||||
@@ -10,6 +10,7 @@ const {
|
|||||||
orthogonalCrossingHeadings,
|
orthogonalCrossingHeadings,
|
||||||
stripeLayout,
|
stripeLayout,
|
||||||
crossingArcSupport,
|
crossingArcSupport,
|
||||||
|
solveIslandContacts,
|
||||||
} = require('./junction-facility-composition');
|
} = require('./junction-facility-composition');
|
||||||
const { complexJunctionMetrics: calculateComplexJunctionMetrics } = require('./junction-metrics');
|
const { complexJunctionMetrics: calculateComplexJunctionMetrics } = require('./junction-metrics');
|
||||||
const { convertGeoJson, boundsOf } = require('../reference/gaode');
|
const { convertGeoJson, boundsOf } = require('../reference/gaode');
|
||||||
@@ -483,8 +484,30 @@ function buildComplexJunctionGeometry(model, cluster, helpers) {
|
|||||||
second.crosswalkFrame.heading,
|
second.crosswalkFrame.heading,
|
||||||
second.crosswalkFrame.groupDepth * 2,
|
second.crosswalkFrame.groupDepth * 2,
|
||||||
);
|
);
|
||||||
const islandRing = buildIslandFromCrossingEdges(crossingCorner, outerFirst, outerSecond);
|
const lonScale = 111320 * Math.cos((crossingCorner[1] * Math.PI) / 180);
|
||||||
const publishedIslandRing = islandRing;
|
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 contactSolution = solveIslandContacts(
|
||||||
|
[[0, 0], toLocal(outerFirst)],
|
||||||
|
[[0, 0], toLocal(outerSecond)],
|
||||||
|
COMPLEX_CROSSWALK_DEPTH_METERS,
|
||||||
|
{ maxLegLength: Math.max(outerRadius * 2, COMPLEX_CROSSWALK_DEPTH_METERS * 4) },
|
||||||
|
);
|
||||||
|
if (contactSolution.status !== 'solved') {
|
||||||
|
cornerDiagnostics.push(
|
||||||
|
helpers.diagnostic(
|
||||||
|
'warning',
|
||||||
|
`corner:${first.cornerKey}`,
|
||||||
|
[...nodeIds],
|
||||||
|
'complex-junction-island-infeasible',
|
||||||
|
contactSolution.reason,
|
||||||
|
crossingCorner,
|
||||||
|
),
|
||||||
|
);
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
const publishedIslandRing = contactSolution.ring.map(fromLocal);
|
||||||
|
const greenRing = contactSolution.greenRing.map(fromLocal);
|
||||||
if (!cornerOverlapsExclusion(publishedIslandRing, first.cornerKey, '安全岛'))
|
if (!cornerOverlapsExclusion(publishedIslandRing, first.cornerKey, '安全岛'))
|
||||||
islands.push({
|
islands.push({
|
||||||
type: 'Feature',
|
type: 'Feature',
|
||||||
@@ -496,9 +519,25 @@ function buildComplexJunctionGeometry(model, cluster, helpers) {
|
|||||||
corner_key: first.cornerKey,
|
corner_key: first.cornerKey,
|
||||||
facility_evidence: 'inferred-complex-junction-corner',
|
facility_evidence: 'inferred-complex-junction-corner',
|
||||||
provenance: 'native-road-complex-junction-inferred-island/v1',
|
provenance: 'native-road-complex-junction-inferred-island/v1',
|
||||||
|
island_leg_lengths_m: contactSolution.legLengths,
|
||||||
|
contact_points: greenRing.slice(0, -1),
|
||||||
},
|
},
|
||||||
geometry: { type: 'Polygon', coordinates: [publishedIslandRing] },
|
geometry: { type: 'Polygon', coordinates: [publishedIslandRing] },
|
||||||
});
|
});
|
||||||
|
if (!cornerOverlapsExclusion(greenRing, first.cornerKey, '安全岛绿色接触区'))
|
||||||
|
islands.push({
|
||||||
|
type: 'Feature',
|
||||||
|
properties: {
|
||||||
|
native_id: `complex-corner-island-green:${cluster.id}:${index + 1}`,
|
||||||
|
object_key: `island:inferred/${first.cornerKey}`,
|
||||||
|
cluster_id: cluster.id,
|
||||||
|
corner_key: first.cornerKey,
|
||||||
|
kind: 'island-green',
|
||||||
|
island_key: `island:inferred/${first.cornerKey}`,
|
||||||
|
provenance: 'native-road-complex-junction-island-contact-hexagon/v1',
|
||||||
|
},
|
||||||
|
geometry: { type: 'Polygon', coordinates: [greenRing] },
|
||||||
|
});
|
||||||
|
|
||||||
if (
|
if (
|
||||||
!first.members.every((item) => publishedCarriageways.has(item.key)) ||
|
!first.members.every((item) => publishedCarriageways.has(item.key)) ||
|
||||||
@@ -508,14 +547,14 @@ function buildComplexJunctionGeometry(model, cluster, helpers) {
|
|||||||
// Complex junctions carry a default diagonal crossing across each safe
|
// Complex junctions carry a default diagonal crossing across each safe
|
||||||
// corner. Source crossing nodes refine provenance/inset values, but are
|
// corner. Source crossing nodes refine provenance/inset values, but are
|
||||||
// not required for the default visual treatment.
|
// not required for the default visual treatment.
|
||||||
const outerMidpoint = [(outerFirst[0] + outerSecond[0]) / 2, (outerFirst[1] + outerSecond[1]) / 2];
|
const outerMidpoint = fromLocal(contactSolution.thirdCenter);
|
||||||
const diagonalDepth = COMPLEX_CROSSWALK_DEPTH_METERS;
|
const diagonalDepth = COMPLEX_CROSSWALK_DEPTH_METERS;
|
||||||
const diagonalHeading = bearing(outerFirst, outerSecond) - 90;
|
const diagonalHeading = bearing(outerFirst, outerSecond) - 90;
|
||||||
const outwardHeading = bearing(crossingCorner, outerMidpoint);
|
const outwardHeading = bearing(crossingCorner, outerMidpoint);
|
||||||
const theta = (outwardHeading * Math.PI) / 180;
|
const theta = (outwardHeading * Math.PI) / 180;
|
||||||
const lonScale = 111320 * Math.cos((outerMidpoint[1] * Math.PI) / 180);
|
const diagonalLonScale = 111320 * Math.cos((outerMidpoint[1] * Math.PI) / 180);
|
||||||
const projectedIsland = publishedIslandRing.map((p) => {
|
const projectedIsland = publishedIslandRing.map((p) => {
|
||||||
const east = (p[0] - outerMidpoint[0]) * lonScale;
|
const east = (p[0] - outerMidpoint[0]) * diagonalLonScale;
|
||||||
const north = (p[1] - outerMidpoint[1]) * 111320;
|
const north = (p[1] - outerMidpoint[1]) * 111320;
|
||||||
return [east * Math.cos(theta) - north * Math.sin(theta), east * Math.sin(theta) + north * Math.cos(theta)];
|
return [east * Math.cos(theta) - north * Math.sin(theta), east * Math.sin(theta) + north * Math.cos(theta)];
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -104,3 +104,94 @@ function crossingArcSupport(ring, halfWidth) {
|
|||||||
return candidates.length ? Math.max(...candidates) : null;
|
return candidates.length ? Math.max(...candidates) : null;
|
||||||
}
|
}
|
||||||
module.exports.crossingArcSupport = crossingArcSupport;
|
module.exports.crossingArcSupport = crossingArcSupport;
|
||||||
|
|
||||||
|
// Solve three complete landings together. All coordinates are local metres.
|
||||||
|
// Quadratic connectors round the supporting triangle outside the green hexagon;
|
||||||
|
// the three contact segments themselves are never shortened by rounding.
|
||||||
|
function solveIslandContacts(firstSegment, secondSegment, thirdWidth, options = {}) {
|
||||||
|
const fail = (reason) => ({ status: 'infeasible', reason });
|
||||||
|
const finitePoint = (p) => Array.isArray(p) && p.length === 2 && p.every(Number.isFinite);
|
||||||
|
if (
|
||||||
|
![firstSegment, secondSegment].every((s) => Array.isArray(s) && s.length === 2 && s.every(finitePoint)) ||
|
||||||
|
!Number.isFinite(thirdWidth) ||
|
||||||
|
thirdWidth <= 0
|
||||||
|
)
|
||||||
|
return fail('invalid-contact');
|
||||||
|
const sub = (a, b) => a.map((v, i) => v - b[i]);
|
||||||
|
const add = (a, b, scale = 1) => a.map((v, i) => v + scale * b[i]);
|
||||||
|
const cross = (a, b) => a[0] * b[1] - a[1] * b[0];
|
||||||
|
const dot = (a, b) => a[0] * b[0] + a[1] * b[1];
|
||||||
|
const length = (a) => Math.hypot(...a);
|
||||||
|
const unit = (a) => a.map((v) => v / length(a));
|
||||||
|
const d1 = sub(firstSegment[1], firstSegment[0]);
|
||||||
|
const d2 = sub(secondSegment[1], secondSegment[0]);
|
||||||
|
if (length(d1) < 1e-8 || length(d2) < 1e-8) return fail('degenerate-contact');
|
||||||
|
const determinant = cross(d1, d2);
|
||||||
|
if (Math.abs(determinant) / length(d1) / length(d2) < 1e-6) return fail('parallel-contact-lines');
|
||||||
|
const corner = add(firstSegment[0], d1, cross(sub(secondSegment[0], firstSegment[0]), d2) / determinant);
|
||||||
|
const ordered = (segment) => [...segment].sort((a, b) => length(sub(a, corner)) - length(sub(b, corner)));
|
||||||
|
const first = ordered(firstSegment),
|
||||||
|
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.
|
||||||
|
const a = length(sub(first[1], corner)),
|
||||||
|
b = length(sub(second[1], corner));
|
||||||
|
const chord = sub(second[1], first[1]),
|
||||||
|
chordLength = length(chord);
|
||||||
|
const tangent = unit(chord);
|
||||||
|
// This scale leaves positive connectors on both sides even for unequal depths.
|
||||||
|
const scale = 1 + thirdWidth / chordLength;
|
||||||
|
const legLengths = [a * scale, b * scale];
|
||||||
|
if (
|
||||||
|
options.maxLegLength !== undefined &&
|
||||||
|
(!Number.isFinite(options.maxLegLength) || legLengths.some((value) => value > options.maxLegLength))
|
||||||
|
)
|
||||||
|
return fail('leg-length-exceeds-space');
|
||||||
|
const firstTip = add(corner, u, legLengths[0]),
|
||||||
|
secondTip = add(corner, v, legLengths[1]);
|
||||||
|
const thirdCenter = firstTip.map((value, i) => (value + secondTip[i]) / 2);
|
||||||
|
const thirdContact = [add(thirdCenter, tangent, -thirdWidth / 2), add(thirdCenter, tangent, thirdWidth / 2)];
|
||||||
|
let outward = [tangent[1], -tangent[0]];
|
||||||
|
if (dot(outward, sub(thirdCenter, corner)) < 0) outward = outward.map((value) => -value);
|
||||||
|
const contacts = [first, thirdContact, [second[1], second[0]]];
|
||||||
|
const vertices = contacts.flat();
|
||||||
|
const hexArea =
|
||||||
|
Math.abs(
|
||||||
|
vertices.reduce((sum, point, i) => {
|
||||||
|
const next = vertices[(i + 1) % 6];
|
||||||
|
return sum + point[0] * next[1] - next[0] * point[1];
|
||||||
|
}, 0),
|
||||||
|
) / 2;
|
||||||
|
if (hexArea <= 1e-8) return fail('degenerate-contact-hexagon');
|
||||||
|
const ring = [];
|
||||||
|
const controls = [firstTip, secondTip, corner];
|
||||||
|
const steps = 16;
|
||||||
|
contacts.forEach((contact, index) => {
|
||||||
|
ring.push(...contact);
|
||||||
|
const start = contact[1],
|
||||||
|
end = contacts[(index + 1) % 3][0],
|
||||||
|
control = controls[index];
|
||||||
|
for (let step = 1; step < steps; step++) {
|
||||||
|
const t = step / steps;
|
||||||
|
ring.push(
|
||||||
|
start.map((value, axis) => (1 - t) ** 2 * value + 2 * t * (1 - t) * control[axis] + t ** 2 * end[axis]),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
ring.push(ring[0]);
|
||||||
|
return {
|
||||||
|
status: 'solved',
|
||||||
|
reason: null,
|
||||||
|
ring,
|
||||||
|
greenRing: [...vertices, vertices[0]],
|
||||||
|
contacts,
|
||||||
|
thirdContact,
|
||||||
|
thirdCenter,
|
||||||
|
outward,
|
||||||
|
thirdOutward: outward,
|
||||||
|
legLengths,
|
||||||
|
};
|
||||||
|
}
|
||||||
|
module.exports.solveIslandContacts = solveIslandContacts;
|
||||||
@@ -75,7 +75,7 @@ for (let i = 1; i < 4; i++) assert.ok(Math.abs(fitted[i] - fitted[i - 1] - 90) <
|
|||||||
assert.deepEqual(orthogonalCrossingHeadings([0, 120, 240]), [0, 120, 240]);
|
assert.deepEqual(orthogonalCrossingHeadings([0, 120, 240]), [0, 120, 240]);
|
||||||
assert.deepEqual(orthogonalCrossingHeadings([0, 40, 180, 270]), [0, 40, 180, 270]);
|
assert.deepEqual(orthogonalCrossingHeadings([0, 40, 180, 270]), [0, 40, 180, 270]);
|
||||||
|
|
||||||
const { crossingArcSupport } = require('../src/compile/junction-facility-composition');
|
const { crossingArcSupport, solveIslandContacts } = 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 === 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 === 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');
|
assert.ok(!sketchIsland.some(([x, y]) => x === -6.8 && y === 0), 'second arc/leg vertex is rounded');
|
||||||
@@ -105,3 +105,21 @@ assert.deepEqual(
|
|||||||
),
|
),
|
||||||
[],
|
[],
|
||||||
);
|
);
|
||||||
|
|
||||||
|
const solvedContacts = solveIslandContacts(
|
||||||
|
[
|
||||||
|
[0, 0],
|
||||||
|
[0, 6.8],
|
||||||
|
],
|
||||||
|
[
|
||||||
|
[0, 0],
|
||||||
|
[-6.8, 0],
|
||||||
|
],
|
||||||
|
3.4,
|
||||||
|
{ maxLegLength: 20 },
|
||||||
|
);
|
||||||
|
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));
|
||||||
@@ -46,7 +46,12 @@ export function createLayers(
|
|||||||
}),
|
}),
|
||||||
sidewalks: new VectorLayer({
|
sidewalks: new VectorLayer({
|
||||||
source: source(),
|
source: source(),
|
||||||
style: () => (scene() ? new Style({ fill: new Fill({ color: '#b7b9ad' }) }) : simple('#9b7c40')),
|
style: (feature) =>
|
||||||
|
feature.get('kind') === 'island-green'
|
||||||
|
? new Style({ fill: new Fill({ color: '#35b86a' }), zIndex: 1 })
|
||||||
|
: scene()
|
||||||
|
? new Style({ fill: new Fill({ color: '#b7b9ad' }) })
|
||||||
|
: simple('#9b7c40'),
|
||||||
}),
|
}),
|
||||||
osm: new VectorLayer({
|
osm: new VectorLayer({
|
||||||
source: source(),
|
source: source(),
|
||||||
|
|||||||
Reference in new issue
Block a user