vehicle-path2 3.0.0 → 4.0.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.js CHANGED
@@ -1,98 +1,171 @@
1
- import { g as f } from "./index-BV93143R.js";
2
- import { P as y, a as v, b as A, c as S, d as p, e as z, f as I, h as M, i as w, j as b, k as j, l as E, m as T, n as q, o as B, p as C, q as N, r as J, s as V, t as F, u as R, v as k, w as D, x as G, y as X, z as Y, A as H, B as K, C as Q, D as U, E as W } from "./index-BV93143R.js";
3
- function u(a, t) {
4
- const s = {
5
- lines: a,
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
1
+ import { g as u, m as x, a as p } from "./index-okJUn3WJ.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-okJUn3WJ.js";
3
+ function P(n, e) {
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
14
14
  }))
15
15
  };
16
- return JSON.stringify(s, null, 2);
16
+ return JSON.stringify(a, null, 2);
17
17
  }
18
- function g(a) {
19
- let t;
18
+ function M(n) {
19
+ let e;
20
20
  try {
21
- t = JSON.parse(a);
21
+ e = JSON.parse(n);
22
22
  } catch {
23
23
  throw new Error("deserializeScene: invalid JSON");
24
24
  }
25
- if (!t || typeof t != "object" || Array.isArray(t))
25
+ if (!e || typeof e != "object" || Array.isArray(e))
26
26
  throw new Error("deserializeScene: expected a JSON object");
27
- const s = t;
28
- if (!Array.isArray(s.lines)) throw new Error('deserializeScene: missing "lines"');
29
- if (!Array.isArray(s.curves)) throw new Error('deserializeScene: missing "curves"');
27
+ const a = e;
28
+ if (!Array.isArray(a.lines)) throw new Error('deserializeScene: missing "lines"');
29
+ if (!Array.isArray(a.curves)) throw new Error('deserializeScene: missing "curves"');
30
30
  return {
31
- lines: s.lines,
32
- curves: s.curves
31
+ lines: a.lines,
32
+ curves: a.curves
33
33
  };
34
34
  }
35
- function h(a, t) {
36
- const s = t.end.x - t.start.x, e = t.end.y - t.start.y, n = s * s + e * e;
37
- if (n === 0)
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)
38
106
  return { offset: 0, distance: Math.sqrt(
39
- (a.x - t.start.x) ** 2 + (a.y - t.start.y) ** 2
107
+ (n.x - e.start.x) ** 2 + (n.y - e.start.y) ** 2
40
108
  ) };
41
- const r = Math.max(
109
+ const i = Math.max(
42
110
  0,
43
111
  Math.min(
44
112
  1,
45
- ((a.x - t.start.x) * s + (a.y - t.start.y) * e) / n
113
+ ((n.x - e.start.x) * a + (n.y - e.start.y) * t) / s
46
114
  )
47
- ), i = t.start.x + r * s, o = t.start.y + r * e, c = Math.sqrt((a.x - i) ** 2 + (a.y - o) ** 2);
48
- return { offset: r * Math.sqrt(n), distance: c };
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 };
49
117
  }
50
- function L(a, t) {
51
- const s = f(a), e = t.reduce((r, i) => r + i, 0);
52
- return [0, Math.max(0, s - e)];
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)];
53
121
  }
54
- function O(a, t) {
55
- let s = 0;
56
- for (const e of t)
57
- e.fromLineId === a && !e.fromIsPercentage && e.fromOffset !== void 0 && (s = Math.max(s, e.fromOffset)), e.toLineId === a && !e.toIsPercentage && e.toOffset !== void 0 && (s = Math.max(s, e.toOffset));
58
- return s;
122
+ function z(n, e) {
123
+ 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));
126
+ return a;
59
127
  }
60
128
  export {
61
- y as PathEngine,
62
- v as arcLengthToSegmentPosition,
63
- A as buildArcLengthTable,
64
- S as buildGraph,
65
- p as calculateBezierArcLength,
66
- z as calculateFrontAxlePosition,
67
- I as calculateInitialAxlePositions,
68
- M as calculatePositionOnCurve,
69
- w as calculatePositionOnLine,
70
- b as calculateTangentLength,
71
- O as computeMinLineLength,
72
- j as createBezierCurve,
73
- E as createInitialMovementState,
74
- g as deserializeScene,
75
- T as distance,
76
- q as distanceToT,
77
- B as findPath,
78
- C as getArcLength,
79
- N as getCumulativeArcLength,
80
- f as getLineLength,
81
- J as getPointOnBezier,
82
- V as getPointOnLine,
83
- F as getPointOnLineByOffset,
84
- R as getPositionFromOffset,
85
- L as getValidRearOffsetRange,
86
- k as handleArrival,
87
- D as initializeAllVehicles,
88
- G as initializeMovingVehicle,
89
- X as isPointNearPoint,
90
- Y as moveVehicle,
91
- H as normalize,
92
- K as prepareCommandPath,
93
- h as projectPointOnLine,
94
- Q as resolveFromLineOffset,
95
- U as resolveToLineOffset,
96
- u as serializeScene,
97
- W as updateAxlePosition
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
98
171
  };
