vehicle-path2 1.0.10 → 1.0.11

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.
@@ -24,6 +24,7 @@ export interface PathSegment {
24
24
  export interface PathResult {
25
25
  segments: PathSegment[];
26
26
  totalDistance: number;
27
+ curveCount: number;
27
28
  }
28
29
  export interface VehiclePosition {
29
30
  lineId: string;
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 V(e,t){return t*(e==="proportional-40"?.4:.5522)}function C(e,t,s,n=!1,o){const{wheelbase:c,tangentMode:r}=s;let i;o?.fromOffset!==void 0?i=D(e,o.fromOffset,o.fromIsPercentage??!1):i=e.end;let l;o?.toOffset!==void 0?l=D(t,o.toOffset,o.toIsPercentage??!1):l=t.start;const d=P(e.start,e.end),f=n?{x:i.x-d.x*c,y:i.y-d.y*c}:i,u=P(e.start,e.end),g=P(t.start,t.end),p=I(f,l),v=V(r,p),a=n?{x:f.x-u.x*v,y:f.y-u.y*v}:{x:f.x+u.x*v,y:f.y+u.y*v},m={x:l.x-g.x*v,y:l.y-g.y*v};return{p0:f,p1:a,p2:m,p3:l}}function B(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 D(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)),B(e,o)}function w(e,t){const{p0:s,p1:n,p2:o,p3:c}=e,r=1-t,i=r*r,l=i*r,d=t*t,f=d*t;return{x:l*s.x+3*i*t*n.x+3*r*d*o.x+f*c.x,y:l*s.y+3*i*t*n.y+3*r*d*o.y+f*c.y}}function H(e,t,s=10){return I(e,t)<=s}function q(e,t=100){const s=[{t:0,distance:0}];let n=e.p0,o=0;for(let c=1;c<=t;c++){const r=c/t,i=w(e,r);o+=I(n,i),s.push({t:r,distance:o}),n=i}return s}function F(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,r=e[o].distance,i=e[n].t,l=e[o].t;if(r===c)return i;const d=(t-c)/(r-c);return i+d*(l-i)}function J(e){return e[e.length-1].distance}function j(e,t=100){let s=0,n=e.p0;for(let o=1;o<=t;o++){const c=o/t,r=w(e,c);s+=I(n,r),n=r}return s}function S(e,t,s,n,o){const c=I(e.start,e.end),r=c-o;if(r<=0)return c;let i;if(t===void 0)i=n;else if(s)i=t;else{const l=Math.max(0,Math.min(t,r));return o+l}return o+i*r}function T(e,t,s,n,o){const r=I(e.start,e.end)-o;if(r<=0)return 0;let i;if(t===void 0)i=n;else if(s)i=t;else return Math.max(0,Math.min(t,r));return i*r}function U(e,t,s){const n=new Map,o=new Map,c=new Map;for(const r of e)o.set(r.id,r),c.set(r.id,I(r.start,r.end)),n.set(r.id,[]);for(let r=0;r<t.length;r++){const i=t[r],l=o.get(i.fromLineId),d=o.get(i.toLineId);if(!l||!d)continue;const f=S(l,i.fromOffset,i.fromIsPercentage,1,s.wheelbase),u=T(d,i.toOffset,i.toIsPercentage,0,s.wheelbase),g=C(l,d,s,!1,{fromOffset:f,fromIsPercentage:!1,toOffset:u,toIsPercentage:!1}),p=j(g),v={curveIndex:r,fromLineId:i.fromLineId,toLineId:i.toLineId,fromOffset:f,toOffset:u,curveLength:p};n.get(i.fromLineId).push(v)}return{adjacency:n,lines:o,lineLengths:c}}function K(e,t,s,n,o=!1){const{adjacency:c,lines:r,lineLengths:i}=e;if(!r.get(s))return null;const d=i.get(s),f=o?n/100*d:n,u=[],g=new Map,p=(a,m)=>`${a}:${Math.round(m)}`;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}}const v=c.get(t.lineId)||[];for(const a of v){if(a.fromOffset<t.offset)continue;const m=a.fromOffset-t.offset,L=m+a.curveLength,x={type:"line",lineId:t.lineId,startOffset:t.offset,endOffset:a.fromOffset,length:m},h={type:"curve",curveIndex:a.curveIndex,startOffset:0,endOffset:a.curveLength,length:a.curveLength};u.push({lineId:a.toLineId,entryOffset:a.toOffset,totalDistance:L,path:[x,h]})}for(u.sort((a,m)=>a.totalDistance-m.totalDistance);u.length>0;){const a=u.shift(),m=p(a.lineId,a.entryOffset),L=g.get(m);if(L!==void 0&&L<=a.totalDistance)continue;if(g.set(m,a.totalDistance),a.lineId===s){const h=Math.abs(f-a.entryOffset);if(f>=a.entryOffset){const y={type:"line",lineId:s,startOffset:a.entryOffset,endOffset:f,length:h};return{segments:[...a.path,y],totalDistance:a.totalDistance+h}}}const x=c.get(a.lineId)||[];for(const h of x){if(h.fromOffset<a.entryOffset)continue;const y=h.fromOffset-a.entryOffset,A=a.totalDistance+y+h.curveLength,W=p(h.toLineId,h.toOffset),z=g.get(W);if(z!==void 0&&z<=A)continue;const _={type:"line",lineId:a.lineId,startOffset:a.entryOffset,endOffset:h.fromOffset,length:y},E={type:"curve",curveIndex:h.curveIndex,startOffset:0,endOffset:h.curveLength,length:h.curveLength};u.push({lineId:h.toLineId,entryOffset:h.toOffset,totalDistance:A,path:[...a.path,_,E]})}u.sort((h,y)=>h.totalDistance-y.totalDistance)}return null}function b(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 N(e,t,s){let n=0;for(let o=0;o<t;o++)n+=e.segments[o].length;return n+=s,n}function $(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 k(e,t,s,n){const c=N(e,t,s)+n;return $(e,c)}function X(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 r=b(n,c);return{lineId:e,position:r,absoluteOffset:c}}function Q(e,t){return{...e,state:"idle"}}function R(e){return{vehicle:e,execution:null}}function Y(e,t){const s=[],n=new Map;for(const o of e){if(!t.get(o.lineId))continue;const r=Q(o);s.push(r);const i=R(r);n.set(o.id,i)}return{movingVehicles:s,stateMap:n}}function O(e,t){return{position:b(e,t),lineId:e.id,absoluteOffset:t}}function M(e,t){const s=F(e.arcLengthTable,t);return{position:w(e.bezier,s)}}function Z(e,t,s,n,o,c,r){const i=s.segments[t.currentSegmentIndex],l=t.segmentDistance+n;if(l>=i.length){const f=l-i.length,u=t.currentSegmentIndex+1;if(u>=s.segments.length){if(r!==void 0&&i.type==="line"){const a=o.get(i.lineId),m=i.startOffset+l;if(m<=r){const x=O(a,m);return{axleState:{...e,...x},execution:{...t,segmentDistance:l},completed:!1}}const L=O(a,r);return{axleState:{...e,...L},execution:{...t,segmentDistance:r-i.startOffset},completed:!0}}const v=i.type==="line"?O(o.get(i.lineId),i.endOffset):M(c.get(i.curveIndex),i.length);return{axleState:{...e,...v},execution:{...t,segmentDistance:i.length},completed:!0}}const g=s.segments[u],p=g.type==="line"?O(o.get(g.lineId),g.startOffset+f):M(c.get(g.curveIndex),f);return{axleState:{...e,...p},execution:{currentSegmentIndex:u,segmentDistance:f},completed:!1}}const d=i.type==="line"?O(o.get(i.lineId),i.startOffset+l):M(c.get(i.curveIndex),l);return{axleState:{...e,...d},execution:{...t,segmentDistance:l},completed:!1}}function ee(e,t,s,n){const o=new Map;for(const c of e.segments)if(c.type==="curve"&&c.curveIndex!==void 0){const r=t[c.curveIndex];if(r){const i=s.get(r.fromLineId),l=s.get(r.toLineId);if(i&&l){const d=S(i,r.fromOffset,r.fromIsPercentage,1,n.wheelbase),f=T(l,r.toOffset,r.toIsPercentage,0,n.wheelbase),u=C(i,l,n,!1,{fromOffset:d,fromIsPercentage:!1,toOffset:f,toIsPercentage:!1}),g=q(u);o.set(c.curveIndex,{bezier:u,arcLengthTable:g})}}}return o}function te(e,t,s){const{graph:n,linesMap:o,curves:c,config:r}=s,i=o.get(t.targetLineId);if(!i)return null;const d=G(i)-r.wheelbase;if(d<=0)return null;const f=t.isPercentage?t.targetOffset*d:Math.min(t.targetOffset,d),u=K(n,{lineId:e.rear.lineId,offset:e.rear.absoluteOffset},t.targetLineId,f,!1);if(!u)return null;const g=ee(u,c,o,r);return{path:u,curveDataMap:g}}function ne(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 i=n[c],l=t.graphRef.current;if(l){const d={graph:l,linesMap:t.linesMap,curves:t.curves,config:t.config},f=t.prepareCommandPath(e.vehicle,i,d);if(f){const u=k(f.path,0,0,t.config.wheelbase);t.onCommandStart&&t.onCommandStart({vehicleId:e.vehicle.id,command:i,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:u?{currentSegmentIndex:u.segmentIndex,segmentDistance:u.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=$;exports.buildArcLengthTable=q;exports.buildGraph=U;exports.calculateBezierArcLength=j;exports.calculateFrontAxlePosition=k;exports.calculateInitialFrontPosition=X;exports.calculatePositionOnCurve=M;exports.calculatePositionOnLine=O;exports.calculateTangentLength=V;exports.createBezierCurve=C;exports.createInitialMovementState=R;exports.distance=I;exports.distanceToT=F;exports.findPath=K;exports.getArcLength=J;exports.getCumulativeArcLength=N;exports.getLineLength=G;exports.getPointOnBezier=w;exports.getPointOnLine=B;exports.getPointOnLineByOffset=D;exports.getPositionFromOffset=b;exports.handleArrival=ne;exports.initializeAllVehicles=Y;exports.initializeMovingVehicle=Q;exports.isPointNearPoint=H;exports.normalize=P;exports.prepareCommandPath=te;exports.resolveFromLineOffset=S;exports.resolveToLineOffset=T;exports.updateAxlePosition=Z;
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;
package/dist/core.js CHANGED
@@ -1,124 +1,124 @@
1
- function v(e, t) {
2
- const o = t.x - e.x, n = t.y - e.y;
3
- return Math.sqrt(o * o + n * n);
1
+ function y(e, t) {
2
+ const s = t.x - e.x, n = t.y - e.y;
3
+ return Math.sqrt(s * s + n * n);
4
4
  }
5
- function M(e, t) {
6
- const o = t.x - e.x, n = t.y - e.y, s = Math.sqrt(o * o + n * n);
7
- return s === 0 ? { x: 0, y: 0 } : { x: o / s, y: n / s };
5
+ function w(e, t) {
6
+ const s = t.x - e.x, n = t.y - e.y, o = Math.sqrt(s * s + n * n);
7
+ return o === 0 ? { x: 0, y: 0 } : { x: s / o, y: n / o };
8
8
  }
9
- function F(e, t) {
9
+ function K(e, t) {
10
10
  return t * (e === "proportional-40" ? 0.4 : 0.5522);
11
11
  }
12
- function T(e, t, o, n = !1, s) {
13
- const { wheelbase: c, tangentMode: i } = o;
12
+ function A(e, t, s, n = !1, o) {
13
+ const { wheelbase: c, tangentMode: i } = s;
14
14
  let r;
15
- s?.fromOffset !== void 0 ? r = S(e, s.fromOffset, s.fromIsPercentage ?? !1) : r = e.end;
16
- let l;
17
- s?.toOffset !== void 0 ? l = S(t, s.toOffset, s.toIsPercentage ?? !1) : l = t.start;
18
- const u = M(e.start, e.end), a = n ? {
15
+ o?.fromOffset !== void 0 ? r = T(e, o.fromOffset, o.fromIsPercentage ?? !1) : r = e.end;
16
+ let u;
17
+ o?.toOffset !== void 0 ? u = T(t, o.toOffset, o.toIsPercentage ?? !1) : u = t.start;
18
+ const l = w(e.start, e.end), a = n ? {
19
19
  // Transition with flip: kurva dimulai dari P (baseP0 - wheelbase in line direction)
20
- x: r.x - u.x * c,
21
- y: r.y - u.y * c
22
- } : r, d = M(e.start, e.end), g = M(t.start, t.end), p = v(a, l), I = F(i, p), f = n ? { x: a.x - d.x * I, y: a.y - d.y * I } : { x: a.x + d.x * I, y: a.y + d.y * I }, m = {
23
- x: l.x - g.x * I,
24
- y: l.y - g.y * I
20
+ x: r.x - l.x * c,
21
+ y: r.y - l.y * c
22
+ } : r, d = w(e.start, e.end), g = w(t.start, t.end), I = y(a, u), m = K(i, I), f = n ? { x: a.x - d.x * m, y: a.y - d.y * m } : { x: a.x + d.x * m, y: a.y + d.y * m }, v = {
23
+ x: u.x - g.x * m,
24
+ y: u.y - g.y * m
25
25
  };
26
- return { p0: a, p1: f, p2: m, p3: l };
26
+ return { p0: a, p1: f, p2: v, p3: u };
27
27
  }
28
- function K(e, t) {
28
+ function k(e, t) {
29
29
  return {
30
30
  x: e.start.x + (e.end.x - e.start.x) * t,
31
31
  y: e.start.y + (e.end.y - e.start.y) * t
32
32
  };
33
33
  }
34
- function S(e, t, o) {
35
- const n = v(e.start, e.end);
36
- let s;
37
- return o ? s = t : s = n > 0 ? t / n : 0, s = Math.max(0, Math.min(1, s)), K(e, s);
34
+ function T(e, t, s) {
35
+ const n = y(e.start, e.end);
36
+ let o;
37
+ return s ? o = t : o = n > 0 ? t / n : 0, o = Math.max(0, Math.min(1, o)), k(e, o);
38
38
  }
39
39
  function D(e, t) {
40
- const { p0: o, p1: n, p2: s, p3: c } = e, i = 1 - t, r = i * i, l = r * i, u = t * t, a = u * t;
40
+ const { p0: s, p1: n, p2: o, p3: c } = e, i = 1 - t, r = i * i, u = r * i, l = t * t, a = l * t;
41
41
  return {
42
- x: l * o.x + 3 * r * t * n.x + 3 * i * u * s.x + a * c.x,
43
- y: l * o.y + 3 * r * t * n.y + 3 * i * u * s.y + a * c.y
42
+ x: u * s.x + 3 * r * t * n.x + 3 * i * l * o.x + a * c.x,
43
+ y: u * s.y + 3 * r * t * n.y + 3 * i * l * o.y + a * c.y
44
44
  };
45
45
  }
46
- function J(e, t, o = 10) {
47
- return v(e, t) <= o;
46
+ function Y(e, t, s = 10) {
47
+ return y(e, t) <= s;
48
48
  }
49
- function j(e, t = 100) {
50
- const o = [{ t: 0, distance: 0 }];
51
- let n = e.p0, s = 0;
49
+ function N(e, t = 100) {
50
+ const s = [{ t: 0, distance: 0 }];
51
+ let n = e.p0, o = 0;
52
52
  for (let c = 1; c <= t; c++) {
53
53
  const i = c / t, r = D(e, i);
54
- s += v(n, r), o.push({ t: i, distance: s }), n = r;
54
+ o += y(n, r), s.push({ t: i, distance: o }), n = r;
55
55
  }
56
- return o;
56
+ return s;
57
57
  }
58
58
  function $(e, t) {
59
59
  if (t <= 0) return 0;
60
- const o = e[e.length - 1].distance;
61
- if (t >= o) return 1;
62
- let n = 0, s = e.length - 1;
63
- for (; n < s - 1; ) {
64
- const a = Math.floor((n + s) / 2);
65
- e[a].distance < t ? n = a : s = a;
60
+ const s = e[e.length - 1].distance;
61
+ if (t >= s) return 1;
62
+ let n = 0, o = e.length - 1;
63
+ for (; n < o - 1; ) {
64
+ const a = Math.floor((n + o) / 2);
65
+ e[a].distance < t ? n = a : o = a;
66
66
  }
67
- const c = e[n].distance, i = e[s].distance, r = e[n].t, l = e[s].t;
67
+ const c = e[n].distance, i = e[o].distance, r = e[n].t, u = e[o].t;
68
68
  if (i === c) return r;
69
- const u = (t - c) / (i - c);
70
- return r + u * (l - r);
69
+ const l = (t - c) / (i - c);
70
+ return r + l * (u - r);
71
71
  }
72
- function U(e) {
72
+ function Z(e) {
73
73
  return e[e.length - 1].distance;
74
74
  }
75
- function k(e, t = 100) {
76
- let o = 0, n = e.p0;
77
- for (let s = 1; s <= t; s++) {
78
- const c = s / t, i = D(e, c);
79
- o += v(n, i), n = i;
75
+ function G(e, t = 100) {
76
+ let s = 0, n = e.p0;
77
+ for (let o = 1; o <= t; o++) {
78
+ const c = o / t, i = D(e, c);
79
+ s += y(n, i), n = i;
80
80
  }
81
- return o;
81
+ return s;
82
82
  }
83
- function b(e, t, o, n, s) {
84
- const c = v(e.start, e.end), i = c - s;
83
+ function V(e, t, s, n, o) {
84
+ const c = y(e.start, e.end), i = c - o;
85
85
  if (i <= 0)
86
86
  return c;
87
87
  let r;
88
88
  if (t === void 0)
89
89
  r = n;
90
- else if (o)
90
+ else if (s)
91
91
  r = t;
92
92
  else {
93
- const l = Math.max(0, Math.min(t, i));
94
- return s + l;
93
+ const u = Math.max(0, Math.min(t, i));
94
+ return o + u;
95
95
  }
96
- return s + r * i;
96
+ return o + r * i;
97
97
  }
98
- function A(e, t, o, n, s) {
99
- const i = v(e.start, e.end) - s;
98
+ function q(e, t, s, n, o) {
99
+ const i = y(e.start, e.end) - o;
100
100
  if (i <= 0)
101
101
  return 0;
102
102
  let r;
103
103
  if (t === void 0)
104
104
  r = n;
105
- else if (o)
105
+ else if (s)
106
106
  r = t;
107
107
  else
108
108
  return Math.max(0, Math.min(t, i));
109
109
  return r * i;
110
110
  }
111
- function X(e, t, o) {
112
- const n = /* @__PURE__ */ new Map(), s = /* @__PURE__ */ new Map(), c = /* @__PURE__ */ new Map();
111
+ function ee(e, t, s) {
112
+ const n = /* @__PURE__ */ new Map(), o = /* @__PURE__ */ new Map(), c = /* @__PURE__ */ new Map();
113
113
  for (const i of e)
114
- s.set(i.id, i), c.set(i.id, v(i.start, i.end)), n.set(i.id, []);
114
+ o.set(i.id, i), c.set(i.id, y(i.start, i.end)), n.set(i.id, []);
115
115
  for (let i = 0; i < t.length; i++) {
116
- const r = t[i], l = s.get(r.fromLineId), u = s.get(r.toLineId);
117
- if (!l || !u) continue;
118
- const a = b(l, r.fromOffset, r.fromIsPercentage, 1, o.wheelbase), d = A(u, r.toOffset, r.toIsPercentage, 0, o.wheelbase), g = T(
119
- l,
116
+ const r = t[i], u = o.get(r.fromLineId), l = o.get(r.toLineId);
117
+ if (!u || !l) continue;
118
+ const a = V(u, r.fromOffset, r.fromIsPercentage, 1, s.wheelbase), d = q(l, r.toOffset, r.toIsPercentage, 0, s.wheelbase), g = A(
120
119
  u,
121
- o,
120
+ l,
121
+ s,
122
122
  !1,
123
123
  // willFlip is always false now
124
124
  {
@@ -129,23 +129,26 @@ function X(e, t, o) {
129
129
  toIsPercentage: !1
130
130
  // Already resolved to absolute
131
131
  }
132
- ), p = k(g), I = {
132
+ ), I = G(g), m = {
133
133
  curveIndex: i,
134
134
  fromLineId: r.fromLineId,
135
135
  toLineId: r.toLineId,
136
136
  fromOffset: a,
137
137
  toOffset: d,
138
- curveLength: p
138
+ curveLength: I
139
139
  };
140
- n.get(r.fromLineId).push(I);
140
+ n.get(r.fromLineId).push(m);
141
141
  }
142
- return { adjacency: n, lines: s, lineLengths: c };
142
+ return { adjacency: n, lines: o, lineLengths: c };
143
143
  }
144
- function G(e, t, o, n, s = !1) {
144
+ function b(e, t) {
145
+ return e.curveCount !== t.curveCount ? e.curveCount - t.curveCount : e.totalDistance - t.totalDistance;
146
+ }
147
+ function Q(e, t, s, n, o = !1) {
145
148
  const { adjacency: c, lines: i, lineLengths: r } = e;
146
- if (!i.get(o)) return null;
147
- const u = r.get(o), a = s ? n / 100 * u : n, d = [], g = /* @__PURE__ */ new Map(), p = (f, m) => `${f}:${Math.round(m)}`;
148
- if (t.lineId === o && a >= t.offset) {
149
+ if (!i.get(s)) return null;
150
+ const l = r.get(s), a = o ? n / 100 * l : n, d = [], g = /* @__PURE__ */ new Map(), I = (f, v) => `${f}:${Math.round(v)}`;
151
+ if (t.lineId === s && a >= t.offset) {
149
152
  const f = a - t.offset;
150
153
  return {
151
154
  segments: [{
@@ -155,18 +158,19 @@ function G(e, t, o, n, s = !1) {
155
158
  endOffset: a,
156
159
  length: f
157
160
  }],
158
- totalDistance: f
161
+ totalDistance: f,
162
+ curveCount: 0
159
163
  };
160
164
  }
161
- const I = c.get(t.lineId) || [];
162
- for (const f of I) {
165
+ const m = c.get(t.lineId) || [];
166
+ for (const f of m) {
163
167
  if (f.fromOffset < t.offset) continue;
164
- const m = f.fromOffset - t.offset, y = m + f.curveLength, L = {
168
+ const v = f.fromOffset - t.offset, p = v + f.curveLength, x = {
165
169
  type: "line",
166
170
  lineId: t.lineId,
167
171
  startOffset: t.offset,
168
172
  endOffset: f.fromOffset,
169
- length: m
173
+ length: v
170
174
  }, h = {
171
175
  type: "curve",
172
176
  curveIndex: f.curveIndex,
@@ -177,43 +181,45 @@ function G(e, t, o, n, s = !1) {
177
181
  d.push({
178
182
  lineId: f.toLineId,
179
183
  entryOffset: f.toOffset,
180
- totalDistance: y,
181
- path: [L, h]
184
+ totalDistance: p,
185
+ curveCount: 1,
186
+ path: [x, h]
182
187
  });
183
188
  }
184
- for (d.sort((f, m) => f.totalDistance - m.totalDistance); d.length > 0; ) {
185
- const f = d.shift(), m = p(f.lineId, f.entryOffset), y = g.get(m);
186
- if (y !== void 0 && y <= f.totalDistance)
189
+ for (d.sort(b); d.length > 0; ) {
190
+ const f = d.shift(), v = I(f.lineId, f.entryOffset), p = g.get(v);
191
+ if (p !== void 0 && (p.curveCount < f.curveCount || p.curveCount === f.curveCount && p.distance <= f.totalDistance))
187
192
  continue;
188
- if (g.set(m, f.totalDistance), f.lineId === o) {
193
+ if (g.set(v, { curveCount: f.curveCount, distance: f.totalDistance }), f.lineId === s) {
189
194
  const h = Math.abs(a - f.entryOffset);
190
195
  if (a >= f.entryOffset) {
191
- const x = {
196
+ const O = {
192
197
  type: "line",
193
- lineId: o,
198
+ lineId: s,
194
199
  startOffset: f.entryOffset,
195
200
  endOffset: a,
196
201
  length: h
197
202
  };
198
203
  return {
199
- segments: [...f.path, x],
200
- totalDistance: f.totalDistance + h
204
+ segments: [...f.path, O],
205
+ totalDistance: f.totalDistance + h,
206
+ curveCount: f.curveCount
201
207
  };
202
208
  }
203
209
  }
204
- const L = c.get(f.lineId) || [];
205
- for (const h of L) {
210
+ const x = c.get(f.lineId) || [];
211
+ for (const h of x) {
206
212
  if (h.fromOffset < f.entryOffset) continue;
207
- const x = h.fromOffset - f.entryOffset, P = f.totalDistance + x + h.curveLength, q = p(h.toLineId, h.toOffset), C = g.get(q);
208
- if (C !== void 0 && C <= P)
213
+ const O = h.fromOffset - f.entryOffset, S = f.totalDistance + O + h.curveLength, M = f.curveCount + 1, B = I(h.toLineId, h.toOffset), C = g.get(B);
214
+ if (C !== void 0 && (C.curveCount < M || C.curveCount === M && C.distance <= S))
209
215
  continue;
210
- const z = {
216
+ const j = {
211
217
  type: "line",
212
218
  lineId: f.lineId,
213
219
  startOffset: f.entryOffset,
214
220
  endOffset: h.fromOffset,
215
- length: x
216
- }, B = {
221
+ length: O
222
+ }, F = {
217
223
  type: "curve",
218
224
  curveIndex: h.curveIndex,
219
225
  startOffset: 0,
@@ -223,42 +229,43 @@ function G(e, t, o, n, s = !1) {
223
229
  d.push({
224
230
  lineId: h.toLineId,
225
231
  entryOffset: h.toOffset,
226
- totalDistance: P,
227
- path: [...f.path, z, B]
232
+ totalDistance: S,
233
+ curveCount: M,
234
+ path: [...f.path, j, F]
228
235
  });
229
236
  }
230
- d.sort((h, x) => h.totalDistance - x.totalDistance);
237
+ d.sort(b);
231
238
  }
232
239
  return null;
233
240
  }
234
- function V(e, t) {
235
- const o = Math.sqrt(
241
+ function z(e, t) {
242
+ const s = Math.sqrt(
236
243
  Math.pow(e.end.x - e.start.x, 2) + Math.pow(e.end.y - e.start.y, 2)
237
- ), n = o > 0 ? t / o : 0;
244
+ ), n = s > 0 ? t / s : 0;
238
245
  return {
239
246
  x: e.start.x + (e.end.x - e.start.x) * Math.min(1, Math.max(0, n)),
240
247
  y: e.start.y + (e.end.y - e.start.y) * Math.min(1, Math.max(0, n))
241
248
  };
242
249
  }
243
- function N(e) {
250
+ function R(e) {
244
251
  return Math.sqrt(
245
252
  Math.pow(e.end.x - e.start.x, 2) + Math.pow(e.end.y - e.start.y, 2)
246
253
  );
247
254
  }
248
- function Q(e, t, o) {
255
+ function W(e, t, s) {
249
256
  let n = 0;
250
- for (let s = 0; s < t; s++)
251
- n += e.segments[s].length;
252
- return n += o, n;
257
+ for (let o = 0; o < t; o++)
258
+ n += e.segments[o].length;
259
+ return n += s, n;
253
260
  }
254
- function R(e, t) {
255
- let o = 0;
261
+ function _(e, t) {
262
+ let s = 0;
256
263
  for (let n = 0; n < e.segments.length; n++) {
257
- const s = e.segments[n], c = o + s.length;
264
+ const o = e.segments[n], c = s + o.length;
258
265
  if (t < c)
259
266
  return {
260
267
  segmentIndex: n,
261
- segmentDistance: t - o
268
+ segmentDistance: t - s
262
269
  };
263
270
  if (t === c)
264
271
  return n + 1 < e.segments.length ? {
@@ -266,107 +273,107 @@ function R(e, t) {
266
273
  segmentDistance: 0
267
274
  } : {
268
275
  segmentIndex: n,
269
- segmentDistance: s.length
276
+ segmentDistance: o.length
270
277
  };
271
- o += s.length;
278
+ s += o.length;
272
279
  }
273
280
  return null;
274
281
  }
275
- function W(e, t, o, n) {
276
- const c = Q(
282
+ function E(e, t, s, n) {
283
+ const c = W(
277
284
  e,
278
285
  t,
279
- o
286
+ s
280
287
  ) + n;
281
- return R(e, c);
288
+ return _(e, c);
282
289
  }
283
- function Y(e, t, o, n) {
284
- const s = Math.sqrt(
290
+ function te(e, t, s, n) {
291
+ const o = Math.sqrt(
285
292
  Math.pow(n.end.x - n.start.x, 2) + Math.pow(n.end.y - n.start.y, 2)
286
293
  );
287
- let c = t + o;
288
- c = Math.min(c, s);
289
- const i = V(n, c);
294
+ let c = t + s;
295
+ c = Math.min(c, o);
296
+ const i = z(n, c);
290
297
  return {
291
298
  lineId: e,
292
299
  position: i,
293
300
  absoluteOffset: c
294
301
  };
295
302
  }
296
- function _(e, t) {
303
+ function H(e, t) {
297
304
  return {
298
305
  ...e,
299
306
  state: "idle"
300
307
  };
301
308
  }
302
- function E(e) {
309
+ function J(e) {
303
310
  return {
304
311
  vehicle: e,
305
312
  execution: null
306
313
  };
307
314
  }
308
- function Z(e, t) {
309
- const o = [], n = /* @__PURE__ */ new Map();
310
- for (const s of e) {
311
- if (!t.get(s.lineId)) continue;
312
- const i = _(s);
313
- o.push(i);
314
- const r = E(i);
315
- n.set(s.id, r);
315
+ function ne(e, t) {
316
+ const s = [], n = /* @__PURE__ */ new Map();
317
+ for (const o of e) {
318
+ if (!t.get(o.lineId)) continue;
319
+ const i = H(o);
320
+ s.push(i);
321
+ const r = J(i);
322
+ n.set(o.id, r);
316
323
  }
317
- return { movingVehicles: o, stateMap: n };
324
+ return { movingVehicles: s, stateMap: n };
318
325
  }
319
- function O(e, t) {
320
- return { position: V(e, t), lineId: e.id, absoluteOffset: t };
326
+ function L(e, t) {
327
+ return { position: z(e, t), lineId: e.id, absoluteOffset: t };
321
328
  }
322
- function w(e, t) {
323
- const o = $(e.arcLengthTable, t);
324
- return { position: D(e.bezier, o) };
325
- }
326
- function ee(e, t, o, n, s, c, i) {
327
- const r = o.segments[t.currentSegmentIndex], l = t.segmentDistance + n;
328
- if (l >= r.length) {
329
- const a = l - r.length, d = t.currentSegmentIndex + 1;
330
- if (d >= o.segments.length) {
329
+ function P(e, t) {
330
+ const s = $(e.arcLengthTable, t);
331
+ return { position: D(e.bezier, s) };
332
+ }
333
+ function oe(e, t, s, n, o, c, i) {
334
+ const r = s.segments[t.currentSegmentIndex], u = t.segmentDistance + n;
335
+ if (u >= r.length) {
336
+ const a = u - r.length, d = t.currentSegmentIndex + 1;
337
+ if (d >= s.segments.length) {
331
338
  if (i !== void 0 && r.type === "line") {
332
- const f = s.get(r.lineId), m = r.startOffset + l;
333
- if (m <= i) {
334
- const L = O(f, m);
339
+ const f = o.get(r.lineId), v = r.startOffset + u;
340
+ if (v <= i) {
341
+ const x = L(f, v);
335
342
  return {
336
- axleState: { ...e, ...L },
337
- execution: { ...t, segmentDistance: l },
343
+ axleState: { ...e, ...x },
344
+ execution: { ...t, segmentDistance: u },
338
345
  completed: !1
339
346
  };
340
347
  }
341
- const y = O(f, i);
348
+ const p = L(f, i);
342
349
  return {
343
- axleState: { ...e, ...y },
350
+ axleState: { ...e, ...p },
344
351
  execution: { ...t, segmentDistance: i - r.startOffset },
345
352
  completed: !0
346
353
  };
347
354
  }
348
- const I = r.type === "line" ? O(
349
- s.get(r.lineId),
355
+ const m = r.type === "line" ? L(
356
+ o.get(r.lineId),
350
357
  r.endOffset
351
- ) : w(
358
+ ) : P(
352
359
  c.get(r.curveIndex),
353
360
  r.length
354
361
  );
355
362
  return {
356
- axleState: { ...e, ...I },
363
+ axleState: { ...e, ...m },
357
364
  execution: { ...t, segmentDistance: r.length },
358
365
  completed: !0
359
366
  };
360
367
  }
361
- const g = o.segments[d], p = g.type === "line" ? O(
362
- s.get(g.lineId),
368
+ const g = s.segments[d], I = g.type === "line" ? L(
369
+ o.get(g.lineId),
363
370
  g.startOffset + a
364
- ) : w(
371
+ ) : P(
365
372
  c.get(g.curveIndex),
366
373
  a
367
374
  );
368
375
  return {
369
- axleState: { ...e, ...p },
376
+ axleState: { ...e, ...I },
370
377
  execution: {
371
378
  currentSegmentIndex: d,
372
379
  segmentDistance: a
@@ -374,67 +381,67 @@ function ee(e, t, o, n, s, c, i) {
374
381
  completed: !1
375
382
  };
376
383
  }
377
- const u = r.type === "line" ? O(
378
- s.get(r.lineId),
379
- r.startOffset + l
380
- ) : w(
384
+ const l = r.type === "line" ? L(
385
+ o.get(r.lineId),
386
+ r.startOffset + u
387
+ ) : P(
381
388
  c.get(r.curveIndex),
382
- l
389
+ u
383
390
  );
384
391
  return {
385
- axleState: { ...e, ...u },
386
- execution: { ...t, segmentDistance: l },
392
+ axleState: { ...e, ...l },
393
+ execution: { ...t, segmentDistance: u },
387
394
  completed: !1
388
395
  };
389
396
  }
390
- function H(e, t, o, n) {
391
- const s = /* @__PURE__ */ new Map();
397
+ function U(e, t, s, n) {
398
+ const o = /* @__PURE__ */ new Map();
392
399
  for (const c of e.segments)
393
400
  if (c.type === "curve" && c.curveIndex !== void 0) {
394
401
  const i = t[c.curveIndex];
395
402
  if (i) {
396
- const r = o.get(i.fromLineId), l = o.get(i.toLineId);
397
- if (r && l) {
398
- const u = b(
403
+ const r = s.get(i.fromLineId), u = s.get(i.toLineId);
404
+ if (r && u) {
405
+ const l = V(
399
406
  r,
400
407
  i.fromOffset,
401
408
  i.fromIsPercentage,
402
409
  1,
403
410
  // Default: 100% = 1.0
404
411
  n.wheelbase
405
- ), a = A(
406
- l,
412
+ ), a = q(
413
+ u,
407
414
  i.toOffset,
408
415
  i.toIsPercentage,
409
416
  0,
410
417
  n.wheelbase
411
- ), d = T(
418
+ ), d = A(
412
419
  r,
413
- l,
420
+ u,
414
421
  n,
415
422
  !1,
416
423
  // willFlip is always false now
417
424
  {
418
- fromOffset: u,
425
+ fromOffset: l,
419
426
  fromIsPercentage: !1,
420
427
  // Already resolved to absolute
421
428
  toOffset: a,
422
429
  toIsPercentage: !1
423
430
  // Already resolved to absolute
424
431
  }
425
- ), g = j(d);
426
- s.set(c.curveIndex, { bezier: d, arcLengthTable: g });
432
+ ), g = N(d);
433
+ o.set(c.curveIndex, { bezier: d, arcLengthTable: g });
427
434
  }
428
435
  }
429
436
  }
430
- return s;
437
+ return o;
431
438
  }
432
- function te(e, t, o) {
433
- const { graph: n, linesMap: s, curves: c, config: i } = o, r = s.get(t.targetLineId);
439
+ function se(e, t, s) {
440
+ const { graph: n, linesMap: o, curves: c, config: i } = s, r = o.get(t.targetLineId);
434
441
  if (!r) return null;
435
- const u = N(r) - i.wheelbase;
436
- if (u <= 0) return null;
437
- const a = t.isPercentage ? t.targetOffset * u : Math.min(t.targetOffset, u), d = G(
442
+ const l = R(r) - i.wheelbase;
443
+ if (l <= 0) return null;
444
+ const a = t.isPercentage ? t.targetOffset * l : Math.min(t.targetOffset, l), d = Q(
438
445
  n,
439
446
  { lineId: e.rear.lineId, offset: e.rear.absoluteOffset },
440
447
  t.targetLineId,
@@ -442,44 +449,44 @@ function te(e, t, o) {
442
449
  !1
443
450
  );
444
451
  if (!d) return null;
445
- const g = H(d, c, s, i);
452
+ const g = U(d, c, o, i);
446
453
  return { path: d, curveDataMap: g };
447
454
  }
448
- function ne(e, t) {
449
- const o = e.execution, n = t.vehicleQueues.get(e.vehicle.id), s = n?.[o.currentCommandIndex];
450
- if (s && t.onCommandComplete && t.onCommandComplete({
455
+ function re(e, t) {
456
+ const s = e.execution, n = t.vehicleQueues.get(e.vehicle.id), o = n?.[s.currentCommandIndex];
457
+ if (o && t.onCommandComplete && t.onCommandComplete({
451
458
  vehicleId: e.vehicle.id,
452
- command: s,
459
+ command: o,
453
460
  finalPosition: {
454
461
  lineId: e.vehicle.rear.lineId,
455
462
  absoluteOffset: e.vehicle.rear.absoluteOffset,
456
463
  position: e.vehicle.rear.position
457
464
  },
458
- payload: s.payload
459
- }), s?.awaitConfirmation)
465
+ payload: o.payload
466
+ }), o?.awaitConfirmation)
460
467
  return {
461
468
  handled: !0,
462
469
  vehicle: { ...e.vehicle, state: "waiting" },
463
- newExecution: o,
470
+ newExecution: s,
464
471
  // Keep execution state for resume
465
472
  isWaiting: !0
466
473
  };
467
- const c = o.currentCommandIndex + 1;
474
+ const c = s.currentCommandIndex + 1;
468
475
  if (n && c < n.length) {
469
- const r = n[c], l = t.graphRef.current;
470
- if (l) {
471
- const u = {
472
- graph: l,
476
+ const r = n[c], u = t.graphRef.current;
477
+ if (u) {
478
+ const l = {
479
+ graph: u,
473
480
  linesMap: t.linesMap,
474
481
  curves: t.curves,
475
482
  config: t.config
476
483
  }, a = t.prepareCommandPath(
477
484
  e.vehicle,
478
485
  r,
479
- u
486
+ l
480
487
  );
481
488
  if (a) {
482
- const d = W(
489
+ const d = E(
483
490
  a.path,
484
491
  0,
485
492
  0,
@@ -521,34 +528,34 @@ function ne(e, t) {
521
528
  }, newExecution: null };
522
529
  }
523
530
  export {
524
- R as arcLengthToSegmentPosition,
525
- j as buildArcLengthTable,
526
- X as buildGraph,
527
- k as calculateBezierArcLength,
528
- W as calculateFrontAxlePosition,
529
- Y as calculateInitialFrontPosition,
530
- w as calculatePositionOnCurve,
531
- O as calculatePositionOnLine,
532
- F as calculateTangentLength,
533
- T as createBezierCurve,
534
- E as createInitialMovementState,
535
- v as distance,
531
+ _ as arcLengthToSegmentPosition,
532
+ N as buildArcLengthTable,
533
+ ee as buildGraph,
534
+ G as calculateBezierArcLength,
535
+ E as calculateFrontAxlePosition,
536
+ te as calculateInitialFrontPosition,
537
+ P as calculatePositionOnCurve,
538
+ L as calculatePositionOnLine,
539
+ K as calculateTangentLength,
540
+ A as createBezierCurve,
541
+ J as createInitialMovementState,
542
+ y as distance,
536
543
  $ as distanceToT,
537
- G as findPath,
538
- U as getArcLength,
539
- Q as getCumulativeArcLength,
540
- N as getLineLength,
544
+ Q as findPath,
545
+ Z as getArcLength,
546
+ W as getCumulativeArcLength,
547
+ R as getLineLength,
541
548
  D as getPointOnBezier,
542
- K as getPointOnLine,
543
- S as getPointOnLineByOffset,
544
- V as getPositionFromOffset,
545
- ne as handleArrival,
546
- Z as initializeAllVehicles,
547
- _ as initializeMovingVehicle,
548
- J as isPointNearPoint,
549
- M as normalize,
550
- te as prepareCommandPath,
551
- b as resolveFromLineOffset,
552
- A as resolveToLineOffset,
553
- ee as updateAxlePosition
549
+ k as getPointOnLine,
550
+ T as getPointOnLineByOffset,
551
+ z as getPositionFromOffset,
552
+ re as handleArrival,
553
+ ne as initializeAllVehicles,
554
+ H as initializeMovingVehicle,
555
+ Y as isPointNearPoint,
556
+ w as normalize,
557
+ se as prepareCommandPath,
558
+ V as resolveFromLineOffset,
559
+ q as resolveToLineOffset,
560
+ oe as updateAxlePosition
554
561
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "vehicle-path2",
3
- "version": "1.0.10",
3
+ "version": "1.0.11",
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",