fix complex junction island geometry
This commit is contained in:
1 parent
c3579074fd
commit
0c42eb46cd
19 files changed
+424
-44
No files matched your search
@@ -14,6 +14,7 @@ const {
|
||||
solveIslandContacts,
|
||||
} = require('./junction-facility-composition');
|
||||
const { complexJunctionMetrics: calculateComplexJunctionMetrics } = require('./junction-metrics');
|
||||
const { radialShift } = require('./junction-island-offset');
|
||||
const { convertGeoJson, boundsOf } = require('../reference/gaode');
|
||||
const metricsCache = new WeakMap();
|
||||
const CORNER_FILLET_SEGMENTS = 12;
|
||||
@@ -88,6 +89,11 @@ function buildComplexJunctionGeometry(model, cluster, helpers) {
|
||||
const crossingRegions = [];
|
||||
const stopLines = [];
|
||||
const islands = [];
|
||||
// Each arm crossing is shared by two corner islands. Corner generation
|
||||
// records its two endpoint displacements here; the stripes are rebuilt once
|
||||
// after every corner has contributed, rather than being mutated per corner.
|
||||
const armEndpointOffsets = new Map();
|
||||
const islandOffsetMeters = Number(helpers.clusterIslandOffsetMeters) || 0;
|
||||
const crossingControls = helpers.clusterCrossingControls || new Map();
|
||||
const crossingPlans = new Map(
|
||||
arms.map((arm) => {
|
||||
@@ -341,6 +347,7 @@ function buildComplexJunctionGeometry(model, cluster, helpers) {
|
||||
arm.crosswalkFrame.center = midpoint(...endpoints);
|
||||
arm.crosswalkFrame.endpoints = endpoints;
|
||||
arm.crosswalkFrame.spanMeters = usableSpan;
|
||||
arm.crosswalkFrame.contactEndpointRatio = (layout.centers[0] - layout.width / 2) / usableSpan;
|
||||
arm.crosswalkFrame.roadEdgeInsetMeters = roadEdgeInset;
|
||||
crossingRegions.push(rectangle(arm.crosswalkFrame.center, crossingHeading, groupDepth, usableSpan));
|
||||
for (let stripe = 0; stripe < stripeCount; stripe += 1) {
|
||||
@@ -510,8 +517,14 @@ function buildComplexJunctionGeometry(model, cluster, helpers) {
|
||||
geometry: { type: 'Polygon', coordinates: [ring] },
|
||||
});
|
||||
if (!first.crosswalkFrame?.endpoints || !second.crosswalkFrame?.endpoints) continue;
|
||||
const endpointPairs = first.crosswalkFrame.endpoints.flatMap((a) =>
|
||||
second.crosswalkFrame.endpoints.map((b) => ({ a, b, distance: helpers.distanceMeters(a, b) })),
|
||||
const endpointPairs = first.crosswalkFrame.endpoints.flatMap((a, firstEndpointIndex) =>
|
||||
second.crosswalkFrame.endpoints.map((b, secondEndpointIndex) => ({
|
||||
a,
|
||||
b,
|
||||
firstEndpointIndex,
|
||||
secondEndpointIndex,
|
||||
distance: helpers.distanceMeters(a, b),
|
||||
})),
|
||||
);
|
||||
const pair = endpointPairs.sort((a, b) => a.distance - b.distance)[0];
|
||||
const crossingCorner = rayIntersection(
|
||||
@@ -543,11 +556,11 @@ function buildComplexJunctionGeometry(model, cluster, helpers) {
|
||||
toLocal(helpers.offsetCoordinate(edgeCenter, frame.heading, (sign * frame.groupDepth) / 2)),
|
||||
);
|
||||
};
|
||||
const contactSolution = solveIslandContacts(
|
||||
let contactSolution = solveIslandContacts(
|
||||
landing(first, pair.a),
|
||||
landing(second, pair.b),
|
||||
COMPLEX_CROSSWALK_DEPTH_METERS,
|
||||
{ maxLegLength: outerRadius, minLegLength: Math.max(outerRadius - coreRadius, COMPLEX_CROSSWALK_DEPTH_METERS) },
|
||||
{ maxLegLength: outerRadius },
|
||||
);
|
||||
if (contactSolution.status !== 'solved') {
|
||||
cornerDiagnostics.push(
|
||||
@@ -562,6 +575,49 @@ function buildComplexJunctionGeometry(model, cluster, helpers) {
|
||||
);
|
||||
continue;
|
||||
}
|
||||
// Dragging moves the whole pedestrian composition away from the cluster
|
||||
// centre. Re-solve from the translated landing segments so the island,
|
||||
// its green contact hexagon and all three complete contacts retain the same
|
||||
// source coordinates instead of merely translating a detached island.
|
||||
let islandShift = [0, 0];
|
||||
if (islandOffsetMeters > 0) {
|
||||
const provisionalRing = contactSolution.ring.map(fromLocal);
|
||||
const provisionalCenter = polygonCenter(provisionalRing);
|
||||
islandShift = radialShift(center, provisionalCenter, islandOffsetMeters);
|
||||
const localShift = toLocal([crossingCorner[0] + islandShift[0], crossingCorner[1] + islandShift[1]]);
|
||||
const translateSegment = (segment) =>
|
||||
segment.map((point) => [point[0] + localShift[0], point[1] + localShift[1]]);
|
||||
const shifted = solveIslandContacts(
|
||||
translateSegment(landing(first, pair.a)),
|
||||
translateSegment(landing(second, pair.b)),
|
||||
COMPLEX_CROSSWALK_DEPTH_METERS,
|
||||
{ maxLegLength: outerRadius },
|
||||
);
|
||||
if (shifted.status !== 'solved') {
|
||||
cornerDiagnostics.push(
|
||||
helpers.diagnostic(
|
||||
'warning',
|
||||
`corner:${first.cornerKey}`,
|
||||
[...nodeIds],
|
||||
'complex-junction-island-offset-infeasible',
|
||||
shifted.reason,
|
||||
crossingCorner,
|
||||
),
|
||||
);
|
||||
continue;
|
||||
}
|
||||
contactSolution = shifted;
|
||||
const rememberOffset = (arm, endpointIndex) => {
|
||||
const offsets = armEndpointOffsets.get(arm.key) || [
|
||||
[0, 0],
|
||||
[0, 0],
|
||||
];
|
||||
offsets[endpointIndex] = islandShift;
|
||||
armEndpointOffsets.set(arm.key, offsets);
|
||||
};
|
||||
rememberOffset(first, pair.firstEndpointIndex);
|
||||
rememberOffset(second, pair.secondEndpointIndex);
|
||||
}
|
||||
const publishedIslandRing = contactSolution.ring.map(fromLocal);
|
||||
const greenRing = contactSolution.greenRing.map(fromLocal);
|
||||
if (!cornerOverlapsExclusion(publishedIslandRing, first.cornerKey, '安全岛'))
|
||||
@@ -722,6 +778,40 @@ function buildComplexJunctionGeometry(model, cluster, helpers) {
|
||||
geometry: { type: 'Polygon', coordinates: [sidewalkRing] },
|
||||
});
|
||||
}
|
||||
// Rebuild each shared arm crossing from its two endpoint displacement values.
|
||||
// Interpolation occurs along its declared support axis, preserving every
|
||||
// stripe's width and spacing while allowing the two neighbouring islands to
|
||||
// move in different radial directions.
|
||||
if (armEndpointOffsets.size) {
|
||||
for (const arm of arms) {
|
||||
const offsets = armEndpointOffsets.get(arm.key);
|
||||
if (!offsets || !arm.crosswalkFrame?.endpoints) continue;
|
||||
const [start, end] = arm.crosswalkFrame.endpoints;
|
||||
const movedRing = (ring) =>
|
||||
ring.map((point) => {
|
||||
const rawRatio = projectionRatio(point, start, end);
|
||||
const contactRatio = arm.crosswalkFrame.contactEndpointRatio || 0;
|
||||
const ratio = Math.max(0, Math.min(1, (rawRatio - contactRatio) / (1 - contactRatio * 2)));
|
||||
const shift = [
|
||||
offsets[0][0] * (1 - ratio) + offsets[1][0] * ratio,
|
||||
offsets[0][1] * (1 - ratio) + offsets[1][1] * ratio,
|
||||
];
|
||||
return [point[0] + shift[0], point[1] + shift[1]];
|
||||
});
|
||||
for (const crossing of crosswalks) {
|
||||
if (crossing.properties.arm_key === arm.key)
|
||||
crossing.geometry.coordinates[0] = movedRing(crossing.geometry.coordinates[0]);
|
||||
}
|
||||
const averageShift = [(offsets[0][0] + offsets[1][0]) / 2, (offsets[0][1] + offsets[1][1]) / 2];
|
||||
for (const stopLine of stopLines) {
|
||||
if (stopLine.properties.arm_key !== arm.key) continue;
|
||||
stopLine.geometry.coordinates[0] = stopLine.geometry.coordinates[0].map((point) => [
|
||||
point[0] + averageShift[0],
|
||||
point[1] + averageShift[1],
|
||||
]);
|
||||
}
|
||||
}
|
||||
}
|
||||
const features = [];
|
||||
let coreFeature = null;
|
||||
if (coreRing)
|
||||
@@ -842,8 +932,12 @@ function buildComplexJunctionGeometry(model, cluster, helpers) {
|
||||
'warning',
|
||||
`junction-cluster:${cluster.id}`,
|
||||
[...nodeIds],
|
||||
'complex-junction-pavement-region-disconnected',
|
||||
'过街与入口无法组成连续铺装区域,保留结构输入面并拒绝发布统一铺装面。',
|
||||
pavementRegion.status === 'unsupported'
|
||||
? 'complex-junction-pavement-region-assembly-failed'
|
||||
: 'complex-junction-pavement-region-disconnected',
|
||||
pavementRegion.status === 'unsupported'
|
||||
? '统一铺装区域无法可靠装配,保留结构输入面并拒绝发布统一铺装面。'
|
||||
: '过街与入口无法组成连续铺装区域,保留结构输入面并拒绝发布统一铺装面。',
|
||||
center,
|
||||
),
|
||||
);
|
||||
@@ -1221,6 +1315,20 @@ function directionalProjectionMeters(origin, point, heading) {
|
||||
const radians = (heading * Math.PI) / 180;
|
||||
return east * Math.sin(radians) + north * Math.cos(radians);
|
||||
}
|
||||
|
||||
function polygonCenter(ring) {
|
||||
const points = ring.slice(0, -1);
|
||||
return points.reduce((sum, point) => [sum[0] + point[0] / points.length, sum[1] + point[1] / points.length], [0, 0]);
|
||||
}
|
||||
|
||||
function projectionRatio(point, start, end) {
|
||||
const lonScale = 111320 * Math.cos((start[1] * Math.PI) / 180);
|
||||
const vector = [(end[0] - start[0]) * lonScale, (end[1] - start[1]) * 111320];
|
||||
const relative = [(point[0] - start[0]) * lonScale, (point[1] - start[1]) * 111320];
|
||||
const lengthSquared = vector[0] * vector[0] + vector[1] * vector[1];
|
||||
if (lengthSquared < 1e-12) return 0;
|
||||
return Math.max(0, Math.min(1, (relative[0] * vector[0] + relative[1] * vector[1]) / lengthSquared));
|
||||
}
|
||||
module.exports = {
|
||||
resolveComplexJunctionTopology,
|
||||
buildComplexJunctionGeometry,
|
||||
|
||||
Reference in new issue
Block a user