fix: preserve corridor markings between complex junctions
This commit is contained in:
1 parent
e0eaa1c950
commit
1679d1bfc1
4 files changed
+105
-8
No files matched your search
@@ -0,0 +1 @@
|
||||
<svg xmlns="http://www.w3.org/2000/svg" width="1200" height="800" viewBox="-80 -53.33 160 106.66"><rect x="-80" y="-53.33" width="160" height="106.66" fill="#d6e1dd"/><path d="M-444.13261,253.71346 L-294.41416,171.29057 L-289.71224,179.83185 L-439.43069,262.25474 L-444.13261,253.71346 Z" fill="#3c494f"/><path d="M-275.28606,115.74802 L-294.00937,80.50900 L-423.15657,-156.17219 L-414.59793,-160.84238 L-285.44404,75.85108 L-266.67608,111.17317 L-275.28606,115.74802 Z" fill="#3c494f"/><path d="M86.00729,-441.32835 L187.50351,-271.88603 L249.88937,-164.75927 L244.27213,-161.48831 L181.91123,-268.57257 L80.43084,-437.98833 L86.00729,-441.32835 Z" fill="#3c494f"/><path d="M-430.42112,-151.61759 L-305.35874,84.49392 L-284.43729,120.85575 L-292.88869,125.71768 L-313.95308,89.09848 L-439.03726,-147.05397 L-430.42112,-151.61759 Z" fill="#3c494f"/><path d="M-33.51874,567.55812 L-45.11454,538.22380 L-208.80803,237.21309 L-232.74749,195.09260 L-239.75252,182.76473 L-231.27604,177.94766 L-224.27132,190.27497 L-200.25403,232.53505 L-36.50213,533.65422 L-24.45538,563.96515 L-33.51874,567.55812 Z" fill="#3c494f"/><path d="M-296.30848,167.36131 L-347.37638,196.04969 L-444.70445,252.94213 L-449.62465,244.52469 L-352.24716,187.60355 L-301.08373,158.86079 L-296.30848,167.36131 Z" fill="#3c494f"/><path d="M-246.92118,186.70231 L-218.34731,242.58539 L-53.35910,531.69448 L-25.37229,562.49077 L-32.60183,569.03251 L-61.70639,536.73262 L-226.85022,247.35619 L-255.60177,191.14161 L-246.92118,186.70231 Z" fill="#3c494f"/><path d="M-225.43269,139.65914 L-162.13782,107.37793 L-154.18814,103.32705 L-17.42759,27.15641 L194.09486,-88.68068 L266.09559,-127.79177 L270.74942,-119.22417 L198.77052,-80.12497 L-12.72049,35.69486 L-149.46118,111.85451 L-157.70818,116.06357 L-221.00303,148.34477 L-225.43269,139.65914 Z" fill="#3c494f"/><path d="M297.14850,-144.65865 L344.31484,-170.27760 L420.62096,-212.94124 L552.47866,-280.85081 L590.69581,-301.79926 L595.38224,-293.24938 L556.99375,-272.20922 L425.19487,-204.33064 L349.03345,-161.74544 L301.80228,-136.09096 L297.14850,-144.65865 Z" fill="#3c494f"/><path d="M554.98888,-294.12175 L550.49035,-291.75987 L339.91566,-176.05522 L262.94627,-135.47224 L258.39868,-144.09680 L335.25935,-184.62158 L545.79827,-300.30668 L550.45489,-302.75347 L554.98888,-294.12175 Z" fill="#3c494f"/><path d="M232.16893,-118.09515 L192.48376,-95.69234 L-165.25138,97.70192 L-254.40802,144.68728 L-258.95373,136.06176 L-169.87016,89.11531 L187.83112,-104.26065 L227.37569,-126.58560 L232.16893,-118.09515 Z" fill="#3c494f"/><path d="M-266.67608,111.17317 L-254.21749,134.62109 L-262.82745,139.19594 L-275.28605,115.74802 L-266.67608,111.17317 Z" fill="#3c494f"/><path d="M-228.83308,131.20937 L-251.47267,143.14033 L-256.01819,134.51477 L-233.37860,122.58381 L-228.83308,131.20937 Z" fill="#3c494f"/><path d="M-239.75382,182.76272 L-252.57725,160.19531 L-244.10036,155.37838 L-231.27696,177.94578 L-239.75382,182.76272 Z" fill="#3c494f"/><path d="M-221.00303,148.34477 L-245.45691,158.30238 L-248.59187,149.07014 L-225.43269,139.65914 L-221.00303,148.34477 Z" fill="#3c494f"/><path d="M-284.43809,120.85454 L-271.15450,143.94449 L-279.60560,148.80653 L-292.88922,125.71658 L-284.43809,120.85454 Z" fill="#3c494f"/><path d="M-301.08373,158.86079 L-278.59331,146.22620 L-273.81805,154.72672 L-296.30848,167.36131 L-301.08373,158.86079 Z" fill="#3c494f"/><path d="M-255.60177,191.14160 L-267.36388,168.14125 L-258.68328,163.70196 L-246.92118,186.70231 L-255.60177,191.14160 Z" fill="#3c494f"/><path d="M-294.41316,171.29001 L-272.26818,159.09877 L-267.56619,167.64003 L-289.71118,179.83127 L-294.41316,171.29001 Z" fill="#3c494f"/><path d="M-230.51095,153.22709 L-232.44909,153.97968 L-234.12480,154.83206 L-235.53810,155.78422 L-236.68898,156.83616 L-237.57744,157.98788 L-238.20348,159.23938 L-238.56710,160.59067 L-238.66830,162.04174 L-238.50709,163.59260 L-238.08345,165.24323 L-237.39739,166.99365 L-236.44892,168.84385 L-261.52885,151.29780 L-230.51095,153.22709 Z" fill="#3c494f"/><path d="M-262.07426,178.48492 L-263.03211,176.79716 L-264.06099,175.34112 L-265.16089,174.11679 L-266.33182,173.12418 L-267.57376,172.36328 L-268.88672,171.83409 L-270.27071,171.53662 L-271.72572,171.47086 L-273.25175,171.63682 L-274.84880,172.03449 L-276.51688,172.66387 L-278.25597,173.52497 L-261.52885,151.29780 L-262.07426,178.48492 Z" fill="#3c494f"/><path d="M-290.91821,153.15004 L-289.29250,152.14139 L-287.89467,151.07006 L-286.72474,149.93603 L-285.78269,148.73930 L-285.06854,147.47989 L-284.58228,146.15779 L-284.32391,144.77299 L-284.29343,143.32550 L-284.49085,141.81533 L-284.91615,140.24246 L-285.56935,138.60689 L-286.45044,136.90864 L-261.52885,151.29780 L-290.91821,153.15004 Z" fill="#3c494f"/><path d="M-259.75423,124.20058 L-258.87310,125.69811 L-257.92926,126.99199 L-256.92272,128.08223 L-255.85349,128.96884 L-254.72154,129.65179 L-253.52690,130.13111 L-252.26956,130.40679 L-250.94951,130.47882 L-249.56676,130.34721 L-248.12131,130.01196 L-246.61316,129.47307 L-2Line truncated
|
||||
|
After Width: | Height: | Size: 244 KiB |
+1
-1
@@ -8,7 +8,7 @@
|
||||
"road-compiler": "bin/road-compiler.js"
|
||||
},
|
||||
"scripts": {
|
||||
"test": "node test/index.js && node test/junction-structure.js && node test/connector-trajectories.js && node test/junction-projection.js && node test/junction-build-plan-counterexamples.js && node test/junction-polygon-ops.js && node test/junction-region-solver.js && node test/junction-facility-composition.js && node test/junction-pavement-region.js && node test/junction-marking-containment.js && node test/native-road-edits.js && node test/road-revisions.js && node test/direct-edit-solver.js && node test/workbench-edit-api.js && node test/workbench-import-compile.js && node test/fixtures.js",
|
||||
"test": "node test/index.js && node test/junction-structure.js && node test/connector-trajectories.js && node test/junction-projection.js && node test/junction-build-plan-counterexamples.js && node test/junction-polygon-ops.js && node test/junction-region-solver.js && node test/junction-facility-composition.js && node test/junction-pavement-region.js && node test/junction-marking-containment.js && node test/junction-corridor-markings.js && node test/native-road-edits.js && node test/road-revisions.js && node test/direct-edit-solver.js && node test/workbench-edit-api.js && node test/workbench-import-compile.js && node test/fixtures.js",
|
||||
"test:fixtures:update-baseline": "node test/update-fixture-baselines.js",
|
||||
"road:workbench": "node bin/road-workbench.js",
|
||||
"road:export": "node bin/road-compiler.js",
|
||||
|
||||
@@ -1126,11 +1126,13 @@ function compileComplexLaneSeparators(features, controls = []) {
|
||||
const groups = new Map();
|
||||
for (const feature of features) {
|
||||
if (!feature.properties?.cluster_preview || !feature.properties.road_id) continue;
|
||||
if (!groups.has(feature.properties.road_id)) groups.set(feature.properties.road_id, []);
|
||||
groups.get(feature.properties.road_id).push(feature);
|
||||
const key = JSON.stringify([feature.properties.cluster_id, feature.properties.road_id]);
|
||||
if (!groups.has(key)) groups.set(key, []);
|
||||
groups.get(key).push(feature);
|
||||
}
|
||||
const result = [];
|
||||
for (const [roadId, lanes] of groups) {
|
||||
for (const lanes of groups.values()) {
|
||||
const roadId = lanes[0].properties.road_id;
|
||||
lanes.sort((first, second) => first.properties.lane_index - second.properties.lane_index);
|
||||
for (let index = 1; index < lanes.length; index += 1) {
|
||||
const left = lanes[index - 1].geometry.coordinates;
|
||||
@@ -1150,7 +1152,7 @@ function compileComplexLaneSeparators(features, controls = []) {
|
||||
result.push({
|
||||
type: 'Feature',
|
||||
properties: {
|
||||
native_id: `complex-lane-separator:${roadId}:${index}-${index + 1}`,
|
||||
native_id: `complex-lane-separator:${lanes[0].properties.cluster_id}:${roadId}:${index}-${index + 1}`,
|
||||
road_id: roadId,
|
||||
cluster_id: lanes[0].properties.cluster_id,
|
||||
left_lane_index: index,
|
||||
@@ -1192,8 +1194,9 @@ function trimLineBeforeFirstControl(line, controls, width) {
|
||||
if (!overlaps(ring)) continue;
|
||||
let cutoff = Math.max(0, distance - step - 0.12);
|
||||
while (cutoff > 0.5) {
|
||||
const candidate = roadRing([line[0], pointAlongLine(line, cutoff)], width);
|
||||
if (candidate && !overlaps(candidate)) return [line[0], pointAlongLine(line, cutoff)];
|
||||
const trimmed = trimLineRange(line, 0, total - cutoff);
|
||||
const candidate = roadRing(trimmed, width);
|
||||
if (candidate && !overlaps(candidate)) return trimmed;
|
||||
cutoff -= 0.25;
|
||||
}
|
||||
return null;
|
||||
@@ -2357,7 +2360,10 @@ function compileLaneCenterlines(
|
||||
boundaryCluster?.template === 'complex-junction-v1'
|
||||
? trimLaneOutsideControls(
|
||||
publishedCoordinates,
|
||||
controlFeatures,
|
||||
// A road can join two distinct complex junctions. A control at
|
||||
// the far junction must not truncate the whole inter-junction
|
||||
// corridor while scanning toward this junction.
|
||||
controlFeatures.filter((feature) => feature.properties.cluster_id === boundaryCluster.id),
|
||||
LANE_CENTERLINE_PROBE_WIDTH_METERS,
|
||||
clusterCenters.get(boundaryCluster.id),
|
||||
)
|
||||
|
||||
@@ -0,0 +1,90 @@
|
||||
'use strict';
|
||||
|
||||
const assert = require('assert/strict');
|
||||
const fs = require('fs');
|
||||
const path = require('path');
|
||||
const { compileRoadModel, compileGeometry } = require('../src/compile/native-road');
|
||||
const model = compileRoadModel(fs.readFileSync(path.join(__dirname, '../inputs/osm/枫树二路.osm'), 'utf8'), {
|
||||
overrides: [],
|
||||
});
|
||||
const clusters = [
|
||||
{
|
||||
id: 'west',
|
||||
template: 'complex-junction-v1',
|
||||
coreRadiusMeters: 21,
|
||||
nodeIds: ['8005332807', '8024512135', '8024512145', '8024512147'],
|
||||
},
|
||||
{ id: 'east', template: 'complex-junction-v1', coreRadiusMeters: 18, nodeIds: ['1590698046', '6538106539'] },
|
||||
];
|
||||
const meters = (a, b) => Math.hypot((a[0] - b[0]) * 111320 * Math.cos((a[1] * Math.PI) / 180), (a[1] - b[1]) * 111320);
|
||||
for (const ordered of [clusters, [...clusters].reverse()]) {
|
||||
const geometry = compileGeometry(
|
||||
model,
|
||||
{ overrides: [] },
|
||||
{ edgeLines: false, junctionTemplates: { enabled: true, clusters: ordered } },
|
||||
);
|
||||
for (const roadId of ['road:way/858770823:segment/2:forward', 'road:way/859509947:segment/5:forward']) {
|
||||
const lanes = geometry.laneCenterlines.features.filter(
|
||||
(f) => f.properties.road_id === roadId && !f.properties.cluster_preview,
|
||||
);
|
||||
assert.equal(lanes.length, 3);
|
||||
for (const lane of lanes) {
|
||||
const coordinates = lane.geometry.coordinates;
|
||||
const length = coordinates.slice(1).reduce((sum, point, i) => sum + meters(coordinates[i], point), 0);
|
||||
assert.ok(length > 500, `${roadId}: external lane truncated to ${length}m by the other junction`);
|
||||
}
|
||||
const road = model.roads.find((r) => r.id === roadId);
|
||||
const midpoint = road.centerline[0].map((v, i) => (v + road.centerline.at(-1)[i]) / 2);
|
||||
const complexSeparators = geometry.laneSeparators.features.filter(
|
||||
(f) => f.properties.road_id === roadId && f.properties.provenance === 'native-road-complex-lane-separator/v1',
|
||||
);
|
||||
for (const separator of complexSeparators) {
|
||||
assert.ok(
|
||||
separator.geometry.coordinates[0].every((p) => meters(p, midpoint) > 180),
|
||||
'junction approach separators must not be synthesized in the middle of the road',
|
||||
);
|
||||
}
|
||||
// Separator bars must bisect adjacent published lane paths, including
|
||||
// source bends; clipping at a stop must not replace that path by a chord.
|
||||
const segmentDistance = (p, a, b) => {
|
||||
const xy = (q) => [(q[0] - p[0]) * Math.cos((p[1] * Math.PI) / 180) * 111320, (q[1] - p[1]) * 111320];
|
||||
const x = xy(a),
|
||||
y = xy(b),
|
||||
v = y.map((n, i) => n - x[i]);
|
||||
const t = Math.max(0, Math.min(1, -(x[0] * v[0] + x[1] * v[1]) / (v[0] ** 2 + v[1] ** 2)));
|
||||
return Math.hypot(x[0] + t * v[0], x[1] + t * v[1]);
|
||||
};
|
||||
for (const feature of geometry.laneSeparators.features.filter(
|
||||
(f) => f.properties.road_id === roadId && f.properties.pattern === 'dashed',
|
||||
)) {
|
||||
const ring = feature.geometry.coordinates[0].slice(0, 4);
|
||||
const p = [0, 1].map((axis) => ring.reduce((sum, q) => sum + q[axis], 0) / 4);
|
||||
if (meters(p, midpoint) > 180) continue;
|
||||
for (const index of [feature.properties.left_lane_index, feature.properties.right_lane_index]) {
|
||||
const line = lanes.find((l) => l.properties.lane_index === index).geometry.coordinates;
|
||||
const distance = Math.min(...line.slice(1).map((q, i) => segmentDistance(p, line[i], q)));
|
||||
assert.ok(
|
||||
Math.abs(distance - 1.625) < 0.12,
|
||||
`separator is ${distance}m from lane ${index}, expected half lane width`,
|
||||
);
|
||||
}
|
||||
}
|
||||
const arrows = geometry.directionArrows.features.filter(
|
||||
(f) => f.properties.road_id === roadId && !f.properties.cluster_preview,
|
||||
);
|
||||
assert.ok(arrows.length > 0);
|
||||
for (const arrow of arrows) {
|
||||
const line = lanes.find((l) => l.properties.lane_index === arrow.properties.lane_index).geometry.coordinates;
|
||||
// The symmetric through-arrow template has its tip on the lane axis.
|
||||
const tip = arrow.geometry.coordinates[0][0];
|
||||
if (meters(tip, midpoint) > 180) continue;
|
||||
const distance = Math.min(...line.slice(1).map((q, i) => segmentDistance(tip, line[i], q)));
|
||||
assert.ok(distance < 0.05, `arrow tip is ${distance}m away from its lane centre`);
|
||||
}
|
||||
const centralSeparators = geometry.laneSeparators.features.filter(
|
||||
(f) => f.properties.road_id === roadId && f.geometry.coordinates[0].some((p) => meters(p, midpoint) < 100),
|
||||
);
|
||||
assert.ok(centralSeparators.length > 20, `${roadId}: dashed separators missing in the middle of the corridor`);
|
||||
}
|
||||
}
|
||||
console.log('junction corridor marking tests passed');
|
||||
Reference in new issue
Block a user