Refactor path deletion logic and add utilities for managing spline corridor path clip intervals

This commit is contained in:
2026-05-13 13:15:01 +02:00
parent 9bc55b468f
commit 61426b5e79
2 changed files with 69 additions and 13 deletions

View File

@@ -65,19 +65,24 @@ export function createDeletePathCommand(pathId: string): EditorCommand {
...currentDocument.paths ...currentDocument.paths
}; };
delete nextPaths[pathId]; delete nextPaths[pathId];
const nextJunctions = Object.fromEntries( const nextJunctions: Record<string, SplineCorridorJunction> = {};
Object.entries(currentDocument.splineCorridorJunctions)
.map(([junctionId, junction]) => [ for (const [junctionId, junction] of Object.entries(
junctionId, currentDocument.splineCorridorJunctions
cloneSplineCorridorJunction({ )) {
...junction, const connections = junction.connections.filter(
connections: junction.connections.filter( (connection) => connection.pathId !== pathId
(connection) => connection.pathId !== pathId );
)
}) if (connections.length < 2) {
]) continue;
.filter(([, junction]) => junction.connections.length >= 2) }
);
nextJunctions[junctionId] = cloneSplineCorridorJunction({
...junction,
connections
});
}
context.setDocument({ context.setDocument({
...currentDocument, ...currentDocument,

View File

@@ -0,0 +1,51 @@
export interface SplineCorridorPathClipInterval {
junctionId: string;
startDistance: number;
endDistance: number;
}
export type SplineCorridorPathClipIntervalMap = Map<
string,
SplineCorridorPathClipInterval[]
>;
export function isDistanceInSplineCorridorClipIntervals(
distance: number,
intervals: readonly SplineCorridorPathClipInterval[] | undefined
): boolean {
if (intervals === undefined || intervals.length === 0) {
return false;
}
return intervals.some(
(interval) =>
distance >= interval.startDistance && distance <= interval.endDistance
);
}
export function mergeSplineCorridorPathClipIntervals(
intervals: readonly SplineCorridorPathClipInterval[]
): SplineCorridorPathClipInterval[] {
if (intervals.length <= 1) {
return [...intervals];
}
const sortedIntervals = [...intervals].sort(
(left, right) => left.startDistance - right.startDistance
);
const merged: SplineCorridorPathClipInterval[] = [];
for (const interval of sortedIntervals) {
const previous = merged[merged.length - 1];
if (previous === undefined || interval.startDistance > previous.endDistance) {
merged.push({ ...interval });
continue;
}
previous.endDistance = Math.max(previous.endDistance, interval.endDistance);
}
return merged;
}