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.
Files changed (44) hide show
  1. package/dist/core/algorithms/pathFinding.d.ts +2 -2
  2. package/dist/core/algorithms/vehicleMovement.d.ts +24 -19
  3. package/dist/core/engine.d.ts +16 -18
  4. package/dist/core/index.d.ts +2 -1
  5. package/dist/core/snapshot.d.ts +39 -0
  6. package/dist/core/types/api.d.ts +9 -0
  7. package/dist/core/types/movement.d.ts +2 -3
  8. package/dist/core/types/vehicle.d.ts +4 -2
  9. package/dist/core.cjs +1 -1
  10. package/dist/core.js +51 -240
  11. package/dist/index-D8o0W80x.js +732 -0
  12. package/dist/index-DfPg-M5u.cjs +1 -0
  13. package/dist/index.d.ts +2 -33
  14. package/dist/utils/event-emitter.d.ts +4 -6
  15. package/dist/vehicle-path.cjs +1 -1
  16. package/dist/vehicle-path.js +29 -61
  17. package/package.json +1 -21
  18. package/dist/animation-loop-bZEm2pMN.js +0 -37
  19. package/dist/animation-loop-fC2LjxCd.cjs +0 -1
  20. package/dist/react/dsl-hooks/useInitialMovement.d.ts +0 -24
  21. package/dist/react/dsl-hooks/useMovementSequence.d.ts +0 -27
  22. package/dist/react/dsl-hooks/useSceneDefinition.d.ts +0 -22
  23. package/dist/react/hooks/useAnimation.d.ts +0 -47
  24. package/dist/react/hooks/useMovementQueue.d.ts +0 -53
  25. package/dist/react/hooks/useScene.d.ts +0 -78
  26. package/dist/react/hooks/useVehicleSimulation.d.ts +0 -128
  27. package/dist/react/hooks/useVehicles.d.ts +0 -55
  28. package/dist/react/index.d.ts +0 -48
  29. package/dist/react/providers/useVehicleEvents.d.ts +0 -78
  30. package/dist/react.cjs +0 -1
  31. package/dist/react.js +0 -18
  32. package/dist/useVehicleEvents-Bp4v5sln.cjs +0 -3
  33. package/dist/useVehicleEvents-C0uaNzNP.js +0 -940
  34. package/dist/utils/animation-loop.d.ts +0 -105
  35. package/dist/utils/dsl-parser.d.ts +0 -151
  36. package/dist/utils/index.d.ts +0 -15
  37. package/dist/utils/type-converters.d.ts +0 -40
  38. package/dist/utils/vehicle-helpers.d.ts +0 -8
  39. package/dist/utils.cjs +0 -1
  40. package/dist/utils.js +0 -17
  41. package/dist/vehicle-helpers-DQ-OThWd.js +0 -275
  42. package/dist/vehicle-helpers-DrCYMVs4.cjs +0 -7
  43. package/dist/vehicleMovement-BiYBE_2a.cjs +0 -1
  44. 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, wheelbase: number): 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, wheelbase: number): 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 both axles of a vehicle by `distance` along a prepared path.
186
+ * Advance semua axle vehicle oleh `distance` sepanjang path.
177
187
  *
178
- * This is the low-level tick primitive. It updates both rear and front axles
179
- * using arc-length parameterization and returns whether the rear axle has
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 rear - Current rear axle state
183
- * @param front - Current front axle state
184
- * @param rearExecution - Current rear axle execution position in path
185
- * @param frontExecution - Current front axle execution position in path
186
- * @param path - The path to follow
187
- * @param distance - Distance to advance this tick
188
- * @param linesMap - Scene lines map for position calculation
189
- * @param curveDataMap - Pre-built bezier curve data for the path's curve segments
190
- * @returns Updated axle states, execution states, and arrival flag
191
- */
192
- export declare function moveVehicle(rear: AxleState, front: AxleState, rearExecution: AxleExecutionState, frontExecution: AxleExecutionState, path: PathResult, distance: number, linesMap: Map<string, Line>, curveDataMap: Map<number, CurveData>): {
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
  };
@@ -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
- wheelbase: number;
33
+ maxWheelbase: number;
34
34
  tangentMode: TangentMode;
35
35
  }
36
36
  /**
37
- * Simplified dual-axle position state for use with PathEngine.
38
- * A flatter alternative to the internal Vehicle type.
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
- rear: {
41
+ axles: Array<{
42
42
  lineId: string;
43
43
  offset: number;
44
44
  position: Point;
45
- };
46
- front: {
47
- lineId: string;
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
- rearSegmentIndex: number;
60
- rearSegmentDistance: number;
61
- frontSegmentIndex: number;
62
- frontSegmentDistance: number;
63
- /** Resolved absolute target offset for rear axle arrival detection */
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 dual-axle position on a line.
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 offset - Absolute distance offset along the line
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, offset: number): VehiclePathState | null;
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
  *