@@ -0,0 +1 @@
1
+ "use strict";function L(t,e){const s=e.x-t.x,n=e.y-t.y;return Math.sqrt(s*s+n*n)}function T(t,e){const s=e.x-t.x,n=e.y-t.y,i=Math.sqrt(s*s+n*n);return i===0?{x:0,y:0}:{x:s/i,y:n/i}}function F(t,e){return e*(t==="proportional-40"?.4:.5522)}function z(t,e,s,n){const{tangentMode:i}=s;let c;n?.fromOffset!==void 0?c=V(t,n.fromOffset,n.fromIsPercentage??!1):c=t.end;let o;n?.toOffset!==void 0?o=V(e,n.toOffset,n.toIsPercentage??!1):o=e.start;const r=T(t.start,t.end),f=T(e.start,e.end),l=L(c,o),a=F(i,l),g={x:c.x+r.x*a,y:c.y+r.y*a},d={x:o.x-f.x*a,y:o.y-f.y*a};return{p0:c,p1:g,p2:d,p3:o}}function N(t,e){return{x:t.start.x+(t.end.x-t.start.x)*e,y:t.start.y+(t.end.y-t.start.y)*e}}function V(t,e,s){const n=L(t.start,t.end);let i;return s?i=e:i=n>0?e/n:0,i=Math.max(0,Math.min(1,i)),N(t,i)}function A(t,e){const{p0:s,p1:n,p2:i,p3:c}=t,o=1-e,r=o*o,f=r*o,l=e*e,a=l*e;return{x:f*s.x+3*r*e*n.x+3*o*l*i.x+a*c.x,y:f*s.y+3*r*e*n.y+3*o*l*i.y+a*c.y}}function ee(t,e,s=10){return L(t,e)<=s}function $(t,e=100){const s=[{t:0,distance:0}];let n=t.p0,i=0;for(let c=1;c<=e;c++){const o=c/e,r=A(t,o);i+=L(n,r),s.push({t:o,distance:i}),n=r}return s}function j(t,e){if(e<=0)return 0;const s=t[t.length-1].distance;if(e>=s)return 1;let n=0,i=t.length-1;for(;n<i-1;){const a=Math.floor((n+i)/2);t[a].distance<e?n=a:i=a}const c=t[n].distance,o=t[i].distance,r=t[n].t,f=t[i].t;if(o===c)return r;const l=(e-c)/(o-c);return r+l*(f-r)}function te(t){return t[t.length-1].distance}function K(t,e=100){let s=0,n=t.p0;for(let i=1;i<=e;i++){const c=i/e,o=A(t,c);s+=L(n,o),n=o}return s}function b(t,e,s,n){const i=L(t.start,t.end);return e===void 0?n*i:s?Math.max(0,Math.min(e,1))*i:Math.max(0,Math.min(e,i))}function B(t,e,s,n){const i=L(t.start,t.end);return e===void 0?n*i:s?Math.max(0,Math.min(e,1))*i:Math.max(0,Math.min(e,i))}function x(t,e,s){const n=new Map,i=new Map,c=new Map;for(const o of t)i.set(o.id,o),c.set(o.id,L(o.start,o.end)),n.set(o.id,[]);for(let o=0;o<e.length;o++){const r=e[o],f=i.get(r.fromLineId),l=i.get(r.toLineId);if(!f||!l)continue;const a=b(f,r.fromOffset,r.fromIsPercentage,1),g=B(l,r.toOffset,r.toIsPercentage,0),d=z(f,l,s,{fromOffset:a,fromIsPercentage:!1,toOffset:g,toIsPercentage:!1}),h=K(d),v={curveIndex:o,fromLineId:r.fromLineId,toLineId:r.toLineId,fromOffset:a,toOffset:g,curveLength:h};n.get(r.fromLineId).push(v)}return{adjacency:n,lines:i,lineLengths:c}}function q(t,e){return t.curveCount!==e.curveCount?t.curveCount-e.curveCount:t.totalDistance-e.totalDistance}function k(t,e,s,n,i=!1){const{adjacency:c,lines:o,lineLengths:r}=t;if(!o.get(s))return null;const l=r.get(s),a=i?n/100*l:n,g=[],d=new Map,h=(u,p)=>`${u}:${Math.round(p)}`;if(e.lineId===s&&a>=e.offset){const u=a-e.offset;return{segments:[{type:"line",lineId:e.lineId,startOffset:e.offset,endOffset:a,length:u}],totalDistance:u,curveCount:0}}const v=c.get(e.lineId)||[];for(const u of v){if(u.fromOffset<e.offset)continue;const p=u.fromOffset-e.offset,I=p+u.curveLength,O={type:"line",lineId:e.lineId,startOffset:e.offset,endOffset:u.fromOffset,length:p},m={type:"curve",curveIndex:u.curveIndex,startOffset:0,endOffset:u.curveLength,length:u.curveLength};g.push({lineId:u.toLineId,entryOffset:u.toOffset,totalDistance:I,curveCount:1,path:[O,m]})}for(g.sort(q);g.length>0;){const u=g.shift(),p=h(u.lineId,u.entryOffset),I=d.get(p);if(I!==void 0&&(I.curveCount<u.curveCount||I.curveCount===u.curveCount&&I.distance<=u.totalDistance))continue;if(d.set(p,{curveCount:u.curveCount,distance:u.totalDistance}),u.lineId===s){const m=Math.abs(a-u.entryOffset);if(a>=u.entryOffset){const C={type:"line",lineId:s,startOffset:u.entryOffset,endOffset:a,length:m};return{segments:[...u.path,C],totalDistance:u.totalDistance+m,curveCount:u.curveCount}}}const O=c.get(u.lineId)||[];for(const m of O){if(m.fromOffset<u.entryOffset)continue;const C=m.fromOffset-u.entryOffset,E=u.totalDistance+C+m.curveLength,w=u.curveCount+1,X=h(m.toLineId,m.toOffset),P=d.get(X);if(P!==void 0&&(P.curveCount<w||P.curveCount===w&&P.distance<=E))continue;const Y={type:"line",lineId:u.lineId,startOffset:u.entryOffset,endOffset:m.fromOffset,length:C},Z={type:"curve",curveIndex:m.curveIndex,startOffset:0,endOffset:m.curveLength,length:m.curveLength};g.push({lineId:m.toLineId,entryOffset:m.toOffset,totalDistance:E,curveCount:w,path:[...u.path,Y,Z]})}g.sort(q)}return null}function S(t,e){const s=Math.sqrt(Math.pow(t.end.x-t.start.x,2)+Math.pow(t.end.y-t.start.y,2)),n=s>0?e/s:0;return{x:t.start.x+(t.end.x-t.start.x)*Math.min(1,Math.max(0,n)),y:t.start.y+(t.end.y-t.start.y)*Math.min(1,Math.max(0,n))}}function M(t){return Math.sqrt(Math.pow(t.end.x-t.start.x,2)+Math.pow(t.end.y-t.start.y,2))}function G(t,e,s){let n=0;for(let i=0;i<e;i++)n+=t.segments[i].length;return n+=s,n}function Q(t,e){let s=0;for(let n=0;n<t.segments.length;n++){const i=t.segments[n],c=s+i.length;if(e<c)return{segmentIndex:n,segmentDistance:e-s};if(e===c)return n+1<t.segments.length?{segmentIndex:n+1,segmentDistance:0}:{segmentIndex:n,segmentDistance:i.length};s+=i.length}return null}function ne(t,e,s,n){const c=G(t,e,s)+n;return Q(t,c)}function R(t,e,s,n){const i=M(n),c=s.length+1,o=new Array(c);o[c-1]={lineId:t,absoluteOffset:e,position:S(n,e)};let r=e;for(let f=c-2;f>=0;f--)r=Math.min(r+s[f],i),o[f]={lineId:t,absoluteOffset:r,position:S(n,r)};return o}function W(t,e){return{...t,state:"idle"}}function _(t){return{vehicle:t,execution:null}}function se(t,e){const s=[],n=new Map;for(const i of t){if(!e.get(i.lineId))continue;const o=W(i);s.push(o);const r=_(o);n.set(i.id,r)}return{movingVehicles:s,stateMap:n}}function y(t,e){return{position:S(t,e),lineId:t.id,absoluteOffset:e}}function D(t,e){const s=j(t.arcLengthTable,e);return{position:A(t.bezier,s)}}function H(t,e,s,n,i,c,o){const r=s.segments[e.currentSegmentIndex],f=e.segmentDistance+n;if(f>=r.length){const a=f-r.length,g=e.currentSegmentIndex+1;if(g>=s.segments.length){if(o!==void 0&&r.type==="line"){const u=i.get(r.lineId),p=r.startOffset+f;if(p<=o){const O=y(u,p);return{axleState:{...t,...O},execution:{...e,segmentDistance:f},completed:!1}}const I=y(u,o);return{axleState:{...t,...I},execution:{...e,segmentDistance:o-r.startOffset},completed:!0}}const v=r.type==="line"?y(i.get(r.lineId),r.endOffset):D(c.get(r.curveIndex),r.length);return{axleState:{...t,...v},execution:{...e,segmentDistance:r.length},completed:!0}}const d=s.segments[g],h=d.type==="line"?y(i.get(d.lineId),d.startOffset+a):D(c.get(d.curveIndex),a);return{axleState:{...t,...h},execution:{currentSegmentIndex:g,segmentDistance:a},completed:!1}}const l=r.type==="line"?y(i.get(r.lineId),r.startOffset+f):D(c.get(r.curveIndex),f);return{axleState:{...t,...l},execution:{...e,segmentDistance:f},completed:!1}}function ie(t,e,s,n){const i=new Map;for(const c of t.segments)if(c.type==="curve"&&c.curveIndex!==void 0){const o=e[c.curveIndex];if(o){const r=s.get(o.fromLineId),f=s.get(o.toLineId);if(r&&f){const l=b(r,o.fromOffset,o.fromIsPercentage,1),a=B(f,o.toOffset,o.toIsPercentage,0),g=z(r,f,n,{fromOffset:l,fromIsPercentage:!1,toOffset:a,toIsPercentage:!1}),d=$(g);i.set(c.curveIndex,{bezier:g,arcLengthTable:d})}}}return i}function J(t,e,s){const{graph:n,linesMap:i,curves:c,config:o}=s,r=i.get(e.targetLineId);if(!r)return null;const f=t.axleSpacings.reduce((u,p)=>u+p,0),a=M(r)-f;if(a<=0)return null;const g=e.isPercentage?e.targetOffset*a:Math.min(e.targetOffset,a),d=t.axles[t.axles.length-1],h=k(n,{lineId:d.lineId,offset:d.absoluteOffset},e.targetLineId,g,!1);if(!h)return null;const v=ie(h,c,i,o);return{path:h,curveDataMap:v}}function re(t,e){const s=t.execution,i=e.vehicleQueues.get(t.vehicle.id)?.[s.currentCommandIndex];return i&&e.onCommandComplete&&e.onCommandComplete({vehicleId:t.vehicle.id,command:i,finalPosition:{lineId:t.vehicle.axles[t.vehicle.axles.length-1].lineId,absoluteOffset:t.vehicle.axles[t.vehicle.axles.length-1].absoluteOffset,position:t.vehicle.axles[t.vehicle.axles.length-1].position},payload:i.payload}),{handled:!0,vehicle:{...t.vehicle,state:"waiting"},newExecution:s,isWaiting:!0}}function U(t,e,s,n,i,c){let o;const r=e[0];if(r.currentSegmentIndex<s.segments.length){const l=s.segments[r.currentSegmentIndex];if(l.type==="line"){const a=i.get(l.lineId);a&&(o=M(a))}}const f=t.map((l,a)=>{const g=a===0?o:void 0;return H(l,e[a],s,n,i,c,g)});return{axles:f.map(l=>l.axleState),axleExecutions:f.map(l=>l.execution),arrived:f[f.length-1].completed}}class oe{graph=null;linesMap=new Map;curves=[];config;constructor(e){this.config={tangentMode:e.tangentMode}}get movementConfig(){return this.config}get lines(){return Array.from(this.linesMap.values())}getCurves(){return this.curves}setScene(e,s){this.linesMap.clear();for(const n of e)this.linesMap.set(n.id,n);this.curves=s,this.graph=x(e,s,this.config)}addLine(e){return this.linesMap.has(e.id)?!1:(this.linesMap.set(e.id,e),this.graph=x(Array.from(this.linesMap.values()),this.curves,this.config),!0)}updateLine(e,s){const n=this.linesMap.get(e);return n?(s.start&&(n.start=s.start),s.end&&(n.end=s.end),this.graph=x(Array.from(this.linesMap.values()),this.curves,this.config),!0):!1}updateLineEndpoint(e,s,n){return this.updateLine(e,{[s]:n})}renameLine(e,s){const n=s.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 i=this.linesMap.get(e);if(!i)return{success:!1,error:`Line "${e}" not found`};i.id=n,this.linesMap.delete(e),this.linesMap.set(n,i);for(const c of this.curves)c.fromLineId===e&&(c.fromLineId=n),c.toLineId===e&&(c.toLineId=n);return this.graph=x(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(s=>s.fromLineId!==e&&s.toLineId!==e),this.graph=x(Array.from(this.linesMap.values()),this.curves,this.config),!0):!1}addCurve(e){this.curves.push(e),this.graph=x(Array.from(this.linesMap.values()),this.curves,this.config)}updateCurve(e,s){return e<0||e>=this.curves.length?!1:(this.curves[e]={...this.curves[e],...s},this.graph=x(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=x(Array.from(this.linesMap.values()),this.curves,this.config),!0)}initializeVehicle(e,s,n){const i=this.linesMap.get(e);if(!i)return null;const{axleSpacings:c}=n;if(c.length===0)throw new Error("initializeVehicle: axleSpacings must have at least one entry (vehicle needs ≥2 axles)");const o=c.reduce((a,g)=>a+g,0),r=M(i),f=Math.min(s,r-o);return{axles:R(e,f,c,i).map(a=>({lineId:a.lineId,offset:a.absoluteOffset,position:a.position})),axleSpacings:c}}preparePath(e,s,n,i=!1){if(!this.graph)return null;const c=e.axleSpacings.reduce((h,v)=>h+v,0),o=e.axles[e.axles.length-1],r={lineId:o.lineId,offset:o.offset,axles:e.axles.map(h=>({lineId:h.lineId,position:h.position,absoluteOffset:h.offset})),axleSpacings:e.axleSpacings},f=J(r,{targetLineId:s,targetOffset:n,isPercentage:i},{graph:this.graph,linesMap:this.linesMap,curves:this.curves,config:this.config});if(!f)return null;let l=n;const a=this.linesMap.get(s);if(a){const h=Math.max(0,M(a)-c);l=i?n*h:Math.min(n,h)}let g=0;const d=[{segmentIndex:0,segmentDistance:c}];for(let h=0;h<e.axleSpacings.length;h++)g+=e.axleSpacings[h],d.push({segmentIndex:0,segmentDistance:c-g});return{path:f.path,curveDataMap:f.curveDataMap,axleExecutions:d,targetLineId:s,targetOffset:l}}moveVehicle(e,s,n){const i=e.axles.map(r=>({lineId:r.lineId,position:r.position,absoluteOffset:r.offset})),c=s.axleExecutions.map(r=>({currentSegmentIndex:r.segmentIndex,segmentDistance:r.segmentDistance})),o=U(i,c,s.path,n,this.linesMap,s.curveDataMap);return{state:{axles:o.axles.map(r=>({lineId:r.lineId,offset:r.absoluteOffset,position:r.position})),axleSpacings:e.axleSpacings},execution:{...s,axleExecutions:o.axleExecutions.map(r=>({segmentIndex:r.currentSegmentIndex,segmentDistance:r.segmentDistance}))},arrived:o.arrived}}}exports.PathEngine=oe;exports.arcLengthToSegmentPosition=Q;exports.buildArcLengthTable=$;exports.buildGraph=x;exports.calculateBezierArcLength=K;exports.calculateFrontAxlePosition=ne;exports.calculateInitialAxlePositions=R;exports.calculatePositionOnCurve=D;exports.calculatePositionOnLine=y;exports.calculateTangentLength=F;exports.createBezierCurve=z;exports.createInitialMovementState=_;exports.distance=L;exports.distanceToT=j;exports.findPath=k;exports.getArcLength=te;exports.getCumulativeArcLength=G;exports.getLineLength=M;exports.getPointOnBezier=A;exports.getPointOnLine=N;exports.getPointOnLineByOffset=V;exports.getPositionFromOffset=S;exports.handleArrival=re;exports.initializeAllVehicles=se;exports.initializeMovingVehicle=W;exports.isPointNearPoint=ee;exports.moveVehicle=U;exports.normalize=T;exports.prepareCommandPath=J;exports.resolveFromLineOffset=b;exports.resolveToLineOffset=B;exports.updateAxlePosition=H;