vehicle-path2 4.0.1 → 4.0.3

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/README.md CHANGED
@@ -68,39 +68,37 @@ Curve menghubungkan **ujung satu line** ke **awal line lain**. Tidak bisa berdir
68
68
  ```typescript
69
69
  import type { Curve } from 'vehicle-path2/core'
70
70
 
71
- // Tambah curve
72
- engine.addCurve({
71
+ // Tambah curve (returns curve id — auto-generated if not provided)
72
+ const curveId = engine.addCurve({
73
+ id: 'c1', // optional — auto-generated if omitted
73
74
  fromLineId: 'L1',
74
75
  toLineId: 'L2',
75
76
  fromOffset: 380, // posisi di L1 (px dari start)
76
77
  fromIsPercentage: false,
77
78
  toOffset: 20, // posisi di L2 (px dari start)
78
79
  toIsPercentage: false,
79
- } as Curve)
80
-
81
- // Atau dengan offset persentase (0–1)
82
- engine.addCurve({
83
- fromLineId: 'L1',
84
- toLineId: 'L2',
85
- fromOffset: 0.95,
86
- fromIsPercentage: true,
87
- toOffset: 0.05,
88
- toIsPercentage: true,
89
- } as Curve)
80
+ })
90
81
 
91
- // Update curve berdasarkan index
92
- engine.updateCurve(0, { fromOffset: 0.9 })
82
+ // Update curve berdasarkan id
83
+ engine.updateCurve('c1', { fromOffset: 100 })
93
84
 
94
- // Hapus curve berdasarkan index
95
- engine.removeCurve(0)
85
+ // Hapus curve berdasarkan id
86
+ engine.removeCurve('c1')
96
87
 
97
88
  // Baca semua curves
98
89
  engine.getCurves() // → Curve[]
90
+
91
+ // Dapatkan computed bezier untuk rendering
92
+ engine.getCurveBeziers() // → Map<string, BezierCurve>
99
93
  ```
100
94
 
101
- > **Catatan:** Curve diidentifikasi via **array index** (bukan named ID). Gunakan `getCurves()` lalu cari index yang sesuai sebelum update/delete.
95
+ > **Catatan:** Curve diidentifikasi via `id` (string). Jika tidak diberikan saat `addCurve`, id otomatis di-generate.
96
+
97
+ > **Konsekuensi `removeLine`:** Curve yang terhubung ke line yang dihapus otomatis ikut terhapus. `removeLine` mengembalikan `{ success, removedCurveIds }`.
98
+
99
+ > **Path validation:** Gunakan `engine.canReach(fromLineId, fromOffset, toLineId, toOffset)` untuk mengecek apakah path ada tanpa membuat execution plan.
102
100
 
103
- > **Konsekuensi `removeLine`:** Curve yang terhubung ke line yang dihapus otomatis ikut terhapus, sehingga index curve-curve lainnya bisa bergeser.
101
+ > **Acceleration:** Gunakan `engine.moveVehicleWithAcceleration(state, exec, accelState, config, deltaTime)` untuk movement dengan physics-based acceleration/deceleration.
104
102
 
105
103
  ---
106
104
 
@@ -2,11 +2,13 @@ import type { Line, Curve, BezierCurve } from '../types/geometry';
2
2
  import type { MovementConfig } from '../types/movement';
3
3
  export interface GraphEdge {
4
4
  curveIndex: number;
5
+ curveId?: string;
5
6
  fromLineId: string;
6
7
  toLineId: string;
7
8
  fromOffset: number;
8
9
  toOffset: number;
9
10
  curveLength: number;
11
+ bezier: BezierCurve;
10
12
  }
11
13
  export interface Graph {
12
14
  adjacency: Map<string, GraphEdge[]>;
@@ -25,11 +25,12 @@
25
25
  * }
