vehicle-path2 4.0.0 → 4.0.1

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.cjs CHANGED
@@ -1 +1 @@
1
- "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const i=require("./index-DQbf63_R.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 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;
package/dist/core.js CHANGED
@@ -1,5 +1,5 @@
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";
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
3
  function P(n, e) {
4
4
  const a = {
5
5
  lines: n,
@@ -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),h=L(c,o),a=F(i,h),l={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:l,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 S(t,e){const{p0:s,p1:n,p2:i,p3:c}=t,o=1-e,r=o*o,f=r*o,h=e*e,a=h*e;return{x:f*s.x+3*r*e*n.x+3*o*h*i.x+a*c.x,y:f*s.y+3*r*e*n.y+3*o*h*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=S(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 h=(e-c)/(o-c);return r+h*(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=S(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),h=i.get(r.toLineId);if(!f||!h)continue;const a=b(f,r.fromOffset,r.fromIsPercentage,1),l=B(h,r.toOffset,r.toIsPercentage,0),d=z(f,h,s,{fromOffset:a,fromIsPercentage:!1,toOffset:l,toIsPercentage:!1}),g=K(d),v={curveIndex:o,fromLineId:r.fromLineId,toLineId:r.toLineId,fromOffset:a,toOffset:l,curveLength:g};n.get(r.fromLineId).push(v)}return{adjacency:n,lines:i,lineLengths:c}}function E(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 h=r.get(s),a=i?n/100*h:n,l=[],d=new Map,g=(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};l.push({lineId:u.toLineId,entryOffset:u.toOffset,totalDistance:I,curveCount:1,path:[O,m]})}for(l.sort(E);l.length>0;){const u=l.shift(),p=g(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,q=u.totalDistance+C+m.curveLength,w=u.curveCount+1,X=g(m.toLineId,m.toOffset),P=d.get(X);if(P!==void 0&&(P.curveCount<w||P.curveCount===w&&P.distance<=q))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};l.push({lineId:m.toLineId,entryOffset:m.toOffset,totalDistance:q,curveCount:w,path:[...u.path,Y,Z]})}l.sort(E)}return null}function A(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 R(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 R(t,c)}function Q(t,e,s,n){const i=M(n),c=s.length+1,o=new Array(c);o[c-1]={lineId:t,absoluteOffset:e,position:A(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:A(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:A(t,e),lineId:t.id,absoluteOffset:e}}function D(t,e){const s=j(t.arcLengthTable,e);return{position:S(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,l=e.currentSegmentIndex+1;if(l>=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[l],g=d.type==="line"?y(i.get(d.lineId),d.startOffset+a):D(c.get(d.curveIndex),a);return{axleState:{...t,...g},execution:{currentSegmentIndex:l,segmentDistance:a},completed:!1}}const h=r.type==="line"?y(i.get(r.lineId),r.startOffset+f):D(c.get(r.curveIndex),f);return{axleState:{...t,...h},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 h=b(r,o.fromOffset,o.fromIsPercentage,1),a=B(f,o.toOffset,o.toIsPercentage,0),l=z(r,f,n,{fromOffset:h,fromIsPercentage:!1,toOffset:a,toIsPercentage:!1}),d=$(l);i.set(c.curveIndex,{bezier:l,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 l=e.isPercentage?e.targetOffset*a:Math.min(e.targetOffset,a),d=t.axles[t.axles.length-1],g=k(n,{lineId:d.lineId,offset:d.absoluteOffset},e.targetLineId,l,!1);if(!g)return null;const v=ie(g,c,i,o);return{path:g,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){const o=t.map((r,f)=>{const h=f===t.length-1;let a;if(!h){const l=e[f];if(l.currentSegmentIndex<s.segments.length){const d=s.segments[l.currentSegmentIndex];if(d.type==="line"){const g=i.get(d.lineId);g&&(a=M(g))}}}return H(r,e[f],s,n,i,c,a)});return{axles:o.map(r=>r.axleState),axleExecutions:o.map(r=>r.execution),arrived:o[o.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,l)=>a+l,0),r=M(i),f=Math.min(s,r-o);return{axles:Q(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((g,v)=>g+v,0),o=e.axles[e.axles.length-1],r={lineId:o.lineId,offset:o.offset,axles:e.axles.map(g=>({lineId:g.lineId,position:g.position,absoluteOffset:g.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 h=n;const a=this.linesMap.get(s);if(a){const g=Math.max(0,M(a)-c);h=i?n*g:Math.min(n,g)}let l=0;const d=[{segmentIndex:0,segmentDistance:c}];for(let g=0;g<e.axleSpacings.length;g++)l+=e.axleSpacings[g],d.push({segmentIndex:0,segmentDistance:c-l});return{path:f.path,curveDataMap:f.curveDataMap,axleExecutions:d,targetLineId:s,targetOffset:h}}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=R;exports.buildArcLengthTable=$;exports.buildGraph=x;exports.calculateBezierArcLength=K;exports.calculateFrontAxlePosition=ne;exports.calculateInitialAxlePositions=Q;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=S;exports.getPointOnLine=N;exports.getPointOnLineByOffset=V;exports.getPositionFromOffset=A;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;
@@ -15,8 +15,8 @@ function q(t, e, s, n) {
15
15
  n?.fromOffset !== void 0 ? c = z(t, n.fromOffset, n.fromIsPercentage ?? !1) : c = t.end;
16
16
  let o;
17
17
  n?.toOffset !== void 0 ? o = z(e, n.toOffset, n.toIsPercentage ?? !1) : o = e.start;
18
- const r = V(t.start, t.end), f = V(e.start, e.end), l = y(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 };
19
- return { p0: c, p1: g, p2: d, p3: o };
18
+ const r = V(t.start, t.end), u = V(e.start, e.end), h = y(c, o), a = F(i, h), l = { x: c.x + r.x * a, y: c.y + r.y * a }, d = { x: o.x - u.x * a, y: o.y - u.y * a };
19
+ return { p0: c, p1: l, p2: d, p3: o };
20
20
  }
21
21
  function K(t, e) {
22
22
  return {
@@ -30,10 +30,10 @@ function z(t, e, s) {
30
30
  return s ? i = e : i = n > 0 ? e / n : 0, i = Math.max(0, Math.min(1, i)), K(t, i);
31
31
  }
32
32
  function A(t, e) {
33
- 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;
33
+ const { p0: s, p1: n, p2: i, p3: c } = t, o = 1 - e, r = o * o, u = r * o, h = e * e, a = h * e;
34
34
  return {
35
- x: f * s.x + 3 * r * e * n.x + 3 * o * l * i.x + a * c.x,
36
- y: f * s.y + 3 * r * e * n.y + 3 * o * l * i.y + a * c.y
35
+ x: u * s.x + 3 * r * e * n.x + 3 * o * h * i.x + a * c.x,
36
+ y: u * s.y + 3 * r * e * n.y + 3 * o * h * i.y + a * c.y
37
37
  };
38
38
  }
39
39
  function ne(t, e, s = 10) {
@@ -48,7 +48,7 @@ function N(t, e = 100) {
48
48
  }
49
49
  return s;
50
50
  }
51
- function G(t, e) {
51
+ function R(t, e) {
52
52
  if (e <= 0) return 0;
53
53
  const s = t[t.length - 1].distance;
54
54
  if (e >= s) return 1;
@@ -57,15 +57,15 @@ function G(t, e) {
57
57
  const a = Math.floor((n + i) / 2);
58
58
  t[a].distance < e ? n = a : i = a;
59
59
  }
60
- const c = t[n].distance, o = t[i].distance, r = t[n].t, f = t[i].t;
60
+ const c = t[n].distance, o = t[i].distance, r = t[n].t, u = t[i].t;
61
61
  if (o === c) return r;
62
- const l = (e - c) / (o - c);
63
- return r + l * (f - r);
62
+ const h = (e - c) / (o - c);
63
+ return r + h * (u - r);
64
64
  }
65
65
  function se(t) {
66
66
  return t[t.length - 1].distance;
67
67
  }
68
- function Q(t, e = 100) {
68
+ function G(t, e = 100) {
69
69
  let s = 0, n = t.p0;
70
70
  for (let i = 1; i <= e; i++) {
71
71
  const c = i / e, o = A(t, c);
@@ -86,25 +86,25 @@ function I(t, e, s) {
86
86
  for (const o of t)
87
87
  i.set(o.id, o), c.set(o.id, y(o.start, o.end)), n.set(o.id, []);
88
88
  for (let o = 0; o < e.length; o++) {
89
- const r = e[o], f = i.get(r.fromLineId), l = i.get(r.toLineId);
90
- if (!f || !l) continue;
91
- const a = E(f, r.fromOffset, r.fromIsPercentage, 1), g = B(l, r.toOffset, r.toIsPercentage, 0), d = q(
92
- f,
93
- l,
89
+ const r = e[o], u = i.get(r.fromLineId), h = i.get(r.toLineId);
90
+ if (!u || !h) continue;
91
+ const a = E(u, r.fromOffset, r.fromIsPercentage, 1), l = B(h, r.toOffset, r.toIsPercentage, 0), d = q(
92
+ u,
93
+ h,
94
94
  s,
95
95
  {
96
96
  fromOffset: a,
97
97
  fromIsPercentage: !1,
98
- toOffset: g,
98
+ toOffset: l,
99
99
  toIsPercentage: !1
100
100
  }
101
- ), h = Q(d), v = {
101
+ ), g = G(d), v = {
102
102
  curveIndex: o,
103
103
  fromLineId: r.fromLineId,
104
104
  toLineId: r.toLineId,
105
105
  fromOffset: a,
106
- toOffset: g,
107
- curveLength: h
106
+ toOffset: l,
107
+ curveLength: g
108
108
  };
109
109
  n.get(r.fromLineId).push(v);
110
110
  }
@@ -113,79 +113,79 @@ function I(t, e, s) {
113
113
  function b(t, e) {
114
114
  return t.curveCount !== e.curveCount ? t.curveCount - e.curveCount : t.totalDistance - e.totalDistance;
115
115
  }
116
- function R(t, e, s, n, i = !1) {
116
+ function Q(t, e, s, n, i = !1) {
117
117
  const { adjacency: c, lines: o, lineLengths: r } = t;
118
118
  if (!o.get(s)) return null;
119
- const l = r.get(s), a = i ? n / 100 * l : n, g = [], d = /* @__PURE__ */ new Map(), h = (u, p) => `${u}:${Math.round(p)}`;
119
+ const h = r.get(s), a = i ? n / 100 * h : n, l = [], d = /* @__PURE__ */ new Map(), g = (f, p) => `${f}:${Math.round(p)}`;
120
120
  if (e.lineId === s && a >= e.offset) {
121
- const u = a - e.offset;
121
+ const f = a - e.offset;
122
122
  return {
123
123
  segments: [{
124
124
  type: "line",
125
125
  lineId: e.lineId,
126
126
  startOffset: e.offset,
127
127
  endOffset: a,
128
- length: u
128
+ length: f
129
129
  }],
130
- totalDistance: u,
130
+ totalDistance: f,
131
131
  curveCount: 0
132
132
  };
133
133
  }
134
134
  const v = c.get(e.lineId) || [];
135
- for (const u of v) {
136
- if (u.fromOffset < e.offset) continue;
137
- const p = u.fromOffset - e.offset, x = p + u.curveLength, L = {
135
+ for (const f of v) {
136
+ if (f.fromOffset < e.offset) continue;
137
+ const p = f.fromOffset - e.offset, x = p + f.curveLength, L = {
138
138
  type: "line",
139
139
  lineId: e.lineId,
140
140
  startOffset: e.offset,
141
- endOffset: u.fromOffset,
141
+ endOffset: f.fromOffset,
142
142
  length: p
143
143
  }, m = {
144
144
  type: "curve",
145
- curveIndex: u.curveIndex,
145
+ curveIndex: f.curveIndex,
146
146
  startOffset: 0,
147
- endOffset: u.curveLength,
148
- length: u.curveLength
147
+ endOffset: f.curveLength,
148
+ length: f.curveLength
149
149
  };
150
- g.push({
151
- lineId: u.toLineId,
152
- entryOffset: u.toOffset,
150
+ l.push({
151
+ lineId: f.toLineId,
152
+ entryOffset: f.toOffset,
153
153
  totalDistance: x,
154
154
  curveCount: 1,
155
155
  path: [L, m]
156
156
  });
157
157
  }
158
- for (g.sort(b); g.length > 0; ) {
159
- const u = g.shift(), p = h(u.lineId, u.entryOffset), x = d.get(p);
160
- if (x !== void 0 && (x.curveCount < u.curveCount || x.curveCount === u.curveCount && x.distance <= u.totalDistance))
158
+ for (l.sort(b); l.length > 0; ) {
159
+ const f = l.shift(), p = g(f.lineId, f.entryOffset), x = d.get(p);
160
+ if (x !== void 0 && (x.curveCount < f.curveCount || x.curveCount === f.curveCount && x.distance <= f.totalDistance))
161
161
  continue;
162
- if (d.set(p, { curveCount: u.curveCount, distance: u.totalDistance }), u.lineId === s) {
163
- const m = Math.abs(a - u.entryOffset);
164
- if (a >= u.entryOffset) {
162
+ if (d.set(p, { curveCount: f.curveCount, distance: f.totalDistance }), f.lineId === s) {
163
+ const m = Math.abs(a - f.entryOffset);
164
+ if (a >= f.entryOffset) {
165
165
  const C = {
166
166
  type: "line",
167
167
  lineId: s,
168
- startOffset: u.entryOffset,
168
+ startOffset: f.entryOffset,
169
169
  endOffset: a,
170
170
  length: m
171
171
  };
172
172
  return {
173
- segments: [...u.path, C],
174
- totalDistance: u.totalDistance + m,
175
- curveCount: u.curveCount
173
+ segments: [...f.path, C],
174
+ totalDistance: f.totalDistance + m,
175
+ curveCount: f.curveCount
176
176
  };
177
177
  }
178
178
  }
179
- const L = c.get(u.lineId) || [];
179
+ const L = c.get(f.lineId) || [];
180
180
  for (const m of L) {
181
- if (m.fromOffset < u.entryOffset) continue;
182
- const C = m.fromOffset - u.entryOffset, T = u.totalDistance + C + m.curveLength, S = u.curveCount + 1, j = h(m.toLineId, m.toOffset), D = d.get(j);
183
- if (D !== void 0 && (D.curveCount < S || D.curveCount === S && D.distance <= T))
181
+ if (m.fromOffset < f.entryOffset) continue;
182
+ const C = m.fromOffset - f.entryOffset, T = f.totalDistance + C + m.curveLength, w = f.curveCount + 1, j = g(m.toLineId, m.toOffset), D = d.get(j);
183
+ if (D !== void 0 && (D.curveCount < w || D.curveCount === w && D.distance <= T))
184
184
  continue;
185
185
  const $ = {
186
186
  type: "line",
187
- lineId: u.lineId,
188
- startOffset: u.entryOffset,
187
+ lineId: f.lineId,
188
+ startOffset: f.entryOffset,
189
189
  endOffset: m.fromOffset,
190
190
  length: C
191
191
  }, k = {
@@ -195,19 +195,19 @@ function R(t, e, s, n, i = !1) {
195
195
  endOffset: m.curveLength,
196
196
  length: m.curveLength
197
197
  };
198
- g.push({
198
+ l.push({
199
199
  lineId: m.toLineId,
200
200
  entryOffset: m.toOffset,
201
201
  totalDistance: T,
202
- curveCount: S,
203
- path: [...u.path, $, k]
202
+ curveCount: w,
203
+ path: [...f.path, $, k]
204
204
  });
205
205
  }
206
- g.sort(b);
206
+ l.sort(b);
207
207
  }
208
208
  return null;
209
209
  }
210
- function P(t, e) {
210
+ function S(t, e) {
211
211
  const s = Math.sqrt(
212
212
  Math.pow(t.end.x - t.start.x, 2) + Math.pow(t.end.y - t.start.y, 2)
213
213
  ), n = s > 0 ? e / s : 0;
@@ -261,14 +261,14 @@ function H(t, e, s, n) {
261
261
  o[c - 1] = {
262
262
  lineId: t,
263
263
  absoluteOffset: e,
264
- position: P(n, e)
264
+ position: S(n, e)
265
265
  };
266
266
  let r = e;
267
- for (let f = c - 2; f >= 0; f--)
268
- r = Math.min(r + s[f], i), o[f] = {
267
+ for (let u = c - 2; u >= 0; u--)
268
+ r = Math.min(r + s[u], i), o[u] = {
269
269
  lineId: t,
270
270
  absoluteOffset: r,
271
- position: P(n, r)
271
+ position: S(n, r)
272
272
  };
273
273
  return o;
274
274
  }
@@ -296,28 +296,28 @@ function re(t, e) {
296
296
  return { movingVehicles: s, stateMap: n };
297
297
  }
298
298
  function M(t, e) {
299
- return { position: P(t, e), lineId: t.id, absoluteOffset: e };
299
+ return { position: S(t, e), lineId: t.id, absoluteOffset: e };
300
300
  }
301
- function w(t, e) {
302
- const s = G(t.arcLengthTable, e);
301
+ function P(t, e) {
302
+ const s = R(t.arcLengthTable, e);
303
303
  return { position: A(t.bezier, s) };
304
304
  }
305
305
  function X(t, e, s, n, i, c, o) {
306
- const r = s.segments[e.currentSegmentIndex], f = e.segmentDistance + n;
307
- if (f >= r.length) {
308
- const a = f - r.length, g = e.currentSegmentIndex + 1;
309
- if (g >= s.segments.length) {
306
+ const r = s.segments[e.currentSegmentIndex], u = e.segmentDistance + n;
307
+ if (u >= r.length) {
308
+ const a = u - r.length, l = e.currentSegmentIndex + 1;
309
+ if (l >= s.segments.length) {
310
310
  if (o !== void 0 && r.type === "line") {
311
- const u = i.get(r.lineId), p = r.startOffset + f;
311
+ const f = i.get(r.lineId), p = r.startOffset + u;
312
312
  if (p <= o) {
313
- const L = M(u, p);
313
+ const L = M(f, p);
314
314
  return {
315
315
  axleState: { ...t, ...L },
316
- execution: { ...e, segmentDistance: f },
316
+ execution: { ...e, segmentDistance: u },
317
317
  completed: !1
318
318
  };
319
319
  }
320
- const x = M(u, o);
320
+ const x = M(f, o);
321
321
  return {
322
322
  axleState: { ...t, ...x },
323
323
  execution: { ...e, segmentDistance: o - r.startOffset },
@@ -327,7 +327,7 @@ function X(t, e, s, n, i, c, o) {
327
327
  const v = r.type === "line" ? M(
328
328
  i.get(r.lineId),
329
329
  r.endOffset
330
- ) : w(
330
+ ) : P(
331
331
  c.get(r.curveIndex),
332
332
  r.length
333
333
  );
@@ -337,32 +337,32 @@ function X(t, e, s, n, i, c, o) {
337
337
  completed: !0
338
338
  };
339
339
  }
340
- const d = s.segments[g], h = d.type === "line" ? M(
340
+ const d = s.segments[l], g = d.type === "line" ? M(
341
341
  i.get(d.lineId),
342
342
  d.startOffset + a
343
- ) : w(
343
+ ) : P(
344
344
  c.get(d.curveIndex),
345
345
  a
346
346
  );
347
347
  return {
348
- axleState: { ...t, ...h },
348
+ axleState: { ...t, ...g },
349
349
  execution: {
350
- currentSegmentIndex: g,
350
+ currentSegmentIndex: l,
351
351
  segmentDistance: a
352
352
  },
353
353
  completed: !1
354
354
  };
355
355
  }
356
- const l = r.type === "line" ? M(
356
+ const h = r.type === "line" ? M(
357
357
  i.get(r.lineId),
358
- r.startOffset + f
359
- ) : w(
358
+ r.startOffset + u
359
+ ) : P(
360
360
  c.get(r.curveIndex),
361
- f
361
+ u
362
362
  );
363
363
  return {
364
- axleState: { ...t, ...l },
365
- execution: { ...e, segmentDistance: f },
364
+ axleState: { ...t, ...h },
365
+ execution: { ...e, segmentDistance: u },
366
366
  completed: !1
367
367
  };
368
368
  }
@@ -372,30 +372,30 @@ function Y(t, e, s, n) {
372
372
  if (c.type === "curve" && c.curveIndex !== void 0) {
373
373
  const o = e[c.curveIndex];
374
374
  if (o) {
375
- const r = s.get(o.fromLineId), f = s.get(o.toLineId);
376
- if (r && f) {
377
- const l = E(
375
+ const r = s.get(o.fromLineId), u = s.get(o.toLineId);
376
+ if (r && u) {
377
+ const h = E(
378
378
  r,
379
379
  o.fromOffset,
380
380
  o.fromIsPercentage,
381
381
  1
382
382
  ), a = B(
383
- f,
383
+ u,
384
384
  o.toOffset,
385
385
  o.toIsPercentage,
386
386
  0
387
- ), g = q(
387
+ ), l = q(
388
388
  r,
389
- f,
389
+ u,
390
390
  n,
391
391
  {
392
- fromOffset: l,
392
+ fromOffset: h,
393
393
  fromIsPercentage: !1,
394
394
  toOffset: a,
395
395
  toIsPercentage: !1
396
396
  }
397
- ), d = N(g);
398
- i.set(c.curveIndex, { bezier: g, arcLengthTable: d });
397
+ ), d = N(l);
398
+ i.set(c.curveIndex, { bezier: l, arcLengthTable: d });
399
399
  }
400
400
  }
401
401
  }
@@ -404,18 +404,18 @@ function Y(t, e, s, n) {
404
404
  function Z(t, e, s) {
405
405
  const { graph: n, linesMap: i, curves: c, config: o } = s, r = i.get(e.targetLineId);
406
406
  if (!r) return null;
407
- const f = t.axleSpacings.reduce((u, p) => u + p, 0), a = O(r) - f;
407
+ const u = t.axleSpacings.reduce((f, p) => f + p, 0), a = O(r) - u;
408
408
  if (a <= 0) return null;
409
- const g = e.isPercentage ? e.targetOffset * a : Math.min(e.targetOffset, a), d = t.axles[t.axles.length - 1], h = R(
409
+ const l = e.isPercentage ? e.targetOffset * a : Math.min(e.targetOffset, a), d = t.axles[t.axles.length - 1], g = Q(
410
410
  n,
411
411
  { lineId: d.lineId, offset: d.absoluteOffset },
412
412
  e.targetLineId,
413
- g,
413
+ l,
414
414
  !1
415
415
  );
416
- if (!h) return null;
417
- const v = Y(h, c, i, o);
418
- return { path: h, curveDataMap: v };
416
+ if (!g) return null;
417
+ const v = Y(g, c, i, o);
418
+ return { path: g, curveDataMap: v };
419
419
  }
420
420
  function oe(t, e) {
421
421
  const s = t.execution, i = e.vehicleQueues.get(t.vehicle.id)?.[s.currentCommandIndex];
@@ -437,23 +437,25 @@ function oe(t, e) {
437
437
  };
438
438
  }
439
439
  function ee(t, e, s, n, i, c) {
440
- let o;
441
- const r = e[0];
442
- if (r.currentSegmentIndex < s.segments.length) {
443
- const l = s.segments[r.currentSegmentIndex];
444
- if (l.type === "line") {
445
- const a = i.get(l.lineId);
446
- a && (o = O(a));
440
+ const o = t.map((r, u) => {
441
+ const h = u === t.length - 1;
442
+ let a;
443
+ if (!h) {
444
+ const l = e[u];
445
+ if (l.currentSegmentIndex < s.segments.length) {
446
+ const d = s.segments[l.currentSegmentIndex];
447
+ if (d.type === "line") {
448
+ const g = i.get(d.lineId);
449
+ g && (a = O(g));
450
+ }
451
+ }
447
452
  }
448
- }
449
- const f = t.map((l, a) => {
450
- const g = a === 0 ? o : void 0;
451
- return X(l, e[a], s, n, i, c, g);
453
+ return X(r, e[u], s, n, i, c, a);
452
454
  });
453
455
  return {
454
- axles: f.map((l) => l.axleState),
455
- axleExecutions: f.map((l) => l.execution),
456
- arrived: f[f.length - 1].completed
456
+ axles: o.map((r) => r.axleState),
457
+ axleExecutions: o.map((r) => r.execution),
458
+ arrived: o[o.length - 1].completed
457
459
  // axles[N-1] = rearmost menentukan arrived
458
460
  };
459
461
  }
@@ -567,9 +569,9 @@ class ce {
567
569
  const { axleSpacings: c } = n;
568
570
  if (c.length === 0)
569
571
  throw new Error("initializeVehicle: axleSpacings must have at least one entry (vehicle needs ≥2 axles)");
570
- const o = c.reduce((a, g) => a + g, 0), r = O(i), f = Math.min(s, r - o);
572
+ const o = c.reduce((a, l) => a + l, 0), r = O(i), u = Math.min(s, r - o);
571
573
  return {
572
- axles: H(e, f, c, i).map((a) => ({ lineId: a.lineId, offset: a.absoluteOffset, position: a.position })),
574
+ axles: H(e, u, c, i).map((a) => ({ lineId: a.lineId, offset: a.absoluteOffset, position: a.position })),
573
575
  axleSpacings: c
574
576
  };
575
577
  }
@@ -585,16 +587,16 @@ class ce {
585
587
  */
586
588
  preparePath(e, s, n, i = !1) {
587
589
  if (!this.graph) return null;
588
- const c = e.axleSpacings.reduce((h, v) => h + v, 0), o = e.axles[e.axles.length - 1], r = {
590
+ const c = e.axleSpacings.reduce((g, v) => g + v, 0), o = e.axles[e.axles.length - 1], r = {
589
591
  lineId: o.lineId,
590
592
  offset: o.offset,
591
- axles: e.axles.map((h) => ({
592
- lineId: h.lineId,
593
- position: h.position,
594
- absoluteOffset: h.offset
593
+ axles: e.axles.map((g) => ({
594
+ lineId: g.lineId,
595
+ position: g.position,
596
+ absoluteOffset: g.offset
595
597
  })),
596
598
  axleSpacings: e.axleSpacings
597
- }, f = Z(r, {
599
+ }, u = Z(r, {
598
600
  targetLineId: s,
599
601
  targetOffset: n,
600
602
  isPercentage: i
@@ -604,26 +606,26 @@ class ce {
604
606
  curves: this.curves,
605
607
  config: this.config
606
608
  });
607
- if (!f) return null;
608
- let l = n;
609
+ if (!u) return null;
610
+ let h = n;
609
611
  const a = this.linesMap.get(s);
610
612
  if (a) {
611
- const h = Math.max(0, O(a) - c);
612
- l = i ? n * h : Math.min(n, h);
613
+ const g = Math.max(0, O(a) - c);
614
+ h = i ? n * g : Math.min(n, g);
613
615
  }
614
- let g = 0;
616
+ let l = 0;
615
617
  const d = [
616
618
  { segmentIndex: 0, segmentDistance: c }
617
619
  // axles[0] = front
618
620
  ];
619
- for (let h = 0; h < e.axleSpacings.length; h++)
620
- g += e.axleSpacings[h], d.push({ segmentIndex: 0, segmentDistance: c - g });
621
+ for (let g = 0; g < e.axleSpacings.length; g++)
622
+ l += e.axleSpacings[g], d.push({ segmentIndex: 0, segmentDistance: c - l });
621
623
  return {
622
- path: f.path,
623
- curveDataMap: f.curveDataMap,
624
+ path: u.path,
625
+ curveDataMap: u.curveDataMap,
624
626
  axleExecutions: d,
625
627
  targetLineId: s,
626
- targetOffset: l
628
+ targetOffset: h
627
629
  };
628
630
  }
629
631
  /**
@@ -672,24 +674,24 @@ export {
672
674
  _ as b,
673
675
  N as c,
674
676
  I as d,
675
- Q as e,
677
+ G as e,
676
678
  ie as f,
677
679
  W as g,
678
680
  H as h,
679
- w as i,
681
+ P as i,
680
682
  M as j,
681
683
  F as k,
682
684
  q as l,
683
685
  ee as m,
684
686
  U as n,
685
687
  y as o,
686
- G as p,
687
- R as q,
688
+ R as p,
689
+ Q as q,
688
690
  se as r,
689
691
  A as s,
690
692
  K as t,
691
693
  z as u,
692
- P as v,
694
+ S as v,
693
695
  oe as w,
694
696
  re as x,
695
697
  J as y,
@@ -1 +1 @@
1
- "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const e=require("./index-DQbf63_R.cjs");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.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.moveVehicle=e.moveVehicle;exports.normalize=e.normalize;exports.prepareCommandPath=e.prepareCommandPath;exports.resolveFromLineOffset=e.resolveFromLineOffset;exports.resolveToLineOffset=e.resolveToLineOffset;exports.updateAxlePosition=e.updateAxlePosition;
1
+ "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const e=require("./index-BQoeJKCj.cjs");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.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.moveVehicle=e.moveVehicle;exports.normalize=e.normalize;exports.prepareCommandPath=e.prepareCommandPath;exports.resolveFromLineOffset=e.resolveFromLineOffset;exports.resolveToLineOffset=e.resolveToLineOffset;exports.updateAxlePosition=e.updateAxlePosition;
@@ -1,4 +1,4 @@
1
- import { P as i, b as t, c as s, d as n, e as o, f as l, h as r, i as c, j as g, l as h, n as P, o as u, p as L, q as f, r as m, g as v, a as A, s as d, t as O, u as p, v as z, w as x, x as B, y as C, m as T, A as b, B as F, C as V, D as y, E } from "./index-okJUn3WJ.js";
1
+ import { P as i, b as t, c as s, d as n, e as o, f as l, h as r, i as c, j as g, l as h, n as P, o as u, p as L, q as f, r as m, g as v, a as A, s as d, t as O, u as p, v as z, w as x, x as B, y as C, m as T, A as b, B as F, C as V, D as y, E } from "./index-DUYG8fxI.js";
2
2
  export {
3
3
  i as PathEngine,
4
4
  t as arcLengthToSegmentPosition,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "vehicle-path2",
3
- "version": "4.0.0",
3
+ "version": "4.0.1",
4
4
  "description": "Vehicle motion simulator library for dual-axle vehicle movement along paths composed of lines and Bezier curves",
5
5
  "type": "module",
6
6
  "main": "./dist/vehicle-path.cjs",
@@ -1 +0,0 @@
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;