feat: establish junction region geometry baseline
This commit is contained in:
1 parent
de97600fe8
commit
76f81d024a
14 files changed
+287
-11
No files matched your search
@@ -4,6 +4,7 @@ const fs = require('fs');
|
||||
const { structureFromTopology } = require('./junction-topology');
|
||||
const { resolveJunctionBuildPlan, stationAtDistanceFrom } = require('./junction-build-plan');
|
||||
const { buildJunctionBoundaryGraph, buildCoreClosure, ringsOverlap } = require('./junction-boundary-graph');
|
||||
const { solveCornerFeasibleRegion } = require('./junction-region-solver');
|
||||
const { complexJunctionMetrics: calculateComplexJunctionMetrics } = require('./junction-metrics');
|
||||
const { convertGeoJson, boundsOf } = require('../reference/gaode');
|
||||
const metricsCache = new WeakMap();
|
||||
@@ -349,6 +350,8 @@ function buildComplexJunctionGeometry(model, cluster, helpers) {
|
||||
// sharp notch instead of a curb. A real corner is one tangent-continuous
|
||||
// sweep between the two outermost road edges, so fit a fixed-radius fillet
|
||||
// into the wedge those edges form and fill the sector behind it.
|
||||
const coreClosure = buildCoreClosure(topology, boundaryGraph, center);
|
||||
const coreRing = coreClosure.status === 'supported' ? coreClosure.ring : null;
|
||||
const cornerFills = [];
|
||||
const sidewalkCorners = [];
|
||||
const cornerDiagnostics = [];
|
||||
@@ -445,12 +448,29 @@ function buildComplexJunctionGeometry(model, cluster, helpers) {
|
||||
},
|
||||
geometry: { type: 'Polygon', coordinates: [ring] },
|
||||
});
|
||||
const islandRadius = 3.5;
|
||||
const islandCenter = helpers.offsetCoordinate(apex, bisector, Math.min(3.5, Math.max(1.5, apexReach * 0.2)));
|
||||
const islandRing = [0, 90, 180, 270, 360].map((angle) =>
|
||||
helpers.offsetCoordinate(islandCenter, bisector + angle, islandRadius),
|
||||
const islandDepth = Math.min(7, Math.max(3, apexReach * 0.35));
|
||||
const islandHalfWidth = Math.min(
|
||||
2.2,
|
||||
Math.max(1.2, Math.min(first.widthMeters || 4, second.widthMeters || 4) * 0.28),
|
||||
);
|
||||
if (!cornerOverlapsExclusion(islandRing, first.cornerKey, '安全岛'))
|
||||
const islandCenter = helpers.offsetCoordinate(apex, bisector, -islandDepth * 0.5);
|
||||
const islandRing = [
|
||||
helpers.offsetCoordinate(helpers.offsetCoordinate(apex, bisector, 0.6), bisector + 90, -islandHalfWidth),
|
||||
helpers.offsetCoordinate(
|
||||
helpers.offsetCoordinate(islandCenter, bisector, islandDepth * 0.5),
|
||||
bisector + 90,
|
||||
-islandHalfWidth * 0.72,
|
||||
),
|
||||
helpers.offsetCoordinate(
|
||||
helpers.offsetCoordinate(islandCenter, bisector, islandDepth * 0.5),
|
||||
bisector + 90,
|
||||
islandHalfWidth * 0.72,
|
||||
),
|
||||
helpers.offsetCoordinate(helpers.offsetCoordinate(apex, bisector, 0.6), bisector + 90, islandHalfWidth),
|
||||
helpers.offsetCoordinate(helpers.offsetCoordinate(apex, bisector, 0.6), bisector + 90, -islandHalfWidth),
|
||||
];
|
||||
const publishedIslandRing = islandRing;
|
||||
if (!cornerOverlapsExclusion(publishedIslandRing, first.cornerKey, '安全岛'))
|
||||
islands.push({
|
||||
type: 'Feature',
|
||||
properties: {
|
||||
@@ -462,7 +482,7 @@ function buildComplexJunctionGeometry(model, cluster, helpers) {
|
||||
facility_evidence: 'inferred-complex-junction-corner',
|
||||
provenance: 'native-road-complex-junction-inferred-island/v1',
|
||||
},
|
||||
geometry: { type: 'Polygon', coordinates: [islandRing] },
|
||||
geometry: { type: 'Polygon', coordinates: [publishedIslandRing] },
|
||||
});
|
||||
|
||||
if (
|
||||
@@ -473,7 +493,16 @@ function buildComplexJunctionGeometry(model, cluster, helpers) {
|
||||
// Complex junctions carry a default diagonal crossing across each safe
|
||||
// corner. Source crossing nodes refine provenance/inset values, but are
|
||||
// not required for the default visual treatment.
|
||||
const diagonalCenter = helpers.offsetCoordinate(apex, bisector, Math.min(5, Math.max(1.5, apexReach * 0.28)));
|
||||
const islandMidpoint = publishedIslandRing
|
||||
.slice(0, -1)
|
||||
.reduce(
|
||||
(sum, point) => [
|
||||
sum[0] + point[0] / (publishedIslandRing.length - 1),
|
||||
sum[1] + point[1] / (publishedIslandRing.length - 1),
|
||||
],
|
||||
[0, 0],
|
||||
);
|
||||
const diagonalCenter = helpers.offsetCoordinate(islandMidpoint, bisector, islandHalfWidth + 1.2);
|
||||
const diagonalSpan = Math.min(6, Math.max(2.4, helpers.distanceMeters(tangents[0], tangents[1]) * 0.35));
|
||||
const diagonalDepth = 2.4;
|
||||
const stripeCount = 7;
|
||||
@@ -515,6 +544,9 @@ function buildComplexJunctionGeometry(model, cluster, helpers) {
|
||||
native_id: `complex-corner-crosswalk:${cluster.id}:${index + 1}:${stripe + 1}`,
|
||||
object_key: `crossing:corner:${first.cornerKey}`,
|
||||
crossing_key: `crossing:corner:${first.cornerKey}`,
|
||||
island_key: `island:inferred/${first.cornerKey}`,
|
||||
from_boundary: `sidewalk:${first.cornerKey}:from`,
|
||||
to_boundary: `island:inferred/${first.cornerKey}`,
|
||||
cluster_id: cluster.id,
|
||||
kind: 'complex-corner-crosswalk',
|
||||
corner_key: first.cornerKey,
|
||||
@@ -583,8 +615,6 @@ function buildComplexJunctionGeometry(model, cluster, helpers) {
|
||||
geometry: { type: 'Polygon', coordinates: [sidewalkRing] },
|
||||
});
|
||||
}
|
||||
const coreClosure = buildCoreClosure(topology, boundaryGraph, center);
|
||||
const coreRing = coreClosure.status === 'supported' ? coreClosure.ring : null;
|
||||
const features = [];
|
||||
let coreFeature = null;
|
||||
if (coreRing)
|
||||
|
||||
@@ -1,5 +1,7 @@
|
||||
'use strict';
|
||||
|
||||
const { solvePavedRegion } = require('./junction-region-solver');
|
||||
|
||||
const { stationAtDistanceFrom } = require('./junction-build-plan');
|
||||
|
||||
function pointAtStation(line, station, helpers) {
|
||||
@@ -252,6 +254,11 @@ function buildCoreClosure(topology, graph, center) {
|
||||
Math.atan2(second.point[1] - center[1], second.point[0] - center[0]),
|
||||
);
|
||||
const ring = [...points.map((item) => item.point), points[0]?.point].filter(Boolean);
|
||||
const pavedRegion = solvePavedRegion(
|
||||
ring,
|
||||
graph.exclusionRegions.filter((region) => !region.isHole).map((region) => region.ring),
|
||||
);
|
||||
if (!pavedRegion.length) return { status: 'unsupported', reason: 'known-exclusion-region' };
|
||||
const hasZeroLengthEdge = ring.slice(1).some((point, index) => {
|
||||
const previous = ring[index];
|
||||
const dx = point[0] - previous[0];
|
||||
|
||||
@@ -0,0 +1,20 @@
|
||||
'use strict';
|
||||
|
||||
function buildPedestrianIsland({ key, ring, crossingKeys, provenance = 'inferred' }) {
|
||||
if (!key || !Array.isArray(ring) || ring.length < 4) return null;
|
||||
const adjacentCrossings = [...new Set(crossingKeys || [])];
|
||||
if (adjacentCrossings.length !== 3) return null;
|
||||
return { key, ring, adjacentCrossings, provenance };
|
||||
}
|
||||
|
||||
function validateFacilityComposition(island, crossings) {
|
||||
if (!island || island.adjacentCrossings.length !== 3) return { valid: false, reason: 'island-needs-three-crossings' };
|
||||
const crossingMap = new Map((crossings || []).map((crossing) => [crossing.key, crossing]));
|
||||
const linked = island.adjacentCrossings.map((key) => crossingMap.get(key));
|
||||
if (linked.some((crossing) => !crossing)) return { valid: false, reason: 'crossing-reference-missing' };
|
||||
if (linked.some((crossing) => !crossing.fromBoundary || !crossing.toBoundary))
|
||||
return { valid: false, reason: 'crossing-boundary-missing' };
|
||||
return { valid: true, reason: null };
|
||||
}
|
||||
|
||||
module.exports = { buildPedestrianIsland, validateFacilityComposition };
|
||||
@@ -0,0 +1,50 @@
|
||||
'use strict';
|
||||
|
||||
const polygonClipping = require('polygon-clipping');
|
||||
|
||||
function normalizeRing(ring) {
|
||||
if (!Array.isArray(ring) || ring.length < 4) return null;
|
||||
const normalized = ring
|
||||
.filter((point) => Array.isArray(point) && point.length >= 2 && point.every(Number.isFinite))
|
||||
.map(([x, y]) => [x, y]);
|
||||
if (normalized.length < 3) return null;
|
||||
const first = normalized[0];
|
||||
const last = normalized.at(-1);
|
||||
if (first[0] !== last[0] || first[1] !== last[1]) normalized.push([...first]);
|
||||
return normalized.length >= 4 ? normalized : null;
|
||||
}
|
||||
|
||||
function normalizeMultiPolygon(value) {
|
||||
if (!Array.isArray(value)) return [];
|
||||
if (value[0]?.[0]?.every?.((item) => Number.isFinite(item))) value = [value];
|
||||
return value.map((polygon) => polygon.map(normalizeRing).filter(Boolean)).filter((polygon) => polygon.length > 0);
|
||||
}
|
||||
|
||||
function difference(subject, ...clips) {
|
||||
const source = normalizeMultiPolygon(subject);
|
||||
const masks = clips.flatMap(normalizeMultiPolygon);
|
||||
if (!source.length) return [];
|
||||
return masks.length ? polygonClipping.difference(source, ...masks) : source;
|
||||
}
|
||||
|
||||
function asMultiPolygon(value) {
|
||||
return normalizeMultiPolygon(value);
|
||||
}
|
||||
|
||||
function intersection(first, second) {
|
||||
const left = normalizeMultiPolygon(first);
|
||||
const right = normalizeMultiPolygon(second);
|
||||
return left.length && right.length ? polygonClipping.intersection(left, right) : [];
|
||||
}
|
||||
|
||||
function union(...values) {
|
||||
const polygons = values.flatMap(normalizeMultiPolygon);
|
||||
return polygons.length ? polygonClipping.union(...polygons) : [];
|
||||
}
|
||||
|
||||
function intersectsOrTouches(first, second, touches) {
|
||||
if (intersection(first, second).length) return true;
|
||||
return touches ? touches(first, second) : false;
|
||||
}
|
||||
|
||||
module.exports = { difference, intersection, union, normalizeMultiPolygon, asMultiPolygon, intersectsOrTouches };
|
||||
@@ -0,0 +1,19 @@
|
||||
'use strict';
|
||||
|
||||
const { difference, asMultiPolygon } = require('./junction-polygon-ops');
|
||||
|
||||
function solvePavedRegion(boundaryRing, exclusionRings = []) {
|
||||
const subject = asMultiPolygon([[boundaryRing]]);
|
||||
const exclusions = exclusionRings
|
||||
.filter((ring) => Array.isArray(ring))
|
||||
.map((ring) => asMultiPolygon([[ring]]))
|
||||
.filter((value) => value.length);
|
||||
return difference(subject, ...exclusions);
|
||||
}
|
||||
|
||||
function solveCornerFeasibleRegion(cornerRing, pavedRing, exclusionRings = []) {
|
||||
const masks = [pavedRing, ...exclusionRings].filter((ring) => Array.isArray(ring));
|
||||
return solvePavedRegion(cornerRing, masks);
|
||||
}
|
||||
|
||||
module.exports = { solvePavedRegion, solveCornerFeasibleRegion };
|
||||
@@ -8,6 +8,8 @@ module.exports = {
|
||||
junctionStructure: require('./compile/junction-structure'),
|
||||
junctionStandards: require('./compile/junction-standards'),
|
||||
junctionProjection: require('./compile/junction-projection'),
|
||||
junctionPolygonOps: require('./compile/junction-polygon-ops'),
|
||||
junctionRegionSolver: require('./compile/junction-region-solver'),
|
||||
osm: require('./osm'),
|
||||
trafficSignals: require('./traffic-signals'),
|
||||
nativeTrafficSignals: require('./native-traffic-signals'),
|
||||
|
||||
Reference in new issue
Block a user