vehicle-path2 1.0.11 → 1.0.13

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