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