@@ -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, calculateInitialFrontPosition, type InitializationResult, updateAxlePosition, calculatePositionOnLine, calculatePositionOnCurve, calculateFrontAxlePosition, getCumulativeArcLength, arcLengthToSegmentPosition, prepareCommandPath, type PreparedPath, handleArrival, type SegmentCompletionContext, type SegmentCompletionResult, type SegmentVehicleState, moveVehicle, getPositionFromOffset, getLineLength } from './algorithms/vehicleMovement';
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;
@@ -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
- rear: AxleExecutionState;
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
- wheelbase: number;
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
- rear: AxleState;
36
- front: AxleState;
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 t=require("./vehicleMovement-BiYBE_2a.cjs");class g{graph=null;linesMap=new Map;curves=[];config;constructor(e){this.config={wheelbase:e.wheelbase,tangentMode:e.tangentMode}}get movementConfig(){return this.config}get lines(){return Array.from(this.linesMap.values())}getCurves(){return this.curves}setScene(e,i){this.linesMap.clear();for(const n of e)this.linesMap.set(n.id,n);this.curves=i,this.graph=t.buildGraph(e,i,this.config)}addLine(e){return this.linesMap.has(e.id)?!1:(this.linesMap.set(e.id,e),this.graph=t.buildGraph(Array.from(this.linesMap.values()),this.curves,this.config),!0)}updateLine(e,i){const n=this.linesMap.get(e);return n?(i.start&&(n.start=i.start),i.end&&(n.end=i.end),this.graph=t.buildGraph(Array.from(this.linesMap.values()),this.curves,this.config),!0):!1}updateLineEndpoint(e,i,n){return this.updateLine(e,{[i]:n})}renameLine(e,i){const n=i.trim();if(!n)return{success:!1,error:"Name cannot be empty"};if(n===e)return{success:!0};if(this.linesMap.has(n))return{success:!1,error:`"${n}" already exists`};const a=this.linesMap.get(e);if(!a)return{success:!1,error:`Line "${e}" not found`};a.id=n,this.linesMap.delete(e),this.linesMap.set(n,a);for(const s of this.curves)s.fromLineId===e&&(s.fromLineId=n),s.toLineId===e&&(s.toLineId=n);return this.graph=t.buildGraph(Array.from(this.linesMap.values()),this.curves,this.config),{success:!0}}removeLine(e){return this.linesMap.has(e)?(this.linesMap.delete(e),this.curves=this.curves.filter(i=>i.fromLineId!==e&&i.toLineId!==e),this.graph=t.buildGraph(Array.from(this.linesMap.values()),this.curves,this.config),!0):!1}addCurve(e){this.curves.push(e),this.graph=t.buildGraph(Array.from(this.linesMap.values()),this.curves,this.config)}updateCurve(e,i){return e<0||e>=this.curves.length?!1:(this.curves[e]={...this.curves[e],...i},this.graph=t.buildGraph(Array.from(this.linesMap.values()),this.curves,this.config),!0)}removeCurve(e){return e<0||e>=this.curves.length?!1:(this.curves.splice(e,1),this.graph=t.buildGraph(Array.from(this.linesMap.values()),this.curves,this.config),!0)}initializeVehicle(e,i){const n=this.linesMap.get(e);if(!n)return null;const a=t.getLineLength(n),s=Math.min(i,a-this.config.wheelbase),l=t.getPositionFromOffset(n,s),o=t.calculateInitialFrontPosition(e,s,this.config.wheelbase,n);return{rear:{lineId:e,offset:s,position:l},front:{lineId:o.lineId,offset:o.absoluteOffset,position:o.position}}}preparePath(e,i,n,a=!1){if(!this.graph)return null;const s={lineId:e.rear.lineId,offset:e.rear.offset,rear:{lineId:e.rear.lineId,position:e.rear.position,absoluteOffset:e.rear.offset},front:{lineId:e.front.lineId,position:e.front.position,absoluteOffset:e.front.offset}},l={targetLineId:i,targetOffset:n,isPercentage:a},o={graph:this.graph,linesMap:this.linesMap,curves:this.curves,config:this.config},r=t.prepareCommandPath(s,l,o);if(!r)return null;let c=n;const f=this.linesMap.get(i);if(f){const u=t.getLineLength(f),h=Math.max(0,u-this.config.wheelbase);c=a?n*h:Math.min(n,h)}return{path:r.path,curveDataMap:r.curveDataMap,rearSegmentIndex:0,rearSegmentDistance:0,frontSegmentIndex:0,frontSegmentDistance:this.config.wheelbase,targetLineId:i,targetOffset:c}}moveVehicle(e,i,n){const a={lineId:e.rear.lineId,position:e.rear.position,absoluteOffset:e.rear.offset},s={lineId:e.front.lineId,position:e.front.position,absoluteOffset:e.front.offset},l={currentSegmentIndex:i.rearSegmentIndex,segmentDistance:i.rearSegmentDistance},o={currentSegmentIndex:i.frontSegmentIndex,segmentDistance:i.frontSegmentDistance},r=t.moveVehicle(a,s,l,o,i.path,n,this.linesMap,i.curveDataMap);return{state:{rear:{lineId:r.rear.lineId,offset:r.rear.absoluteOffset,position:r.rear.position},front:{lineId:r.front.lineId,offset:r.front.absoluteOffset,position:r.front.position}},execution:{...i,rearSegmentIndex:r.rearExecution.currentSegmentIndex,rearSegmentDistance:r.rearExecution.segmentDistance,frontSegmentIndex:r.frontExecution.currentSegmentIndex,frontSegmentDistance:r.frontExecution.segmentDistance},arrived:r.arrived}}}exports.arcLengthToSegmentPosition=t.arcLengthToSegmentPosition;exports.buildArcLengthTable=t.buildArcLengthTable;exports.buildGraph=t.buildGraph;exports.calculateBezierArcLength=t.calculateBezierArcLength;exports.calculateFrontAxlePosition=t.calculateFrontAxlePosition;exports.calculateInitialFrontPosition=t.calculateInitialFrontPosition;exports.calculatePositionOnCurve=t.calculatePositionOnCurve;exports.calculatePositionOnLine=t.calculatePositionOnLine;exports.calculateTangentLength=t.calculateTangentLength;exports.createBezierCurve=t.createBezierCurve;exports.createInitialMovementState=t.createInitialMovementState;exports.distance=t.distance;exports.distanceToT=t.distanceToT;exports.findPath=t.findPath;exports.getArcLength=t.getArcLength;exports.getCumulativeArcLength=t.getCumulativeArcLength;exports.getLineLength=t.getLineLength;exports.getPointOnBezier=t.getPointOnBezier;exports.getPointOnLine=t.getPointOnLine;exports.getPointOnLineByOffset=t.getPointOnLineByOffset;exports.getPositionFromOffset=t.getPositionFromOffset;exports.handleArrival=t.handleArrival;exports.initializeAllVehicles=t.initializeAllVehicles;exports.initializeMovingVehicle=t.initializeMovingVehicle;exports.isPointNearPoint=t.isPointNearPoint;exports.moveVehicle=t.moveVehicle;exports.normalize=t.normalize;exports.prepareCommandPath=t.prepareCommandPath;exports.resolveFromLineOffset=t.resolveFromLineOffset;exports.resolveToLineOffset=t.resolveToLineOffset;exports.updateAxlePosition=t.updateAxlePosition;exports.PathEngine=g;
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 { c as a, p as u, t as p, f as m, z as v, x as d } from "./vehicleMovement-TkCt4q_a.js";
2
- import { a as O, b as P, d as x, e as D, g as y, h as S, D as C, i as E, j as w, k as z, l as T, m as B, n as V, o as F, q as N, r as $, s as j, u as k, v as q, w as G, E as H, y as J, A as K, B as Q, C as R } from "./vehicleMovement-TkCt4q_a.js";
3
- class I {
4
- graph = null;
5
- linesMap = /* @__PURE__ */ new Map();
6
- curves = [];
7
- config;
8
- constructor(e) {
9
- this.config = {
10
- wheelbase: e.wheelbase,
11
- tangentMode: e.tangentMode
12
- };
13
- }
14
- // ---------------------------------------------------------------------------
15
- // Accessors
16
- // ---------------------------------------------------------------------------
17
- get movementConfig() {
18
- return this.config;
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
- I as PathEngine,
212
- O as arcLengthToSegmentPosition,
213
- P as buildArcLengthTable,
214
- a as buildGraph,
215
- x as calculateBezierArcLength,
216
- D as calculateFrontAxlePosition,
217
- m as calculateInitialFrontPosition,
218
- y as calculatePositionOnCurve,
219
- S as calculatePositionOnLine,
220
- C as calculateTangentLength,
221
- E as createBezierCurve,
222
- w as createInitialMovementState,
223
- z as distance,
224
- T as distanceToT,
225
- B as findPath,
226
- V as getArcLength,
227
- F as getCumulativeArcLength,
228
- u as getLineLength,
229
- N as getPointOnBezier,
230
- $ as getPointOnLine,
231
- j as getPointOnLineByOffset,
232
- p as getPositionFromOffset,
233
- k as handleArrival,
234
- q as initializeAllVehicles,
235
- G as initializeMovingVehicle,
236
- H as isPointNearPoint,
237
- d as moveVehicle,
238
- J as normalize,
239
- v as prepareCommandPath,
240
- K as resolveFromLineOffset,
241
- Q as resolveToLineOffset,
242
- R as updateAxlePosition
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
  };