Refactor path deletion logic and add utilities for managing spline corridor path clip intervals
This commit is contained in:
@@ -65,19 +65,24 @@ export function createDeletePathCommand(pathId: string): EditorCommand {
|
||||
...currentDocument.paths
|
||||
};
|
||||
delete nextPaths[pathId];
|
||||
const nextJunctions = Object.fromEntries(
|
||||
Object.entries(currentDocument.splineCorridorJunctions)
|
||||
.map(([junctionId, junction]) => [
|
||||
junctionId,
|
||||
cloneSplineCorridorJunction({
|
||||
...junction,
|
||||
connections: junction.connections.filter(
|
||||
(connection) => connection.pathId !== pathId
|
||||
)
|
||||
})
|
||||
])
|
||||
.filter(([, junction]) => junction.connections.length >= 2)
|
||||
);
|
||||
const nextJunctions: Record<string, SplineCorridorJunction> = {};
|
||||
|
||||
for (const [junctionId, junction] of Object.entries(
|
||||
currentDocument.splineCorridorJunctions
|
||||
)) {
|
||||
const connections = junction.connections.filter(
|
||||
(connection) => connection.pathId !== pathId
|
||||
);
|
||||
|
||||
if (connections.length < 2) {
|
||||
continue;
|
||||
}
|
||||
|
||||
nextJunctions[junctionId] = cloneSplineCorridorJunction({
|
||||
...junction,
|
||||
connections
|
||||
});
|
||||
}
|
||||
|
||||
context.setDocument({
|
||||
...currentDocument,
|
||||
|
||||
51
src/spline-corridor/spline-corridor-clips.ts
Normal file
51
src/spline-corridor/spline-corridor-clips.ts
Normal 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;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user