fix(junction): align complex boundary trims
This commit is contained in:
1 parent
a12e2ac823
commit
4de971ce68
5 files changed
+123
-22
No files matched your search
@@ -18,6 +18,7 @@
|
|||||||
|
|
||||||
## 2. 连续边界与区域求解(最高风险)
|
## 2. 连续边界与区域求解(最高风险)
|
||||||
|
|
||||||
|
- [x] 将复杂路口边界半径映射到来源折线的实际首次相交站点,并把同一车行道裁切传递给道路面、边线、中心线、人行道和车道发布线。
|
||||||
- [ ] 实现接入断面到固定远端过渡;以共享边界构建中心/进口/角部,取消独立半径拼接作为权威。
|
- [ ] 实现接入断面到固定远端过渡;以共享边界构建中心/进口/角部,取消独立半径拼接作为权威。
|
||||||
- [ ] 支持凹形与已知排除区域,检查环、自交、接缝、必要连接;设计边界可行域并由 solver/manifest 共用。
|
- [ ] 支持凹形与已知排除区域,检查环、自交、接缝、必要连接;设计边界可行域并由 solver/manifest 共用。
|
||||||
- [ ] 审计 roadSurface、sidewalkSurface、edgeLines、lane/center markings 的每个裁切入口,确保消费同一计划。
|
- [ ] 审计 roadSurface、sidewalkSurface、edgeLines、lane/center markings 的每个裁切入口,确保消费同一计划。
|
||||||
|
|||||||
@@ -2,7 +2,7 @@
|
|||||||
|
|
||||||
const fs = require('fs');
|
const fs = require('fs');
|
||||||
const { structureFromTopology } = require('./junction-topology');
|
const { structureFromTopology } = require('./junction-topology');
|
||||||
const { resolveJunctionBuildPlan } = require('./junction-build-plan');
|
const { resolveJunctionBuildPlan, stationAtDistanceFrom } = require('./junction-build-plan');
|
||||||
const { convertGeoJson, boundsOf } = require('../reference/gaode');
|
const { convertGeoJson, boundsOf } = require('../reference/gaode');
|
||||||
const metricsCache = new WeakMap();
|
const metricsCache = new WeakMap();
|
||||||
const CORNER_FILLET_SEGMENTS = 12;
|
const CORNER_FILLET_SEGMENTS = 12;
|
||||||
@@ -784,9 +784,8 @@ function positiveHeadingDelta(first, second) {
|
|||||||
return (((second - first) % 360) + 360) % 360;
|
return (((second - first) % 360) + 360) % 360;
|
||||||
}
|
}
|
||||||
function pointOnCarriagewayRadius(item, center, radius, helpers) {
|
function pointOnCarriagewayRadius(item, center, radius, helpers) {
|
||||||
const start = item.approach.line[0];
|
const station = stationAtDistanceFrom(item.approach.line, center, radius, helpers);
|
||||||
const startRadius = directionalProjectionMeters(center, start, item.heading);
|
return helpers.pointAlongLine(item.approach.line, Math.max(0, Math.min(item.length, station)));
|
||||||
return helpers.pointAlongLine(item.approach.line, Math.max(0, Math.min(item.length, radius - startRadius)));
|
|
||||||
}
|
}
|
||||||
function armEnvelopeAtRadius(arm, radius, center, helpers) {
|
function armEnvelopeAtRadius(arm, radius, center, helpers) {
|
||||||
if (!arm.members.length) return null;
|
if (!arm.members.length) return null;
|
||||||
|
|||||||
@@ -49,6 +49,40 @@ function boundaryAt(point, tangent, widthMeters) {
|
|||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function interpolate(first, second, ratio) {
|
||||||
|
return [first[0] + (second[0] - first[0]) * ratio, first[1] + (second[1] - first[1]) * ratio];
|
||||||
|
}
|
||||||
|
|
||||||
|
// Return the first source-polyline station whose actual distance to `center`
|
||||||
|
// reaches the requested boundary. This intentionally does not project a fixed
|
||||||
|
// initial heading: curved approaches must terminate where their own geometry
|
||||||
|
// meets the boundary.
|
||||||
|
function stationAtDistanceFrom(line, center, radius, helpers) {
|
||||||
|
if (!center || !Array.isArray(line) || line.length < 2 || !Number.isFinite(radius)) return 0;
|
||||||
|
let station = 0;
|
||||||
|
let previousDistance = helpers.distanceMeters(line[0], center);
|
||||||
|
if (previousDistance >= radius) return 0;
|
||||||
|
for (let index = 1; index < line.length; index += 1) {
|
||||||
|
const start = line[index - 1];
|
||||||
|
const end = line[index];
|
||||||
|
const segmentLength = helpers.distanceMeters(start, end);
|
||||||
|
const endDistance = helpers.distanceMeters(end, center);
|
||||||
|
if (previousDistance < radius && endDistance >= radius) {
|
||||||
|
let low = 0;
|
||||||
|
let high = 1;
|
||||||
|
for (let iteration = 0; iteration < 32; iteration += 1) {
|
||||||
|
const middle = (low + high) / 2;
|
||||||
|
if (helpers.distanceMeters(interpolate(start, end, middle), center) < radius) low = middle;
|
||||||
|
else high = middle;
|
||||||
|
}
|
||||||
|
return station + segmentLength * ((low + high) / 2);
|
||||||
|
}
|
||||||
|
station += segmentLength;
|
||||||
|
previousDistance = endDistance;
|
||||||
|
}
|
||||||
|
return station;
|
||||||
|
}
|
||||||
|
|
||||||
function entrySectionFor(item, helpers) {
|
function entrySectionFor(item, helpers) {
|
||||||
const length = item.length;
|
const length = item.length;
|
||||||
const line = item.approach.line;
|
const line = item.approach.line;
|
||||||
@@ -148,4 +182,4 @@ function resolveJunctionBuildPlan(model, cluster, helpers) {
|
|||||||
return { schema: 'junction-build-plan/v1', cluster, nodeIds: [...nodeIds].sort(), carriageways, arms };
|
return { schema: 'junction-build-plan/v1', cluster, nodeIds: [...nodeIds].sort(), carriageways, arms };
|
||||||
}
|
}
|
||||||
|
|
||||||
module.exports = { MIN_ENTRY_SECTION_METERS, resolveJunctionBuildPlan };
|
module.exports = { MIN_ENTRY_SECTION_METERS, resolveJunctionBuildPlan, stationAtDistanceFrom };
|
||||||
+61
-16
@@ -8,6 +8,7 @@ const {
|
|||||||
complexJunctionMetrics,
|
complexJunctionMetrics,
|
||||||
resolveComplexJunctionTopology,
|
resolveComplexJunctionTopology,
|
||||||
} = require('./complex-junction');
|
} = require('./complex-junction');
|
||||||
|
const { stationAtDistanceFrom } = require('./junction-build-plan');
|
||||||
const { diagnostic } = require('./diagnostics');
|
const { diagnostic } = require('./diagnostics');
|
||||||
// Default marking placement lives with the constraint bounds in the solver, which
|
// Default marking placement lives with the constraint bounds in the solver, which
|
||||||
// is the IO-free module; importing the other way would drag fs into it.
|
// is the IO-free module; importing the other way would drag fs into it.
|
||||||
@@ -783,12 +784,21 @@ function compileGeometry(model, overrides = { overrides: [] }, options = {}) {
|
|||||||
if (generated.islands) generatedComplexSidewalks.push(...generated.islands);
|
if (generated.islands) generatedComplexSidewalks.push(...generated.islands);
|
||||||
diagnostics.push(...generated.diagnostics);
|
diagnostics.push(...generated.diagnostics);
|
||||||
}
|
}
|
||||||
const lanes = compileLaneCenterlines(model, diagnostics, junctionPlans, options, {
|
const lanes = compileLaneCenterlines(
|
||||||
|
model,
|
||||||
|
diagnostics,
|
||||||
|
junctionPlans,
|
||||||
|
options,
|
||||||
|
{
|
||||||
crosswalks: generatedComplexCrosswalks,
|
crosswalks: generatedComplexCrosswalks,
|
||||||
stopLines: generatedComplexStopLines,
|
stopLines: generatedComplexStopLines,
|
||||||
});
|
},
|
||||||
|
complexApproachBoundaries,
|
||||||
|
);
|
||||||
const edgeLines =
|
const edgeLines =
|
||||||
options.edgeLines === false ? [] : compileEdgeLines(model, overrides, junctionPlans, options, features);
|
options.edgeLines === false
|
||||||
|
? []
|
||||||
|
: compileEdgeLines(model, overrides, junctionPlans, options, features, complexApproachBoundaries);
|
||||||
const controls = compileControlMarkings(
|
const controls = compileControlMarkings(
|
||||||
model,
|
model,
|
||||||
lanes,
|
lanes,
|
||||||
@@ -800,13 +810,21 @@ function compileGeometry(model, overrides = { overrides: [] }, options = {}) {
|
|||||||
crosswalks: [...controls.crosswalks, ...generatedComplexCrosswalks],
|
crosswalks: [...controls.crosswalks, ...generatedComplexCrosswalks],
|
||||||
stopLines: [...controls.stopLines, ...generatedComplexStopLines],
|
stopLines: [...controls.stopLines, ...generatedComplexStopLines],
|
||||||
};
|
};
|
||||||
const centerLines = compileCenterLines(model, overrides, junctionPlans, allControls, diagnostics, options);
|
const centerLines = compileCenterLines(
|
||||||
|
model,
|
||||||
|
overrides,
|
||||||
|
junctionPlans,
|
||||||
|
allControls,
|
||||||
|
diagnostics,
|
||||||
|
options,
|
||||||
|
complexApproachBoundaries,
|
||||||
|
);
|
||||||
const markings = compileLaneMarkings(model, overrides, lanes, diagnostics, junctionPlans, allControls, options);
|
const markings = compileLaneMarkings(model, overrides, lanes, diagnostics, junctionPlans, allControls, options);
|
||||||
markings.separators.push(
|
markings.separators.push(
|
||||||
...compileComplexLaneSeparators(lanes.features, [...allControls.crosswalks, ...allControls.stopLines]),
|
...compileComplexLaneSeparators(lanes.features, [...allControls.crosswalks, ...allControls.stopLines]),
|
||||||
);
|
);
|
||||||
markings.directionArrows.push(...compileComplexPreviewArrows(lanes.features, generatedComplexStopLines));
|
markings.directionArrows.push(...compileComplexPreviewArrows(lanes.features, generatedComplexStopLines));
|
||||||
const sidewalks = compileSidewalkSurfaces(model, diagnostics, junctionPlans, options);
|
const sidewalks = compileSidewalkSurfaces(model, diagnostics, junctionPlans, options, complexApproachBoundaries);
|
||||||
// Complex crosswalks are generated from native approach tangents; do not
|
// Complex crosswalks are generated from native approach tangents; do not
|
||||||
// synthesize side strips that can be mistaken for crosswalks.
|
// synthesize side strips that can be mistaken for crosswalks.
|
||||||
sidewalks.push(...generatedComplexSidewalks);
|
sidewalks.push(...generatedComplexSidewalks);
|
||||||
@@ -1068,7 +1086,14 @@ function laneWasClipped(original, visible) {
|
|||||||
return Boolean(visible) && lineLengthMeters(visible) < lineLengthMeters(original) - 0.01;
|
return Boolean(visible) && lineLengthMeters(visible) < lineLengthMeters(original) - 0.01;
|
||||||
}
|
}
|
||||||
|
|
||||||
function compileEdgeLines(model, overrides, junctionPlans, options = {}, roadSurfaces = []) {
|
function compileEdgeLines(
|
||||||
|
model,
|
||||||
|
overrides,
|
||||||
|
junctionPlans,
|
||||||
|
options = {},
|
||||||
|
roadSurfaces = [],
|
||||||
|
complexBoundaries = new Map(),
|
||||||
|
) {
|
||||||
const features = [];
|
const features = [];
|
||||||
const clusters = options.junctionTemplates?.enabled ? options.junctionTemplates.clusters || [] : [];
|
const clusters = options.junctionTemplates?.enabled ? options.junctionTemplates.clusters || [] : [];
|
||||||
const clusterByNode = new Map(
|
const clusterByNode = new Map(
|
||||||
@@ -1104,6 +1129,7 @@ function compileEdgeLines(model, overrides, junctionPlans, options = {}, roadSur
|
|||||||
junctionPlans,
|
junctionPlans,
|
||||||
cluster,
|
cluster,
|
||||||
clusterCenters.get(cluster.id),
|
clusterCenters.get(cluster.id),
|
||||||
|
complexBoundaries.get(cluster.id)?.get(road.id),
|
||||||
)
|
)
|
||||||
: trimLineAtJunctions(road.centerline, road.sourceNodeIds, junctionPlans);
|
: trimLineAtJunctions(road.centerline, road.sourceNodeIds, junctionPlans);
|
||||||
// On a two-way segment, the inner edge is the road centre boundary and is
|
// On a two-way segment, the inner edge is the road centre boundary and is
|
||||||
@@ -1155,7 +1181,15 @@ function edgeLineFeature(road, side, style, ring, part = null) {
|
|||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
function compileCenterLines(model, overrides, junctionPlans, controls, diagnostics, options = {}) {
|
function compileCenterLines(
|
||||||
|
model,
|
||||||
|
overrides,
|
||||||
|
junctionPlans,
|
||||||
|
controls,
|
||||||
|
diagnostics,
|
||||||
|
options = {},
|
||||||
|
complexBoundaries = new Map(),
|
||||||
|
) {
|
||||||
const features = [];
|
const features = [];
|
||||||
const controlFeatures = [...controls.crosswalks, ...controls.stopLines];
|
const controlFeatures = [...controls.crosswalks, ...controls.stopLines];
|
||||||
const segments = new Map();
|
const segments = new Map();
|
||||||
@@ -1177,6 +1211,7 @@ function compileCenterLines(model, overrides, junctionPlans, controls, diagnosti
|
|||||||
junctionPlans,
|
junctionPlans,
|
||||||
cluster,
|
cluster,
|
||||||
clusterCenter(cluster, junctionPlans),
|
clusterCenter(cluster, junctionPlans),
|
||||||
|
complexBoundaries.get(cluster.id)?.get(forward.id),
|
||||||
)
|
)
|
||||||
: trimLineAtJunctions(forward.centerline, forward.sourceNodeIds, junctionPlans);
|
: trimLineAtJunctions(forward.centerline, forward.sourceNodeIds, junctionPlans);
|
||||||
const length = lineLengthMeters(line);
|
const length = lineLengthMeters(line);
|
||||||
@@ -1827,7 +1862,7 @@ function ringsOverlap(first, second) {
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
function compileSidewalkSurfaces(model, diagnostics, junctionPlans, options = {}) {
|
function compileSidewalkSurfaces(model, diagnostics, junctionPlans, options = {}, complexBoundaries = new Map()) {
|
||||||
const features = [];
|
const features = [];
|
||||||
const byWay = new Map();
|
const byWay = new Map();
|
||||||
for (const road of model.roads) {
|
for (const road of model.roads) {
|
||||||
@@ -1850,7 +1885,14 @@ function compileSidewalkSurfaces(model, diagnostics, junctionPlans, options = {}
|
|||||||
const sidewalkWidth = profile?.sidewalkWidths?.[side] ?? DEFAULT_SIDEWALK_WIDTH_METERS;
|
const sidewalkWidth = profile?.sidewalkWidths?.[side] ?? DEFAULT_SIDEWALK_WIDTH_METERS;
|
||||||
if (!enabled || sidewalkWidth <= 0) continue;
|
if (!enabled || sidewalkWidth <= 0) continue;
|
||||||
const centerline = cluster
|
const centerline = cluster
|
||||||
? trimLineAtComplexCluster(forward.centerline, forward.sourceNodeIds, junctionPlans, cluster, center)
|
? trimLineAtComplexCluster(
|
||||||
|
forward.centerline,
|
||||||
|
forward.sourceNodeIds,
|
||||||
|
junctionPlans,
|
||||||
|
cluster,
|
||||||
|
center,
|
||||||
|
complexBoundaries.get(cluster.id)?.get(forward.id),
|
||||||
|
)
|
||||||
: trimLineAtJunctions(forward.centerline, forward.sourceNodeIds, junctionPlans);
|
: trimLineAtJunctions(forward.centerline, forward.sourceNodeIds, junctionPlans);
|
||||||
const ring = sidewalkRing(centerline, totalWidth / 2, totalWidth / 2 + sidewalkWidth, side === 'left' ? 1 : -1);
|
const ring = sidewalkRing(centerline, totalWidth / 2, totalWidth / 2 + sidewalkWidth, side === 'left' ? 1 : -1);
|
||||||
if (!ring) {
|
if (!ring) {
|
||||||
@@ -2088,7 +2130,14 @@ function pointOnSegment(point, a, b) {
|
|||||||
// templates already emitted. Ordinary controls cannot be passed here: they are
|
// templates already emitted. Ordinary controls cannot be passed here: they are
|
||||||
// placed *from* these lane centerlines, so only the template-generated ones
|
// placed *from* these lane centerlines, so only the template-generated ones
|
||||||
// exist this early.
|
// exist this early.
|
||||||
function compileLaneCenterlines(model, diagnostics, junctionPlans, options = {}, complexControls = {}) {
|
function compileLaneCenterlines(
|
||||||
|
model,
|
||||||
|
diagnostics,
|
||||||
|
junctionPlans,
|
||||||
|
options = {},
|
||||||
|
complexControls = {},
|
||||||
|
complexBoundaries = new Map(),
|
||||||
|
) {
|
||||||
const features = [];
|
const features = [];
|
||||||
const controlFeatures = [...(complexControls.crosswalks || []), ...(complexControls.stopLines || [])];
|
const controlFeatures = [...(complexControls.crosswalks || []), ...(complexControls.stopLines || [])];
|
||||||
const byRoadId = new Map();
|
const byRoadId = new Map();
|
||||||
@@ -2115,6 +2164,7 @@ function compileLaneCenterlines(model, diagnostics, junctionPlans, options = {},
|
|||||||
junctionPlans,
|
junctionPlans,
|
||||||
boundaryCluster,
|
boundaryCluster,
|
||||||
clusterCenters.get(boundaryCluster.id),
|
clusterCenters.get(boundaryCluster.id),
|
||||||
|
complexBoundaries.get(boundaryCluster.id)?.get(road.id),
|
||||||
)
|
)
|
||||||
: trimLineAtJunctions(road.centerline, road.sourceNodeIds, junctionPlans);
|
: trimLineAtJunctions(road.centerline, road.sourceNodeIds, junctionPlans);
|
||||||
// OSM centerline is the shared carriageway center. On a two-way road,
|
// OSM centerline is the shared carriageway center. On a two-way road,
|
||||||
@@ -3237,12 +3287,7 @@ function complexApproachBoundaryRadii(model, clusters, junctionPlans) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
function distanceAlongLineToRadius(line, center, radius) {
|
function distanceAlongLineToRadius(line, center, radius) {
|
||||||
if (!center || line.length < 2) return 0;
|
return stationAtDistanceFrom(line, center, radius, { distanceMeters });
|
||||||
const heading = headingAtEndpoint(line);
|
|
||||||
const vector = project(line[0], center);
|
|
||||||
const radians = (heading * Math.PI) / 180;
|
|
||||||
const startRadius = vector[0] * Math.sin(radians) + vector[1] * Math.cos(radians);
|
|
||||||
return Math.max(0, radius - startRadius);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
function trimLineRange(line, startCutback, endCutback) {
|
function trimLineRange(line, startCutback, endCutback) {
|
||||||
|
|||||||
@@ -3,7 +3,7 @@
|
|||||||
// Source-independent counterexamples for the JunctionBuildPlan contract.
|
// Source-independent counterexamples for the JunctionBuildPlan contract.
|
||||||
|
|
||||||
const assert = require('assert/strict');
|
const assert = require('assert/strict');
|
||||||
const { resolveJunctionBuildPlan } = require('../src/compile/junction-build-plan');
|
const { resolveJunctionBuildPlan, stationAtDistanceFrom } = require('../src/compile/junction-build-plan');
|
||||||
const { classifyJunctionShape } = require('../src/compile/complex-junction');
|
const { classifyJunctionShape } = require('../src/compile/complex-junction');
|
||||||
|
|
||||||
const metersPerDegree = 111320;
|
const metersPerDegree = 111320;
|
||||||
@@ -22,6 +22,22 @@ function length(line) {
|
|||||||
return line.slice(1).reduce((total, item, index) => total + distance(line[index], item), 0);
|
return line.slice(1).reduce((total, item, index) => total + distance(line[index], item), 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function pointAtStation(line, station) {
|
||||||
|
let remaining = station;
|
||||||
|
for (let index = 1; index < line.length; index += 1) {
|
||||||
|
const segmentLength = distance(line[index - 1], line[index]);
|
||||||
|
if (remaining <= segmentLength) {
|
||||||
|
const ratio = remaining / segmentLength;
|
||||||
|
return [
|
||||||
|
line[index - 1][0] + (line[index][0] - line[index - 1][0]) * ratio,
|
||||||
|
line[index - 1][1] + (line[index][1] - line[index - 1][1]) * ratio,
|
||||||
|
];
|
||||||
|
}
|
||||||
|
remaining -= segmentLength;
|
||||||
|
}
|
||||||
|
return line.at(-1);
|
||||||
|
}
|
||||||
|
|
||||||
function fixture(name, entries) {
|
function fixture(name, entries) {
|
||||||
const nodeId = `${name}:node`;
|
const nodeId = `${name}:node`;
|
||||||
const approaches = entries.map((entry, index) => ({
|
const approaches = entries.map((entry, index) => ({
|
||||||
@@ -120,4 +136,10 @@ assert.notEqual(
|
|||||||
curvedShort.topology.carriageways[0].entrySection.farTangent,
|
curvedShort.topology.carriageways[0].entrySection.farTangent,
|
||||||
);
|
);
|
||||||
|
|
||||||
|
const curvedBoundaryLine = [point(0, 0), point(0, 5), point(10, 10)];
|
||||||
|
const curvedBoundaryStation = stationAtDistanceFrom(curvedBoundaryLine, point(0, 0), 9, {
|
||||||
|
distanceMeters: distance,
|
||||||
|
});
|
||||||
|
assert.ok(Math.abs(distance(pointAtStation(curvedBoundaryLine, curvedBoundaryStation), point(0, 0)) - 9) < 0.01);
|
||||||
|
|
||||||
console.log('junction build-plan counterexample tests passed');
|
console.log('junction build-plan counterexample tests passed');
|
||||||
Reference in new issue
Block a user