feat(junction): edit complex cutbacks and corners
This commit is contained in:
1 parent
d0e1f62f2b
commit
80f122be46
15 files changed
+354
-38
No files matched your search
@@ -316,14 +316,20 @@ then `structureFromTopology(topology, shape, center, features)`. Projection is
|
||||
`cluster:<id>`. The legacy singular field is null at this unscoped entry point.
|
||||
- `GET /api/edit-state?junction=<node>` preserves the node selection contract;
|
||||
`?cluster=<id>` selects a cluster. Preview uses the equivalent `selection`
|
||||
object. A selected editable cluster publishes only `cluster-carriageway-width`
|
||||
handles for its external carriageways.
|
||||
- A `cluster-carriageway-width` anchor contains `clusterId`, stable
|
||||
object. A selected editable cluster publishes `cluster-carriageway-width`,
|
||||
`cluster-carriageway-cutback`, and `cluster-corner-radius` handles only for
|
||||
its external geometry.
|
||||
- A cluster carriageway anchor contains `clusterId`, stable
|
||||
`carriagewayKey`, `sourceNodeIds`, and `sourceRoadIds`. Replay matches all
|
||||
source identity; a missing or changed source is stale with `anchor-missing`.
|
||||
The solver stores accepted values in `clusterPlans`, and `compileGeometry()`
|
||||
applies them to the matching complex-junction approach before geometry is
|
||||
generated. It must not widen unrelated member-node approaches.
|
||||
The solver stores width and cutback values separately, and `compileGeometry()`
|
||||
applies them only to the matching complex-junction approach before geometry is
|
||||
generated.
|
||||
- A cluster corner anchor contains its stable adjacent-arm `cornerKey` and the
|
||||
two representative carriageway keys. It is replayed against the same
|
||||
source-sorted arm grouping used by `resolveComplexJunctionTopology()`. The
|
||||
complex generator reads a local radius by that `cornerKey`; no other corner is
|
||||
rewritten.
|
||||
- Preview and save both evaluate the same candidate through the resolver and
|
||||
`compileGeometry()`. Save rejects every `severity: error` diagnostic before
|
||||
writing the edit document.
|
||||
|
||||
@@ -281,15 +281,15 @@ reuse the unscoped singular structure when its ref differs. A missing structure
|
||||
stays unavailable. Use `junctionEditSelection(ref)` for edit-state and preview
|
||||
requests so a cluster never falls back to the last selected road or node.
|
||||
|
||||
## 17. Complex carriageway width editing
|
||||
## 17. Complex geometry editing
|
||||
|
||||
Complex JunctionTools consumes the same v2 `EditSession`, `PreviewRequester`,
|
||||
`ParameterPanel`, and map handle callbacks as ordinary junctions. The only
|
||||
editable handle in this stage is `cluster-carriageway-width` with a
|
||||
`cluster-carriageway` anchor. Before edit mode, a selected cluster loads its
|
||||
scoped manifest so `canEditJunction()` can use an editable server handle as the
|
||||
capability signal. Once enabled, those same handles are rendered on the map and
|
||||
in the panel; `App.tsx` resolves the anchor snapshot from `sourceRoadIds[0]`.
|
||||
`ParameterPanel`, and map handle callbacks as ordinary junctions. Editable
|
||||
handles are `cluster-carriageway-width`, `cluster-carriageway-cutback`, and
|
||||
`cluster-corner-radius`. The first two use a `cluster-carriageway` anchor; a
|
||||
corner anchor is resolved to its representative carriageway only to create the
|
||||
snapshot. Before edit mode, a selected cluster loads its scoped manifest so
|
||||
`canEditJunction()` can use an editable server handle as the capability signal.
|
||||
Do not add a cluster-local draft, preview, undo, or save flow.
|
||||
|
||||
Compiler structure provenance supplies cluster hotspots and external road IDs.
|
||||
|
||||
@@ -3,7 +3,7 @@
|
||||
"name": "cj-03-geometry",
|
||||
"title": "复杂路口 03:收口与角部局部编辑",
|
||||
"description": "让复杂路口可以逐进口调整收口、逐角部调整圆角,并与统一默认值可靠协作。",
|
||||
"status": "planning",
|
||||
"status": "in_progress",
|
||||
"dev_type": "fullstack",
|
||||
"scope": "junction",
|
||||
"package": null,
|
||||
@@ -29,4 +29,4 @@
|
||||
],
|
||||
"notes": "依赖:02 验收通过。规划已补齐,等待最终评审后启动;不表示实现已完成。",
|
||||
"meta": {}
|
||||
}
|
||||
}
|
||||
@@ -153,7 +153,10 @@ function buildComplexJunctionGeometry(model, cluster, helpers) {
|
||||
const islands = [];
|
||||
const armCrosswalkRadius = coreRadius * 0.68;
|
||||
for (const item of carriageways) {
|
||||
const outer = pointOnCarriagewayRadius(item, center, outerRadius, helpers);
|
||||
// The approach plan owns the editable handoff distance. It shifts only this
|
||||
// carriageway's outer transition, leaving neighboring arms untouched.
|
||||
const itemOuterRadius = Math.max(coreRadius + 4, outerRadius - Math.max(0, Number(item.approach.cutback) || 0));
|
||||
const outer = pointOnCarriagewayRadius(item, center, itemOuterRadius, helpers);
|
||||
const inner = pointOnCarriagewayRadius(item, center, coreRadius * 0.7, helpers);
|
||||
const outerHalf = item.approach.widthMeters / 2;
|
||||
const innerHalf = outerHalf;
|
||||
@@ -415,10 +418,11 @@ function buildComplexJunctionGeometry(model, cluster, helpers) {
|
||||
const cornerFills = [];
|
||||
const sidewalkCorners = [];
|
||||
const cornerDiagnostics = [];
|
||||
const cornerRadius = Math.max(4, Math.min(25, Number(cluster.cornerRadiusMeters) || 12));
|
||||
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];
|
||||
const second = arms[(index + 1) % arms.length];
|
||||
const cornerRadius = helpers.clusterCornerRadii?.get(first.cornerKey) ?? defaultCornerRadius;
|
||||
const delta = positiveHeadingDelta(first.heading, second.heading);
|
||||
if (delta < 45 || delta > 135) continue;
|
||||
const bisector = normalizeHeading(first.heading + delta / 2);
|
||||
|
||||
@@ -24,6 +24,8 @@ const SOLVED_KINDS = new Set([
|
||||
'road-lane-divider',
|
||||
'junction-approach-width',
|
||||
'cluster-carriageway-width',
|
||||
'cluster-carriageway-cutback',
|
||||
'cluster-corner-radius',
|
||||
'junction-cutback',
|
||||
'junction-corner-radius',
|
||||
'junction-crosswalk-inset',
|
||||
@@ -37,6 +39,8 @@ const KINDS = [
|
||||
'road-lane-divider',
|
||||
'junction-approach-width',
|
||||
'cluster-carriageway-width',
|
||||
'cluster-carriageway-cutback',
|
||||
'cluster-corner-radius',
|
||||
'junction-cutback',
|
||||
'junction-corner-radius',
|
||||
'junction-crosswalk-inset',
|
||||
@@ -163,6 +167,18 @@ function constraintFor(constraints, kind, anchor) {
|
||||
item.anchor.clusterId === anchor.clusterId &&
|
||||
item.anchor.carriagewayKey === anchor.carriagewayKey
|
||||
);
|
||||
if (kind === 'cluster-carriageway-cutback')
|
||||
return (
|
||||
item.anchor.type === 'cluster-carriageway' &&
|
||||
item.anchor.clusterId === anchor.clusterId &&
|
||||
item.anchor.carriagewayKey === anchor.carriagewayKey
|
||||
);
|
||||
if (kind === 'cluster-corner-radius')
|
||||
return (
|
||||
item.anchor.type === 'cluster-corner' &&
|
||||
item.anchor.clusterId === anchor.clusterId &&
|
||||
item.anchor.cornerKey === anchor.cornerKey
|
||||
);
|
||||
if (kind === 'junction-crosswalk-inset' || kind === 'junction-stop-line-offset')
|
||||
return (
|
||||
item.anchor.type === 'junction-crossing' &&
|
||||
@@ -206,6 +222,7 @@ function clusterCarriageways(model, junctionData, clusters) {
|
||||
nodeId: String(nodeId),
|
||||
approach,
|
||||
roads,
|
||||
identity: topologyIdentity(source),
|
||||
key: `cluster:${encodeURIComponent(cluster.id)}:carriageway:${topologyIdentity(source)}`,
|
||||
sourceNodeIds: [...new Set(roads.flatMap((road) => (road.sourceNodeIds || []).map(String)))].sort(),
|
||||
sourceRoadIds: roads.map((road) => String(road.id)).sort(),
|
||||
@@ -223,6 +240,51 @@ function clusterCarriageways(model, junctionData, clusters) {
|
||||
return result;
|
||||
}
|
||||
|
||||
function clusterApproachLine(item) {
|
||||
const road = item.approach.items[0]?.road;
|
||||
if (!road) return [];
|
||||
return item.approach.endpoint.side === 'end' ? [...road.centerline].reverse() : road.centerline;
|
||||
}
|
||||
|
||||
function headingDifference(first, second) {
|
||||
return Math.abs(((first - second + 540) % 360) - 180);
|
||||
}
|
||||
|
||||
function averageHeading(headings) {
|
||||
const vector = headings.reduce(
|
||||
(sum, heading) => {
|
||||
const radians = (heading * Math.PI) / 180;
|
||||
return [sum[0] + Math.sin(radians), sum[1] + Math.cos(radians)];
|
||||
},
|
||||
[0, 0],
|
||||
);
|
||||
return ((Math.atan2(vector[0], vector[1]) * 180) / Math.PI + 360) % 360;
|
||||
}
|
||||
|
||||
// Mirrors resolveComplexJunctionTopology(): corner identity belongs to adjacent
|
||||
// external arms, not whichever individual carriageways happened to be listed.
|
||||
function clusterArms(clusterId, items) {
|
||||
const arms = [];
|
||||
for (const item of [...items].sort((a, b) => a.identity.localeCompare(b.identity))) {
|
||||
item.heading = tangentAzimuth(clusterApproachLine(item), 0.05);
|
||||
let arm = arms.find((candidate) => headingDifference(candidate.representative.heading, item.heading) < 20);
|
||||
if (!arm) {
|
||||
arm = { representative: item, members: [] };
|
||||
arms.push(arm);
|
||||
}
|
||||
arm.members.push(item);
|
||||
}
|
||||
for (const arm of arms) {
|
||||
arm.heading = averageHeading(arm.members.map((member) => member.heading));
|
||||
arm.key = `cluster:${encodeURIComponent(clusterId)}:arm:${arm.members
|
||||
.map((member) => member.identity)
|
||||
.sort()
|
||||
.join('|')}`;
|
||||
}
|
||||
arms.sort((a, b) => a.heading - b.heading || a.representative.identity.localeCompare(b.representative.identity));
|
||||
return arms;
|
||||
}
|
||||
|
||||
function numericValue(constraint, key, fallback) {
|
||||
const value = constraint?.value?.[key];
|
||||
return Number.isFinite(value) ? value : fallback;
|
||||
@@ -300,6 +362,17 @@ function reconcileConstraints(model, constraints, base, junctionData, context) {
|
||||
junctionData,
|
||||
context.junctionTemplates?.clusters || context.junctionClusters || [],
|
||||
);
|
||||
const clusterCorners = new Map(
|
||||
[...clusterItems].map(([clusterId, items]) => [
|
||||
clusterId,
|
||||
new Map(
|
||||
clusterArms(clusterId, items).map((arm, index, arms) => [
|
||||
`corner:${arm.key}>${arms[(index + 1) % arms.length].key}`,
|
||||
[arm.representative.key, arms[(index + 1) % arms.length].representative.key],
|
||||
]),
|
||||
),
|
||||
]),
|
||||
);
|
||||
const versionChanged = Boolean(
|
||||
context.compilerGeometryVersion &&
|
||||
base?.compilerGeometryVersion &&
|
||||
@@ -328,6 +401,22 @@ function reconcileConstraints(model, constraints, base, junctionData, context) {
|
||||
if (versionChanged) return { ...constraint, status: 'recheck' };
|
||||
return constraint;
|
||||
}
|
||||
if (constraint.kind === 'cluster-carriageway-cutback') {
|
||||
const item = clusterItems
|
||||
.get(String(constraint.anchor.clusterId))
|
||||
?.find((candidate) => candidate.key === constraint.anchor.carriagewayKey);
|
||||
if (!item) return { ...constraint, status: 'stale', replayReason: 'anchor-missing' };
|
||||
if (versionChanged) return { ...constraint, status: 'recheck' };
|
||||
return constraint;
|
||||
}
|
||||
if (constraint.kind === 'cluster-corner-radius') {
|
||||
const expected = clusterCorners.get(String(constraint.anchor.clusterId))?.get(constraint.anchor.cornerKey);
|
||||
const supplied = [...constraint.anchor.carriagewayKeys].sort();
|
||||
if (!expected || JSON.stringify([...expected].sort()) !== JSON.stringify(supplied))
|
||||
return { ...constraint, status: 'stale', replayReason: 'anchor-missing' };
|
||||
if (versionChanged) return { ...constraint, status: 'recheck' };
|
||||
return constraint;
|
||||
}
|
||||
if (constraint.kind.startsWith('road-')) {
|
||||
const road = roadForAnchor(model, constraint.anchor.roadId);
|
||||
matched = Boolean(road);
|
||||
@@ -676,6 +765,8 @@ function solveConstraints(model, constraints, junctionData, diagnostics, cluster
|
||||
const laneManeuvers = new Map();
|
||||
const crossingControls = new Map();
|
||||
const clusterPlans = new Map();
|
||||
const clusterCutbacks = new Map();
|
||||
const clusterCorners = new Map();
|
||||
const clusterItems = clusterCarriageways(model, junctionData, clusters);
|
||||
const states = [];
|
||||
for (const constraint of constraints) {
|
||||
@@ -707,6 +798,8 @@ function solveConstraints(model, constraints, junctionData, diagnostics, cluster
|
||||
const laneSnapshot = new Map(laneManeuvers);
|
||||
const crossingSnapshot = new Map([...crossingControls].map(([key, value]) => [key, { ...value }]));
|
||||
const clusterSnapshot = new Map([...clusterPlans].map(([key, value]) => [key, new Map(value)]));
|
||||
const cutbackSnapshot = new Map([...clusterCutbacks].map(([key, value]) => [key, new Map(value)]));
|
||||
const cornerSnapshot = new Map([...clusterCorners].map(([key, value]) => [key, new Map(value)]));
|
||||
const junctionSnapshot = new Map(
|
||||
[...junctionPlans].map(([key, plan]) => [
|
||||
key,
|
||||
@@ -718,29 +811,48 @@ function solveConstraints(model, constraints, junctionData, diagnostics, cluster
|
||||
]),
|
||||
);
|
||||
let applied;
|
||||
if (constraint.kind === 'cluster-carriageway-width') {
|
||||
if (constraint.kind === 'cluster-carriageway-width' || constraint.kind === 'cluster-carriageway-cutback') {
|
||||
const item = clusterItems
|
||||
.get(String(constraint.anchor?.clusterId))
|
||||
?.find((candidate) => candidate.key === constraint.anchor?.carriagewayKey);
|
||||
const width = Number(constraint.value?.widthMeters);
|
||||
const value = Number(
|
||||
constraint.kind === 'cluster-carriageway-width'
|
||||
? constraint.value?.widthMeters
|
||||
: constraint.value?.cutbackMeters,
|
||||
);
|
||||
if (!item) {
|
||||
blocking(diagnostics, constraint, 'direct-edit-cluster-carriageway-missing', '复杂路口车行道锚点不存在。');
|
||||
applied = false;
|
||||
} else if (
|
||||
!Number.isFinite(width) ||
|
||||
width < Math.max(MIN_LANE_WIDTH_METERS, item.laneCount * MIN_LANE_WIDTH_METERS) ||
|
||||
width > item.widthMeters * 2
|
||||
!Number.isFinite(value) ||
|
||||
(constraint.kind === 'cluster-carriageway-width' &&
|
||||
(value < Math.max(MIN_LANE_WIDTH_METERS, item.laneCount * MIN_LANE_WIDTH_METERS) ||
|
||||
value > item.widthMeters * 2)) ||
|
||||
(constraint.kind === 'cluster-carriageway-cutback' && (value < 1 || value > item.approach.length * 0.45))
|
||||
) {
|
||||
blocking(
|
||||
diagnostics,
|
||||
constraint,
|
||||
'direct-edit-cluster-carriageway-width-invalid',
|
||||
'复杂路口车行道宽度超出当前可用范围。',
|
||||
'direct-edit-cluster-carriageway-geometry-invalid',
|
||||
'复杂路口车行道参数超出当前可用范围。',
|
||||
);
|
||||
applied = false;
|
||||
} else {
|
||||
if (!clusterPlans.has(item.clusterId)) clusterPlans.set(item.clusterId, new Map());
|
||||
clusterPlans.get(item.clusterId).set(item.key, width);
|
||||
const target = constraint.kind === 'cluster-carriageway-width' ? clusterPlans : clusterCutbacks;
|
||||
if (!target.has(item.clusterId)) target.set(item.clusterId, new Map());
|
||||
target.get(item.clusterId).set(item.key, value);
|
||||
applied = true;
|
||||
}
|
||||
} else if (constraint.kind === 'cluster-corner-radius') {
|
||||
const cluster = clusters.find((item) => String(item.id) === String(constraint.anchor?.clusterId));
|
||||
const radius = Number(constraint.value?.radiusMeters);
|
||||
const keys = constraint.anchor?.carriagewayKeys || [];
|
||||
if (!cluster || !Number.isFinite(radius) || radius < 1 || radius > 25 || keys.length !== 2) {
|
||||
blocking(diagnostics, constraint, 'direct-edit-cluster-corner-invalid', '复杂路口角部圆角超出当前可用范围。');
|
||||
applied = false;
|
||||
} else {
|
||||
if (!clusterCorners.has(String(cluster.id))) clusterCorners.set(String(cluster.id), new Map());
|
||||
clusterCorners.get(String(cluster.id)).set(String(constraint.anchor.cornerKey), radius);
|
||||
applied = true;
|
||||
}
|
||||
} else if (constraint.kind === 'lane-maneuver') {
|
||||
@@ -780,10 +892,23 @@ function solveConstraints(model, constraints, junctionData, diagnostics, cluster
|
||||
for (const [key, value] of crossingSnapshot) crossingControls.set(key, value);
|
||||
clusterPlans.clear();
|
||||
for (const [key, value] of clusterSnapshot) clusterPlans.set(key, value);
|
||||
clusterCutbacks.clear();
|
||||
for (const [key, value] of cutbackSnapshot) clusterCutbacks.set(key, value);
|
||||
clusterCorners.clear();
|
||||
for (const [key, value] of cornerSnapshot) clusterCorners.set(key, value);
|
||||
}
|
||||
states.push(constraintState(constraint, applied, applied ? null : 'invalid'));
|
||||
}
|
||||
return { roadProfiles, junctionPlans, laneManeuvers, crossingControls, clusterPlans, states };
|
||||
return {
|
||||
roadProfiles,
|
||||
junctionPlans,
|
||||
laneManeuvers,
|
||||
crossingControls,
|
||||
clusterPlans,
|
||||
clusterCutbacks,
|
||||
clusterCorners,
|
||||
states,
|
||||
};
|
||||
}
|
||||
|
||||
function roadAffects(roads, model, side, boundaryIndex) {
|
||||
@@ -1213,6 +1338,69 @@ function makeClusterCarriagewayHandles(model, junctionData, constraints, cluster
|
||||
affects: [`complex-junction:${clusterId}:carriageway:${item.approach.segmentId}`],
|
||||
editable: true,
|
||||
});
|
||||
const cutbackConstraint = constraintFor(constraints, 'cluster-carriageway-cutback', {
|
||||
clusterId,
|
||||
carriagewayKey: item.key,
|
||||
});
|
||||
handles.push({
|
||||
handleId: `handle:cluster-carriageway-cutback:${item.key}`,
|
||||
kind: 'cluster-carriageway-cutback',
|
||||
anchor: {
|
||||
type: 'cluster-carriageway',
|
||||
clusterId,
|
||||
carriagewayKey: item.key,
|
||||
sourceNodeIds: item.sourceNodeIds,
|
||||
sourceRoadIds: item.sourceRoadIds,
|
||||
},
|
||||
position: coordinateAt(
|
||||
line,
|
||||
Math.min(0.95, Math.max(0.05, item.approach.cutback / Math.max(item.approach.length, 1))),
|
||||
),
|
||||
axisAzimuth: tangentAzimuth(line, 0.1),
|
||||
value: {
|
||||
current: numericValue(cutbackConstraint, 'cutbackMeters', item.approach.cutback),
|
||||
min: 1,
|
||||
max: item.approach.length * 0.45,
|
||||
unit: 'meter',
|
||||
},
|
||||
...(cutbackConstraint ? { constraintId: cutbackConstraint.id } : {}),
|
||||
affects: [`complex-junction:${clusterId}:carriageway:${item.approach.segmentId}`],
|
||||
editable: true,
|
||||
});
|
||||
}
|
||||
}
|
||||
return handles;
|
||||
}
|
||||
|
||||
function makeClusterCornerHandles(model, junctionData, constraints, clusters) {
|
||||
const handles = [];
|
||||
for (const [clusterId, items] of clusterCarriageways(model, junctionData, clusters)) {
|
||||
const arms = clusterArms(clusterId, items);
|
||||
for (let index = 0; index < arms.length; index += 1) {
|
||||
const first = arms[index];
|
||||
const second = arms[(index + 1) % arms.length];
|
||||
const cornerKey = `corner:${first.key}>${second.key}`;
|
||||
const constraint = constraintFor(constraints, 'cluster-corner-radius', { clusterId, cornerKey });
|
||||
const firstLine = clusterApproachLine(first.representative);
|
||||
const secondLine = clusterApproachLine(second.representative);
|
||||
const firstPoint = firstLine[0];
|
||||
const secondPoint = secondLine[0];
|
||||
handles.push({
|
||||
handleId: `handle:cluster-corner-radius:${cornerKey}`,
|
||||
kind: 'cluster-corner-radius',
|
||||
anchor: {
|
||||
type: 'cluster-corner',
|
||||
clusterId,
|
||||
cornerKey,
|
||||
carriagewayKeys: [first.representative.key, second.representative.key],
|
||||
},
|
||||
position: [(firstPoint[0] + secondPoint[0]) / 2, (firstPoint[1] + secondPoint[1]) / 2],
|
||||
axisAzimuth: first.heading,
|
||||
value: { current: numericValue(constraint, 'radiusMeters', 12), min: 1, max: 25, unit: 'meter' },
|
||||
...(constraint ? { constraintId: constraint.id } : {}),
|
||||
affects: [`complex-junction:${clusterId}:corner:${cornerKey}`],
|
||||
editable: true,
|
||||
});
|
||||
}
|
||||
}
|
||||
return handles;
|
||||
@@ -1234,7 +1422,7 @@ function selectHandles(handles, model, selection) {
|
||||
if (!selection || !selection.type) return handles;
|
||||
if (selection.type === 'cluster')
|
||||
return handles.filter(
|
||||
(handle) => handle.kind === 'cluster-carriageway-width' && handle.anchor?.clusterId === String(selection.id),
|
||||
(handle) => handle.anchor?.clusterId === String(selection.id) && handle.kind.startsWith('cluster-'),
|
||||
);
|
||||
if (selection.type === 'segment') {
|
||||
const segmentOf = new Map((model.roads || []).map((road) => [road.id, road.segmentId]));
|
||||
@@ -1280,6 +1468,7 @@ function resolveDirectEditConstraints(model, editDocument = null, context = {})
|
||||
...makeRoadHandles(model || {}, groups, handles.reserves, reconciled, solved.roadProfiles),
|
||||
...makeJunctionHandles(model || {}, junctionData, reconciled),
|
||||
...makeClusterCarriagewayHandles(model || {}, junctionData, reconciled, clusters),
|
||||
...makeClusterCornerHandles(model || {}, junctionData, reconciled, clusters),
|
||||
...makeLaneManeuverHandles(model || {}, reconciled),
|
||||
],
|
||||
model || {},
|
||||
@@ -1292,6 +1481,8 @@ function resolveDirectEditConstraints(model, editDocument = null, context = {})
|
||||
effectiveJunctionPlans,
|
||||
crossingControls: solved.crossingControls,
|
||||
clusterPlans: solved.clusterPlans,
|
||||
clusterCutbacks: solved.clusterCutbacks,
|
||||
clusterCorners: solved.clusterCorners,
|
||||
laneManeuvers: solved.laneManeuvers,
|
||||
handles,
|
||||
constraintStates: solved.states,
|
||||
|
||||
@@ -14,6 +14,8 @@ const CONSTRAINT_ANCHORS = {
|
||||
'road-lane-divider': 'road-interval',
|
||||
'junction-approach-width': 'junction-approach',
|
||||
'cluster-carriageway-width': 'cluster-carriageway',
|
||||
'cluster-carriageway-cutback': 'cluster-carriageway',
|
||||
'cluster-corner-radius': 'cluster-corner',
|
||||
'junction-cutback': 'junction-approach',
|
||||
'junction-corner-radius': 'junction-corner',
|
||||
'junction-crosswalk-inset': 'junction-approach',
|
||||
@@ -29,6 +31,7 @@ const ANCHOR_TYPES = new Set([
|
||||
'junction-crossing',
|
||||
'junction-corner',
|
||||
'cluster-carriageway',
|
||||
'cluster-corner',
|
||||
'lane',
|
||||
]);
|
||||
const CONSTRAINT_STATUSES = new Set(['exact', 'recheck', 'pending', 'conflicted', 'stale']);
|
||||
@@ -110,6 +113,15 @@ function validateAnchor(scope, kind, anchor) {
|
||||
!anchor.sourceRoadIds.every((id) => typeof id === 'string' && id)
|
||||
)
|
||||
fail(scope, 'anchor.sourceRoadIds', 'must be a non-empty array of source road IDs');
|
||||
} else if (expected === 'cluster-corner') {
|
||||
requireString(scope, 'anchor.clusterId', anchor.clusterId);
|
||||
requireString(scope, 'anchor.cornerKey', anchor.cornerKey);
|
||||
if (
|
||||
!Array.isArray(anchor.carriagewayKeys) ||
|
||||
anchor.carriagewayKeys.length !== 2 ||
|
||||
!anchor.carriagewayKeys.every((key) => typeof key === 'string' && key)
|
||||
)
|
||||
fail(scope, 'anchor.carriagewayKeys', 'must contain exactly two carriageway keys');
|
||||
} else if (expected === 'junction-crossing') {
|
||||
requireString(scope, 'anchor.crossingId', anchor.crossingId);
|
||||
requireString(scope, 'anchor.nodeId', anchor.nodeId);
|
||||
@@ -151,10 +163,10 @@ function validateValue(scope, kind, value) {
|
||||
} else if (kind === 'junction-approach-width' || kind === 'cluster-carriageway-width') {
|
||||
if (!isFiniteNumber(value.widthMeters) || value.widthMeters <= 0)
|
||||
fail(scope, 'value.widthMeters', 'must be a positive number of meters');
|
||||
} else if (kind === 'junction-cutback') {
|
||||
} else if (kind === 'junction-cutback' || kind === 'cluster-carriageway-cutback') {
|
||||
if (!isFiniteNumber(value.cutbackMeters) || value.cutbackMeters < 0)
|
||||
fail(scope, 'value.cutbackMeters', 'must be a non-negative number of meters');
|
||||
} else if (kind === 'junction-corner-radius') {
|
||||
} 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');
|
||||
} else if (kind === 'junction-crosswalk-inset') {
|
||||
|
||||
@@ -769,6 +769,7 @@ function compileGeometry(model, overrides = { overrides: [] }, options = {}) {
|
||||
headingAtEndpoint,
|
||||
headingVector,
|
||||
circleRing,
|
||||
clusterCornerRadii: options.directEdit?.clusterCorners?.get(String(cluster.id)),
|
||||
});
|
||||
features.push(...generated.features);
|
||||
if (generated.crosswalks) generatedComplexCrosswalks.push(...generated.crosswalks);
|
||||
@@ -912,8 +913,14 @@ function applyDirectJunctionPlans(plans, directEdit) {
|
||||
}
|
||||
|
||||
function applyDirectClusterPlans(model, junctionPlans, directEdit, clusters) {
|
||||
if (!directEdit?.clusterPlans?.size) return;
|
||||
for (const [clusterId, widths] of directEdit.clusterPlans) {
|
||||
if (!directEdit?.clusterPlans?.size && !directEdit?.clusterCutbacks?.size) return;
|
||||
const clusterIds = new Set([
|
||||
...(directEdit.clusterPlans || new Map()).keys(),
|
||||
...(directEdit.clusterCutbacks || new Map()).keys(),
|
||||
]);
|
||||
for (const clusterId of clusterIds) {
|
||||
const widths = directEdit.clusterPlans?.get(clusterId) || new Map();
|
||||
const cutbacks = directEdit.clusterCutbacks?.get(clusterId) || new Map();
|
||||
const cluster = clusters.find((item) => String(item.id) === String(clusterId));
|
||||
if (!cluster || cluster.template !== 'complex-junction-v1') continue;
|
||||
const topology = resolveComplexJunctionTopology(model, cluster, {
|
||||
@@ -925,6 +932,8 @@ function applyDirectClusterPlans(model, junctionPlans, directEdit, clusters) {
|
||||
for (const item of topology.carriageways) {
|
||||
const width = widths.get(item.key);
|
||||
if (Number.isFinite(width)) item.approach.widthMeters = width;
|
||||
const cutback = cutbacks.get(item.key);
|
||||
if (Number.isFinite(cutback)) item.approach.cutback = cutback;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -247,13 +247,17 @@ test.describe('workbench editing shell', () => {
|
||||
expect(scoped.handles.handles.length).toBeGreaterThan(0);
|
||||
expect(
|
||||
scoped.handles.handles.every(
|
||||
(handle: { kind: string; editable: boolean }) => handle.kind === 'cluster-carriageway-width' && handle.editable,
|
||||
(handle: { kind: string; editable: boolean }) =>
|
||||
['cluster-carriageway-width', 'cluster-carriageway-cutback', 'cluster-corner-radius'].includes(handle.kind) &&
|
||||
handle.editable,
|
||||
),
|
||||
).toBe(true);
|
||||
expect(scoped.junctionStructure.topologyFingerprint).toBe(structure.topologyFingerprint);
|
||||
await page.getByRole('button', { name: '开启编辑模式' }).click();
|
||||
await expect(workspace.getByText('路口参数', { exact: true })).toBeVisible();
|
||||
await expect(workspace.getByText(/车行道宽度/).first()).toBeVisible();
|
||||
await expect(workspace.getByText(/车行道收口距离/).first()).toBeVisible();
|
||||
await expect(workspace.getByText(/角部圆角/).first()).toBeVisible();
|
||||
await page.reload();
|
||||
await expect(armButtons).toHaveCount(structure.arms.length);
|
||||
await expect(armButtons.first()).toHaveAttribute('aria-pressed', 'false');
|
||||
|
||||
@@ -33,6 +33,13 @@ function anchorFor(kind) {
|
||||
sourceNodeIds: ['node/9', 'node/10'],
|
||||
sourceRoadIds: ['road:way/1:forward'],
|
||||
};
|
||||
if (type === 'cluster-corner')
|
||||
return {
|
||||
type,
|
||||
clusterId: 'cluster/9',
|
||||
cornerKey: 'corner:one>two',
|
||||
carriagewayKeys: ['carriageway:one', 'carriageway:two'],
|
||||
};
|
||||
if (type === 'lane') return { type, laneId: 'lane:road:way/1:forward:1' };
|
||||
return { type, nodeId: 'node/9', incomingRoadId: 'road:way/1:forward', outgoingRoadId: 'road:way/2:forward' };
|
||||
}
|
||||
@@ -52,6 +59,10 @@ function valueFor(kind) {
|
||||
return { widthMeters: 12.5 };
|
||||
case 'cluster-carriageway-width':
|
||||
return { widthMeters: 12.5 };
|
||||
case 'cluster-carriageway-cutback':
|
||||
return { cutbackMeters: 4 };
|
||||
case 'cluster-corner-radius':
|
||||
return { radiusMeters: 6 };
|
||||
case 'junction-cutback':
|
||||
return { cutbackMeters: 4 };
|
||||
case 'junction-corner-radius':
|
||||
@@ -113,6 +124,8 @@ assert.deepEqual(CONSTRAINT_KINDS, [
|
||||
'road-lane-divider',
|
||||
'junction-approach-width',
|
||||
'cluster-carriageway-width',
|
||||
'cluster-carriageway-cutback',
|
||||
'cluster-corner-radius',
|
||||
'junction-cutback',
|
||||
'junction-corner-radius',
|
||||
'junction-crosswalk-inset',
|
||||
|
||||
@@ -257,8 +257,10 @@ const complexInput = {
|
||||
const complexArea = compileInput(complexInput).area;
|
||||
const clusterState = editState(complexArea, selectionFrom({ cluster: cluster.id }));
|
||||
assert.ok(
|
||||
clusterState.handles.handles.every((handle) => handle.kind === 'cluster-carriageway-width'),
|
||||
'cluster selection publishes only scoped complex carriageway width handles',
|
||||
clusterState.handles.handles.every((handle) =>
|
||||
['cluster-carriageway-width', 'cluster-carriageway-cutback', 'cluster-corner-radius'].includes(handle.kind),
|
||||
),
|
||||
'cluster selection publishes only scoped complex geometry handles',
|
||||
);
|
||||
assert.ok(clusterState.handles.handles.length, 'the complex fixture must publish editable carriageways');
|
||||
assert.deepEqual(clusterState.junctionStructure.junctionRef, { type: 'cluster', id: cluster.id });
|
||||
@@ -320,6 +322,56 @@ assert.notDeepEqual(
|
||||
complexSurface(clusterPreview).geometry,
|
||||
'a cluster carriageway constraint must change compiled complex geometry',
|
||||
);
|
||||
const complexCornerHandle = clusterState.handles.handles.find((handle) => handle.kind === 'cluster-corner-radius');
|
||||
assert.ok(complexCornerHandle, 'the complex fixture must publish stable corner-radius handles');
|
||||
const complexCornerConstraint = {
|
||||
id: 'constraint:complex-corner',
|
||||
kind: 'cluster-corner-radius',
|
||||
anchor: complexCornerHandle.anchor,
|
||||
anchorSnapshot: {
|
||||
coordinate: complexCornerHandle.position,
|
||||
tangentAzimuth: complexCornerHandle.axisAzimuth,
|
||||
roadLengthMeters: 120,
|
||||
osmNodeIds: cluster.nodeIds,
|
||||
},
|
||||
value: { radiusMeters: complexCornerHandle.value.min },
|
||||
enabled: true,
|
||||
status: 'exact',
|
||||
provenance: { operationId: 'operation:complex-corner', createdAt: '2026-09-08T00:00:00.000Z' },
|
||||
};
|
||||
const roundedClusterPreview = editPreview(complexArea, {
|
||||
document: {
|
||||
...emptyDocument,
|
||||
constraints: [complexCornerConstraint],
|
||||
operations: [
|
||||
{
|
||||
id: 'operation:complex-corner',
|
||||
createdAt: '2026-09-08T00:00:00.000Z',
|
||||
constraintIds: [complexCornerConstraint.id],
|
||||
},
|
||||
],
|
||||
},
|
||||
selection: { cluster: cluster.id },
|
||||
});
|
||||
assert.deepEqual(
|
||||
roundedClusterPreview.constraintStates?.map((state) => state.applied),
|
||||
[true],
|
||||
);
|
||||
const complexCorner = (preview) =>
|
||||
preview.layers.roadSurface.features.find(
|
||||
(feature) => feature.properties.corner_key === complexCornerHandle.anchor.cornerKey,
|
||||
);
|
||||
assert.ok(complexCorner(clusterPreview), 'the corner handle must identify a compiled corner surface');
|
||||
assert.equal(
|
||||
complexCorner(roundedClusterPreview).properties.corner_radius_m,
|
||||
complexCornerConstraint.value.radiusMeters,
|
||||
'the compiled corner must consume its scoped radius value',
|
||||
);
|
||||
assert.notDeepEqual(
|
||||
complexCorner(roundedClusterPreview).geometry,
|
||||
complexCorner(clusterPreview).geometry,
|
||||
'a cluster corner constraint must change its compiled corner geometry',
|
||||
);
|
||||
const browsing = browseState(complexArea);
|
||||
const unavailableStructureState = browseState({
|
||||
...complexArea,
|
||||
|
||||
@@ -266,8 +266,10 @@ function App() {
|
||||
if (junctionDescriptor.ref.type === 'cluster')
|
||||
return manifest.handles.filter(
|
||||
(handle) =>
|
||||
handle.kind === 'cluster-carriageway-width' &&
|
||||
handle.anchor.type === 'cluster-carriageway' &&
|
||||
(handle.kind === 'cluster-carriageway-width' ||
|
||||
handle.kind === 'cluster-carriageway-cutback' ||
|
||||
handle.kind === 'cluster-corner-radius') &&
|
||||
'clusterId' in handle.anchor &&
|
||||
handle.anchor.clusterId === junctionDescriptor.ref.id,
|
||||
);
|
||||
const nodeIds = new Set(junctionDescriptor.nodeIds.map(String));
|
||||
@@ -486,12 +488,23 @@ function App() {
|
||||
// control handles silently returned null and never scheduled a preview.
|
||||
const roadId = 'roadId' in handle.anchor ? handle.anchor.roadId : null;
|
||||
const sourceRoadId = handle.anchor.type === 'cluster-carriageway' ? handle.anchor.sourceRoadIds[0] : null;
|
||||
const cornerAnchor = handle.anchor.type === 'cluster-corner' ? handle.anchor : null;
|
||||
const cornerHandle = cornerAnchor
|
||||
? manifest?.handles.find(
|
||||
(candidate) =>
|
||||
candidate.anchor.type === 'cluster-carriageway' &&
|
||||
cornerAnchor.carriagewayKeys.includes(candidate.anchor.carriagewayKey),
|
||||
)
|
||||
: undefined;
|
||||
const cornerSourceRoadId =
|
||||
cornerHandle?.anchor.type === 'cluster-carriageway' ? cornerHandle.anchor.sourceRoadIds[0] : null;
|
||||
const segmentId = 'segmentId' in handle.anchor ? handle.anchor.segmentId : null;
|
||||
const cornerRoadId = handle.anchor.type === 'junction-corner' ? handle.anchor.incomingRoadId : null;
|
||||
const road = state?.compiled.model.roads.find(
|
||||
(item) =>
|
||||
(roadId ? item.id === roadId : false) ||
|
||||
(sourceRoadId ? item.id === sourceRoadId : false) ||
|
||||
(cornerSourceRoadId ? item.id === cornerSourceRoadId : false) ||
|
||||
(segmentId ? item.segmentId === segmentId : false) ||
|
||||
(cornerRoadId ? item.id === cornerRoadId || item.segmentId === cornerRoadId : false),
|
||||
);
|
||||
|
||||
@@ -114,6 +114,8 @@ const KIND_LABELS: Record<ConstraintKind, string> = {
|
||||
'road-lane-divider': '车道分隔',
|
||||
'junction-approach-width': '进口宽度',
|
||||
'cluster-carriageway-width': '车行道宽度',
|
||||
'cluster-carriageway-cutback': '车行道收口距离',
|
||||
'cluster-corner-radius': '角部圆角',
|
||||
'junction-cutback': '进口收口距离',
|
||||
'junction-corner-radius': '角部圆角',
|
||||
'junction-crosswalk-inset': '斑马线退让',
|
||||
|
||||
@@ -104,6 +104,10 @@ export function constraintValueFor(
|
||||
case 'junction-approach-width':
|
||||
case 'cluster-carriageway-width':
|
||||
return { widthMeters: Math.max(0, scalar) };
|
||||
case 'cluster-carriageway-cutback':
|
||||
return { cutbackMeters: Math.max(0, scalar) };
|
||||
case 'cluster-corner-radius':
|
||||
return { radiusMeters: Math.max(0, scalar) };
|
||||
case 'junction-cutback':
|
||||
return { cutbackMeters: Math.max(0, scalar) };
|
||||
case 'junction-corner-radius':
|
||||
|
||||
@@ -27,6 +27,8 @@ export const CONTROL_KINDS = ['junction-crosswalk-inset', 'junction-stop-line-of
|
||||
export const JUNCTION_KINDS = [
|
||||
'junction-approach-width',
|
||||
'cluster-carriageway-width',
|
||||
'cluster-carriageway-cutback',
|
||||
'cluster-corner-radius',
|
||||
'junction-cutback',
|
||||
'junction-corner-radius',
|
||||
...CONTROL_KINDS,
|
||||
@@ -59,6 +61,7 @@ export type SemanticAnchor =
|
||||
// in projection.ts is the only place that moves it across.
|
||||
boundaryIndex?: number;
|
||||
}
|
||||
| { type: 'cluster-corner'; clusterId: string; cornerKey: string; carriagewayKeys: string[] }
|
||||
| { type: 'junction-approach'; nodeId: string; segmentId: string; side?: Side }
|
||||
| {
|
||||
type: 'cluster-carriageway';
|
||||
|
||||
@@ -59,7 +59,10 @@ export function junctionLabelForHandle(handle: EditHandle, roads: Road[], juncti
|
||||
return `${approachName(road, roads, junction)} · ${base}`;
|
||||
}
|
||||
const clusterAnchor = handle.anchor;
|
||||
if (handle.kind === 'cluster-carriageway-width' && clusterAnchor.type === 'cluster-carriageway') {
|
||||
if (
|
||||
(handle.kind === 'cluster-carriageway-width' || handle.kind === 'cluster-carriageway-cutback') &&
|
||||
clusterAnchor.type === 'cluster-carriageway'
|
||||
) {
|
||||
const road = roads.find((item) => clusterAnchor.sourceRoadIds.includes(item.id));
|
||||
return `${approachName(road, roads, junction)} · ${base}`;
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user