vehicle-path2 1.0.11 → 1.0.12

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
@@ -91,7 +91,6 @@ sim.clearVehicles()
91
91
  sim.goto({ id: 'v1', lineId: 'line2' }) // default position = 1.0 (ujung)
92
92
  sim.goto({ id: 'v1', lineId: 'line2', position: 0.5 }) // 0.5 = tengah line
93
93
  sim.goto({ id: 'v1', lineId: 'line2', position: 150, isPercentage: false }) // absolute
94
- sim.goto({ id: 'v1', lineId: 'line2', position: 0.5, wait: true }) // berhenti di tujuan
95
94
  sim.goto({ id: 'v1', lineId: 'line2', payload: { orderId: '123' } }) // dengan payload
96
95
  sim.clearQueue('v1')
97
96
  ```
@@ -106,7 +106,6 @@ export interface ConnectionUpdateInput {
106
106
  * goto({ id: 'v1', lineId: 'line002' }) // position defaults to 1.0 (end)
107
107
  * goto({ id: 'v1', lineId: 'line002', position: 0.5 }) // 50% of line
108
108
  * goto({ id: 'v1', lineId: 'line002', position: 150, isPercentage: false }) // absolute 150
109
- * goto({ id: 'v1', lineId: 'line002', position: 0.5, wait: true }) // wait at destination
110
109
  * goto({ id: 'v1', lineId: 'line002', payload: { orderId: '123' } }) // with payload
111
110
  */
112
111
  export interface GotoInput {
@@ -114,7 +113,6 @@ export interface GotoInput {
114
113
  lineId: string;
115
114
  position?: number;
116
115
  isPercentage?: boolean;
117
- wait?: boolean;
118
116
  payload?: unknown;
119
117
  }
120
118
  /**
@@ -126,7 +124,6 @@ export interface GotoInput {
126
124
  * queueMovement('v1', {
127
125
  * targetLineId: 'line002',
128
126
  * targetPosition: 0.5,
129
- * wait: true,
130
127
  * payload: { orderId: '123' }
131
128
  * })
132
129
  * queueMovement('v1', { targetLineId: 'line002', targetPosition: 150, isPercentage: false })
@@ -135,7 +132,6 @@ export interface GotoCommandInput {
135
132
  targetLineId: string;
136
133
  targetPosition?: number;
137
134
  isPercentage?: boolean;
138
- wait?: boolean;
139
135
  payload?: unknown;
140
136
  }
141
137
  /**
@@ -151,7 +147,6 @@ export interface MovementCommandInput {
151
147
  targetLineId: string;
152
148
  targetPosition?: number;
153
149
  isPercentage?: boolean;
154
- wait?: boolean;
155
150
  payload?: unknown;
156
151
  }
157
152
  /**
@@ -43,7 +43,6 @@ export interface GotoCommand {
43
43
  targetLineId: string;
44
44
  targetOffset: number;
45
45
  isPercentage: boolean;
46
- awaitConfirmation?: boolean;
47
46
  payload?: unknown;
48
47
  }
49
48
  /**
package/dist/core.cjs CHANGED
@@ -1 +1 @@
1
- "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});function I(e,t){const s=t.x-e.x,n=t.y-e.y;return Math.sqrt(s*s+n*n)}function P(e,t){const s=t.x-e.x,n=t.y-e.y,o=Math.sqrt(s*s+n*n);return o===0?{x:0,y:0}:{x:s/o,y:n/o}}function q(e,t){return t*(e==="proportional-40"?.4:.5522)}function T(e,t,s,n=!1,o){const{wheelbase:c,tangentMode:i}=s;let r;o?.fromOffset!==void 0?r=S(e,o.fromOffset,o.fromIsPercentage??!1):r=e.end;let u;o?.toOffset!==void 0?u=S(t,o.toOffset,o.toIsPercentage??!1):u=t.start;const d=P(e.start,e.end),f=n?{x:r.x-d.x*c,y:r.y-d.y*c}:r,l=P(e.start,e.end),g=P(t.start,t.end),p=I(f,u),m=q(i,p),a=n?{x:f.x-l.x*m,y:f.y-l.y*m}:{x:f.x+l.x*m,y:f.y+l.y*m},v={x:u.x-g.x*m,y:u.y-g.y*m};return{p0:f,p1:a,p2:v,p3:u}}function F(e,t){return{x:e.start.x+(e.end.x-e.start.x)*t,y:e.start.y+(e.end.y-e.start.y)*t}}function S(e,t,s){const n=I(e.start,e.end);let o;return s?o=t:o=n>0?t/n:0,o=Math.max(0,Math.min(1,o)),F(e,o)}function w(e,t){const{p0:s,p1:n,p2:o,p3:c}=e,i=1-t,r=i*i,u=r*i,d=t*t,f=d*t;return{x:u*s.x+3*r*t*n.x+3*i*d*o.x+f*c.x,y:u*s.y+3*r*t*n.y+3*i*d*o.y+f*c.y}}function U(e,t,s=10){return I(e,t)<=s}function j(e,t=100){const s=[{t:0,distance:0}];let n=e.p0,o=0;for(let c=1;c<=t;c++){const i=c/t,r=w(e,i);o+=I(n,r),s.push({t:i,distance:o}),n=r}return s}function K(e,t){if(t<=0)return 0;const s=e[e.length-1].distance;if(t>=s)return 1;let n=0,o=e.length-1;for(;n<o-1;){const f=Math.floor((n+o)/2);e[f].distance<t?n=f:o=f}const c=e[n].distance,i=e[o].distance,r=e[n].t,u=e[o].t;if(i===c)return r;const d=(t-c)/(i-c);return r+d*(u-r)}function X(e){return e[e.length-1].distance}function N(e,t=100){let s=0,n=e.p0;for(let o=1;o<=t;o++){const c=o/t,i=w(e,c);s+=I(n,i),n=i}return s}function A(e,t,s,n,o){const c=I(e.start,e.end),i=c-o;if(i<=0)return c;let r;if(t===void 0)r=n;else if(s)r=t;else{const u=Math.max(0,Math.min(t,i));return o+u}return o+r*i}function b(e,t,s,n,o){const i=I(e.start,e.end)-o;if(i<=0)return 0;let r;if(t===void 0)r=n;else if(s)r=t;else return Math.max(0,Math.min(t,i));return r*i}function Y(e,t,s){const n=new Map,o=new Map,c=new Map;for(const i of e)o.set(i.id,i),c.set(i.id,I(i.start,i.end)),n.set(i.id,[]);for(let i=0;i<t.length;i++){const r=t[i],u=o.get(r.fromLineId),d=o.get(r.toLineId);if(!u||!d)continue;const f=A(u,r.fromOffset,r.fromIsPercentage,1,s.wheelbase),l=b(d,r.toOffset,r.toIsPercentage,0,s.wheelbase),g=T(u,d,s,!1,{fromOffset:f,fromIsPercentage:!1,toOffset:l,toIsPercentage:!1}),p=N(g),m={curveIndex:i,fromLineId:r.fromLineId,toLineId:r.toLineId,fromOffset:f,toOffset:l,curveLength:p};n.get(r.fromLineId).push(m)}return{adjacency:n,lines:o,lineLengths:c}}function B(e,t){return e.curveCount!==t.curveCount?e.curveCount-t.curveCount:e.totalDistance-t.totalDistance}function k(e,t,s,n,o=!1){const{adjacency:c,lines:i,lineLengths:r}=e;if(!i.get(s))return null;const d=r.get(s),f=o?n/100*d:n,l=[],g=new Map,p=(a,v)=>`${a}:${Math.round(v)}`;if(t.lineId===s&&f>=t.offset){const a=f-t.offset;return{segments:[{type:"line",lineId:t.lineId,startOffset:t.offset,endOffset:f,length:a}],totalDistance:a,curveCount:0}}const m=c.get(t.lineId)||[];for(const a of m){if(a.fromOffset<t.offset)continue;const v=a.fromOffset-t.offset,L=v+a.curveLength,O={type:"line",lineId:t.lineId,startOffset:t.offset,endOffset:a.fromOffset,length:v},h={type:"curve",curveIndex:a.curveIndex,startOffset:0,endOffset:a.curveLength,length:a.curveLength};l.push({lineId:a.toLineId,entryOffset:a.toOffset,totalDistance:L,curveCount:1,path:[O,h]})}for(l.sort(B);l.length>0;){const a=l.shift(),v=p(a.lineId,a.entryOffset),L=g.get(v);if(L!==void 0&&(L.curveCount<a.curveCount||L.curveCount===a.curveCount&&L.distance<=a.totalDistance))continue;if(g.set(v,{curveCount:a.curveCount,distance:a.totalDistance}),a.lineId===s){const h=Math.abs(f-a.entryOffset);if(f>=a.entryOffset){const x={type:"line",lineId:s,startOffset:a.entryOffset,endOffset:f,length:h};return{segments:[...a.path,x],totalDistance:a.totalDistance+h,curveCount:a.curveCount}}}const O=c.get(a.lineId)||[];for(const h of O){if(h.fromOffset<a.entryOffset)continue;const x=h.fromOffset-a.entryOffset,V=a.totalDistance+x+h.curveLength,D=a.curveCount+1,E=p(h.toLineId,h.toOffset),C=g.get(E);if(C!==void 0&&(C.curveCount<D||C.curveCount===D&&C.distance<=V))continue;const H={type:"line",lineId:a.lineId,startOffset:a.entryOffset,endOffset:h.fromOffset,length:x},J={type:"curve",curveIndex:h.curveIndex,startOffset:0,endOffset:h.curveLength,length:h.curveLength};l.push({lineId:h.toLineId,entryOffset:h.toOffset,totalDistance:V,curveCount:D,path:[...a.path,H,J]})}l.sort(B)}return null}function z(e,t){const s=Math.sqrt(Math.pow(e.end.x-e.start.x,2)+Math.pow(e.end.y-e.start.y,2)),n=s>0?t/s:0;return{x:e.start.x+(e.end.x-e.start.x)*Math.min(1,Math.max(0,n)),y:e.start.y+(e.end.y-e.start.y)*Math.min(1,Math.max(0,n))}}function G(e){return Math.sqrt(Math.pow(e.end.x-e.start.x,2)+Math.pow(e.end.y-e.start.y,2))}function $(e,t,s){let n=0;for(let o=0;o<t;o++)n+=e.segments[o].length;return n+=s,n}function Q(e,t){let s=0;for(let n=0;n<e.segments.length;n++){const o=e.segments[n],c=s+o.length;if(t<c)return{segmentIndex:n,segmentDistance:t-s};if(t===c)return n+1<e.segments.length?{segmentIndex:n+1,segmentDistance:0}:{segmentIndex:n,segmentDistance:o.length};s+=o.length}return null}function R(e,t,s,n){const c=$(e,t,s)+n;return Q(e,c)}function Z(e,t,s,n){const o=Math.sqrt(Math.pow(n.end.x-n.start.x,2)+Math.pow(n.end.y-n.start.y,2));let c=t+s;c=Math.min(c,o);const i=z(n,c);return{lineId:e,position:i,absoluteOffset:c}}function W(e,t){return{...e,state:"idle"}}function _(e){return{vehicle:e,execution:null}}function ee(e,t){const s=[],n=new Map;for(const o of e){if(!t.get(o.lineId))continue;const i=W(o);s.push(i);const r=_(i);n.set(o.id,r)}return{movingVehicles:s,stateMap:n}}function y(e,t){return{position:z(e,t),lineId:e.id,absoluteOffset:t}}function M(e,t){const s=K(e.arcLengthTable,t);return{position:w(e.bezier,s)}}function te(e,t,s,n,o,c,i){const r=s.segments[t.currentSegmentIndex],u=t.segmentDistance+n;if(u>=r.length){const f=u-r.length,l=t.currentSegmentIndex+1;if(l>=s.segments.length){if(i!==void 0&&r.type==="line"){const a=o.get(r.lineId),v=r.startOffset+u;if(v<=i){const O=y(a,v);return{axleState:{...e,...O},execution:{...t,segmentDistance:u},completed:!1}}const L=y(a,i);return{axleState:{...e,...L},execution:{...t,segmentDistance:i-r.startOffset},completed:!0}}const m=r.type==="line"?y(o.get(r.lineId),r.endOffset):M(c.get(r.curveIndex),r.length);return{axleState:{...e,...m},execution:{...t,segmentDistance:r.length},completed:!0}}const g=s.segments[l],p=g.type==="line"?y(o.get(g.lineId),g.startOffset+f):M(c.get(g.curveIndex),f);return{axleState:{...e,...p},execution:{currentSegmentIndex:l,segmentDistance:f},completed:!1}}const d=r.type==="line"?y(o.get(r.lineId),r.startOffset+u):M(c.get(r.curveIndex),u);return{axleState:{...e,...d},execution:{...t,segmentDistance:u},completed:!1}}function ne(e,t,s,n){const o=new Map;for(const c of e.segments)if(c.type==="curve"&&c.curveIndex!==void 0){const i=t[c.curveIndex];if(i){const r=s.get(i.fromLineId),u=s.get(i.toLineId);if(r&&u){const d=A(r,i.fromOffset,i.fromIsPercentage,1,n.wheelbase),f=b(u,i.toOffset,i.toIsPercentage,0,n.wheelbase),l=T(r,u,n,!1,{fromOffset:d,fromIsPercentage:!1,toOffset:f,toIsPercentage:!1}),g=j(l);o.set(c.curveIndex,{bezier:l,arcLengthTable:g})}}}return o}function oe(e,t,s){const{graph:n,linesMap:o,curves:c,config:i}=s,r=o.get(t.targetLineId);if(!r)return null;const d=G(r)-i.wheelbase;if(d<=0)return null;const f=t.isPercentage?t.targetOffset*d:Math.min(t.targetOffset,d),l=k(n,{lineId:e.rear.lineId,offset:e.rear.absoluteOffset},t.targetLineId,f,!1);if(!l)return null;const g=ne(l,c,o,i);return{path:l,curveDataMap:g}}function se(e,t){const s=e.execution,n=t.vehicleQueues.get(e.vehicle.id),o=n?.[s.currentCommandIndex];if(o&&t.onCommandComplete&&t.onCommandComplete({vehicleId:e.vehicle.id,command:o,finalPosition:{lineId:e.vehicle.rear.lineId,absoluteOffset:e.vehicle.rear.absoluteOffset,position:e.vehicle.rear.position},payload:o.payload}),o?.awaitConfirmation)return{handled:!0,vehicle:{...e.vehicle,state:"waiting"},newExecution:s,isWaiting:!0};const c=s.currentCommandIndex+1;if(n&&c<n.length){const r=n[c],u=t.graphRef.current;if(u){const d={graph:u,linesMap:t.linesMap,curves:t.curves,config:t.config},f=t.prepareCommandPath(e.vehicle,r,d);if(f){const l=R(f.path,0,0,t.config.wheelbase);t.onCommandStart&&t.onCommandStart({vehicleId:e.vehicle.id,command:r,commandIndex:c,startPosition:{lineId:e.vehicle.rear.lineId,absoluteOffset:e.vehicle.rear.absoluteOffset,position:e.vehicle.rear.position}});const g={path:f.path,curveDataMap:f.curveDataMap,currentCommandIndex:c,rear:{currentSegmentIndex:0,segmentDistance:0},front:l?{currentSegmentIndex:l.segmentIndex,segmentDistance:l.segmentDistance}:{currentSegmentIndex:0,segmentDistance:0}};return{handled:!0,vehicle:{...e.vehicle,state:"moving"},newExecution:g}}}}return{handled:!0,vehicle:{...e.vehicle,state:"idle"},newExecution:null}}exports.arcLengthToSegmentPosition=Q;exports.buildArcLengthTable=j;exports.buildGraph=Y;exports.calculateBezierArcLength=N;exports.calculateFrontAxlePosition=R;exports.calculateInitialFrontPosition=Z;exports.calculatePositionOnCurve=M;exports.calculatePositionOnLine=y;exports.calculateTangentLength=q;exports.createBezierCurve=T;exports.createInitialMovementState=_;exports.distance=I;exports.distanceToT=K;exports.findPath=k;exports.getArcLength=X;exports.getCumulativeArcLength=$;exports.getLineLength=G;exports.getPointOnBezier=w;exports.getPointOnLine=F;exports.getPointOnLineByOffset=S;exports.getPositionFromOffset=z;exports.handleArrival=se;exports.initializeAllVehicles=ee;exports.initializeMovingVehicle=W;exports.isPointNearPoint=U;exports.normalize=P;exports.prepareCommandPath=oe;exports.resolveFromLineOffset=A;exports.resolveToLineOffset=b;exports.updateAxlePosition=te;
1
+ "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});function L(t,e){const s=e.x-t.x,o=e.y-t.y;return Math.sqrt(s*s+o*o)}function M(t,e){const s=e.x-t.x,o=e.y-t.y,n=Math.sqrt(s*s+o*o);return n===0?{x:0,y:0}:{x:s/n,y:o/n}}function V(t,e){return e*(t==="proportional-40"?.4:.5522)}function S(t,e,s,o=!1,n){const{wheelbase:c,tangentMode:i}=s;let r;n?.fromOffset!==void 0?r=D(t,n.fromOffset,n.fromIsPercentage??!1):r=t.end;let a;n?.toOffset!==void 0?a=D(e,n.toOffset,n.toIsPercentage??!1):a=e.start;const d=M(t.start,t.end),u=o?{x:r.x-d.x*c,y:r.y-d.y*c}:r,l=M(t.start,t.end),g=M(e.start,e.end),y=L(u,a),m=V(i,y),f=o?{x:u.x-l.x*m,y:u.y-l.y*m}:{x:u.x+l.x*m,y:u.y+l.y*m},v={x:a.x-g.x*m,y:a.y-g.y*m};return{p0:u,p1:f,p2:v,p3:a}}function F(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 D(t,e,s){const o=L(t.start,t.end);let n;return s?n=e:n=o>0?e/o:0,n=Math.max(0,Math.min(1,n)),F(t,n)}function w(t,e){const{p0:s,p1:o,p2:n,p3:c}=t,i=1-e,r=i*i,a=r*i,d=e*e,u=d*e;return{x:a*s.x+3*r*e*o.x+3*i*d*n.x+u*c.x,y:a*s.y+3*r*e*o.y+3*i*d*n.y+u*c.y}}function U(t,e,s=10){return L(t,e)<=s}function j(t,e=100){const s=[{t:0,distance:0}];let o=t.p0,n=0;for(let c=1;c<=e;c++){const i=c/e,r=w(t,i);n+=L(o,r),s.push({t:i,distance:n}),o=r}return s}function K(t,e){if(e<=0)return 0;const s=t[t.length-1].distance;if(e>=s)return 1;let o=0,n=t.length-1;for(;o<n-1;){const u=Math.floor((o+n)/2);t[u].distance<e?o=u:n=u}const c=t[o].distance,i=t[n].distance,r=t[o].t,a=t[n].t;if(i===c)return r;const d=(e-c)/(i-c);return r+d*(a-r)}function X(t){return t[t.length-1].distance}function N(t,e=100){let s=0,o=t.p0;for(let n=1;n<=e;n++){const c=n/e,i=w(t,c);s+=L(o,i),o=i}return s}function A(t,e,s,o,n){const c=L(t.start,t.end),i=c-n;if(i<=0)return c;let r;if(e===void 0)r=o;else if(s)r=e;else{const a=Math.max(0,Math.min(e,i));return n+a}return n+r*i}function b(t,e,s,o,n){const i=L(t.start,t.end)-n;if(i<=0)return 0;let r;if(e===void 0)r=o;else if(s)r=e;else return Math.max(0,Math.min(e,i));return r*i}function Y(t,e,s){const o=new Map,n=new Map,c=new Map;for(const i of t)n.set(i.id,i),c.set(i.id,L(i.start,i.end)),o.set(i.id,[]);for(let i=0;i<e.length;i++){const r=e[i],a=n.get(r.fromLineId),d=n.get(r.toLineId);if(!a||!d)continue;const u=A(a,r.fromOffset,r.fromIsPercentage,1,s.wheelbase),l=b(d,r.toOffset,r.toIsPercentage,0,s.wheelbase),g=S(a,d,s,!1,{fromOffset:u,fromIsPercentage:!1,toOffset:l,toIsPercentage:!1}),y=N(g),m={curveIndex:i,fromLineId:r.fromLineId,toLineId:r.toLineId,fromOffset:u,toOffset:l,curveLength:y};o.get(r.fromLineId).push(m)}return{adjacency:o,lines:n,lineLengths:c}}function B(t,e){return t.curveCount!==e.curveCount?t.curveCount-e.curveCount:t.totalDistance-e.totalDistance}function k(t,e,s,o,n=!1){const{adjacency:c,lines:i,lineLengths:r}=t;if(!i.get(s))return null;const d=r.get(s),u=n?o/100*d:o,l=[],g=new Map,y=(f,v)=>`${f}:${Math.round(v)}`;if(e.lineId===s&&u>=e.offset){const f=u-e.offset;return{segments:[{type:"line",lineId:e.lineId,startOffset:e.offset,endOffset:u,length:f}],totalDistance:f,curveCount:0}}const m=c.get(e.lineId)||[];for(const f of m){if(f.fromOffset<e.offset)continue;const v=f.fromOffset-e.offset,I=v+f.curveLength,O={type:"line",lineId:e.lineId,startOffset:e.offset,endOffset:f.fromOffset,length:v},h={type:"curve",curveIndex:f.curveIndex,startOffset:0,endOffset:f.curveLength,length:f.curveLength};l.push({lineId:f.toLineId,entryOffset:f.toOffset,totalDistance:I,curveCount:1,path:[O,h]})}for(l.sort(B);l.length>0;){const f=l.shift(),v=y(f.lineId,f.entryOffset),I=g.get(v);if(I!==void 0&&(I.curveCount<f.curveCount||I.curveCount===f.curveCount&&I.distance<=f.totalDistance))continue;if(g.set(v,{curveCount:f.curveCount,distance:f.totalDistance}),f.lineId===s){const h=Math.abs(u-f.entryOffset);if(u>=f.entryOffset){const x={type:"line",lineId:s,startOffset:f.entryOffset,endOffset:u,length:h};return{segments:[...f.path,x],totalDistance:f.totalDistance+h,curveCount:f.curveCount}}}const O=c.get(f.lineId)||[];for(const h of O){if(h.fromOffset<f.entryOffset)continue;const x=h.fromOffset-f.entryOffset,q=f.totalDistance+x+h.curveLength,T=f.curveCount+1,H=y(h.toLineId,h.toOffset),P=g.get(H);if(P!==void 0&&(P.curveCount<T||P.curveCount===T&&P.distance<=q))continue;const J={type:"line",lineId:f.lineId,startOffset:f.entryOffset,endOffset:h.fromOffset,length:x},R={type:"curve",curveIndex:h.curveIndex,startOffset:0,endOffset:h.curveLength,length:h.curveLength};l.push({lineId:h.toLineId,entryOffset:h.toOffset,totalDistance:q,curveCount:T,path:[...f.path,J,R]})}l.sort(B)}return null}function z(t,e){const s=Math.sqrt(Math.pow(t.end.x-t.start.x,2)+Math.pow(t.end.y-t.start.y,2)),o=s>0?e/s:0;return{x:t.start.x+(t.end.x-t.start.x)*Math.min(1,Math.max(0,o)),y:t.start.y+(t.end.y-t.start.y)*Math.min(1,Math.max(0,o))}}function G(t){return Math.sqrt(Math.pow(t.end.x-t.start.x,2)+Math.pow(t.end.y-t.start.y,2))}function $(t,e,s){let o=0;for(let n=0;n<e;n++)o+=t.segments[n].length;return o+=s,o}function Q(t,e){let s=0;for(let o=0;o<t.segments.length;o++){const n=t.segments[o],c=s+n.length;if(e<c)return{segmentIndex:o,segmentDistance:e-s};if(e===c)return o+1<t.segments.length?{segmentIndex:o+1,segmentDistance:0}:{segmentIndex:o,segmentDistance:n.length};s+=n.length}return null}function Z(t,e,s,o){const c=$(t,e,s)+o;return Q(t,c)}function E(t,e,s,o){const n=Math.sqrt(Math.pow(o.end.x-o.start.x,2)+Math.pow(o.end.y-o.start.y,2));let c=e+s;c=Math.min(c,n);const i=z(o,c);return{lineId:t,position:i,absoluteOffset:c}}function W(t,e){return{...t,state:"idle"}}function _(t){return{vehicle:t,execution:null}}function tt(t,e){const s=[],o=new Map;for(const n of t){if(!e.get(n.lineId))continue;const i=W(n);s.push(i);const r=_(i);o.set(n.id,r)}return{movingVehicles:s,stateMap:o}}function p(t,e){return{position:z(t,e),lineId:t.id,absoluteOffset:e}}function C(t,e){const s=K(t.arcLengthTable,e);return{position:w(t.bezier,s)}}function et(t,e,s,o,n,c,i){const r=s.segments[e.currentSegmentIndex],a=e.segmentDistance+o;if(a>=r.length){const u=a-r.length,l=e.currentSegmentIndex+1;if(l>=s.segments.length){if(i!==void 0&&r.type==="line"){const f=n.get(r.lineId),v=r.startOffset+a;if(v<=i){const O=p(f,v);return{axleState:{...t,...O},execution:{...e,segmentDistance:a},completed:!1}}const I=p(f,i);return{axleState:{...t,...I},execution:{...e,segmentDistance:i-r.startOffset},completed:!0}}const m=r.type==="line"?p(n.get(r.lineId),r.endOffset):C(c.get(r.curveIndex),r.length);return{axleState:{...t,...m},execution:{...e,segmentDistance:r.length},completed:!0}}const g=s.segments[l],y=g.type==="line"?p(n.get(g.lineId),g.startOffset+u):C(c.get(g.curveIndex),u);return{axleState:{...t,...y},execution:{currentSegmentIndex:l,segmentDistance:u},completed:!1}}const d=r.type==="line"?p(n.get(r.lineId),r.startOffset+a):C(c.get(r.curveIndex),a);return{axleState:{...t,...d},execution:{...e,segmentDistance:a},completed:!1}}function nt(t,e,s,o){const n=new Map;for(const c of t.segments)if(c.type==="curve"&&c.curveIndex!==void 0){const i=e[c.curveIndex];if(i){const r=s.get(i.fromLineId),a=s.get(i.toLineId);if(r&&a){const d=A(r,i.fromOffset,i.fromIsPercentage,1,o.wheelbase),u=b(a,i.toOffset,i.toIsPercentage,0,o.wheelbase),l=S(r,a,o,!1,{fromOffset:d,fromIsPercentage:!1,toOffset:u,toIsPercentage:!1}),g=j(l);n.set(c.curveIndex,{bezier:l,arcLengthTable:g})}}}return n}function ot(t,e,s){const{graph:o,linesMap:n,curves:c,config:i}=s,r=n.get(e.targetLineId);if(!r)return null;const d=G(r)-i.wheelbase;if(d<=0)return null;const u=e.isPercentage?e.targetOffset*d:Math.min(e.targetOffset,d),l=k(o,{lineId:t.rear.lineId,offset:t.rear.absoluteOffset},e.targetLineId,u,!1);if(!l)return null;const g=nt(l,c,n,i);return{path:l,curveDataMap:g}}function st(t,e){const s=t.execution,n=e.vehicleQueues.get(t.vehicle.id)?.[s.currentCommandIndex];return n&&e.onCommandComplete&&e.onCommandComplete({vehicleId:t.vehicle.id,command:n,finalPosition:{lineId:t.vehicle.rear.lineId,absoluteOffset:t.vehicle.rear.absoluteOffset,position:t.vehicle.rear.position},payload:n.payload}),{handled:!0,vehicle:{...t.vehicle,state:"waiting"},newExecution:s,isWaiting:!0}}exports.arcLengthToSegmentPosition=Q;exports.buildArcLengthTable=j;exports.buildGraph=Y;exports.calculateBezierArcLength=N;exports.calculateFrontAxlePosition=Z;exports.calculateInitialFrontPosition=E;exports.calculatePositionOnCurve=C;exports.calculatePositionOnLine=p;exports.calculateTangentLength=V;exports.createBezierCurve=S;exports.createInitialMovementState=_;exports.distance=L;exports.distanceToT=K;exports.findPath=k;exports.getArcLength=X;exports.getCumulativeArcLength=$;exports.getLineLength=G;exports.getPointOnBezier=w;exports.getPointOnLine=F;exports.getPointOnLineByOffset=D;exports.getPositionFromOffset=z;exports.handleArrival=st;exports.initializeAllVehicles=tt;exports.initializeMovingVehicle=W;exports.isPointNearPoint=U;exports.normalize=M;exports.prepareCommandPath=ot;exports.resolveFromLineOffset=A;exports.resolveToLineOffset=b;exports.updateAxlePosition=et;