feat(compile): expose effective junction plans
This commit is contained in:
1 parent
4b38ce3c31
commit
f6f51fe90b
4 files changed
+98
No files matched your search
@@ -48,6 +48,7 @@ function compileInput(input) {
|
||||
const directEdits = input.editsFile ? loadEditDocument(input.editsFile) : null;
|
||||
const directEdit = resolveDirectEditConstraints(model, directEdits, {
|
||||
compilerGeometryVersion: GEOMETRY_VERSION,
|
||||
junctionTemplates: area.nativeRoad.junctionTemplates,
|
||||
});
|
||||
const compiled = compileGeometry(model, overrides, {
|
||||
edgeLines: area.nativeRoad.edgeLines,
|
||||
|
||||
@@ -1116,6 +1116,12 @@ function resolveDirectEditConstraints(model, editDocument = null, context = {})
|
||||
const junctionData = junctionReserves(model || {});
|
||||
const reconciled = reconcileConstraints(model || {}, constraints, editDocument?.base, junctionData, context);
|
||||
const solved = solveConstraints(model || {}, reconciled, junctionData, diagnostics);
|
||||
const effectiveJunctionPlans = buildEffectiveJunctionPlans(
|
||||
model || {},
|
||||
solved.junctionPlans,
|
||||
junctionData,
|
||||
context.junctionTemplates?.clusters || context.junctionClusters || [],
|
||||
);
|
||||
handles.reserves = junctionData.reserves;
|
||||
handles.handles = selectHandles(
|
||||
[
|
||||
@@ -1130,6 +1136,7 @@ function resolveDirectEditConstraints(model, editDocument = null, context = {})
|
||||
schema: RESOLUTION_SCHEMA,
|
||||
roadProfiles: solved.roadProfiles,
|
||||
junctionPlans: solved.junctionPlans,
|
||||
effectiveJunctionPlans,
|
||||
crossingControls: solved.crossingControls,
|
||||
laneManeuvers: solved.laneManeuvers,
|
||||
handles,
|
||||
@@ -1138,6 +1145,70 @@ function resolveDirectEditConstraints(model, editDocument = null, context = {})
|
||||
};
|
||||
}
|
||||
|
||||
// Normalize node plans and configured clusters into the read model consumed by
|
||||
// JunctionTools. Clusters deliberately remain read-only in this phase: their
|
||||
// effective plan is assembled from member nodes without rewriting constraints or
|
||||
// silently splitting the cluster into independent editors.
|
||||
function buildEffectiveJunctionPlans(model, solvedPlans, junctionData, clusters = []) {
|
||||
const nodePlan = (nodeId) => {
|
||||
const id = String(nodeId);
|
||||
const solved = solvedPlans.get(id);
|
||||
const approaches = junctionData.approaches.get(id) || [];
|
||||
if (solved)
|
||||
return {
|
||||
schema: 'junction-effective-plan/v1',
|
||||
junctionRef: { type: 'node', id },
|
||||
...solved,
|
||||
nodeId: id,
|
||||
readOnly: false,
|
||||
};
|
||||
if (!approaches.length) return null;
|
||||
return {
|
||||
schema: 'junction-effective-plan/v1',
|
||||
junctionRef: { type: 'node', id },
|
||||
nodeId: id,
|
||||
approaches: Object.fromEntries(
|
||||
approaches.map((item) => [
|
||||
item.segmentId,
|
||||
{
|
||||
widthMeters: item.items.reduce((sum, entry) => sum + entry.road.widthMeters, 0),
|
||||
cutbackMeters: item.cutback,
|
||||
},
|
||||
]),
|
||||
),
|
||||
corners: {},
|
||||
readOnly: false,
|
||||
};
|
||||
};
|
||||
const result = new Map();
|
||||
for (const [nodeId] of junctionData.approaches) {
|
||||
const plan = nodePlan(nodeId);
|
||||
if (plan) result.set(`node:${nodeId}`, plan);
|
||||
}
|
||||
for (const cluster of Array.isArray(clusters) ? clusters : []) {
|
||||
if (!cluster || !cluster.id || !Array.isArray(cluster.nodeIds)) continue;
|
||||
const members = cluster.nodeIds.map((id) => nodePlan(id)).filter(Boolean);
|
||||
if (!members.length) continue;
|
||||
const approaches = members.flatMap((member) =>
|
||||
Object.entries(member.approaches || {}).map(([segmentId, value]) => ({
|
||||
nodeId: member.nodeId,
|
||||
segmentId,
|
||||
...value,
|
||||
})),
|
||||
);
|
||||
const corners = Object.assign({}, ...members.map((member) => member.corners || {}));
|
||||
result.set(`cluster:${cluster.id}`, {
|
||||
schema: 'junction-effective-plan/v1',
|
||||
junctionRef: { type: 'cluster', id: String(cluster.id) },
|
||||
nodeIds: cluster.nodeIds.map(String),
|
||||
approaches,
|
||||
corners,
|
||||
readOnly: true,
|
||||
});
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
module.exports = {
|
||||
CROSSWALK_DEPTH_METERS,
|
||||
CROSSWALK_STRIPE_PITCH_METERS,
|
||||
@@ -1155,4 +1226,5 @@ module.exports = {
|
||||
roadEdgeOffsetRange,
|
||||
SUPPORTED_MANEUVERS,
|
||||
resolveDirectEditConstraints,
|
||||
buildEffectiveJunctionPlans,
|
||||
};
|
||||
Reference in new issue
Block a user