vehicle-path2 1.0.15 → 2.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/core/algorithms/pathFinding.d.ts +2 -2
- package/dist/core/algorithms/vehicleMovement.d.ts +24 -19
- package/dist/core/engine.d.ts +16 -18
- package/dist/core/index.d.ts +2 -1
- package/dist/core/snapshot.d.ts +39 -0
- package/dist/core/types/api.d.ts +9 -0
- package/dist/core/types/movement.d.ts +2 -3
- package/dist/core/types/vehicle.d.ts +4 -2
- package/dist/core.cjs +1 -1
- package/dist/core.js +51 -240
- package/dist/index-D8o0W80x.js +732 -0
- package/dist/index-DfPg-M5u.cjs +1 -0
- package/dist/index.d.ts +2 -33
- package/dist/utils/event-emitter.d.ts +4 -6
- package/dist/vehicle-path.cjs +1 -1
- package/dist/vehicle-path.js +29 -61
- package/package.json +1 -21
- package/dist/animation-loop-bZEm2pMN.js +0 -37
- package/dist/animation-loop-fC2LjxCd.cjs +0 -1
- package/dist/react/dsl-hooks/useInitialMovement.d.ts +0 -24
- package/dist/react/dsl-hooks/useMovementSequence.d.ts +0 -27
- package/dist/react/dsl-hooks/useSceneDefinition.d.ts +0 -22
- package/dist/react/hooks/useAnimation.d.ts +0 -47
- package/dist/react/hooks/useMovementQueue.d.ts +0 -53
- package/dist/react/hooks/useScene.d.ts +0 -78
- package/dist/react/hooks/useVehicleSimulation.d.ts +0 -128
- package/dist/react/hooks/useVehicles.d.ts +0 -55
- package/dist/react/index.d.ts +0 -48
- package/dist/react/providers/useVehicleEvents.d.ts +0 -78
- package/dist/react.cjs +0 -1
- package/dist/react.js +0 -18
- package/dist/useVehicleEvents-Bp4v5sln.cjs +0 -3
- package/dist/useVehicleEvents-C0uaNzNP.js +0 -940
- package/dist/utils/animation-loop.d.ts +0 -105
- package/dist/utils/dsl-parser.d.ts +0 -151
- package/dist/utils/index.d.ts +0 -15
- package/dist/utils/type-converters.d.ts +0 -40
- package/dist/utils/vehicle-helpers.d.ts +0 -8
- package/dist/utils.cjs +0 -1
- package/dist/utils.js +0 -17
- package/dist/vehicle-helpers-DQ-OThWd.js +0 -275
- package/dist/vehicle-helpers-DrCYMVs4.cjs +0 -7
- package/dist/vehicleMovement-BiYBE_2a.cjs +0 -1
- package/dist/vehicleMovement-TkCt4q_a.js +0 -524
|
@@ -41,7 +41,7 @@ export declare function calculateBezierArcLength(bezier: BezierCurve, segments?:
|
|
|
41
41
|
*
|
|
42
42
|
* Effective range: [wheelbase, lineLength]
|
|
43
43
|
*/
|
|
44
|
-
export declare function resolveFromLineOffset(line: Line, offset: number | undefined, isPercentage: boolean | undefined, defaultPercentage: number,
|
|
44
|
+
export declare function resolveFromLineOffset(line: Line, offset: number | undefined, isPercentage: boolean | undefined, defaultPercentage: number, maxWheelbase: number): number;
|
|
45
45
|
/**
|
|
46
46
|
* Resolve offset untuk TO line (garis tujuan kurva)
|
|
47
47
|
* - 0% → 0 (awal garis)
|
|
@@ -49,7 +49,7 @@ export declare function resolveFromLineOffset(line: Line, offset: number | undef
|
|
|
49
49
|
*
|
|
50
50
|
* Effective range: [0, lineLength - wheelbase]
|
|
51
51
|
*/
|
|
52
|
-
export declare function resolveToLineOffset(line: Line, offset: number | undefined, isPercentage: boolean | undefined, defaultPercentage: number,
|
|
52
|
+
export declare function resolveToLineOffset(line: Line, offset: number | undefined, isPercentage: boolean | undefined, defaultPercentage: number, maxWheelbase: number): number;
|
|
53
53
|
/**
|
|
54
54
|
* Membangun graph dari lines dan curves
|
|
55
55
|
*/
|
|
@@ -55,6 +55,16 @@ export declare function calculateFrontAxlePosition(path: PathResult, rearSegment
|
|
|
55
55
|
segmentIndex: number;
|
|
56
56
|
segmentDistance: number;
|
|
57
57
|
} | null;
|
|
58
|
+
/**
|
|
59
|
+
* Hitung posisi awal semua axle dari posisi rearmost axle.
|
|
60
|
+
*
|
|
61
|
+
* @param lineId - Line ID tempat vehicle diinisialisasi
|
|
62
|
+
* @param rearOffset - Absolute offset axle paling belakang (axles[N-1])
|
|
63
|
+
* @param axleSpacings - Jarak antar axle berurutan (N-1 nilai untuk N axle)
|
|
64
|
+
* @param line - Line object untuk kalkulasi posisi
|
|
65
|
+
* @returns Array AxleState, axles[0] = terdepan, axles[N-1] = paling belakang
|
|
66
|
+
*/
|
|
67
|
+
export declare function calculateInitialAxlePositions(lineId: string, rearOffset: number, axleSpacings: number[], line: Line): AxleState[];
|
|
58
68
|
/**
|
|
59
69
|
* Calculate initial front axle position from rear position
|
|
60
70
|
*
|
|
@@ -173,26 +183,21 @@ export interface SegmentCompletionResult {
|
|
|
173
183
|
export declare function handleArrival(state: VehicleMovementState, ctx: SegmentCompletionContext): SegmentCompletionResult;
|
|
174
184
|
export type { VehicleMovementState as SegmentVehicleState };
|
|
175
185
|
/**
|
|
176
|
-
* Advance
|
|
186
|
+
* Advance semua axle vehicle oleh `distance` sepanjang path.
|
|
177
187
|
*
|
|
178
|
-
*
|
|
179
|
-
*
|
|
180
|
-
* reached the end of the path (arrived).
|
|
188
|
+
* Ini adalah low-level tick primitive. Update semua axle menggunakan
|
|
189
|
+
* arc-length parameterization. Arrival = axles[0] (terdepan) mencapai ujung path.
|
|
181
190
|
*
|
|
182
|
-
* @param
|
|
183
|
-
* @param
|
|
184
|
-
* @param
|
|
185
|
-
* @param
|
|
186
|
-
* @param
|
|
187
|
-
* @param
|
|
188
|
-
* @
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
rear: AxleState;
|
|
194
|
-
front: AxleState;
|
|
195
|
-
rearExecution: AxleExecutionState;
|
|
196
|
-
frontExecution: AxleExecutionState;
|
|
191
|
+
* @param axleStates - Array AxleState saat ini, axles[0] = terdepan
|
|
192
|
+
* @param axleExecutions - Array AxleExecutionState sesuai urutan axleStates
|
|
193
|
+
* @param path - Path yang diikuti
|
|
194
|
+
* @param distance - Jarak yang dimaju per tick
|
|
195
|
+
* @param linesMap - Map line ID ke Line object
|
|
196
|
+
* @param curveDataMap - Pre-built bezier curve data
|
|
197
|
+
* @returns Updated axles, axleExecutions, dan arrival flag
|
|
198
|
+
*/
|
|
199
|
+
export declare function moveVehicle(axleStates: AxleState[], axleExecutions: AxleExecutionState[], path: PathResult, distance: number, linesMap: Map<string, Line>, curveDataMap: Map<number, CurveData>): {
|
|
200
|
+
axles: AxleState[];
|
|
201
|
+
axleExecutions: AxleExecutionState[];
|
|
197
202
|
arrived: boolean;
|
|
198
203
|
};
|
package/dist/core/engine.d.ts
CHANGED
|
@@ -30,24 +30,21 @@ import type { MovementConfig, CurveData } from './types/movement';
|
|
|
30
30
|
import type { PathResult } from './algorithms/pathFinding';
|
|
31
31
|
import type { TangentMode } from './types/config';
|
|
32
32
|
export interface PathEngineConfig {
|
|
33
|
-
|
|
33
|
+
maxWheelbase: number;
|
|
34
34
|
tangentMode: TangentMode;
|
|
35
35
|
}
|
|
36
36
|
/**
|
|
37
|
-
*
|
|
38
|
-
*
|
|
37
|
+
* Multi-axle position state for use with PathEngine.
|
|
38
|
+
* axles[0] = terdepan, axles[N-1] = paling belakang.
|
|
39
39
|
*/
|
|
40
40
|
export interface VehiclePathState {
|
|
41
|
-
|
|
41
|
+
axles: Array<{
|
|
42
42
|
lineId: string;
|
|
43
43
|
offset: number;
|
|
44
44
|
position: Point;
|
|
45
|
-
}
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
offset: number;
|
|
49
|
-
position: Point;
|
|
50
|
-
};
|
|
45
|
+
}>;
|
|
46
|
+
/** N-1 jarak arc-length antar axle berurutan */
|
|
47
|
+
axleSpacings: number[];
|
|
51
48
|
}
|
|
52
49
|
/**
|
|
53
50
|
* Active path execution state for a vehicle in motion.
|
|
@@ -56,11 +53,11 @@ export interface VehiclePathState {
|
|
|
56
53
|
export interface PathExecution {
|
|
57
54
|
path: PathResult;
|
|
58
55
|
curveDataMap: Map<number, CurveData>;
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
56
|
+
/** Execution state per axle, sesuai urutan VehiclePathState.axles */
|
|
57
|
+
axleExecutions: Array<{
|
|
58
|
+
segmentIndex: number;
|
|
59
|
+
segmentDistance: number;
|
|
60
|
+
}>;
|
|
64
61
|
targetLineId: string;
|
|
65
62
|
targetOffset: number;
|
|
66
63
|
}
|
|
@@ -126,13 +123,14 @@ export declare class PathEngine {
|
|
|
126
123
|
*/
|
|
127
124
|
removeCurve(index: number): boolean;
|
|
128
125
|
/**
|
|
129
|
-
* Initialize a vehicle's
|
|
126
|
+
* Initialize a vehicle's N-axle position on a line.
|
|
130
127
|
*
|
|
131
128
|
* @param lineId - The line to place the vehicle on
|
|
132
|
-
* @param
|
|
129
|
+
* @param rearOffset - Absolute distance offset untuk axle paling belakang
|
|
130
|
+
* @param axleSpacings - Jarak antar axle berurutan (N-1 nilai untuk N axle)
|
|
133
131
|
* @returns Initial VehiclePathState, or null if lineId does not exist
|
|
134
132
|
*/
|
|
135
|
-
initializeVehicle(lineId: string,
|
|
133
|
+
initializeVehicle(lineId: string, rearOffset: number, axleSpacings: number[]): VehiclePathState | null;
|
|
136
134
|
/**
|
|
137
135
|
* Prepare a path from the vehicle's current position to a target.
|
|
138
136
|
*
|
package/dist/core/index.d.ts
CHANGED
|
@@ -16,6 +16,7 @@ export type { CurveData, AxleExecutionState, PathExecutionState, VehicleMovement
|
|
|
16
16
|
export type { TangentMode } from './types/config';
|
|
17
17
|
export type { CoordinateInput, SceneLineInput, SceneConnectionInput, SceneConfig, VehicleInput, VehicleUpdateInput, ConnectionUpdateInput, GotoCommandInput } from './types/api';
|
|
18
18
|
export { buildGraph, findPath, calculateBezierArcLength, resolveFromLineOffset, resolveToLineOffset, type Graph, type GraphEdge, type PathSegment, type PathResult, type VehiclePosition } from './algorithms/pathFinding';
|
|
19
|
-
export { initializeMovingVehicle, createInitialMovementState, initializeAllVehicles,
|
|
19
|
+
export { initializeMovingVehicle, createInitialMovementState, initializeAllVehicles, calculateInitialAxlePositions, type InitializationResult, updateAxlePosition, calculatePositionOnLine, calculatePositionOnCurve, calculateFrontAxlePosition, getCumulativeArcLength, arcLengthToSegmentPosition, prepareCommandPath, type PreparedPath, handleArrival, type SegmentCompletionContext, type SegmentCompletionResult, type SegmentVehicleState, moveVehicle, getPositionFromOffset, getLineLength } from './algorithms/vehicleMovement';
|
|
20
20
|
export { PathEngine, type PathEngineConfig, type VehiclePathState, type PathExecution } from './engine';
|
|
21
21
|
export { distance, normalize, getPointOnLine, getPointOnLineByOffset, getPointOnBezier, createBezierCurve, buildArcLengthTable, distanceToT, getArcLength, calculateTangentLength, isPointNearPoint, type ArcLengthEntry, type CurveOffsetOptions } from './algorithms/math';
|
|
22
|
+
export { serializeScene, type SceneSnapshot } from './snapshot';
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
import type { Line } from './types/geometry';
|
|
2
|
+
export interface SceneSnapshot {
|
|
3
|
+
lines: Line[];
|
|
4
|
+
curves: Array<{
|
|
5
|
+
id: string;
|
|
6
|
+
fromLineId: string;
|
|
7
|
+
toLineId: string;
|
|
8
|
+
fromOffset: number;
|
|
9
|
+
toOffset: number;
|
|
10
|
+
}>;
|
|
11
|
+
vehicles: Array<{
|
|
12
|
+
id: string;
|
|
13
|
+
axles: Array<{
|
|
14
|
+
lineId: string;
|
|
15
|
+
offset: number;
|
|
16
|
+
}>;
|
|
17
|
+
axleSpacings: number[];
|
|
18
|
+
}>;
|
|
19
|
+
}
|
|
20
|
+
/**
|
|
21
|
+
* Serialize scene state to a JSON string suitable for clipboard or storage.
|
|
22
|
+
* Strips derived fields (bezier curves, axle positions) — only source-of-truth
|
|
23
|
+
* data is included.
|
|
24
|
+
*/
|
|
25
|
+
export declare function serializeScene(lines: Line[], curves: Array<{
|
|
26
|
+
id: string;
|
|
27
|
+
fromLineId: string;
|
|
28
|
+
toLineId: string;
|
|
29
|
+
fromOffset: number;
|
|
30
|
+
toOffset: number;
|
|
31
|
+
}>, vehicles: Array<{
|
|
32
|
+
id: string;
|
|
33
|
+
axles: Array<{
|
|
34
|
+
lineId: string;
|
|
35
|
+
offset: number;
|
|
36
|
+
[key: string]: unknown;
|
|
37
|
+
}>;
|
|
38
|
+
axleSpacings: number[];
|
|
39
|
+
}>): string;
|
package/dist/core/types/api.d.ts
CHANGED
|
@@ -70,6 +70,15 @@ export interface VehicleInput {
|
|
|
70
70
|
lineId: string;
|
|
71
71
|
position?: number;
|
|
72
72
|
isPercentage?: boolean;
|
|
73
|
+
/**
|
|
74
|
+
* Jarak arc-length antar axle berurutan.
|
|
75
|
+
* axleSpacings[i] = jarak antara axles[i] dan axles[i+1].
|
|
76
|
+
* axles[0] = terdepan, axles[N-1] = paling belakang.
|
|
77
|
+
* Contoh truk biasa: [30] → 2 axle, jarak 30px
|
|
78
|
+
* Contoh truck+trailer: [20, 45] → 3 axle
|
|
79
|
+
* Total panjang vehicle = sum(axleSpacings) harus ≤ maxWheelbase
|
|
80
|
+
*/
|
|
81
|
+
axleSpacings: number[];
|
|
73
82
|
}
|
|
74
83
|
/**
|
|
75
84
|
* Vehicle update input for updateVehicle()
|
|
@@ -27,8 +27,7 @@ export interface PathExecutionState {
|
|
|
27
27
|
path: import('../algorithms/pathFinding').PathResult;
|
|
28
28
|
curveDataMap: Map<number, CurveData>;
|
|
29
29
|
currentCommandIndex: number;
|
|
30
|
-
|
|
31
|
-
front: AxleExecutionState;
|
|
30
|
+
axles: AxleExecutionState[];
|
|
32
31
|
}
|
|
33
32
|
/**
|
|
34
33
|
* Movement state container for a vehicle
|
|
@@ -41,7 +40,7 @@ export interface VehicleMovementState {
|
|
|
41
40
|
* Configuration for vehicle movement
|
|
42
41
|
*/
|
|
43
42
|
export interface MovementConfig {
|
|
44
|
-
|
|
43
|
+
maxWheelbase: number;
|
|
45
44
|
tangentMode: TangentMode;
|
|
46
45
|
}
|
|
47
46
|
/**
|
|
@@ -14,6 +14,8 @@ export interface VehicleStart {
|
|
|
14
14
|
lineId: string;
|
|
15
15
|
offset: number;
|
|
16
16
|
isPercentage: boolean;
|
|
17
|
+
/** Optional: defaults to [maxWheelbase] jika tidak disediakan */
|
|
18
|
+
axleSpacings?: number[];
|
|
17
19
|
}
|
|
18
20
|
/**
|
|
19
21
|
* State for a single axle (Front or Rear)
|
|
@@ -32,8 +34,8 @@ export interface Vehicle {
|
|
|
32
34
|
offset: number;
|
|
33
35
|
isPercentage: boolean;
|
|
34
36
|
state: VehicleState;
|
|
35
|
-
|
|
36
|
-
|
|
37
|
+
axles: AxleState[];
|
|
38
|
+
axleSpacings: number[];
|
|
37
39
|
}
|
|
38
40
|
/**
|
|
39
41
|
* Command to move a vehicle to a target position
|
package/dist/core.cjs
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const
|
|
1
|
+
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const e=require("./index-DfPg-M5u.cjs");function r(n,a,o){const l={lines:n,curves:a.map(i=>({id:i.id,fromLineId:i.fromLineId,toLineId:i.toLineId,fromOffset:i.fromOffset,toOffset:i.toOffset})),vehicles:o.map(i=>({id:i.id,axles:i.axles.map(t=>({lineId:t.lineId,offset:t.offset})),axleSpacings:i.axleSpacings}))};return JSON.stringify(l,null,2)}exports.PathEngine=e.PathEngine;exports.arcLengthToSegmentPosition=e.arcLengthToSegmentPosition;exports.buildArcLengthTable=e.buildArcLengthTable;exports.buildGraph=e.buildGraph;exports.calculateBezierArcLength=e.calculateBezierArcLength;exports.calculateFrontAxlePosition=e.calculateFrontAxlePosition;exports.calculateInitialAxlePositions=e.calculateInitialAxlePositions;exports.calculatePositionOnCurve=e.calculatePositionOnCurve;exports.calculatePositionOnLine=e.calculatePositionOnLine;exports.calculateTangentLength=e.calculateTangentLength;exports.createBezierCurve=e.createBezierCurve;exports.createInitialMovementState=e.createInitialMovementState;exports.distance=e.distance;exports.distanceToT=e.distanceToT;exports.findPath=e.findPath;exports.getArcLength=e.getArcLength;exports.getCumulativeArcLength=e.getCumulativeArcLength;exports.getLineLength=e.getLineLength;exports.getPointOnBezier=e.getPointOnBezier;exports.getPointOnLine=e.getPointOnLine;exports.getPointOnLineByOffset=e.getPointOnLineByOffset;exports.getPositionFromOffset=e.getPositionFromOffset;exports.handleArrival=e.handleArrival;exports.initializeAllVehicles=e.initializeAllVehicles;exports.initializeMovingVehicle=e.initializeMovingVehicle;exports.isPointNearPoint=e.isPointNearPoint;exports.moveVehicle=e.moveVehicle;exports.normalize=e.normalize;exports.prepareCommandPath=e.prepareCommandPath;exports.resolveFromLineOffset=e.resolveFromLineOffset;exports.resolveToLineOffset=e.resolveToLineOffset;exports.updateAxlePosition=e.updateAxlePosition;exports.serializeScene=r;
|
package/dist/core.js
CHANGED
|
@@ -1,243 +1,54 @@
|
|
|
1
|
-
import {
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
}
|
|
20
|
-
get lines() {
|
|
21
|
-
return Array.from(this.linesMap.values());
|
|
22
|
-
}
|
|
23
|
-
getCurves() {
|
|
24
|
-
return this.curves;
|
|
25
|
-
}
|
|
26
|
-
// ---------------------------------------------------------------------------
|
|
27
|
-
// Scene management
|
|
28
|
-
// ---------------------------------------------------------------------------
|
|
29
|
-
/**
|
|
30
|
-
* Replace the entire scene and rebuild the graph.
|
|
31
|
-
*/
|
|
32
|
-
setScene(e, t) {
|
|
33
|
-
this.linesMap.clear();
|
|
34
|
-
for (const s of e)
|
|
35
|
-
this.linesMap.set(s.id, s);
|
|
36
|
-
this.curves = t, this.graph = a(e, t, this.config);
|
|
37
|
-
}
|
|
38
|
-
/**
|
|
39
|
-
* Add a single line. Returns false if a line with the same ID already exists.
|
|
40
|
-
*/
|
|
41
|
-
addLine(e) {
|
|
42
|
-
return this.linesMap.has(e.id) ? !1 : (this.linesMap.set(e.id, e), this.graph = a(Array.from(this.linesMap.values()), this.curves, this.config), !0);
|
|
43
|
-
}
|
|
44
|
-
/**
|
|
45
|
-
* Update start and/or end coordinates of an existing line.
|
|
46
|
-
*/
|
|
47
|
-
updateLine(e, t) {
|
|
48
|
-
const s = this.linesMap.get(e);
|
|
49
|
-
return s ? (t.start && (s.start = t.start), t.end && (s.end = t.end), this.graph = a(Array.from(this.linesMap.values()), this.curves, this.config), !0) : !1;
|
|
50
|
-
}
|
|
51
|
-
/**
|
|
52
|
-
* Update a single endpoint ('start' or 'end') of a line.
|
|
53
|
-
*/
|
|
54
|
-
updateLineEndpoint(e, t, s) {
|
|
55
|
-
return this.updateLine(e, { [t]: s });
|
|
56
|
-
}
|
|
57
|
-
/**
|
|
58
|
-
* Rename a line ID and cascade the change to all connected curves.
|
|
59
|
-
*/
|
|
60
|
-
renameLine(e, t) {
|
|
61
|
-
const s = t.trim();
|
|
62
|
-
if (!s) return { success: !1, error: "Name cannot be empty" };
|
|
63
|
-
if (s === e) return { success: !0 };
|
|
64
|
-
if (this.linesMap.has(s)) return { success: !1, error: `"${s}" already exists` };
|
|
65
|
-
const i = this.linesMap.get(e);
|
|
66
|
-
if (!i) return { success: !1, error: `Line "${e}" not found` };
|
|
67
|
-
i.id = s, this.linesMap.delete(e), this.linesMap.set(s, i);
|
|
68
|
-
for (const r of this.curves)
|
|
69
|
-
r.fromLineId === e && (r.fromLineId = s), r.toLineId === e && (r.toLineId = s);
|
|
70
|
-
return this.graph = a(Array.from(this.linesMap.values()), this.curves, this.config), { success: !0 };
|
|
71
|
-
}
|
|
72
|
-
/**
|
|
73
|
-
* Remove a line and all curves connected to it.
|
|
74
|
-
*/
|
|
75
|
-
removeLine(e) {
|
|
76
|
-
return this.linesMap.has(e) ? (this.linesMap.delete(e), this.curves = this.curves.filter((t) => t.fromLineId !== e && t.toLineId !== e), this.graph = a(Array.from(this.linesMap.values()), this.curves, this.config), !0) : !1;
|
|
77
|
-
}
|
|
78
|
-
/**
|
|
79
|
-
* Add a directional curve (connection) from one line to another.
|
|
80
|
-
*/
|
|
81
|
-
addCurve(e) {
|
|
82
|
-
this.curves.push(e), this.graph = a(Array.from(this.linesMap.values()), this.curves, this.config);
|
|
83
|
-
}
|
|
84
|
-
/**
|
|
85
|
-
* Update a curve by index. Returns false if index is out of bounds.
|
|
86
|
-
*/
|
|
87
|
-
updateCurve(e, t) {
|
|
88
|
-
return e < 0 || e >= this.curves.length ? !1 : (this.curves[e] = { ...this.curves[e], ...t }, this.graph = a(Array.from(this.linesMap.values()), this.curves, this.config), !0);
|
|
89
|
-
}
|
|
90
|
-
/**
|
|
91
|
-
* Remove a curve by index. Returns false if index is out of bounds.
|
|
92
|
-
*/
|
|
93
|
-
removeCurve(e) {
|
|
94
|
-
return e < 0 || e >= this.curves.length ? !1 : (this.curves.splice(e, 1), this.graph = a(Array.from(this.linesMap.values()), this.curves, this.config), !0);
|
|
95
|
-
}
|
|
96
|
-
// ---------------------------------------------------------------------------
|
|
97
|
-
// Vehicle operations
|
|
98
|
-
// ---------------------------------------------------------------------------
|
|
99
|
-
/**
|
|
100
|
-
* Initialize a vehicle's dual-axle position on a line.
|
|
101
|
-
*
|
|
102
|
-
* @param lineId - The line to place the vehicle on
|
|
103
|
-
* @param offset - Absolute distance offset along the line
|
|
104
|
-
* @returns Initial VehiclePathState, or null if lineId does not exist
|
|
105
|
-
*/
|
|
106
|
-
initializeVehicle(e, t) {
|
|
107
|
-
const s = this.linesMap.get(e);
|
|
108
|
-
if (!s) return null;
|
|
109
|
-
const i = u(s), r = Math.min(t, i - this.config.wheelbase), f = p(s, r), o = m(e, r, this.config.wheelbase, s);
|
|
110
|
-
return {
|
|
111
|
-
rear: { lineId: e, offset: r, position: f },
|
|
112
|
-
front: { lineId: o.lineId, offset: o.absoluteOffset, position: o.position }
|
|
113
|
-
};
|
|
114
|
-
}
|
|
115
|
-
/**
|
|
116
|
-
* Prepare a path from the vehicle's current position to a target.
|
|
117
|
-
*
|
|
118
|
-
* Must be called before moveVehicle(). Returns null if no path exists.
|
|
119
|
-
*
|
|
120
|
-
* @param vehicleState - Current vehicle state (from initializeVehicle or previous tick)
|
|
121
|
-
* @param targetLineId - ID of the target line
|
|
122
|
-
* @param targetOffset - Position on the target line
|
|
123
|
-
* @param isPercentage - If true, targetOffset is 0-1 fraction; if false, absolute distance
|
|
124
|
-
*/
|
|
125
|
-
preparePath(e, t, s, i = !1) {
|
|
126
|
-
if (!this.graph) return null;
|
|
127
|
-
const r = {
|
|
128
|
-
lineId: e.rear.lineId,
|
|
129
|
-
offset: e.rear.offset,
|
|
130
|
-
rear: {
|
|
131
|
-
lineId: e.rear.lineId,
|
|
132
|
-
position: e.rear.position,
|
|
133
|
-
absoluteOffset: e.rear.offset
|
|
134
|
-
},
|
|
135
|
-
front: {
|
|
136
|
-
lineId: e.front.lineId,
|
|
137
|
-
position: e.front.position,
|
|
138
|
-
absoluteOffset: e.front.offset
|
|
139
|
-
}
|
|
140
|
-
}, f = {
|
|
141
|
-
targetLineId: t,
|
|
142
|
-
targetOffset: s,
|
|
143
|
-
isPercentage: i
|
|
144
|
-
}, o = {
|
|
145
|
-
graph: this.graph,
|
|
146
|
-
linesMap: this.linesMap,
|
|
147
|
-
curves: this.curves,
|
|
148
|
-
config: this.config
|
|
149
|
-
}, n = v(r, f, o);
|
|
150
|
-
if (!n) return null;
|
|
151
|
-
let c = s;
|
|
152
|
-
const l = this.linesMap.get(t);
|
|
153
|
-
if (l) {
|
|
154
|
-
const g = u(l), h = Math.max(0, g - this.config.wheelbase);
|
|
155
|
-
c = i ? s * h : Math.min(s, h);
|
|
156
|
-
}
|
|
157
|
-
return {
|
|
158
|
-
path: n.path,
|
|
159
|
-
curveDataMap: n.curveDataMap,
|
|
160
|
-
rearSegmentIndex: 0,
|
|
161
|
-
rearSegmentDistance: 0,
|
|
162
|
-
frontSegmentIndex: 0,
|
|
163
|
-
frontSegmentDistance: this.config.wheelbase,
|
|
164
|
-
targetLineId: t,
|
|
165
|
-
targetOffset: c
|
|
166
|
-
};
|
|
167
|
-
}
|
|
168
|
-
/**
|
|
169
|
-
* Advance a vehicle by `distance` along its prepared path.
|
|
170
|
-
*
|
|
171
|
-
* Call this every tick. The returned `state` and `execution` replace the
|
|
172
|
-
* previous values. When `arrived` is true, the vehicle has reached the target.
|
|
173
|
-
*
|
|
174
|
-
* @param state - Current vehicle state
|
|
175
|
-
* @param execution - Current path execution (from preparePath or previous tick)
|
|
176
|
-
* @param distance - Distance to advance this tick (speed × deltaTime)
|
|
177
|
-
*/
|
|
178
|
-
moveVehicle(e, t, s) {
|
|
179
|
-
const i = {
|
|
180
|
-
lineId: e.rear.lineId,
|
|
181
|
-
position: e.rear.position,
|
|
182
|
-
absoluteOffset: e.rear.offset
|
|
183
|
-
}, r = {
|
|
184
|
-
lineId: e.front.lineId,
|
|
185
|
-
position: e.front.position,
|
|
186
|
-
absoluteOffset: e.front.offset
|
|
187
|
-
}, f = {
|
|
188
|
-
currentSegmentIndex: t.rearSegmentIndex,
|
|
189
|
-
segmentDistance: t.rearSegmentDistance
|
|
190
|
-
}, o = {
|
|
191
|
-
currentSegmentIndex: t.frontSegmentIndex,
|
|
192
|
-
segmentDistance: t.frontSegmentDistance
|
|
193
|
-
}, n = d(i, r, f, o, t.path, s, this.linesMap, t.curveDataMap);
|
|
194
|
-
return {
|
|
195
|
-
state: {
|
|
196
|
-
rear: { lineId: n.rear.lineId, offset: n.rear.absoluteOffset, position: n.rear.position },
|
|
197
|
-
front: { lineId: n.front.lineId, offset: n.front.absoluteOffset, position: n.front.position }
|
|
198
|
-
},
|
|
199
|
-
execution: {
|
|
200
|
-
...t,
|
|
201
|
-
rearSegmentIndex: n.rearExecution.currentSegmentIndex,
|
|
202
|
-
rearSegmentDistance: n.rearExecution.segmentDistance,
|
|
203
|
-
frontSegmentIndex: n.frontExecution.currentSegmentIndex,
|
|
204
|
-
frontSegmentDistance: n.frontExecution.segmentDistance
|
|
205
|
-
},
|
|
206
|
-
arrived: n.arrived
|
|
207
|
-
};
|
|
208
|
-
}
|
|
1
|
+
import { P as f, a as c, b as g, c as d, d as h, e as m, f as u, g as L, h as P, i as O, j as p, k as v, l as x, m as A, n as z, o as I, p as S, q as T, r as B, s as C, t as b, u as y, v as F, w as V, x as E, y as M, z as N, A as j, B as k, C as q, D as w, E as D } from "./index-D8o0W80x.js";
|
|
2
|
+
function o(i, t, s) {
|
|
3
|
+
const n = {
|
|
4
|
+
lines: i,
|
|
5
|
+
curves: t.map((e) => ({
|
|
6
|
+
id: e.id,
|
|
7
|
+
fromLineId: e.fromLineId,
|
|
8
|
+
toLineId: e.toLineId,
|
|
9
|
+
fromOffset: e.fromOffset,
|
|
10
|
+
toOffset: e.toOffset
|
|
11
|
+
})),
|
|
12
|
+
vehicles: s.map((e) => ({
|
|
13
|
+
id: e.id,
|
|
14
|
+
axles: e.axles.map((a) => ({ lineId: a.lineId, offset: a.offset })),
|
|
15
|
+
axleSpacings: e.axleSpacings
|
|
16
|
+
}))
|
|
17
|
+
};
|
|
18
|
+
return JSON.stringify(n, null, 2);
|
|
209
19
|
}
|
|
210
20
|
export {
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
21
|
+
f as PathEngine,
|
|
22
|
+
c as arcLengthToSegmentPosition,
|
|
23
|
+
g as buildArcLengthTable,
|
|
24
|
+
d as buildGraph,
|
|
25
|
+
h as calculateBezierArcLength,
|
|
26
|
+
m as calculateFrontAxlePosition,
|
|
27
|
+
u as calculateInitialAxlePositions,
|
|
28
|
+
L as calculatePositionOnCurve,
|
|
29
|
+
P as calculatePositionOnLine,
|
|
30
|
+
O as calculateTangentLength,
|
|
31
|
+
p as createBezierCurve,
|
|
32
|
+
v as createInitialMovementState,
|
|
33
|
+
x as distance,
|
|
34
|
+
A as distanceToT,
|
|
35
|
+
z as findPath,
|
|
36
|
+
I as getArcLength,
|
|
37
|
+
S as getCumulativeArcLength,
|
|
38
|
+
T as getLineLength,
|
|
39
|
+
B as getPointOnBezier,
|
|
40
|
+
C as getPointOnLine,
|
|
41
|
+
b as getPointOnLineByOffset,
|
|
42
|
+
y as getPositionFromOffset,
|
|
43
|
+
F as handleArrival,
|
|
44
|
+
V as initializeAllVehicles,
|
|
45
|
+
E as initializeMovingVehicle,
|
|
46
|
+
M as isPointNearPoint,
|
|
47
|
+
N as moveVehicle,
|
|
48
|
+
j as normalize,
|
|
49
|
+
k as prepareCommandPath,
|
|
50
|
+
q as resolveFromLineOffset,
|
|
51
|
+
w as resolveToLineOffset,
|
|
52
|
+
o as serializeScene,
|
|
53
|
+
D as updateAxlePosition
|
|
243
54
|
};
|