feat: support complex carriageway edge offsets

This commit is contained in:
que01 committed 2026-09-10 11:01:11 +08:00
1 parent 3e74732190
commit 38dc9d6f52
3 files changed
+27 -2

No files matched your search

+16 -2
View File
@@ -29,6 +29,7 @@ const SOLVED_KINDS = new Set([
'cluster-carriageway-transition-length',
'cluster-carriageway-position',
'cluster-carriageway-direction',
'cluster-carriageway-edge-offset',
'cluster-corner-radius',
'cluster-crossing-inset',
'cluster-stop-line-offset',
@@ -49,6 +50,7 @@ const KINDS = [
'cluster-carriageway-transition-length',
'cluster-carriageway-position',
'cluster-carriageway-direction',
'cluster-carriageway-edge-offset',
'cluster-corner-radius',
'cluster-crossing-inset',
'cluster-stop-line-offset',
@@ -873,6 +875,7 @@ function solveConstraints(model, constraints, junctionData, diagnostics, cluster
const clusterTransitions = new Map();
const clusterPositions = new Map();
const clusterDirections = new Map();
const clusterEdgeOffsets = new Map();
const clusterCorners = new Map();
const clusterCrossings = new Map();
const clusterItems = clusterCarriageways(model, junctionData, clusters);
@@ -910,6 +913,7 @@ function solveConstraints(model, constraints, junctionData, diagnostics, cluster
const transitionSnapshot = new Map([...clusterTransitions].map(([key, value]) => [key, new Map(value)]));
const positionSnapshot = new Map([...clusterPositions].map(([key, value]) => [key, new Map(value)]));
const directionSnapshot = new Map([...clusterDirections].map(([key, value]) => [key, new Map(value)]));
const edgeSnapshot = new Map([...clusterEdgeOffsets].map(([key, value]) => [key, new Map(value)]));
const cornerSnapshot = new Map([...clusterCorners].map(([key, value]) => [key, new Map(value)]));
const crossingClusterSnapshot = new Map([...clusterCrossings].map(([key, value]) => [key, new Map(value)]));
const junctionSnapshot = new Map(
@@ -928,7 +932,8 @@ function solveConstraints(model, constraints, junctionData, diagnostics, cluster
constraint.kind === 'cluster-carriageway-cutback' ||
constraint.kind === 'cluster-carriageway-transition-length' ||
constraint.kind === 'cluster-carriageway-position' ||
constraint.kind === 'cluster-carriageway-direction'
constraint.kind === 'cluster-carriageway-direction' ||
constraint.kind === 'cluster-carriageway-edge-offset'
) {
const item = clusterItems
.get(String(constraint.anchor?.clusterId))
@@ -942,7 +947,9 @@ function solveConstraints(model, constraints, junctionData, diagnostics, cluster
? constraint.value?.offsetMeters
: constraint.kind === 'cluster-carriageway-direction'
? constraint.value?.offsetDegrees
: constraint.value?.cutbackMeters,
: constraint.kind === 'cluster-carriageway-edge-offset'
? constraint.value
: constraint.value?.cutbackMeters,
);
const cluster = clusters.find((candidate) => String(candidate.id) === String(item?.clusterId));
const cutbackMax = cluster ? clusterCutbackMaximum(cluster, item?.approach.length || 0) : 0;
@@ -981,6 +988,10 @@ function solveConstraints(model, constraints, junctionData, diagnostics, cluster
: clusterCutbacks;
if (!target.has(item.clusterId)) target.set(item.clusterId, new Map());
target.get(item.clusterId).set(item.key, value);
if (constraint.kind === 'cluster-carriageway-edge-offset') {
if (!clusterEdgeOffsets.has(item.clusterId)) clusterEdgeOffsets.set(item.clusterId, new Map());
clusterEdgeOffsets.get(item.clusterId).set(item.key, value);
}
applied = true;
}
} else if (constraint.kind === 'cluster-corner-radius') {
@@ -1064,6 +1075,8 @@ function solveConstraints(model, constraints, junctionData, diagnostics, cluster
for (const [key, value] of positionSnapshot) clusterPositions.set(key, value);
clusterDirections.clear();
for (const [key, value] of directionSnapshot) clusterDirections.set(key, value);
clusterEdgeOffsets.clear();
for (const [key, value] of edgeSnapshot) clusterEdgeOffsets.set(key, value);
clusterCorners.clear();
for (const [key, value] of cornerSnapshot) clusterCorners.set(key, value);
clusterCrossings.clear();
@@ -1081,6 +1094,7 @@ function solveConstraints(model, constraints, junctionData, diagnostics, cluster
clusterTransitions,
clusterPositions,
clusterDirections,
clusterEdgeOffsets,
clusterCorners,
clusterCrossings,
states,
+4
View File
@@ -18,6 +18,7 @@ const CONSTRAINT_ANCHORS = {
'cluster-carriageway-transition-length': 'cluster-carriageway',
'cluster-carriageway-position': 'cluster-carriageway',
'cluster-carriageway-direction': 'cluster-carriageway',
'cluster-carriageway-edge-offset': 'cluster-carriageway',
'cluster-corner-radius': 'cluster-corner',
'cluster-crossing-inset': 'cluster-crossing',
'cluster-stop-line-offset': 'cluster-crossing',
@@ -189,6 +190,9 @@ function validateValue(scope, kind, value) {
} else if (kind === 'cluster-carriageway-direction') {
if (!isFiniteNumber(value.offsetDegrees) || value.offsetDegrees < -15 || value.offsetDegrees > 15)
fail(scope, 'value.offsetDegrees', 'must be between -15 and 15 degrees');
} else if (kind === 'cluster-carriageway-edge-offset') {
if (!isFiniteNumber(value.leftOffsetMeters) || !isFiniteNumber(value.rightOffsetMeters))
fail(scope, 'value', 'leftOffsetMeters and rightOffsetMeters must be finite meters');
} else if (kind === 'junction-corner-radius' || kind === 'cluster-corner-radius') {
if (!isFiniteNumber(value.radiusMeters) || value.radiusMeters < 0)
fail(scope, 'value.radiusMeters', 'must be a non-negative number of meters');
+7
View File
@@ -1026,6 +1026,7 @@ function applyDirectClusterPlans(model, junctionPlans, directEdit, clusters) {
...(directEdit.clusterTransitions || new Map()).keys(),
...(directEdit.clusterPositions || new Map()).keys(),
...(directEdit.clusterDirections || new Map()).keys(),
...(directEdit.clusterEdgeOffsets || new Map()).keys(),
]);
for (const clusterId of clusterIds) {
const widths = directEdit.clusterPlans?.get(clusterId) || new Map();
@@ -1055,6 +1056,12 @@ function applyDirectClusterPlans(model, junctionPlans, directEdit, clusters) {
if (Number.isFinite(position)) item.approach.positionOffsetMeters = position;
const direction = directEdit.clusterDirections?.get(clusterId)?.get(item.key);
if (Number.isFinite(direction)) item.heading += direction;
const edges = directEdit.clusterEdgeOffsets?.get(clusterId)?.get(item.key);
if (edges && Number.isFinite(edges.leftOffsetMeters) && Number.isFinite(edges.rightOffsetMeters)) {
item.approach.leftEdgeOffsetMeters = edges.leftOffsetMeters;
item.approach.rightEdgeOffsetMeters = edges.rightOffsetMeters;
item.approach.widthMeters += edges.leftOffsetMeters + edges.rightOffsetMeters;
}
}
}
}