26
26
  * ```
27
27
  */
28
- import type { Line, Curve, Point } from './types/geometry';
28
+ import type { Line, Curve, BezierCurve, Point } from './types/geometry';
29
29
  import type { VehicleDefinition } from './types/vehicle';
30
30
  import type { MovementConfig, CurveData } from './types/movement';
31
- import type { PathResult } from './algorithms/pathFinding';
31
+ import type { PathResult, Graph } from './algorithms/pathFinding';
32
32
  import type { TangentMode } from './types/config';
33
+ import { type AccelerationConfig, type AccelerationState } from './algorithms/acceleration';
33
34
  export interface PathEngineConfig {
34
35
  tangentMode: TangentMode;
35
36
  }
@@ -71,15 +72,29 @@ export { moveVehicle } from './algorithms/vehicleMovement';
71
72
  */
72
73
  export declare class PathEngine {
73
74
  private graph;
75
+ private graphDirty;
74
76
  private linesMap;
75
- private curves;
77
+ private curvesMap;
78
+ private curveSeq;
76
79
  private config;
77
80
  constructor(engineConfig: PathEngineConfig);
81
+ private ensureGraph;
78
82
  get movementConfig(): MovementConfig;
79
83
  get lines(): Line[];
80
84
  getCurves(): Curve[];
81
85
  /**
82
- * Replace the entire scene and rebuild the graph.
86
+ * Expose the graph (lazily built) for consumers that need it
87
+ * (e.g., scene stats, custom pathfinding).
88
+ */
89
+ getGraph(): Graph;
90
+ /**
91
+ * Returns computed bezier for each curve by id.
92
+ * Internally calls ensureGraph() to guarantee beziers are computed,
93
+ * then iterates graph edges to build the return map.
94
+ */
95
+ getCurveBeziers(): Map<string, BezierCurve>;
96
+ /**
97
+ * Replace the entire scene. Graph is rebuilt lazily on first access.
83
98
  */
84
99
  setScene(lines: Line[], curves: Curve[]): void;
85
100
  /**
@@ -88,6 +103,7 @@ export declare class PathEngine {
88
103
  addLine(line: Line): boolean;
89
104
  /**
90
105
  * Update start and/or end coordinates of an existing line.
106
+ * Immutable — does not mutate the original line object.
91
107
  */
92
108
  updateLine(lineId: string, updates: {
93
109
  start?: Point;
@@ -99,27 +115,39 @@ export declare class PathEngine {
99
115
  updateLineEndpoint(lineId: string, endpoint: 'start' | 'end', point: Point): boolean;
100
116
  /**
101
117
  * Rename a line ID and cascade the change to all connected curves.
118
+ * Immutable — does not mutate original objects.
102
119
  */
103
120
  renameLine(oldId: string, newId: string): {
104
121
  success: boolean;
105
122
  error?: string;
123
+ renamedCurveIds?: string[];
106
124
  };
107
125
  /**
108
126
  * Remove a line and all curves connected to it.
127
+ * Returns which curves were also removed.
109
128
  */
110
- removeLine(lineId: string): boolean;
129
+ removeLine(lineId: string): {
130
+ success: boolean;
131
+ removedCurveIds: string[];
132
+ };
111
133
  /**
112
134
  * Add a directional curve (connection) from one line to another.
135
+ * Returns the curve id (auto-generated if not provided).
136
+ */
137
+ addCurve(curve: Curve): string;
138
+ /**
139
+ * Update a curve by id. Returns false if curve not found.
113
140
  */
114
- addCurve(curve: Curve): void;
141
+ updateCurve(curveId: string, updates: Partial<Curve>): boolean;
115
142
  /**
116
- * Update a curve by index. Returns false if index is out of bounds.
143
+ * Remove a curve by id. Returns false if curve not found.
117
144
  */
118
- updateCurve(index: number, updates: Partial<Curve>): boolean;
145
+ removeCurve(curveId: string): boolean;
119
146
  /**
120
- * Remove a curve by index. Returns false if index is out of bounds.
147
+ * Check if a path exists from one position to another.
148
+ * Both offsets are absolute pixel values.
121
149
  */
122
- removeCurve(index: number): boolean;
150
+ canReach(fromLineId: string, fromOffset: number, toLineId: string, toOffset: number): boolean;
123
151
  /**
124
152
  * Initialize a vehicle's N-axle position on a line.
125
153
  *
@@ -156,4 +184,16 @@ export declare class PathEngine {
156
184
  execution: PathExecution;
157
185
  arrived: boolean;
158
186
  };
187
+ /**
188
+ * Advance a vehicle with physics-based acceleration/deceleration.
189
+ *
190
+ * Thin wrapper — internally calls the standalone moveVehicleWithAcceleration()
191
+ * function from acceleration.ts, injecting this.linesMap as the 6th argument.
192
+ */
193
+ moveVehicleWithAcceleration(state: VehiclePathState, execution: PathExecution, accelState: AccelerationState, config: AccelerationConfig, deltaTime: number): {
194
+ state: VehiclePathState;
195
+ execution: PathExecution;
196
+ accelState: AccelerationState;
197
+ arrived: boolean;
198
+ };
159
199
  }
@@ -17,6 +17,7 @@ export interface BezierCurve {
17
17
  p3: Point;
18
18
  }
19
19
  export interface Curve {
20
+ id?: string;
20
21
  fromLineId: string;
21
22
  toLineId: string;
22
23
  fromOffset?: number;
package/dist/core.cjs CHANGED
@@ -1 +1 @@
1
- "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const i=require("./index-BQoeJKCj.cjs");function P(n,e){const a={lines:n,curves:e.map(t=>({id:t.id,fromLineId:t.fromLineId,toLineId:t.toLineId,fromOffset:t.fromOffset,fromIsPercentage:t.fromIsPercentage??!1,toOffset:t.toOffset,toIsPercentage:t.toIsPercentage??!1}))};return JSON.stringify(a,null,2)}function O(n){let e;try{e=JSON.parse(n)}catch{throw new Error("deserializeScene: invalid JSON")}if(!e||typeof e!="object"||Array.isArray(e))throw new Error("deserializeScene: expected a JSON object");const a=e;if(!Array.isArray(a.lines))throw new Error('deserializeScene: missing "lines"');if(!Array.isArray(a.curves))throw new Error('deserializeScene: missing "curves"');return{lines:a.lines,curves:a.curves}}function h(n){const e=n.axleExecutions[n.axleExecutions.length-1],a=i.getCumulativeArcLength(n.path,e.segmentIndex,e.segmentDistance);return Math.max(0,n.path.totalDistance-a)}function d(n){const e=n.axleExecutions[0],a=i.getCumulativeArcLength(n.path,e.segmentIndex,e.segmentDistance);let t=0;for(let r=0;r<n.path.segments.length;r++){const o=n.path.segments[r];if(r>=e.segmentIndex&&o.type==="curve")return Math.max(0,t-a);t+=o.length}return null}function p(n,e,a){let t=a.maxSpeed;const r=Math.sqrt(2*a.deceleration*Math.max(0,n));if(t=Math.min(t,r),e!==null){const o=Math.sqrt(a.minCurveSpeed**2+2*a.deceleration*e);t=Math.min(t,o)}return Math.max(0,t)}function x(n,e,a,t,r){return n<e?Math.min(e,n+a*r):n>e?Math.max(e,n-t*r):n}function S(n,e,a,t,r,o){const c=h(e),l=d(e),f=p(c,l,t),g=x(a.currentSpeed,f,t.acceleration,t.deceleration,r),u=g*r,v=n.axles.map(s=>({lineId:s.lineId,position:s.position,absoluteOffset:s.offset})),L=e.axleExecutions.map(s=>({currentSegmentIndex:s.segmentIndex,segmentDistance:s.segmentDistance})),m=i.moveVehicle(v,L,e.path,u,o,e.curveDataMap);return{state:{axles:m.axles.map(s=>({lineId:s.lineId,offset:s.absoluteOffset,position:s.position})),axleSpacings:n.axleSpacings},execution:{...e,axleExecutions:m.axleExecutions.map(s=>({segmentIndex:s.currentSegmentIndex,segmentDistance:s.segmentDistance}))},accelState:{currentSpeed:g},arrived:m.arrived}}function A(n,e){const a=e.end.x-e.start.x,t=e.end.y-e.start.y,r=a*a+t*t;if(r===0)return{offset:0,distance:Math.sqrt((n.x-e.start.x)**2+(n.y-e.start.y)**2)};const o=Math.max(0,Math.min(1,((n.x-e.start.x)*a+(n.y-e.start.y)*t)/r)),c=e.start.x+o*a,l=e.start.y+o*t,f=Math.sqrt((n.x-c)**2+(n.y-l)**2);return{offset:o*Math.sqrt(r),distance:f}}function I(n,e){const a=i.getLineLength(n),t=e.reduce((o,c)=>o+c,0);return[0,Math.max(0,a-t)]}function M(n,e){let a=0;for(const t of e)t.fromLineId===n&&!t.fromIsPercentage&&t.fromOffset!==void 0&&(a=Math.max(a,t.fromOffset)),t.toLineId===n&&!t.toIsPercentage&&t.toOffset!==void 0&&(a=Math.max(a,t.toOffset));return a}exports.PathEngine=i.PathEngine;exports.arcLengthToSegmentPosition=i.arcLengthToSegmentPosition;exports.buildArcLengthTable=i.buildArcLengthTable;exports.buildGraph=i.buildGraph;exports.calculateBezierArcLength=i.calculateBezierArcLength;exports.calculateFrontAxlePosition=i.calculateFrontAxlePosition;exports.calculateInitialAxlePositions=i.calculateInitialAxlePositions;exports.calculatePositionOnCurve=i.calculatePositionOnCurve;exports.calculatePositionOnLine=i.calculatePositionOnLine;exports.calculateTangentLength=i.calculateTangentLength;exports.createBezierCurve=i.createBezierCurve;exports.createInitialMovementState=i.createInitialMovementState;exports.distance=i.distance;exports.distanceToT=i.distanceToT;exports.findPath=i.findPath;exports.getArcLength=i.getArcLength;exports.getCumulativeArcLength=i.getCumulativeArcLength;exports.getLineLength=i.getLineLength;exports.getPointOnBezier=i.getPointOnBezier;exports.getPointOnLine=i.getPointOnLine;exports.getPointOnLineByOffset=i.getPointOnLineByOffset;exports.getPositionFromOffset=i.getPositionFromOffset;exports.handleArrival=i.handleArrival;exports.initializeAllVehicles=i.initializeAllVehicles;exports.initializeMovingVehicle=i.initializeMovingVehicle;exports.isPointNearPoint=i.isPointNearPoint;exports.moveVehicle=i.moveVehicle;exports.normalize=i.normalize;exports.prepareCommandPath=i.prepareCommandPath;exports.resolveFromLineOffset=i.resolveFromLineOffset;exports.resolveToLineOffset=i.resolveToLineOffset;exports.updateAxlePosition=i.updateAxlePosition;exports.approachSpeed=x;exports.computeDistToNextCurve=d;exports.computeMinLineLength=M;exports.computeRemainingToArrival=h;exports.computeTargetSpeed=p;exports.deserializeScene=O;exports.getValidRearOffsetRange=I;exports.moveVehicleWithAcceleration=S;exports.projectPointOnLine=A;exports.serializeScene=P;
1
+ "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const e=require("./index-BpTZXV22.cjs");function f(r,i){const n={lines:r,curves:i.map(t=>({id:t.id,fromLineId:t.fromLineId,toLineId:t.toLineId,fromOffset:t.fromOffset,fromIsPercentage:t.fromIsPercentage??!1,toOffset:t.toOffset,toIsPercentage:t.toIsPercentage??!1}))};return JSON.stringify(n,null,2)}function g(r){let i;try{i=JSON.parse(r)}catch{throw new Error("deserializeScene: invalid JSON")}if(!i||typeof i!="object"||Array.isArray(i))throw new Error("deserializeScene: expected a JSON object");const n=i;if(!Array.isArray(n.lines))throw new Error('deserializeScene: missing "lines"');if(!Array.isArray(n.curves))throw new Error('deserializeScene: missing "curves"');return{lines:n.lines,curves:n.curves}}function u(r,i){const n=i.end.x-i.start.x,t=i.end.y-i.start.y,a=n*n+t*t;if(a===0)return{offset:0,distance:Math.sqrt((r.x-i.start.x)**2+(r.y-i.start.y)**2)};const o=Math.max(0,Math.min(1,((r.x-i.start.x)*n+(r.y-i.start.y)*t)/a)),s=i.start.x+o*n,c=i.start.y+o*t,l=Math.sqrt((r.x-s)**2+(r.y-c)**2);return{offset:o*Math.sqrt(a),distance:l}}function h(r,i){const n=e.getLineLength(r),t=i.reduce((o,s)=>o+s,0);return[0,Math.max(0,n-t)]}function m(r,i){let n=0;for(const t of i)t.fromLineId===r&&!t.fromIsPercentage&&t.fromOffset!==void 0&&(n=Math.max(n,t.fromOffset)),t.toLineId===r&&!t.toIsPercentage&&t.toOffset!==void 0&&(n=Math.max(n,t.toOffset));return n}exports.PathEngine=e.PathEngine;exports.approachSpeed=e.approachSpeed;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.computeDistToNextCurve=e.computeDistToNextCurve;exports.computeRemainingToArrival=e.computeRemainingToArrival;exports.computeTargetSpeed=e.computeTargetSpeed;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.moveVehicleWithAcceleration=e.moveVehicleWithAcceleration;exports.normalize=e.normalize;exports.prepareCommandPath=e.prepareCommandPath;exports.resolveFromLineOffset=e.resolveFromLineOffset;exports.resolveToLineOffset=e.resolveToLineOffset;exports.updateAxlePosition=e.updateAxlePosition;exports.computeMinLineLength=m;exports.deserializeScene=g;exports.getValidRearOffsetRange=h;exports.projectPointOnLine=u;exports.serializeScene=f;
package/dist/core.js CHANGED
@@ -1,30 +1,30 @@
1
- import { g as u, m as x, a as p } from "./index-DUYG8fxI.js";
2
- import { P as T, b, c as j, d as q, e as C, f as N, h as B, i as V, j as J, k as F, l as R, n as k, o as G, p as W, q as X, r as Y, s as H, t as K, u as Q, v as U, w as Z, x as _, y as $, z as ee, A as te, B as ne, C as ae, D as se, E as re } from "./index-DUYG8fxI.js";
3
- function P(n, e) {
1
+ import { g as f } from "./index-BObuJxsC.js";
2
+ import { P as v, a as p, b as y, c as A, d as S, e as I, f as z, h as M, i as w, j as T, k as b, l as j, m as C, n as E, o as N, p as q, q as B, r as J, s as V, t as F, u as R, v as D, w as G, x as k, y as H, z as W, A as X, B as Y, C as K, D as Q, E as U, F as Z, G as _, H as $, I as ee, J as te } from "./index-BObuJxsC.js";
3
+ function d(s, t) {
4
4
  const a = {
5
- lines: n,
6
- curves: e.map((t) => ({
7
- id: t.id,
8
- fromLineId: t.fromLineId,
9
- toLineId: t.toLineId,
10
- fromOffset: t.fromOffset,
11
- fromIsPercentage: t.fromIsPercentage ?? !1,
12
- toOffset: t.toOffset,
13
- toIsPercentage: t.toIsPercentage ?? !1
5
+ lines: s,
6
+ curves: t.map((e) => ({
7
+ id: e.id,
8
+ fromLineId: e.fromLineId,
9
+ toLineId: e.toLineId,
10
+ fromOffset: e.fromOffset,
11
+ fromIsPercentage: e.fromIsPercentage ?? !1,
12
+ toOffset: e.toOffset,
13
+ toIsPercentage: e.toIsPercentage ?? !1
14
14
  }))
15
15
  };
16
16
  return JSON.stringify(a, null, 2);
17
17
  }
18
- function M(n) {
19
- let e;
18
+ function g(s) {
19
+ let t;
20
20
  try {
21
- e = JSON.parse(n);
21
+ t = JSON.parse(s);
22
22
  } catch {
23
23
  throw new Error("deserializeScene: invalid JSON");
24
24
  }
25
- if (!e || typeof e != "object" || Array.isArray(e))
25
+ if (!t || typeof t != "object" || Array.isArray(t))
26
26
  throw new Error("deserializeScene: expected a JSON object");
27
- const a = e;
27
+ const a = t;
28
28
  if (!Array.isArray(a.lines)) throw new Error('deserializeScene: missing "lines"');
29
29
  if (!Array.isArray(a.curves)) throw new Error('deserializeScene: missing "curves"');
30
30
  return {
@@ -32,140 +32,72 @@ function M(n) {
32
32
  curves: a.curves
33
33
  };
34
34
  }
35
- function v(n) {
36
- const e = n.axleExecutions[n.axleExecutions.length - 1], a = u(
37
- n.path,
38
- e.segmentIndex,
39
- e.segmentDistance
40
- );
41
- return Math.max(0, n.path.totalDistance - a);
42
- }
43
- function S(n) {
44
- const e = n.axleExecutions[0], a = u(
45
- n.path,
46
- e.segmentIndex,
47
- e.segmentDistance
48
- );
49
- let t = 0;
50
- for (let s = 0; s < n.path.segments.length; s++) {
51
- const i = n.path.segments[s];
52
- if (s >= e.segmentIndex && i.type === "curve")
53
- return Math.max(0, t - a);
54
- t += i.length;
55
- }
56
- return null;
57
- }
58
- function L(n, e, a) {
59
- let t = a.maxSpeed;
60
- const s = Math.sqrt(2 * a.deceleration * Math.max(0, n));
61
- if (t = Math.min(t, s), e !== null) {
62
- const i = Math.sqrt(
63
- a.minCurveSpeed ** 2 + 2 * a.deceleration * e
64
- );
65
- t = Math.min(t, i);
66
- }
67
- return Math.max(0, t);
68
- }
69
- function O(n, e, a, t, s) {
70
- return n < e ? Math.min(e, n + a * s) : n > e ? Math.max(e, n - t * s) : n;
71
- }
72
- function y(n, e, a, t, s, i) {
73
- const o = v(e), c = S(e), l = L(o, c, t), f = O(
74
- a.currentSpeed,
75
- l,
76
- t.acceleration,
77
- t.deceleration,
78
- s
79
- ), d = f * s, h = n.axles.map((r) => ({
80
- lineId: r.lineId,
81
- position: r.position,
82
- absoluteOffset: r.offset
83
- })), g = e.axleExecutions.map((r) => ({
84
- currentSegmentIndex: r.segmentIndex,
85
- segmentDistance: r.segmentDistance
86
- })), m = x(h, g, e.path, d, i, e.curveDataMap);
87
- return {
88
- state: {
89
- axles: m.axles.map((r) => ({ lineId: r.lineId, offset: r.absoluteOffset, position: r.position })),
90
- axleSpacings: n.axleSpacings
91
- },
92
- execution: {
93
- ...e,
94
- axleExecutions: m.axleExecutions.map((r) => ({
95
- segmentIndex: r.currentSegmentIndex,
96
- segmentDistance: r.segmentDistance
97
- }))
98
- },
99
- accelState: { currentSpeed: f },
100
- arrived: m.arrived
101
- };
102
- }
103
- function A(n, e) {
104
- const a = e.end.x - e.start.x, t = e.end.y - e.start.y, s = a * a + t * t;
105
- if (s === 0)
35
+ function h(s, t) {
36
+ const a = t.end.x - t.start.x, e = t.end.y - t.start.y, n = a * a + e * e;
37
+ if (n === 0)
106
38
  return { offset: 0, distance: Math.sqrt(
107
- (n.x - e.start.x) ** 2 + (n.y - e.start.y) ** 2
39
+ (s.x - t.start.x) ** 2 + (s.y - t.start.y) ** 2
108
40
  ) };
109
- const i = Math.max(
41
+ const r = Math.max(
110
42
  0,
111
43
  Math.min(
112
44
  1,
113
- ((n.x - e.start.x) * a + (n.y - e.start.y) * t) / s
45
+ ((s.x - t.start.x) * a + (s.y - t.start.y) * e) / n
114
46
  )
115
- ), o = e.start.x + i * a, c = e.start.y + i * t, l = Math.sqrt((n.x - o) ** 2 + (n.y - c) ** 2);
116
- return { offset: i * Math.sqrt(s), distance: l };
47
+ ), i = t.start.x + r * a, o = t.start.y + r * e, c = Math.sqrt((s.x - i) ** 2 + (s.y - o) ** 2);
48
+ return { offset: r * Math.sqrt(n), distance: c };
117
49
  }
118
- function E(n, e) {
119
- const a = p(n), t = e.reduce((i, o) => i + o, 0);
120
- return [0, Math.max(0, a - t)];
50
+ function x(s, t) {
51
+ const a = f(s), e = t.reduce((r, i) => r + i, 0);
52
+ return [0, Math.max(0, a - e)];
121
53
  }
122
- function z(n, e) {
54
+ function L(s, t) {
123
55
  let a = 0;
124
- for (const t of e)
125
- t.fromLineId === n && !t.fromIsPercentage && t.fromOffset !== void 0 && (a = Math.max(a, t.fromOffset)), t.toLineId === n && !t.toIsPercentage && t.toOffset !== void 0 && (a = Math.max(a, t.toOffset));
56
+ for (const e of t)
57
+ e.fromLineId === s && !e.fromIsPercentage && e.fromOffset !== void 0 && (a = Math.max(a, e.fromOffset)), e.toLineId === s && !e.toIsPercentage && e.toOffset !== void 0 && (a = Math.max(a, e.toOffset));
126
58
  return a;
127
59
  }
128
60
  export {
129
- T as PathEngine,
130
- O as approachSpeed,
131
- b as arcLengthToSegmentPosition,
132
- j as buildArcLengthTable,
133
- q as buildGraph,
134
- C as calculateBezierArcLength,
135
- N as calculateFrontAxlePosition,
136
- B as calculateInitialAxlePositions,
137
- V as calculatePositionOnCurve,
138
- J as calculatePositionOnLine,
139
- F as calculateTangentLength,
140
- S as computeDistToNextCurve,
141
- z as computeMinLineLength,
142
- v as computeRemainingToArrival,
143
- L as computeTargetSpeed,
144
- R as createBezierCurve,
145
- k as createInitialMovementState,
146
- M as deserializeScene,
147
- G as distance,
148
- W as distanceToT,
149
- X as findPath,
150
- Y as getArcLength,
151
- u as getCumulativeArcLength,
152
- p as getLineLength,
153
- H as getPointOnBezier,
154
- K as getPointOnLine,
155
- Q as getPointOnLineByOffset,
156
- U as getPositionFromOffset,
157
- E as getValidRearOffsetRange,
158
- Z as handleArrival,
159
- _ as initializeAllVehicles,
160
- $ as initializeMovingVehicle,
161
- ee as isPointNearPoint,
162
- x as moveVehicle,
163
- y as moveVehicleWithAcceleration,
164
- te as normalize,
165
- ne as prepareCommandPath,
166
- A as projectPointOnLine,
167
- ae as resolveFromLineOffset,
168
- se as resolveToLineOffset,
169
- P as serializeScene,
170
- re as updateAxlePosition
61
+ v as PathEngine,
62
+ p as approachSpeed,
63
+ y as arcLengthToSegmentPosition,
64
+ A as buildArcLengthTable,
65
+ S as buildGraph,
66
+ I as calculateBezierArcLength,
67
+ z as calculateFrontAxlePosition,
68
+ M as calculateInitialAxlePositions,
69
+ w as calculatePositionOnCurve,
70
+ T as calculatePositionOnLine,
71
+ b as calculateTangentLength,
72
+ j as computeDistToNextCurve,
73
+ L as computeMinLineLength,
74
+ C as computeRemainingToArrival,
75
+ E as computeTargetSpeed,
76
+ N as createBezierCurve,
77
+ q as createInitialMovementState,
78
+ g as deserializeScene,
79
+ B as distance,
80
+ J as distanceToT,
81
+ V as findPath,
82
+ F as getArcLength,
83
+ R as getCumulativeArcLength,
84
+ f as getLineLength,
85
+ D as getPointOnBezier,
86
+ G as getPointOnLine,
87
+ k as getPointOnLineByOffset,
88
+ H as getPositionFromOffset,
89
+ x as getValidRearOffsetRange,
90
+ W as handleArrival,
91
+ X as initializeAllVehicles,
92
+ Y as initializeMovingVehicle,
93
+ K as isPointNearPoint,
94
+ Q as moveVehicle,
95
+ U as moveVehicleWithAcceleration,
96
+ Z as normalize,
97
+ _ as prepareCommandPath,
98
+ h as projectPointOnLine,
99
+ $ as resolveFromLineOffset,
100
+ ee as resolveToLineOffset,
101
+ d as serializeScene,
102
+ te as updateAxlePosition
171
103
  };