vehicle-path2 3.0.1 → 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/algorithms/math.d.ts +1 -1
- package/dist/core/algorithms/pathFinding.d.ts +2 -2
- package/dist/core/engine.d.ts +1 -2
- package/dist/core/types/movement.d.ts +0 -1
- package/dist/core/types/vehicle.d.ts +1 -1
- package/dist/core.cjs +1 -1
- package/dist/core.js +2 -2
- package/dist/index-BQoeJKCj.cjs +1 -0
- package/dist/index-DUYG8fxI.js +699 -0
- package/dist/vehicle-path.cjs +1 -1
- package/dist/vehicle-path.js +1 -1
- package/package.json +1 -1
- package/dist/index-C4FckUel.cjs +0 -1
- package/dist/index-C7pH7jZo.js +0 -716
package/dist/index-C7pH7jZo.js
DELETED
|
@@ -1,716 +0,0 @@
|
|
|
1
|
-
function y(t, e) {
|
|
2
|
-
const n = e.x - t.x, s = e.y - t.y;
|
|
3
|
-
return Math.sqrt(n * n + s * s);
|
|
4
|
-
}
|
|
5
|
-
function S(t, e) {
|
|
6
|
-
const n = e.x - t.x, s = e.y - t.y, i = Math.sqrt(n * n + s * s);
|
|
7
|
-
return i === 0 ? { x: 0, y: 0 } : { x: n / i, y: s / i };
|
|
8
|
-
}
|
|
9
|
-
function k(t, e) {
|
|
10
|
-
return e * (t === "proportional-40" ? 0.4 : 0.5522);
|
|
11
|
-
}
|
|
12
|
-
function W(t, e, n, s = !1, i) {
|
|
13
|
-
const { maxWheelbase: o, tangentMode: a } = n;
|
|
14
|
-
let r;
|
|
15
|
-
i?.fromOffset !== void 0 ? r = V(t, i.fromOffset, i.fromIsPercentage ?? !1) : r = t.end;
|
|
16
|
-
let f;
|
|
17
|
-
i?.toOffset !== void 0 ? f = V(e, i.toOffset, i.toIsPercentage ?? !1) : f = e.start;
|
|
18
|
-
const l = S(t.start, t.end), c = s ? {
|
|
19
|
-
// Transition with flip: kurva dimulai dari P (baseP0 - wheelbase in line direction)
|
|
20
|
-
x: r.x - l.x * o,
|
|
21
|
-
y: r.y - l.y * o
|
|
22
|
-
} : r, g = S(t.start, t.end), d = S(e.start, e.end), h = y(c, f), p = k(a, h), u = s ? { x: c.x - g.x * p, y: c.y - g.y * p } : { x: c.x + g.x * p, y: c.y + g.y * p }, v = {
|
|
23
|
-
x: f.x - d.x * p,
|
|
24
|
-
y: f.y - d.y * p
|
|
25
|
-
};
|
|
26
|
-
return { p0: c, p1: u, p2: v, p3: f };
|
|
27
|
-
}
|
|
28
|
-
function K(t, e) {
|
|
29
|
-
return {
|
|
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
|
-
};
|
|
33
|
-
}
|
|
34
|
-
function V(t, e, n) {
|
|
35
|
-
const s = y(t.start, t.end);
|
|
36
|
-
let i;
|
|
37
|
-
return n ? i = e : i = s > 0 ? e / s : 0, i = Math.max(0, Math.min(1, i)), K(t, i);
|
|
38
|
-
}
|
|
39
|
-
function b(t, e) {
|
|
40
|
-
const { p0: n, p1: s, p2: i, p3: o } = t, a = 1 - e, r = a * a, f = r * a, l = e * e, c = l * e;
|
|
41
|
-
return {
|
|
42
|
-
x: f * n.x + 3 * r * e * s.x + 3 * a * l * i.x + c * o.x,
|
|
43
|
-
y: f * n.y + 3 * r * e * s.y + 3 * a * l * i.y + c * o.y
|
|
44
|
-
};
|
|
45
|
-
}
|
|
46
|
-
function ne(t, e, n = 10) {
|
|
47
|
-
return y(t, e) <= n;
|
|
48
|
-
}
|
|
49
|
-
function N(t, e = 100) {
|
|
50
|
-
const n = [{ t: 0, distance: 0 }];
|
|
51
|
-
let s = t.p0, i = 0;
|
|
52
|
-
for (let o = 1; o <= e; o++) {
|
|
53
|
-
const a = o / e, r = b(t, a);
|
|
54
|
-
i += y(s, r), n.push({ t: a, distance: i }), s = r;
|
|
55
|
-
}
|
|
56
|
-
return n;
|
|
57
|
-
}
|
|
58
|
-
function _(t, e) {
|
|
59
|
-
if (e <= 0) return 0;
|
|
60
|
-
const n = t[t.length - 1].distance;
|
|
61
|
-
if (e >= n) return 1;
|
|
62
|
-
let s = 0, i = t.length - 1;
|
|
63
|
-
for (; s < i - 1; ) {
|
|
64
|
-
const c = Math.floor((s + i) / 2);
|
|
65
|
-
t[c].distance < e ? s = c : i = c;
|
|
66
|
-
}
|
|
67
|
-
const o = t[s].distance, a = t[i].distance, r = t[s].t, f = t[i].t;
|
|
68
|
-
if (a === o) return r;
|
|
69
|
-
const l = (e - o) / (a - o);
|
|
70
|
-
return r + l * (f - r);
|
|
71
|
-
}
|
|
72
|
-
function se(t) {
|
|
73
|
-
return t[t.length - 1].distance;
|
|
74
|
-
}
|
|
75
|
-
function F(t, e = 100) {
|
|
76
|
-
let n = 0, s = t.p0;
|
|
77
|
-
for (let i = 1; i <= e; i++) {
|
|
78
|
-
const o = i / e, a = b(t, o);
|
|
79
|
-
n += y(s, a), s = a;
|
|
80
|
-
}
|
|
81
|
-
return n;
|
|
82
|
-
}
|
|
83
|
-
function q(t, e, n, s, i) {
|
|
84
|
-
const o = y(t.start, t.end);
|
|
85
|
-
return e === void 0 ? s * o : n ? Math.max(0, Math.min(e, 1)) * o : Math.max(0, Math.min(e, o));
|
|
86
|
-
}
|
|
87
|
-
function E(t, e, n, s, i) {
|
|
88
|
-
const o = y(t.start, t.end);
|
|
89
|
-
return e === void 0 ? s * o : n ? Math.max(0, Math.min(e, 1)) * o : Math.max(0, Math.min(e, o));
|
|
90
|
-
}
|
|
91
|
-
function I(t, e, n) {
|
|
92
|
-
const s = /* @__PURE__ */ new Map(), i = /* @__PURE__ */ new Map(), o = /* @__PURE__ */ new Map();
|
|
93
|
-
for (const a of t)
|
|
94
|
-
i.set(a.id, a), o.set(a.id, y(a.start, a.end)), s.set(a.id, []);
|
|
95
|
-
for (let a = 0; a < e.length; a++) {
|
|
96
|
-
const r = e[a], f = i.get(r.fromLineId), l = i.get(r.toLineId);
|
|
97
|
-
if (!f || !l) continue;
|
|
98
|
-
const c = q(f, r.fromOffset, r.fromIsPercentage, 1, n.maxWheelbase), g = E(l, r.toOffset, r.toIsPercentage, 0, n.maxWheelbase), d = W(
|
|
99
|
-
f,
|
|
100
|
-
l,
|
|
101
|
-
n,
|
|
102
|
-
!1,
|
|
103
|
-
// willFlip is always false now
|
|
104
|
-
{
|
|
105
|
-
fromOffset: c,
|
|
106
|
-
fromIsPercentage: !1,
|
|
107
|
-
// Already resolved to absolute
|
|
108
|
-
toOffset: g,
|
|
109
|
-
toIsPercentage: !1
|
|
110
|
-
// Already resolved to absolute
|
|
111
|
-
}
|
|
112
|
-
), h = F(d), p = {
|
|
113
|
-
curveIndex: a,
|
|
114
|
-
fromLineId: r.fromLineId,
|
|
115
|
-
toLineId: r.toLineId,
|
|
116
|
-
fromOffset: c,
|
|
117
|
-
toOffset: g,
|
|
118
|
-
curveLength: h
|
|
119
|
-
};
|
|
120
|
-
s.get(r.fromLineId).push(p);
|
|
121
|
-
}
|
|
122
|
-
return { adjacency: s, lines: i, lineLengths: o };
|
|
123
|
-
}
|
|
124
|
-
function z(t, e) {
|
|
125
|
-
return t.curveCount !== e.curveCount ? t.curveCount - e.curveCount : t.totalDistance - e.totalDistance;
|
|
126
|
-
}
|
|
127
|
-
function G(t, e, n, s, i = !1) {
|
|
128
|
-
const { adjacency: o, lines: a, lineLengths: r } = t;
|
|
129
|
-
if (!a.get(n)) return null;
|
|
130
|
-
const l = r.get(n), c = i ? s / 100 * l : s, g = [], d = /* @__PURE__ */ new Map(), h = (u, v) => `${u}:${Math.round(v)}`;
|
|
131
|
-
if (e.lineId === n && c >= e.offset) {
|
|
132
|
-
const u = c - e.offset;
|
|
133
|
-
return {
|
|
134
|
-
segments: [{
|
|
135
|
-
type: "line",
|
|
136
|
-
lineId: e.lineId,
|
|
137
|
-
startOffset: e.offset,
|
|
138
|
-
endOffset: c,
|
|
139
|
-
length: u
|
|
140
|
-
}],
|
|
141
|
-
totalDistance: u,
|
|
142
|
-
curveCount: 0
|
|
143
|
-
};
|
|
144
|
-
}
|
|
145
|
-
const p = o.get(e.lineId) || [];
|
|
146
|
-
for (const u of p) {
|
|
147
|
-
if (u.fromOffset < e.offset) continue;
|
|
148
|
-
const v = u.fromOffset - e.offset, x = v + u.curveLength, L = {
|
|
149
|
-
type: "line",
|
|
150
|
-
lineId: e.lineId,
|
|
151
|
-
startOffset: e.offset,
|
|
152
|
-
endOffset: u.fromOffset,
|
|
153
|
-
length: v
|
|
154
|
-
}, m = {
|
|
155
|
-
type: "curve",
|
|
156
|
-
curveIndex: u.curveIndex,
|
|
157
|
-
startOffset: 0,
|
|
158
|
-
endOffset: u.curveLength,
|
|
159
|
-
length: u.curveLength
|
|
160
|
-
};
|
|
161
|
-
g.push({
|
|
162
|
-
lineId: u.toLineId,
|
|
163
|
-
entryOffset: u.toOffset,
|
|
164
|
-
totalDistance: x,
|
|
165
|
-
curveCount: 1,
|
|
166
|
-
path: [L, m]
|
|
167
|
-
});
|
|
168
|
-
}
|
|
169
|
-
for (g.sort(z); g.length > 0; ) {
|
|
170
|
-
const u = g.shift(), v = h(u.lineId, u.entryOffset), x = d.get(v);
|
|
171
|
-
if (x !== void 0 && (x.curveCount < u.curveCount || x.curveCount === u.curveCount && x.distance <= u.totalDistance))
|
|
172
|
-
continue;
|
|
173
|
-
if (d.set(v, { curveCount: u.curveCount, distance: u.totalDistance }), u.lineId === n) {
|
|
174
|
-
const m = Math.abs(c - u.entryOffset);
|
|
175
|
-
if (c >= u.entryOffset) {
|
|
176
|
-
const C = {
|
|
177
|
-
type: "line",
|
|
178
|
-
lineId: n,
|
|
179
|
-
startOffset: u.entryOffset,
|
|
180
|
-
endOffset: c,
|
|
181
|
-
length: m
|
|
182
|
-
};
|
|
183
|
-
return {
|
|
184
|
-
segments: [...u.path, C],
|
|
185
|
-
totalDistance: u.totalDistance + m,
|
|
186
|
-
curveCount: u.curveCount
|
|
187
|
-
};
|
|
188
|
-
}
|
|
189
|
-
}
|
|
190
|
-
const L = o.get(u.lineId) || [];
|
|
191
|
-
for (const m of L) {
|
|
192
|
-
if (m.fromOffset < u.entryOffset) continue;
|
|
193
|
-
const C = m.fromOffset - u.entryOffset, T = u.totalDistance + C + m.curveLength, P = u.curveCount + 1, B = h(m.toLineId, m.toOffset), D = d.get(B);
|
|
194
|
-
if (D !== void 0 && (D.curveCount < P || D.curveCount === P && D.distance <= T))
|
|
195
|
-
continue;
|
|
196
|
-
const j = {
|
|
197
|
-
type: "line",
|
|
198
|
-
lineId: u.lineId,
|
|
199
|
-
startOffset: u.entryOffset,
|
|
200
|
-
endOffset: m.fromOffset,
|
|
201
|
-
length: C
|
|
202
|
-
}, $ = {
|
|
203
|
-
type: "curve",
|
|
204
|
-
curveIndex: m.curveIndex,
|
|
205
|
-
startOffset: 0,
|
|
206
|
-
endOffset: m.curveLength,
|
|
207
|
-
length: m.curveLength
|
|
208
|
-
};
|
|
209
|
-
g.push({
|
|
210
|
-
lineId: m.toLineId,
|
|
211
|
-
entryOffset: m.toOffset,
|
|
212
|
-
totalDistance: T,
|
|
213
|
-
curveCount: P,
|
|
214
|
-
path: [...u.path, j, $]
|
|
215
|
-
});
|
|
216
|
-
}
|
|
217
|
-
g.sort(z);
|
|
218
|
-
}
|
|
219
|
-
return null;
|
|
220
|
-
}
|
|
221
|
-
function A(t, e) {
|
|
222
|
-
const n = Math.sqrt(
|
|
223
|
-
Math.pow(t.end.x - t.start.x, 2) + Math.pow(t.end.y - t.start.y, 2)
|
|
224
|
-
), s = n > 0 ? e / n : 0;
|
|
225
|
-
return {
|
|
226
|
-
x: t.start.x + (t.end.x - t.start.x) * Math.min(1, Math.max(0, s)),
|
|
227
|
-
y: t.start.y + (t.end.y - t.start.y) * Math.min(1, Math.max(0, s))
|
|
228
|
-
};
|
|
229
|
-
}
|
|
230
|
-
function O(t) {
|
|
231
|
-
return Math.sqrt(
|
|
232
|
-
Math.pow(t.end.x - t.start.x, 2) + Math.pow(t.end.y - t.start.y, 2)
|
|
233
|
-
);
|
|
234
|
-
}
|
|
235
|
-
function Q(t, e, n) {
|
|
236
|
-
let s = 0;
|
|
237
|
-
for (let i = 0; i < e; i++)
|
|
238
|
-
s += t.segments[i].length;
|
|
239
|
-
return s += n, s;
|
|
240
|
-
}
|
|
241
|
-
function R(t, e) {
|
|
242
|
-
let n = 0;
|
|
243
|
-
for (let s = 0; s < t.segments.length; s++) {
|
|
244
|
-
const i = t.segments[s], o = n + i.length;
|
|
245
|
-
if (e < o)
|
|
246
|
-
return {
|
|
247
|
-
segmentIndex: s,
|
|
248
|
-
segmentDistance: e - n
|
|
249
|
-
};
|
|
250
|
-
if (e === o)
|
|
251
|
-
return s + 1 < t.segments.length ? {
|
|
252
|
-
segmentIndex: s + 1,
|
|
253
|
-
segmentDistance: 0
|
|
254
|
-
} : {
|
|
255
|
-
segmentIndex: s,
|
|
256
|
-
segmentDistance: i.length
|
|
257
|
-
};
|
|
258
|
-
n += i.length;
|
|
259
|
-
}
|
|
260
|
-
return null;
|
|
261
|
-
}
|
|
262
|
-
function ie(t, e, n, s) {
|
|
263
|
-
const o = Q(
|
|
264
|
-
t,
|
|
265
|
-
e,
|
|
266
|
-
n
|
|
267
|
-
) + s;
|
|
268
|
-
return R(t, o);
|
|
269
|
-
}
|
|
270
|
-
function H(t, e, n, s) {
|
|
271
|
-
const i = O(s), o = n.length + 1, a = new Array(o);
|
|
272
|
-
a[o - 1] = {
|
|
273
|
-
lineId: t,
|
|
274
|
-
absoluteOffset: e,
|
|
275
|
-
position: A(s, e)
|
|
276
|
-
};
|
|
277
|
-
let r = e;
|
|
278
|
-
for (let f = o - 2; f >= 0; f--)
|
|
279
|
-
r = Math.min(r + n[f], i), a[f] = {
|
|
280
|
-
lineId: t,
|
|
281
|
-
absoluteOffset: r,
|
|
282
|
-
position: A(s, r)
|
|
283
|
-
};
|
|
284
|
-
return a;
|
|
285
|
-
}
|
|
286
|
-
function J(t, e) {
|
|
287
|
-
return {
|
|
288
|
-
...t,
|
|
289
|
-
state: "idle"
|
|
290
|
-
};
|
|
291
|
-
}
|
|
292
|
-
function U(t) {
|
|
293
|
-
return {
|
|
294
|
-
vehicle: t,
|
|
295
|
-
execution: null
|
|
296
|
-
};
|
|
297
|
-
}
|
|
298
|
-
function re(t, e) {
|
|
299
|
-
const n = [], s = /* @__PURE__ */ new Map();
|
|
300
|
-
for (const i of t) {
|
|
301
|
-
if (!e.get(i.lineId)) continue;
|
|
302
|
-
const a = J(i);
|
|
303
|
-
n.push(a);
|
|
304
|
-
const r = U(a);
|
|
305
|
-
s.set(i.id, r);
|
|
306
|
-
}
|
|
307
|
-
return { movingVehicles: n, stateMap: s };
|
|
308
|
-
}
|
|
309
|
-
function M(t, e) {
|
|
310
|
-
return { position: A(t, e), lineId: t.id, absoluteOffset: e };
|
|
311
|
-
}
|
|
312
|
-
function w(t, e) {
|
|
313
|
-
const n = _(t.arcLengthTable, e);
|
|
314
|
-
return { position: b(t.bezier, n) };
|
|
315
|
-
}
|
|
316
|
-
function X(t, e, n, s, i, o, a) {
|
|
317
|
-
const r = n.segments[e.currentSegmentIndex], f = e.segmentDistance + s;
|
|
318
|
-
if (f >= r.length) {
|
|
319
|
-
const c = f - r.length, g = e.currentSegmentIndex + 1;
|
|
320
|
-
if (g >= n.segments.length) {
|
|
321
|
-
if (a !== void 0 && r.type === "line") {
|
|
322
|
-
const u = i.get(r.lineId), v = r.startOffset + f;
|
|
323
|
-
if (v <= a) {
|
|
324
|
-
const L = M(u, v);
|
|
325
|
-
return {
|
|
326
|
-
axleState: { ...t, ...L },
|
|
327
|
-
execution: { ...e, segmentDistance: f },
|
|
328
|
-
completed: !1
|
|
329
|
-
};
|
|
330
|
-
}
|
|
331
|
-
const x = M(u, a);
|
|
332
|
-
return {
|
|
333
|
-
axleState: { ...t, ...x },
|
|
334
|
-
execution: { ...e, segmentDistance: a - r.startOffset },
|
|
335
|
-
completed: !0
|
|
336
|
-
};
|
|
337
|
-
}
|
|
338
|
-
const p = r.type === "line" ? M(
|
|
339
|
-
i.get(r.lineId),
|
|
340
|
-
r.endOffset
|
|
341
|
-
) : w(
|
|
342
|
-
o.get(r.curveIndex),
|
|
343
|
-
r.length
|
|
344
|
-
);
|
|
345
|
-
return {
|
|
346
|
-
axleState: { ...t, ...p },
|
|
347
|
-
execution: { ...e, segmentDistance: r.length },
|
|
348
|
-
completed: !0
|
|
349
|
-
};
|
|
350
|
-
}
|
|
351
|
-
const d = n.segments[g], h = d.type === "line" ? M(
|
|
352
|
-
i.get(d.lineId),
|
|
353
|
-
d.startOffset + c
|
|
354
|
-
) : w(
|
|
355
|
-
o.get(d.curveIndex),
|
|
356
|
-
c
|
|
357
|
-
);
|
|
358
|
-
return {
|
|
359
|
-
axleState: { ...t, ...h },
|
|
360
|
-
execution: {
|
|
361
|
-
currentSegmentIndex: g,
|
|
362
|
-
segmentDistance: c
|
|
363
|
-
},
|
|
364
|
-
completed: !1
|
|
365
|
-
};
|
|
366
|
-
}
|
|
367
|
-
const l = r.type === "line" ? M(
|
|
368
|
-
i.get(r.lineId),
|
|
369
|
-
r.startOffset + f
|
|
370
|
-
) : w(
|
|
371
|
-
o.get(r.curveIndex),
|
|
372
|
-
f
|
|
373
|
-
);
|
|
374
|
-
return {
|
|
375
|
-
axleState: { ...t, ...l },
|
|
376
|
-
execution: { ...e, segmentDistance: f },
|
|
377
|
-
completed: !1
|
|
378
|
-
};
|
|
379
|
-
}
|
|
380
|
-
function Y(t, e, n, s) {
|
|
381
|
-
const i = /* @__PURE__ */ new Map();
|
|
382
|
-
for (const o of t.segments)
|
|
383
|
-
if (o.type === "curve" && o.curveIndex !== void 0) {
|
|
384
|
-
const a = e[o.curveIndex];
|
|
385
|
-
if (a) {
|
|
386
|
-
const r = n.get(a.fromLineId), f = n.get(a.toLineId);
|
|
387
|
-
if (r && f) {
|
|
388
|
-
const l = q(
|
|
389
|
-
r,
|
|
390
|
-
a.fromOffset,
|
|
391
|
-
a.fromIsPercentage,
|
|
392
|
-
1,
|
|
393
|
-
// Default: 100% = 1.0
|
|
394
|
-
s.maxWheelbase
|
|
395
|
-
), c = E(
|
|
396
|
-
f,
|
|
397
|
-
a.toOffset,
|
|
398
|
-
a.toIsPercentage,
|
|
399
|
-
0,
|
|
400
|
-
s.maxWheelbase
|
|
401
|
-
), g = W(
|
|
402
|
-
r,
|
|
403
|
-
f,
|
|
404
|
-
s,
|
|
405
|
-
!1,
|
|
406
|
-
// willFlip is always false now
|
|
407
|
-
{
|
|
408
|
-
fromOffset: l,
|
|
409
|
-
fromIsPercentage: !1,
|
|
410
|
-
// Already resolved to absolute
|
|
411
|
-
toOffset: c,
|
|
412
|
-
toIsPercentage: !1
|
|
413
|
-
// Already resolved to absolute
|
|
414
|
-
}
|
|
415
|
-
), d = N(g);
|
|
416
|
-
i.set(o.curveIndex, { bezier: g, arcLengthTable: d });
|
|
417
|
-
}
|
|
418
|
-
}
|
|
419
|
-
}
|
|
420
|
-
return i;
|
|
421
|
-
}
|
|
422
|
-
function Z(t, e, n) {
|
|
423
|
-
const { graph: s, linesMap: i, curves: o, config: a } = n, r = i.get(e.targetLineId);
|
|
424
|
-
if (!r) return null;
|
|
425
|
-
const f = t.axleSpacings.reduce((u, v) => u + v, 0), c = O(r) - f;
|
|
426
|
-
if (c <= 0) return null;
|
|
427
|
-
const g = e.isPercentage ? e.targetOffset * c : Math.min(e.targetOffset, c), d = t.axles[t.axles.length - 1], h = G(
|
|
428
|
-
s,
|
|
429
|
-
{ lineId: d.lineId, offset: d.absoluteOffset },
|
|
430
|
-
e.targetLineId,
|
|
431
|
-
g,
|
|
432
|
-
!1
|
|
433
|
-
);
|
|
434
|
-
if (!h) return null;
|
|
435
|
-
const p = Y(h, o, i, a);
|
|
436
|
-
return { path: h, curveDataMap: p };
|
|
437
|
-
}
|
|
438
|
-
function oe(t, e) {
|
|
439
|
-
const n = t.execution, i = e.vehicleQueues.get(t.vehicle.id)?.[n.currentCommandIndex];
|
|
440
|
-
return i && e.onCommandComplete && e.onCommandComplete({
|
|
441
|
-
vehicleId: t.vehicle.id,
|
|
442
|
-
command: i,
|
|
443
|
-
finalPosition: {
|
|
444
|
-
lineId: t.vehicle.axles[t.vehicle.axles.length - 1].lineId,
|
|
445
|
-
absoluteOffset: t.vehicle.axles[t.vehicle.axles.length - 1].absoluteOffset,
|
|
446
|
-
position: t.vehicle.axles[t.vehicle.axles.length - 1].position
|
|
447
|
-
},
|
|
448
|
-
payload: i.payload
|
|
449
|
-
}), {
|
|
450
|
-
handled: !0,
|
|
451
|
-
vehicle: { ...t.vehicle, state: "waiting" },
|
|
452
|
-
newExecution: n,
|
|
453
|
-
// Keep execution state for resume
|
|
454
|
-
isWaiting: !0
|
|
455
|
-
};
|
|
456
|
-
}
|
|
457
|
-
function ee(t, e, n, s, i, o) {
|
|
458
|
-
let a;
|
|
459
|
-
const r = e[0];
|
|
460
|
-
if (r.currentSegmentIndex < n.segments.length) {
|
|
461
|
-
const l = n.segments[r.currentSegmentIndex];
|
|
462
|
-
if (l.type === "line") {
|
|
463
|
-
const c = i.get(l.lineId);
|
|
464
|
-
c && (a = O(c));
|
|
465
|
-
}
|
|
466
|
-
}
|
|
467
|
-
const f = t.map((l, c) => {
|
|
468
|
-
const g = c === 0 ? a : void 0;
|
|
469
|
-
return X(l, e[c], n, s, i, o, g);
|
|
470
|
-
});
|
|
471
|
-
return {
|
|
472
|
-
axles: f.map((l) => l.axleState),
|
|
473
|
-
axleExecutions: f.map((l) => l.execution),
|
|
474
|
-
arrived: f[f.length - 1].completed
|
|
475
|
-
// axles[N-1] = rearmost menentukan arrived
|
|
476
|
-
};
|
|
477
|
-
}
|
|
478
|
-
class ae {
|
|
479
|
-
graph = null;
|
|
480
|
-
linesMap = /* @__PURE__ */ new Map();
|
|
481
|
-
curves = [];
|
|
482
|
-
config;
|
|
483
|
-
constructor(e) {
|
|
484
|
-
this.config = {
|
|
485
|
-
maxWheelbase: e.maxWheelbase,
|
|
486
|
-
tangentMode: e.tangentMode
|
|
487
|
-
};
|
|
488
|
-
}
|
|
489
|
-
// ---------------------------------------------------------------------------
|
|
490
|
-
// Accessors
|
|
491
|
-
// ---------------------------------------------------------------------------
|
|
492
|
-
get movementConfig() {
|
|
493
|
-
return this.config;
|
|
494
|
-
}
|
|
495
|
-
get lines() {
|
|
496
|
-
return Array.from(this.linesMap.values());
|
|
497
|
-
}
|
|
498
|
-
getCurves() {
|
|
499
|
-
return this.curves;
|
|
500
|
-
}
|
|
501
|
-
// ---------------------------------------------------------------------------
|
|
502
|
-
// Scene management
|
|
503
|
-
// ---------------------------------------------------------------------------
|
|
504
|
-
/**
|
|
505
|
-
* Replace the entire scene and rebuild the graph.
|
|
506
|
-
*/
|
|
507
|
-
setScene(e, n) {
|
|
508
|
-
this.linesMap.clear();
|
|
509
|
-
for (const s of e)
|
|
510
|
-
this.linesMap.set(s.id, s);
|
|
511
|
-
this.curves = n, this.graph = I(e, n, this.config);
|
|
512
|
-
}
|
|
513
|
-
/**
|
|
514
|
-
* Add a single line. Returns false if a line with the same ID already exists.
|
|
515
|
-
*/
|
|
516
|
-
addLine(e) {
|
|
517
|
-
return this.linesMap.has(e.id) ? !1 : (this.linesMap.set(e.id, e), this.graph = I(Array.from(this.linesMap.values()), this.curves, this.config), !0);
|
|
518
|
-
}
|
|
519
|
-
/**
|
|
520
|
-
* Update start and/or end coordinates of an existing line.
|
|
521
|
-
*/
|
|
522
|
-
updateLine(e, n) {
|
|
523
|
-
const s = this.linesMap.get(e);
|
|
524
|
-
return s ? (n.start && (s.start = n.start), n.end && (s.end = n.end), this.graph = I(Array.from(this.linesMap.values()), this.curves, this.config), !0) : !1;
|
|
525
|
-
}
|
|
526
|
-
/**
|
|
527
|
-
* Update a single endpoint ('start' or 'end') of a line.
|
|
528
|
-
*/
|
|
529
|
-
updateLineEndpoint(e, n, s) {
|
|
530
|
-
return this.updateLine(e, { [n]: s });
|
|
531
|
-
}
|
|
532
|
-
/**
|
|
533
|
-
* Rename a line ID and cascade the change to all connected curves.
|
|
534
|
-
*/
|
|
535
|
-
renameLine(e, n) {
|
|
536
|
-
const s = n.trim();
|
|
537
|
-
if (!s) return { success: !1, error: "Name cannot be empty" };
|
|
538
|
-
if (s === e) return { success: !0 };
|
|
539
|
-
if (this.linesMap.has(s)) return { success: !1, error: `"${s}" already exists` };
|
|
540
|
-
const i = this.linesMap.get(e);
|
|
541
|
-
if (!i) return { success: !1, error: `Line "${e}" not found` };
|
|
542
|
-
i.id = s, this.linesMap.delete(e), this.linesMap.set(s, i);
|
|
543
|
-
for (const o of this.curves)
|
|
544
|
-
o.fromLineId === e && (o.fromLineId = s), o.toLineId === e && (o.toLineId = s);
|
|
545
|
-
return this.graph = I(Array.from(this.linesMap.values()), this.curves, this.config), { success: !0 };
|
|
546
|
-
}
|
|
547
|
-
/**
|
|
548
|
-
* Remove a line and all curves connected to it.
|
|
549
|
-
*/
|
|
550
|
-
removeLine(e) {
|
|
551
|
-
return this.linesMap.has(e) ? (this.linesMap.delete(e), this.curves = this.curves.filter((n) => n.fromLineId !== e && n.toLineId !== e), this.graph = I(Array.from(this.linesMap.values()), this.curves, this.config), !0) : !1;
|
|
552
|
-
}
|
|
553
|
-
/**
|
|
554
|
-
* Add a directional curve (connection) from one line to another.
|
|
555
|
-
*/
|
|
556
|
-
addCurve(e) {
|
|
557
|
-
this.curves.push(e), this.graph = I(Array.from(this.linesMap.values()), this.curves, this.config);
|
|
558
|
-
}
|
|
559
|
-
/**
|
|
560
|
-
* Update a curve by index. Returns false if index is out of bounds.
|
|
561
|
-
*/
|
|
562
|
-
updateCurve(e, n) {
|
|
563
|
-
return e < 0 || e >= this.curves.length ? !1 : (this.curves[e] = { ...this.curves[e], ...n }, this.graph = I(Array.from(this.linesMap.values()), this.curves, this.config), !0);
|
|
564
|
-
}
|
|
565
|
-
/**
|
|
566
|
-
* Remove a curve by index. Returns false if index is out of bounds.
|
|
567
|
-
*/
|
|
568
|
-
removeCurve(e) {
|
|
569
|
-
return e < 0 || e >= this.curves.length ? !1 : (this.curves.splice(e, 1), this.graph = I(Array.from(this.linesMap.values()), this.curves, this.config), !0);
|
|
570
|
-
}
|
|
571
|
-
// ---------------------------------------------------------------------------
|
|
572
|
-
// Vehicle operations
|
|
573
|
-
// ---------------------------------------------------------------------------
|
|
574
|
-
/**
|
|
575
|
-
* Initialize a vehicle's N-axle position on a line.
|
|
576
|
-
*
|
|
577
|
-
* @param lineId - The line to place the vehicle on
|
|
578
|
-
* @param rearOffset - Absolute distance offset untuk axle paling belakang
|
|
579
|
-
* @param vehicle - VehicleDefinition (or any object extending it with axleSpacings)
|
|
580
|
-
* @returns Initial VehiclePathState, or null if lineId does not exist
|
|
581
|
-
* @throws if axleSpacings is empty
|
|
582
|
-
*/
|
|
583
|
-
initializeVehicle(e, n, s) {
|
|
584
|
-
const i = this.linesMap.get(e);
|
|
585
|
-
if (!i) return null;
|
|
586
|
-
const { axleSpacings: o } = s;
|
|
587
|
-
if (o.length === 0)
|
|
588
|
-
throw new Error("initializeVehicle: axleSpacings must have at least one entry (vehicle needs ≥2 axles)");
|
|
589
|
-
const a = o.reduce((c, g) => c + g, 0), r = O(i), f = Math.min(n, r - a);
|
|
590
|
-
return {
|
|
591
|
-
axles: H(e, f, o, i).map((c) => ({ lineId: c.lineId, offset: c.absoluteOffset, position: c.position })),
|
|
592
|
-
axleSpacings: o
|
|
593
|
-
};
|
|
594
|
-
}
|
|
595
|
-
/**
|
|
596
|
-
* Prepare a path from the vehicle's current position to a target.
|
|
597
|
-
*
|
|
598
|
-
* Must be called before moveVehicle(). Returns null if no path exists.
|
|
599
|
-
*
|
|
600
|
-
* @param vehicleState - Current vehicle state (from initializeVehicle or previous tick)
|
|
601
|
-
* @param targetLineId - ID of the target line
|
|
602
|
-
* @param targetOffset - Position on the target line
|
|
603
|
-
* @param isPercentage - If true, targetOffset is 0-1 fraction; if false, absolute distance
|
|
604
|
-
*/
|
|
605
|
-
preparePath(e, n, s, i = !1) {
|
|
606
|
-
if (!this.graph) return null;
|
|
607
|
-
const o = e.axleSpacings.reduce((h, p) => h + p, 0), a = e.axles[e.axles.length - 1], r = {
|
|
608
|
-
lineId: a.lineId,
|
|
609
|
-
offset: a.offset,
|
|
610
|
-
axles: e.axles.map((h) => ({
|
|
611
|
-
lineId: h.lineId,
|
|
612
|
-
position: h.position,
|
|
613
|
-
absoluteOffset: h.offset
|
|
614
|
-
})),
|
|
615
|
-
axleSpacings: e.axleSpacings
|
|
616
|
-
}, f = Z(r, {
|
|
617
|
-
targetLineId: n,
|
|
618
|
-
targetOffset: s,
|
|
619
|
-
isPercentage: i
|
|
620
|
-
}, {
|
|
621
|
-
graph: this.graph,
|
|
622
|
-
linesMap: this.linesMap,
|
|
623
|
-
curves: this.curves,
|
|
624
|
-
config: this.config
|
|
625
|
-
});
|
|
626
|
-
if (!f) return null;
|
|
627
|
-
let l = s;
|
|
628
|
-
const c = this.linesMap.get(n);
|
|
629
|
-
if (c) {
|
|
630
|
-
const h = Math.max(0, O(c) - o);
|
|
631
|
-
l = i ? s * h : Math.min(s, h);
|
|
632
|
-
}
|
|
633
|
-
let g = 0;
|
|
634
|
-
const d = [
|
|
635
|
-
{ segmentIndex: 0, segmentDistance: o }
|
|
636
|
-
// axles[0] = front
|
|
637
|
-
];
|
|
638
|
-
for (let h = 0; h < e.axleSpacings.length; h++)
|
|
639
|
-
g += e.axleSpacings[h], d.push({ segmentIndex: 0, segmentDistance: o - g });
|
|
640
|
-
return {
|
|
641
|
-
path: f.path,
|
|
642
|
-
curveDataMap: f.curveDataMap,
|
|
643
|
-
axleExecutions: d,
|
|
644
|
-
targetLineId: n,
|
|
645
|
-
targetOffset: l
|
|
646
|
-
};
|
|
647
|
-
}
|
|
648
|
-
/**
|
|
649
|
-
* Advance a vehicle by `distance` along its prepared path.
|
|
650
|
-
*
|
|
651
|
-
* Call this every tick. The returned `state` and `execution` replace the
|
|
652
|
-
* previous values. When `arrived` is true, the vehicle has reached the target.
|
|
653
|
-
*
|
|
654
|
-
* @param state - Current vehicle state
|
|
655
|
-
* @param execution - Current path execution (from preparePath or previous tick)
|
|
656
|
-
* @param distance - Distance to advance this tick (speed × deltaTime)
|
|
657
|
-
*/
|
|
658
|
-
moveVehicle(e, n, s) {
|
|
659
|
-
const i = e.axles.map((r) => ({
|
|
660
|
-
lineId: r.lineId,
|
|
661
|
-
position: r.position,
|
|
662
|
-
absoluteOffset: r.offset
|
|
663
|
-
})), o = n.axleExecutions.map((r) => ({
|
|
664
|
-
currentSegmentIndex: r.segmentIndex,
|
|
665
|
-
segmentDistance: r.segmentDistance
|
|
666
|
-
})), a = ee(i, o, n.path, s, this.linesMap, n.curveDataMap);
|
|
667
|
-
return {
|
|
668
|
-
state: {
|
|
669
|
-
axles: a.axles.map((r) => ({ lineId: r.lineId, offset: r.absoluteOffset, position: r.position })),
|
|
670
|
-
axleSpacings: e.axleSpacings
|
|
671
|
-
},
|
|
672
|
-
execution: {
|
|
673
|
-
...n,
|
|
674
|
-
axleExecutions: a.axleExecutions.map((r) => ({
|
|
675
|
-
segmentIndex: r.currentSegmentIndex,
|
|
676
|
-
segmentDistance: r.segmentDistance
|
|
677
|
-
}))
|
|
678
|
-
},
|
|
679
|
-
arrived: a.arrived
|
|
680
|
-
};
|
|
681
|
-
}
|
|
682
|
-
}
|
|
683
|
-
export {
|
|
684
|
-
S as A,
|
|
685
|
-
Z as B,
|
|
686
|
-
q as C,
|
|
687
|
-
E as D,
|
|
688
|
-
X as E,
|
|
689
|
-
ae as P,
|
|
690
|
-
O as a,
|
|
691
|
-
R as b,
|
|
692
|
-
N as c,
|
|
693
|
-
I as d,
|
|
694
|
-
F as e,
|
|
695
|
-
ie as f,
|
|
696
|
-
Q as g,
|
|
697
|
-
H as h,
|
|
698
|
-
w as i,
|
|
699
|
-
M as j,
|
|
700
|
-
k,
|
|
701
|
-
W as l,
|
|
702
|
-
ee as m,
|
|
703
|
-
U as n,
|
|
704
|
-
y as o,
|
|
705
|
-
_ as p,
|
|
706
|
-
G as q,
|
|
707
|
-
se as r,
|
|
708
|
-
b as s,
|
|
709
|
-
K as t,
|
|
710
|
-
V as u,
|
|
711
|
-
A as v,
|
|
712
|
-
oe as w,
|
|
713
|
-
re as x,
|
|
714
|
-
J as y,
|
|
715
|
-
ne as z
|
|
716
|
-
};
|