fix(junction): omit unsupported corner facilities
This commit is contained in:
1 parent
f56c0978b0
commit
b6f4dfeb0c
3 files changed
+30
-182
No files matched your search
+19
-182
@@ -173,12 +173,6 @@ function buildComplexJunctionGeometry(model, cluster, helpers) {
|
||||
envelopeWidthMeters: envelope.widthMeters,
|
||||
};
|
||||
}
|
||||
const frameCorners = arms.map((arm, index) => {
|
||||
const next = arms[(index + 1) % arms.length];
|
||||
const delta = positiveHeadingDelta(arm.heading, next.heading);
|
||||
if (delta < 45 || delta > 135 || !arm.crosswalkFrame || !next.crosswalkFrame) return null;
|
||||
return supportLineIntersection(arm.crosswalkFrame, next.crosswalkFrame, center);
|
||||
});
|
||||
for (let index = 0; index < arms.length; index += 1) {
|
||||
const arm = arms[index];
|
||||
if (!arm.crosswalkFrame) continue;
|
||||
@@ -254,111 +248,9 @@ function buildComplexJunctionGeometry(model, cluster, helpers) {
|
||||
});
|
||||
}
|
||||
}
|
||||
// The four arm groups are the sides of one pedestrian frame. Each diagonal
|
||||
// group is anchored at the intersection of its adjacent side support lines,
|
||||
// so all eight groups stay one composition when the OSM arms are skewed.
|
||||
for (let index = 0; index < arms.length; index += 1) {
|
||||
const first = arms[index];
|
||||
const second = arms[(index + 1) % arms.length];
|
||||
const delta = positiveHeadingDelta(first.heading, second.heading);
|
||||
if (delta < 45 || delta > 135) continue;
|
||||
if (!first.crosswalkFrame || !second.crosswalkFrame) continue;
|
||||
const bisector = normalizeHeading(first.heading + delta / 2);
|
||||
const frameCorner = frameCorners[index];
|
||||
if (!frameCorner) continue;
|
||||
const cornerStripeSpacing = 0.62;
|
||||
const cornerStripeWidth = 0.4;
|
||||
const cornerGroupHalfDepth = (5 * cornerStripeSpacing + cornerStripeWidth) / 2;
|
||||
const endpointForCorner = (arm) =>
|
||||
[...arm.crosswalkFrame.endpoints].sort(
|
||||
(a, b) => helpers.distanceMeters(a, frameCorner) - helpers.distanceMeters(b, frameCorner),
|
||||
)[0];
|
||||
const outerEdgeAtCorner = (arm) => {
|
||||
const endpoint = endpointForCorner(arm);
|
||||
return [arm.heading, arm.heading + 180]
|
||||
.map((heading) => helpers.offsetCoordinate(endpoint, heading, arm.crosswalkFrame.groupDepth / 2))
|
||||
.sort(
|
||||
(a, b) => directionalProjectionMeters(center, b, bisector) - directionalProjectionMeters(center, a, bisector),
|
||||
)[0];
|
||||
};
|
||||
const islandBaseGap = 0.05;
|
||||
const islandApexOffset = 1.5;
|
||||
const islandBase = [outerEdgeAtCorner(first), outerEdgeAtCorner(second)].map((point) =>
|
||||
helpers.offsetCoordinate(point, bisector, islandBaseGap),
|
||||
);
|
||||
const islandApex = helpers.offsetCoordinate(frameCorner, bisector, islandApexOffset);
|
||||
const islandCrossingClearance = 0.2;
|
||||
const cornerCrossingOffset = islandApexOffset + islandCrossingClearance + cornerGroupHalfDepth;
|
||||
const islandInnerRadius = Math.min(
|
||||
...islandBase.map((point) => directionalProjectionMeters(center, point, bisector)),
|
||||
);
|
||||
const islandOuterRadius = directionalProjectionMeters(center, islandApex, bisector);
|
||||
const cornerCrossingCenter = helpers.offsetCoordinate(frameCorner, bisector, cornerCrossingOffset);
|
||||
const islandRing = roundedPolygonRing([islandBase[0], islandApex, islandBase[1]], 0.24);
|
||||
islands.push({
|
||||
type: 'Feature',
|
||||
properties: {
|
||||
native_id: `complex-corner-island:${cluster.id}:${index + 1}`,
|
||||
cluster_id: cluster.id,
|
||||
kind: 'complex-corner-island',
|
||||
object_key: `island:${first.cornerKey}`,
|
||||
corner_key: first.cornerKey,
|
||||
corner_index: index + 1,
|
||||
from_heading: first.heading,
|
||||
to_heading: second.heading,
|
||||
frame_corner: frameCorner,
|
||||
base_points: islandBase,
|
||||
apex_point: islandApex,
|
||||
inner_radius_m: islandInnerRadius,
|
||||
outer_radius_m: islandOuterRadius,
|
||||
base_width_m: helpers.distanceMeters(...islandBase),
|
||||
crossing_clearance_m: islandCrossingClearance,
|
||||
corner_rounding_ratio: 0.24,
|
||||
provenance: 'native-road-complex-junction-corner/v7-road-gap-fill',
|
||||
},
|
||||
geometry: { type: 'Polygon', coordinates: [islandRing] },
|
||||
});
|
||||
|
||||
let cornerCrossingHalfSpan = 0.4;
|
||||
for (let stripe = 0; stripe < 6; stripe += 1) {
|
||||
const stripeOffset = (stripe - 2.5) * cornerStripeSpacing;
|
||||
const stripeCenter = helpers.offsetCoordinate(cornerCrossingCenter, bisector, stripeOffset);
|
||||
const stripeRadius = directionalProjectionMeters(center, stripeCenter, bisector);
|
||||
const curbPair = limitedCornerPair(first, second, stripeRadius, bisector, center, 6.5, helpers);
|
||||
if (!curbPair) continue;
|
||||
const halfSpan = Math.max(0.4, Math.min(6.5, helpers.distanceMeters(...curbPair)) / 2);
|
||||
cornerCrossingHalfSpan = Math.max(cornerCrossingHalfSpan, halfSpan);
|
||||
const stripePair = [
|
||||
helpers.offsetCoordinate(stripeCenter, bisector - 90, halfSpan),
|
||||
helpers.offsetCoordinate(stripeCenter, bisector + 90, halfSpan),
|
||||
];
|
||||
const ring = [
|
||||
helpers.offsetCoordinate(stripePair[0], bisector, -cornerStripeWidth / 2),
|
||||
helpers.offsetCoordinate(stripePair[1], bisector, -cornerStripeWidth / 2),
|
||||
helpers.offsetCoordinate(stripePair[1], bisector, cornerStripeWidth / 2),
|
||||
helpers.offsetCoordinate(stripePair[0], bisector, cornerStripeWidth / 2),
|
||||
helpers.offsetCoordinate(stripePair[0], bisector, -cornerStripeWidth / 2),
|
||||
];
|
||||
crosswalks.push({
|
||||
type: 'Feature',
|
||||
properties: {
|
||||
native_id: `complex-corner-crosswalk:${cluster.id}:${index + 1}:${stripe + 1}`,
|
||||
cluster_id: cluster.id,
|
||||
kind: 'complex-corner-crosswalk',
|
||||
object_key: `crossing:${first.cornerKey}`,
|
||||
corner_key: first.cornerKey,
|
||||
corner_index: index + 1,
|
||||
direction: bisector,
|
||||
radial_distance_m: stripeRadius,
|
||||
frame_corner: frameCorner,
|
||||
from_heading: first.heading,
|
||||
to_heading: second.heading,
|
||||
provenance: 'native-road-complex-junction-corner-crosswalk/v3',
|
||||
},
|
||||
geometry: { type: 'Polygon', coordinates: [ring] },
|
||||
});
|
||||
}
|
||||
}
|
||||
// Corner islands and diagonal crossings need explicit island or pedestrian
|
||||
// connection sources. Angle and road width alone do not establish either,
|
||||
// so this compiler deliberately leaves them absent until that data exists.
|
||||
// Each carriageway ends in its own rectangle, so adjacent arms meet at a
|
||||
// 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
|
||||
@@ -366,6 +258,22 @@ function buildComplexJunctionGeometry(model, cluster, helpers) {
|
||||
const cornerFills = [];
|
||||
const sidewalkCorners = [];
|
||||
const cornerDiagnostics = [];
|
||||
const omittedCornerFacilityCount = arms.filter((arm, index) => {
|
||||
const next = arms[(index + 1) % arms.length];
|
||||
const delta = positiveHeadingDelta(arm.heading, next.heading);
|
||||
return delta >= 45 && delta <= 135;
|
||||
}).length;
|
||||
if (omittedCornerFacilityCount)
|
||||
cornerDiagnostics.push(
|
||||
helpers.diagnostic(
|
||||
'info',
|
||||
`junction-cluster:${cluster.id}`,
|
||||
[...nodeIds],
|
||||
'complex-junction-corner-facilities-omitted',
|
||||
`已省略 ${omittedCornerFacilityCount} 组缺少岛体或步行连接来源的角部导流岛和斑马线。`,
|
||||
center,
|
||||
),
|
||||
);
|
||||
const defaultCornerRadius = Math.max(4, Math.min(25, Number(cluster.cornerRadiusMeters) || 12));
|
||||
for (let index = 0; index < arms.length; index += 1) {
|
||||
const first = arms[index];
|
||||
@@ -789,45 +697,6 @@ function armEnvelopeAtRadius(arm, radius, center, helpers) {
|
||||
widthMeters: maximum - minimum,
|
||||
};
|
||||
}
|
||||
function supportLineIntersection(first, second, origin) {
|
||||
const lonScale = 111320 * Math.cos((origin[1] * Math.PI) / 180);
|
||||
const toLocal = (point) => [(point[0] - origin[0]) * lonScale, (point[1] - origin[1]) * 111320];
|
||||
const firstPoint = toLocal(first.center);
|
||||
const secondPoint = toLocal(second.center);
|
||||
const direction = (heading) => {
|
||||
const radians = (heading * Math.PI) / 180;
|
||||
return [Math.sin(radians), Math.cos(radians)];
|
||||
};
|
||||
const firstDirection = direction(first.supportHeading);
|
||||
const secondDirection = direction(second.supportHeading);
|
||||
const denominator = firstDirection[0] * secondDirection[1] - firstDirection[1] * secondDirection[0];
|
||||
if (Math.abs(denominator) < 1e-6) return null;
|
||||
const delta = [secondPoint[0] - firstPoint[0], secondPoint[1] - firstPoint[1]];
|
||||
const distanceAlongFirst = (delta[0] * secondDirection[1] - delta[1] * secondDirection[0]) / denominator;
|
||||
const intersection = [
|
||||
firstPoint[0] + firstDirection[0] * distanceAlongFirst,
|
||||
firstPoint[1] + firstDirection[1] * distanceAlongFirst,
|
||||
];
|
||||
return [origin[0] + intersection[0] / lonScale, origin[1] + intersection[1] / 111320];
|
||||
}
|
||||
function limitedCornerPair(first, second, radius, bisector, center, maxWidth, helpers) {
|
||||
const pair = [
|
||||
cornerEdgeAtRadius(first, radius, bisector, center, helpers),
|
||||
cornerEdgeAtRadius(second, radius, bisector, center, helpers),
|
||||
];
|
||||
if (!pair.every(Boolean)) return null;
|
||||
const width = helpers.distanceMeters(pair[0], pair[1]);
|
||||
const middle = midpoint(pair[0], pair[1]);
|
||||
const halfWidth = Math.max(0.4, Math.min(width, maxWidth) / 2);
|
||||
const acrossHeading = width > 0.1 ? bearing(pair[0], pair[1]) : bisector + 90;
|
||||
return [
|
||||
helpers.offsetCoordinate(middle, acrossHeading + 180, halfWidth),
|
||||
helpers.offsetCoordinate(middle, acrossHeading, halfWidth),
|
||||
];
|
||||
}
|
||||
function cornerEdgeAtRadius(arm, radius, bisector, center, helpers) {
|
||||
return cornerEdgeAt(arm, radius, bisector, center, helpers)?.point || null;
|
||||
}
|
||||
function cornerEdgeAt(arm, radius, bisector, center, helpers) {
|
||||
const candidates = arm.members.flatMap((member) => {
|
||||
const point = pointOnCarriagewayRadius(member, center, radius, helpers);
|
||||
@@ -885,38 +754,6 @@ function directionalProjectionMeters(origin, point, heading) {
|
||||
const radians = (heading * Math.PI) / 180;
|
||||
return east * Math.sin(radians) + north * Math.cos(radians);
|
||||
}
|
||||
function smoothClosedRing(vertices) {
|
||||
// Curb-edge candidates can arrive in opposite winding orders when an OSM
|
||||
// carriageway bends slightly. Sort this local corner only around its own
|
||||
// centroid before rounding, avoiding a self-crossing safety island while
|
||||
// keeping the global junction boundary fully OSM-driven.
|
||||
const centroid = vertices.reduce(
|
||||
(sum, point) => [sum[0] + point[0] / vertices.length, sum[1] + point[1] / vertices.length],
|
||||
[0, 0],
|
||||
);
|
||||
const ordered = [...vertices].sort(
|
||||
(first, second) =>
|
||||
Math.atan2(first[1] - centroid[1], first[0] - centroid[0]) -
|
||||
Math.atan2(second[1] - centroid[1], second[0] - centroid[0]),
|
||||
);
|
||||
const points = ordered.flatMap((point, index) => {
|
||||
const next = ordered[(index + 1) % ordered.length];
|
||||
return [interpolateCoordinate(point, next, 0.18), interpolateCoordinate(point, next, 0.82)];
|
||||
});
|
||||
return [...points, points[0]];
|
||||
}
|
||||
function roundedPolygonRing(vertices, ratio) {
|
||||
const points = vertices.flatMap((point, index) => {
|
||||
const previous = vertices[(index - 1 + vertices.length) % vertices.length];
|
||||
const next = vertices[(index + 1) % vertices.length];
|
||||
return [interpolateCoordinate(previous, point, 1 - ratio), interpolateCoordinate(point, next, ratio)];
|
||||
});
|
||||
return [...points, points[0]];
|
||||
}
|
||||
function interpolateCoordinate(first, second, ratio) {
|
||||
return [first[0] + (second[0] - first[0]) * ratio, first[1] + (second[1] - first[1]) * ratio];
|
||||
}
|
||||
|
||||
module.exports = {
|
||||
resolveComplexJunctionTopology,
|
||||
buildComplexJunctionGeometry,
|
||||
|
||||
Reference in new issue
Block a user