vehicle-path2 1.0.11 → 1.0.12
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +0 -1
- package/dist/core/types/api.d.ts +0 -5
- package/dist/core/types/vehicle.d.ts +0 -1
- package/dist/core.cjs +1 -1
- package/dist/core.js +260 -316
- package/dist/react/hooks/useMovementQueue.d.ts +0 -1
- package/dist/react.cjs +1 -1
- package/dist/react.js +1 -1
- package/dist/useVehicleEvents-BZVmIugl.cjs +3 -0
- package/dist/{useVehicleEvents-t_p-Bwhj.js → useVehicleEvents-CabztfQ4.js} +185 -189
- package/dist/utils/dsl-parser.d.ts +4 -5
- package/dist/utils/type-converters.d.ts +0 -1
- package/dist/utils.cjs +1 -1
- package/dist/utils.js +1 -1
- package/dist/{vehicle-helpers-BYb2Ibex.js → vehicle-helpers-BgD4BTAJ.js} +15 -16
- package/dist/{vehicle-helpers-bgHGBdo9.cjs → vehicle-helpers-DrnYWjm3.cjs} +7 -7
- package/dist/vehicle-path.cjs +1 -1
- package/dist/vehicle-path.js +2 -2
- package/package.json +1 -1
- package/dist/useVehicleEvents-B7Z-9Hn2.cjs +0 -3
package/README.md
CHANGED
|
@@ -91,7 +91,6 @@ sim.clearVehicles()
|
|
|
91
91
|
sim.goto({ id: 'v1', lineId: 'line2' }) // default position = 1.0 (ujung)
|
|
92
92
|
sim.goto({ id: 'v1', lineId: 'line2', position: 0.5 }) // 0.5 = tengah line
|
|
93
93
|
sim.goto({ id: 'v1', lineId: 'line2', position: 150, isPercentage: false }) // absolute
|
|
94
|
-
sim.goto({ id: 'v1', lineId: 'line2', position: 0.5, wait: true }) // berhenti di tujuan
|
|
95
94
|
sim.goto({ id: 'v1', lineId: 'line2', payload: { orderId: '123' } }) // dengan payload
|
|
96
95
|
sim.clearQueue('v1')
|
|
97
96
|
```
|
package/dist/core/types/api.d.ts
CHANGED
|
@@ -106,7 +106,6 @@ export interface ConnectionUpdateInput {
|
|
|
106
106
|
* goto({ id: 'v1', lineId: 'line002' }) // position defaults to 1.0 (end)
|
|
107
107
|
* goto({ id: 'v1', lineId: 'line002', position: 0.5 }) // 50% of line
|
|
108
108
|
* goto({ id: 'v1', lineId: 'line002', position: 150, isPercentage: false }) // absolute 150
|
|
109
|
-
* goto({ id: 'v1', lineId: 'line002', position: 0.5, wait: true }) // wait at destination
|
|
110
109
|
* goto({ id: 'v1', lineId: 'line002', payload: { orderId: '123' } }) // with payload
|
|
111
110
|
*/
|
|
112
111
|
export interface GotoInput {
|
|
@@ -114,7 +113,6 @@ export interface GotoInput {
|
|
|
114
113
|
lineId: string;
|
|
115
114
|
position?: number;
|
|
116
115
|
isPercentage?: boolean;
|
|
117
|
-
wait?: boolean;
|
|
118
116
|
payload?: unknown;
|
|
119
117
|
}
|
|
120
118
|
/**
|
|
@@ -126,7 +124,6 @@ export interface GotoInput {
|
|
|
126
124
|
* queueMovement('v1', {
|
|
127
125
|
* targetLineId: 'line002',
|
|
128
126
|
* targetPosition: 0.5,
|
|
129
|
-
* wait: true,
|
|
130
127
|
* payload: { orderId: '123' }
|
|
131
128
|
* })
|
|
132
129
|
* queueMovement('v1', { targetLineId: 'line002', targetPosition: 150, isPercentage: false })
|
|
@@ -135,7 +132,6 @@ export interface GotoCommandInput {
|
|
|
135
132
|
targetLineId: string;
|
|
136
133
|
targetPosition?: number;
|
|
137
134
|
isPercentage?: boolean;
|
|
138
|
-
wait?: boolean;
|
|
139
135
|
payload?: unknown;
|
|
140
136
|
}
|
|
141
137
|
/**
|
|
@@ -151,7 +147,6 @@ export interface MovementCommandInput {
|
|
|
151
147
|
targetLineId: string;
|
|
152
148
|
targetPosition?: number;
|
|
153
149
|
isPercentage?: boolean;
|
|
154
|
-
wait?: boolean;
|
|
155
150
|
payload?: unknown;
|
|
156
151
|
}
|
|
157
152
|
/**
|
package/dist/core.cjs
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});function
|
|
1
|
+
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});function L(t,e){const s=e.x-t.x,o=e.y-t.y;return Math.sqrt(s*s+o*o)}function M(t,e){const s=e.x-t.x,o=e.y-t.y,n=Math.sqrt(s*s+o*o);return n===0?{x:0,y:0}:{x:s/n,y:o/n}}function V(t,e){return e*(t==="proportional-40"?.4:.5522)}function S(t,e,s,o=!1,n){const{wheelbase:c,tangentMode:i}=s;let r;n?.fromOffset!==void 0?r=D(t,n.fromOffset,n.fromIsPercentage??!1):r=t.end;let a;n?.toOffset!==void 0?a=D(e,n.toOffset,n.toIsPercentage??!1):a=e.start;const d=M(t.start,t.end),u=o?{x:r.x-d.x*c,y:r.y-d.y*c}:r,l=M(t.start,t.end),g=M(e.start,e.end),y=L(u,a),m=V(i,y),f=o?{x:u.x-l.x*m,y:u.y-l.y*m}:{x:u.x+l.x*m,y:u.y+l.y*m},v={x:a.x-g.x*m,y:a.y-g.y*m};return{p0:u,p1:f,p2:v,p3:a}}function F(t,e){return{x:t.start.x+(t.end.x-t.start.x)*e,y:t.start.y+(t.end.y-t.start.y)*e}}function D(t,e,s){const o=L(t.start,t.end);let n;return s?n=e:n=o>0?e/o:0,n=Math.max(0,Math.min(1,n)),F(t,n)}function w(t,e){const{p0:s,p1:o,p2:n,p3:c}=t,i=1-e,r=i*i,a=r*i,d=e*e,u=d*e;return{x:a*s.x+3*r*e*o.x+3*i*d*n.x+u*c.x,y:a*s.y+3*r*e*o.y+3*i*d*n.y+u*c.y}}function U(t,e,s=10){return L(t,e)<=s}function j(t,e=100){const s=[{t:0,distance:0}];let o=t.p0,n=0;for(let c=1;c<=e;c++){const i=c/e,r=w(t,i);n+=L(o,r),s.push({t:i,distance:n}),o=r}return s}function K(t,e){if(e<=0)return 0;const s=t[t.length-1].distance;if(e>=s)return 1;let o=0,n=t.length-1;for(;o<n-1;){const u=Math.floor((o+n)/2);t[u].distance<e?o=u:n=u}const c=t[o].distance,i=t[n].distance,r=t[o].t,a=t[n].t;if(i===c)return r;const d=(e-c)/(i-c);return r+d*(a-r)}function X(t){return t[t.length-1].distance}function N(t,e=100){let s=0,o=t.p0;for(let n=1;n<=e;n++){const c=n/e,i=w(t,c);s+=L(o,i),o=i}return s}function A(t,e,s,o,n){const c=L(t.start,t.end),i=c-n;if(i<=0)return c;let r;if(e===void 0)r=o;else if(s)r=e;else{const a=Math.max(0,Math.min(e,i));return n+a}return n+r*i}function b(t,e,s,o,n){const i=L(t.start,t.end)-n;if(i<=0)return 0;let r;if(e===void 0)r=o;else if(s)r=e;else return Math.max(0,Math.min(e,i));return r*i}function Y(t,e,s){const o=new Map,n=new Map,c=new Map;for(const i of t)n.set(i.id,i),c.set(i.id,L(i.start,i.end)),o.set(i.id,[]);for(let i=0;i<e.length;i++){const r=e[i],a=n.get(r.fromLineId),d=n.get(r.toLineId);if(!a||!d)continue;const u=A(a,r.fromOffset,r.fromIsPercentage,1,s.wheelbase),l=b(d,r.toOffset,r.toIsPercentage,0,s.wheelbase),g=S(a,d,s,!1,{fromOffset:u,fromIsPercentage:!1,toOffset:l,toIsPercentage:!1}),y=N(g),m={curveIndex:i,fromLineId:r.fromLineId,toLineId:r.toLineId,fromOffset:u,toOffset:l,curveLength:y};o.get(r.fromLineId).push(m)}return{adjacency:o,lines:n,lineLengths:c}}function B(t,e){return t.curveCount!==e.curveCount?t.curveCount-e.curveCount:t.totalDistance-e.totalDistance}function k(t,e,s,o,n=!1){const{adjacency:c,lines:i,lineLengths:r}=t;if(!i.get(s))return null;const d=r.get(s),u=n?o/100*d:o,l=[],g=new Map,y=(f,v)=>`${f}:${Math.round(v)}`;if(e.lineId===s&&u>=e.offset){const f=u-e.offset;return{segments:[{type:"line",lineId:e.lineId,startOffset:e.offset,endOffset:u,length:f}],totalDistance:f,curveCount:0}}const m=c.get(e.lineId)||[];for(const f of m){if(f.fromOffset<e.offset)continue;const v=f.fromOffset-e.offset,I=v+f.curveLength,O={type:"line",lineId:e.lineId,startOffset:e.offset,endOffset:f.fromOffset,length:v},h={type:"curve",curveIndex:f.curveIndex,startOffset:0,endOffset:f.curveLength,length:f.curveLength};l.push({lineId:f.toLineId,entryOffset:f.toOffset,totalDistance:I,curveCount:1,path:[O,h]})}for(l.sort(B);l.length>0;){const f=l.shift(),v=y(f.lineId,f.entryOffset),I=g.get(v);if(I!==void 0&&(I.curveCount<f.curveCount||I.curveCount===f.curveCount&&I.distance<=f.totalDistance))continue;if(g.set(v,{curveCount:f.curveCount,distance:f.totalDistance}),f.lineId===s){const h=Math.abs(u-f.entryOffset);if(u>=f.entryOffset){const x={type:"line",lineId:s,startOffset:f.entryOffset,endOffset:u,length:h};return{segments:[...f.path,x],totalDistance:f.totalDistance+h,curveCount:f.curveCount}}}const O=c.get(f.lineId)||[];for(const h of O){if(h.fromOffset<f.entryOffset)continue;const x=h.fromOffset-f.entryOffset,q=f.totalDistance+x+h.curveLength,T=f.curveCount+1,H=y(h.toLineId,h.toOffset),P=g.get(H);if(P!==void 0&&(P.curveCount<T||P.curveCount===T&&P.distance<=q))continue;const J={type:"line",lineId:f.lineId,startOffset:f.entryOffset,endOffset:h.fromOffset,length:x},R={type:"curve",curveIndex:h.curveIndex,startOffset:0,endOffset:h.curveLength,length:h.curveLength};l.push({lineId:h.toLineId,entryOffset:h.toOffset,totalDistance:q,curveCount:T,path:[...f.path,J,R]})}l.sort(B)}return null}function z(t,e){const s=Math.sqrt(Math.pow(t.end.x-t.start.x,2)+Math.pow(t.end.y-t.start.y,2)),o=s>0?e/s:0;return{x:t.start.x+(t.end.x-t.start.x)*Math.min(1,Math.max(0,o)),y:t.start.y+(t.end.y-t.start.y)*Math.min(1,Math.max(0,o))}}function G(t){return Math.sqrt(Math.pow(t.end.x-t.start.x,2)+Math.pow(t.end.y-t.start.y,2))}function $(t,e,s){let o=0;for(let n=0;n<e;n++)o+=t.segments[n].length;return o+=s,o}function Q(t,e){let s=0;for(let o=0;o<t.segments.length;o++){const n=t.segments[o],c=s+n.length;if(e<c)return{segmentIndex:o,segmentDistance:e-s};if(e===c)return o+1<t.segments.length?{segmentIndex:o+1,segmentDistance:0}:{segmentIndex:o,segmentDistance:n.length};s+=n.length}return null}function Z(t,e,s,o){const c=$(t,e,s)+o;return Q(t,c)}function E(t,e,s,o){const n=Math.sqrt(Math.pow(o.end.x-o.start.x,2)+Math.pow(o.end.y-o.start.y,2));let c=e+s;c=Math.min(c,n);const i=z(o,c);return{lineId:t,position:i,absoluteOffset:c}}function W(t,e){return{...t,state:"idle"}}function _(t){return{vehicle:t,execution:null}}function tt(t,e){const s=[],o=new Map;for(const n of t){if(!e.get(n.lineId))continue;const i=W(n);s.push(i);const r=_(i);o.set(n.id,r)}return{movingVehicles:s,stateMap:o}}function p(t,e){return{position:z(t,e),lineId:t.id,absoluteOffset:e}}function C(t,e){const s=K(t.arcLengthTable,e);return{position:w(t.bezier,s)}}function et(t,e,s,o,n,c,i){const r=s.segments[e.currentSegmentIndex],a=e.segmentDistance+o;if(a>=r.length){const u=a-r.length,l=e.currentSegmentIndex+1;if(l>=s.segments.length){if(i!==void 0&&r.type==="line"){const f=n.get(r.lineId),v=r.startOffset+a;if(v<=i){const O=p(f,v);return{axleState:{...t,...O},execution:{...e,segmentDistance:a},completed:!1}}const I=p(f,i);return{axleState:{...t,...I},execution:{...e,segmentDistance:i-r.startOffset},completed:!0}}const m=r.type==="line"?p(n.get(r.lineId),r.endOffset):C(c.get(r.curveIndex),r.length);return{axleState:{...t,...m},execution:{...e,segmentDistance:r.length},completed:!0}}const g=s.segments[l],y=g.type==="line"?p(n.get(g.lineId),g.startOffset+u):C(c.get(g.curveIndex),u);return{axleState:{...t,...y},execution:{currentSegmentIndex:l,segmentDistance:u},completed:!1}}const d=r.type==="line"?p(n.get(r.lineId),r.startOffset+a):C(c.get(r.curveIndex),a);return{axleState:{...t,...d},execution:{...e,segmentDistance:a},completed:!1}}function nt(t,e,s,o){const n=new Map;for(const c of t.segments)if(c.type==="curve"&&c.curveIndex!==void 0){const i=e[c.curveIndex];if(i){const r=s.get(i.fromLineId),a=s.get(i.toLineId);if(r&&a){const d=A(r,i.fromOffset,i.fromIsPercentage,1,o.wheelbase),u=b(a,i.toOffset,i.toIsPercentage,0,o.wheelbase),l=S(r,a,o,!1,{fromOffset:d,fromIsPercentage:!1,toOffset:u,toIsPercentage:!1}),g=j(l);n.set(c.curveIndex,{bezier:l,arcLengthTable:g})}}}return n}function ot(t,e,s){const{graph:o,linesMap:n,curves:c,config:i}=s,r=n.get(e.targetLineId);if(!r)return null;const d=G(r)-i.wheelbase;if(d<=0)return null;const u=e.isPercentage?e.targetOffset*d:Math.min(e.targetOffset,d),l=k(o,{lineId:t.rear.lineId,offset:t.rear.absoluteOffset},e.targetLineId,u,!1);if(!l)return null;const g=nt(l,c,n,i);return{path:l,curveDataMap:g}}function st(t,e){const s=t.execution,n=e.vehicleQueues.get(t.vehicle.id)?.[s.currentCommandIndex];return n&&e.onCommandComplete&&e.onCommandComplete({vehicleId:t.vehicle.id,command:n,finalPosition:{lineId:t.vehicle.rear.lineId,absoluteOffset:t.vehicle.rear.absoluteOffset,position:t.vehicle.rear.position},payload:n.payload}),{handled:!0,vehicle:{...t.vehicle,state:"waiting"},newExecution:s,isWaiting:!0}}exports.arcLengthToSegmentPosition=Q;exports.buildArcLengthTable=j;exports.buildGraph=Y;exports.calculateBezierArcLength=N;exports.calculateFrontAxlePosition=Z;exports.calculateInitialFrontPosition=E;exports.calculatePositionOnCurve=C;exports.calculatePositionOnLine=p;exports.calculateTangentLength=V;exports.createBezierCurve=S;exports.createInitialMovementState=_;exports.distance=L;exports.distanceToT=K;exports.findPath=k;exports.getArcLength=X;exports.getCumulativeArcLength=$;exports.getLineLength=G;exports.getPointOnBezier=w;exports.getPointOnLine=F;exports.getPointOnLineByOffset=D;exports.getPositionFromOffset=z;exports.handleArrival=st;exports.initializeAllVehicles=tt;exports.initializeMovingVehicle=W;exports.isPointNearPoint=U;exports.normalize=M;exports.prepareCommandPath=ot;exports.resolveFromLineOffset=A;exports.resolveToLineOffset=b;exports.updateAxlePosition=et;
|