perf: reduce junction preview handle and collision work

This commit is contained in:
que01 committed 2026-09-14 12:14:59 +08:00
1 parent 6a8f026d12
commit d0a4cfa7ff
11 files changed
+291 -5

No files matched your search

+7 -3
View File
@@ -1926,15 +1926,19 @@ function resolveDirectEditConstraints(model, editDocument = null, context = {})
clusters,
solved.clusterPlans,
);
// Cluster manifests discard other handle families; keep solving all constraints.
const clusterSelection = context.selection?.type === 'cluster';
handles.reserves = junctionData.reserves;
handles.handles = selectHandles(
[
...makeRoadHandles(model || {}, groups, handles.reserves, reconciled, solved.roadProfiles),
...makeJunctionHandles(model || {}, junctionData, reconciled),
...(clusterSelection
? []
: makeRoadHandles(model || {}, groups, handles.reserves, reconciled, solved.roadProfiles)),
...(clusterSelection ? [] : makeJunctionHandles(model || {}, junctionData, reconciled)),
...makeClusterCarriagewayHandles(model || {}, junctionData, reconciled, clusters),
...makeClusterCornerHandles(model || {}, junctionData, reconciled, clusters),
...makeClusterCrossingHandles(model || {}, junctionData, reconciled, clusters),
...makeLaneManeuverHandles(model || {}, reconciled),
...(clusterSelection ? [] : makeLaneManeuverHandles(model || {}, reconciled)),
],
model || {},
context.selection,
+17 -2
View File
@@ -1163,17 +1163,32 @@ function compileComplexLaneSeparators(features, controls = []) {
}
function trimLineBeforeFirstControl(line, controls, width) {
// Build once per line; preserve the exact polygon overlap predicate.
const indexed = controls
.map((feature) => {
const ring = feature.geometry.coordinates[0];
return { ring, box: controlBounds(ring) };
})
.sort((a, b) => a.box[0] - b.box[0]);
const overlaps = (ring) => {
const box = ringBounds(ring);
for (const control of indexed) {
if (control.box[0] > box[2]) break;
if (!boundsDisjoint(box, control.box) && ringsOverlap(ring, control.ring)) return true;
}
return false;
};
const total = lineLengthMeters(line);
const step = 0.25;
for (let distance = step; distance <= total; distance += step) {
const placement = pointAndAxisAlongLine(line, Math.min(total, distance - step / 2));
if (!placement) continue;
const ring = rectangleAt(placement.point, placement.axis, [-placement.axis[1], placement.axis[0]], step, width, 0);
if (!ringsOverlapControl([ring], controls)) continue;
if (!overlaps(ring)) continue;
let cutoff = Math.max(0, distance - step - 0.12);
while (cutoff > 0.5) {
const candidate = roadRing([line[0], pointAlongLine(line, cutoff)], width);
if (candidate && !ringsOverlapControl([candidate], controls)) return [line[0], pointAlongLine(line, cutoff)];
if (candidate && !overlaps(candidate)) return [line[0], pointAlongLine(line, cutoff)];
cutoff -= 0.25;
}
return null;