vehicle-path 1.0.0 → 1.0.2
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/vehicle-path.cjs +11 -11
- package/dist/vehicle-path.js +486 -470
- package/package.json +1 -1
- package/dist/index.d.cts +0 -28
package/dist/vehicle-path.js
CHANGED
|
@@ -1,28 +1,28 @@
|
|
|
1
1
|
import { useState as L, useMemo as Z, useRef as P, useEffect as b, useCallback as G, createContext as he, useContext as pe } from "react";
|
|
2
2
|
function j(e, t) {
|
|
3
|
-
const n = t.x - e.x,
|
|
4
|
-
return Math.sqrt(n * n +
|
|
3
|
+
const n = t.x - e.x, s = t.y - e.y;
|
|
4
|
+
return Math.sqrt(n * n + s * s);
|
|
5
5
|
}
|
|
6
6
|
function Q(e, t) {
|
|
7
|
-
const n = t.x - e.x,
|
|
8
|
-
return
|
|
7
|
+
const n = t.x - e.x, s = t.y - e.y, r = Math.sqrt(n * n + s * s);
|
|
8
|
+
return r === 0 ? { x: 0, y: 0 } : { x: n / r, y: s / r };
|
|
9
9
|
}
|
|
10
10
|
function Ie(e, t) {
|
|
11
11
|
return t * (e === "proportional-40" ? 0.4 : 0.5522);
|
|
12
12
|
}
|
|
13
|
-
function ue(e, t, n,
|
|
14
|
-
const { wheelbase: c, tangentMode:
|
|
15
|
-
let
|
|
16
|
-
|
|
13
|
+
function ue(e, t, n, s = !1, r) {
|
|
14
|
+
const { wheelbase: c, tangentMode: i } = n;
|
|
15
|
+
let o;
|
|
16
|
+
r?.fromOffset !== void 0 ? o = ee(e, r.fromOffset, r.fromIsPercentage ?? !1) : o = e.end;
|
|
17
17
|
let f;
|
|
18
|
-
|
|
19
|
-
const a = Q(e.start, e.end), u =
|
|
18
|
+
r?.toOffset !== void 0 ? f = ee(t, r.toOffset, r.toIsPercentage ?? !1) : f = t.start;
|
|
19
|
+
const a = Q(e.start, e.end), u = s ? {
|
|
20
20
|
// Transition with flip: kurva dimulai dari P (baseP0 - wheelbase in line direction)
|
|
21
|
-
x:
|
|
22
|
-
y:
|
|
23
|
-
} :
|
|
24
|
-
x: f.x -
|
|
25
|
-
y: f.y -
|
|
21
|
+
x: o.x - a.x * c,
|
|
22
|
+
y: o.y - a.y * c
|
|
23
|
+
} : o, d = Q(e.start, e.end), g = Q(t.start, t.end), v = j(u, f), h = Ie(i, v), l = s ? { x: u.x - d.x * h, y: u.y - d.y * h } : { x: u.x + d.x * h, y: u.y + d.y * h }, p = {
|
|
24
|
+
x: f.x - g.x * h,
|
|
25
|
+
y: f.y - g.y * h
|
|
26
26
|
};
|
|
27
27
|
return { p0: u, p1: l, p2: p, p3: f };
|
|
28
28
|
}
|
|
@@ -33,23 +33,23 @@ function ve(e, t) {
|
|
|
33
33
|
};
|
|
34
34
|
}
|
|
35
35
|
function ee(e, t, n) {
|
|
36
|
-
const
|
|
37
|
-
let
|
|
38
|
-
return n ?
|
|
36
|
+
const s = j(e.start, e.end);
|
|
37
|
+
let r;
|
|
38
|
+
return n ? r = t / 100 : r = s > 0 ? t / s : 0, r = Math.max(0, Math.min(1, r)), ve(e, r);
|
|
39
39
|
}
|
|
40
40
|
function ne(e, t) {
|
|
41
|
-
const { p0: n, p1:
|
|
41
|
+
const { p0: n, p1: s, p2: r, p3: c } = e, i = 1 - t, o = i * i, f = o * i, a = t * t, u = a * t;
|
|
42
42
|
return {
|
|
43
|
-
x: f * n.x + 3 *
|
|
44
|
-
y: f * n.y + 3 *
|
|
43
|
+
x: f * n.x + 3 * o * t * s.x + 3 * i * a * r.x + u * c.x,
|
|
44
|
+
y: f * n.y + 3 * o * t * s.y + 3 * i * a * r.y + u * c.y
|
|
45
45
|
};
|
|
46
46
|
}
|
|
47
47
|
function xe(e, t = 100) {
|
|
48
48
|
const n = [{ t: 0, distance: 0 }];
|
|
49
|
-
let
|
|
49
|
+
let s = e.p0, r = 0;
|
|
50
50
|
for (let c = 1; c <= t; c++) {
|
|
51
|
-
const
|
|
52
|
-
|
|
51
|
+
const i = c / t, o = ne(e, i);
|
|
52
|
+
r += j(s, o), n.push({ t: i, distance: r }), s = o;
|
|
53
53
|
}
|
|
54
54
|
return n;
|
|
55
55
|
}
|
|
@@ -57,65 +57,65 @@ function ye(e, t) {
|
|
|
57
57
|
if (t <= 0) return 0;
|
|
58
58
|
const n = e[e.length - 1].distance;
|
|
59
59
|
if (t >= n) return 1;
|
|
60
|
-
let
|
|
61
|
-
for (;
|
|
62
|
-
const u = Math.floor((
|
|
63
|
-
e[u].distance < t ?
|
|
60
|
+
let s = 0, r = e.length - 1;
|
|
61
|
+
for (; s < r - 1; ) {
|
|
62
|
+
const u = Math.floor((s + r) / 2);
|
|
63
|
+
e[u].distance < t ? s = u : r = u;
|
|
64
64
|
}
|
|
65
|
-
const c = e[
|
|
66
|
-
if (
|
|
67
|
-
const a = (t - c) / (
|
|
68
|
-
return
|
|
65
|
+
const c = e[s].distance, i = e[r].distance, o = e[s].t, f = e[r].t;
|
|
66
|
+
if (i === c) return o;
|
|
67
|
+
const a = (t - c) / (i - c);
|
|
68
|
+
return o + a * (f - o);
|
|
69
69
|
}
|
|
70
70
|
function je(e) {
|
|
71
71
|
return e[e.length - 1].distance;
|
|
72
72
|
}
|
|
73
73
|
function Me(e, t = 100) {
|
|
74
|
-
let n = 0,
|
|
75
|
-
for (let
|
|
76
|
-
const c =
|
|
77
|
-
n += j(
|
|
74
|
+
let n = 0, s = e.p0;
|
|
75
|
+
for (let r = 1; r <= t; r++) {
|
|
76
|
+
const c = r / t, i = ne(e, c);
|
|
77
|
+
n += j(s, i), s = i;
|
|
78
78
|
}
|
|
79
79
|
return n;
|
|
80
80
|
}
|
|
81
|
-
function ze(e, t, n,
|
|
82
|
-
const
|
|
83
|
-
return t === void 0 ?
|
|
81
|
+
function ze(e, t, n, s) {
|
|
82
|
+
const r = j(e.start, e.end);
|
|
83
|
+
return t === void 0 ? s / 100 * r : n ? t / 100 * r : t;
|
|
84
84
|
}
|
|
85
|
-
function fe(e, t, n,
|
|
86
|
-
const c = j(e.start, e.end),
|
|
87
|
-
if (
|
|
85
|
+
function fe(e, t, n, s, r) {
|
|
86
|
+
const c = j(e.start, e.end), i = c - r;
|
|
87
|
+
if (i <= 0)
|
|
88
88
|
return c;
|
|
89
|
-
let
|
|
89
|
+
let o;
|
|
90
90
|
if (t === void 0)
|
|
91
|
-
|
|
91
|
+
o = s;
|
|
92
92
|
else if (n)
|
|
93
|
-
|
|
93
|
+
o = t;
|
|
94
94
|
else
|
|
95
|
-
return Math.max(
|
|
96
|
-
return
|
|
95
|
+
return Math.max(r, Math.min(t, c));
|
|
96
|
+
return r + o / 100 * i;
|
|
97
97
|
}
|
|
98
|
-
function le(e, t, n,
|
|
99
|
-
const
|
|
100
|
-
if (
|
|
98
|
+
function le(e, t, n, s, r) {
|
|
99
|
+
const i = j(e.start, e.end) - r;
|
|
100
|
+
if (i <= 0)
|
|
101
101
|
return 0;
|
|
102
|
-
let
|
|
102
|
+
let o;
|
|
103
103
|
if (t === void 0)
|
|
104
|
-
|
|
104
|
+
o = s;
|
|
105
105
|
else if (n)
|
|
106
|
-
|
|
106
|
+
o = t;
|
|
107
107
|
else
|
|
108
|
-
return Math.max(0, Math.min(t,
|
|
109
|
-
return
|
|
108
|
+
return Math.max(0, Math.min(t, i));
|
|
109
|
+
return o / 100 * i;
|
|
110
110
|
}
|
|
111
111
|
function Le(e, t, n) {
|
|
112
|
-
const
|
|
113
|
-
for (const
|
|
114
|
-
|
|
115
|
-
for (let
|
|
116
|
-
const
|
|
112
|
+
const s = /* @__PURE__ */ new Map(), r = /* @__PURE__ */ new Map(), c = /* @__PURE__ */ new Map();
|
|
113
|
+
for (const i of e)
|
|
114
|
+
r.set(i.id, i), c.set(i.id, j(i.start, i.end)), s.set(i.id, []);
|
|
115
|
+
for (let i = 0; i < t.length; i++) {
|
|
116
|
+
const o = t[i], f = r.get(o.fromLineId), a = r.get(o.toLineId);
|
|
117
117
|
if (!f || !a) continue;
|
|
118
|
-
const u = fe(f,
|
|
118
|
+
const u = fe(f, o.fromOffset, o.fromIsPercentage, 100, n.wheelbase), d = le(a, o.toOffset, o.toIsPercentage, 0, n.wheelbase), g = ue(
|
|
119
119
|
f,
|
|
120
120
|
a,
|
|
121
121
|
n,
|
|
@@ -129,22 +129,22 @@ function Le(e, t, n) {
|
|
|
129
129
|
toIsPercentage: !1
|
|
130
130
|
// Already resolved to absolute
|
|
131
131
|
}
|
|
132
|
-
),
|
|
133
|
-
curveIndex:
|
|
134
|
-
fromLineId:
|
|
135
|
-
toLineId:
|
|
132
|
+
), v = Me(g), h = {
|
|
133
|
+
curveIndex: i,
|
|
134
|
+
fromLineId: o.fromLineId,
|
|
135
|
+
toLineId: o.toLineId,
|
|
136
136
|
fromOffset: u,
|
|
137
137
|
toOffset: d,
|
|
138
|
-
curveLength:
|
|
138
|
+
curveLength: v
|
|
139
139
|
};
|
|
140
|
-
|
|
140
|
+
s.get(o.fromLineId).push(h);
|
|
141
141
|
}
|
|
142
|
-
return { adjacency:
|
|
142
|
+
return { adjacency: s, lines: r, lineLengths: c };
|
|
143
143
|
}
|
|
144
|
-
function de(e, t, n,
|
|
145
|
-
const { adjacency: c, lines:
|
|
146
|
-
if (!
|
|
147
|
-
const a =
|
|
144
|
+
function de(e, t, n, s, r = !1) {
|
|
145
|
+
const { adjacency: c, lines: i, lineLengths: o } = e;
|
|
146
|
+
if (!i.get(n)) return null;
|
|
147
|
+
const a = o.get(n), u = r ? s / 100 * a : s, d = [], g = /* @__PURE__ */ new Map(), v = (l, p) => `${l}:${Math.round(p)}`;
|
|
148
148
|
if (t.lineId === n && u >= t.offset) {
|
|
149
149
|
const l = u - t.offset;
|
|
150
150
|
return {
|
|
@@ -167,7 +167,7 @@ function de(e, t, n, r, s = !1) {
|
|
|
167
167
|
startOffset: t.offset,
|
|
168
168
|
endOffset: l.fromOffset,
|
|
169
169
|
length: p
|
|
170
|
-
},
|
|
170
|
+
}, m = {
|
|
171
171
|
type: "curve",
|
|
172
172
|
curveIndex: l.curveIndex,
|
|
173
173
|
startOffset: 0,
|
|
@@ -178,72 +178,72 @@ function de(e, t, n, r, s = !1) {
|
|
|
178
178
|
lineId: l.toLineId,
|
|
179
179
|
entryOffset: l.toOffset,
|
|
180
180
|
totalDistance: S,
|
|
181
|
-
path: [M,
|
|
181
|
+
path: [M, m]
|
|
182
182
|
});
|
|
183
183
|
}
|
|
184
184
|
for (d.sort((l, p) => l.totalDistance - p.totalDistance); d.length > 0; ) {
|
|
185
|
-
const l = d.shift(), p =
|
|
185
|
+
const l = d.shift(), p = v(l.lineId, l.entryOffset), S = g.get(p);
|
|
186
186
|
if (S !== void 0 && S <= l.totalDistance)
|
|
187
187
|
continue;
|
|
188
|
-
if (
|
|
189
|
-
const
|
|
188
|
+
if (g.set(p, l.totalDistance), l.lineId === n) {
|
|
189
|
+
const m = Math.abs(u - l.entryOffset);
|
|
190
190
|
if (u >= l.entryOffset) {
|
|
191
|
-
const
|
|
191
|
+
const x = {
|
|
192
192
|
type: "line",
|
|
193
193
|
lineId: n,
|
|
194
194
|
startOffset: l.entryOffset,
|
|
195
195
|
endOffset: u,
|
|
196
|
-
length:
|
|
196
|
+
length: m
|
|
197
197
|
};
|
|
198
198
|
return {
|
|
199
|
-
segments: [...l.path,
|
|
200
|
-
totalDistance: l.totalDistance +
|
|
199
|
+
segments: [...l.path, x],
|
|
200
|
+
totalDistance: l.totalDistance + m
|
|
201
201
|
};
|
|
202
202
|
}
|
|
203
203
|
}
|
|
204
204
|
const M = c.get(l.lineId) || [];
|
|
205
|
-
for (const
|
|
206
|
-
if (
|
|
207
|
-
const
|
|
208
|
-
if (
|
|
205
|
+
for (const m of M) {
|
|
206
|
+
if (m.fromOffset < l.entryOffset) continue;
|
|
207
|
+
const x = m.fromOffset - l.entryOffset, O = l.totalDistance + x + m.curveLength, C = v(m.toLineId, m.toOffset), q = g.get(C);
|
|
208
|
+
if (q !== void 0 && q <= O)
|
|
209
209
|
continue;
|
|
210
210
|
const D = {
|
|
211
211
|
type: "line",
|
|
212
212
|
lineId: l.lineId,
|
|
213
213
|
startOffset: l.entryOffset,
|
|
214
|
-
endOffset:
|
|
215
|
-
length:
|
|
216
|
-
},
|
|
214
|
+
endOffset: m.fromOffset,
|
|
215
|
+
length: x
|
|
216
|
+
}, I = {
|
|
217
217
|
type: "curve",
|
|
218
|
-
curveIndex:
|
|
218
|
+
curveIndex: m.curveIndex,
|
|
219
219
|
startOffset: 0,
|
|
220
|
-
endOffset:
|
|
221
|
-
length:
|
|
220
|
+
endOffset: m.curveLength,
|
|
221
|
+
length: m.curveLength
|
|
222
222
|
};
|
|
223
223
|
d.push({
|
|
224
|
-
lineId:
|
|
225
|
-
entryOffset:
|
|
224
|
+
lineId: m.toLineId,
|
|
225
|
+
entryOffset: m.toOffset,
|
|
226
226
|
totalDistance: O,
|
|
227
|
-
path: [...l.path, D,
|
|
227
|
+
path: [...l.path, D, I]
|
|
228
228
|
});
|
|
229
229
|
}
|
|
230
|
-
d.sort((
|
|
230
|
+
d.sort((m, x) => m.totalDistance - x.totalDistance);
|
|
231
231
|
}
|
|
232
232
|
return null;
|
|
233
233
|
}
|
|
234
|
-
function Je(e, t, n,
|
|
235
|
-
return de(e, t, n,
|
|
234
|
+
function Je(e, t, n, s, r = !1) {
|
|
235
|
+
return de(e, t, n, s, r) !== null;
|
|
236
236
|
}
|
|
237
237
|
function Ke(e, t, n) {
|
|
238
|
-
return (e.adjacency.get(t) || []).filter((
|
|
238
|
+
return (e.adjacency.get(t) || []).filter((r) => r.fromOffset >= n);
|
|
239
239
|
}
|
|
240
|
-
function
|
|
240
|
+
function ge(e, t) {
|
|
241
241
|
const n = Math.sqrt(
|
|
242
242
|
Math.pow(e.end.x - e.start.x, 2) + Math.pow(e.end.y - e.start.y, 2)
|
|
243
|
-
),
|
|
243
|
+
), s = n > 0 ? t / n : 0;
|
|
244
244
|
return {
|
|
245
|
-
x: e.start.x + (e.end.x - e.start.x) * Math.min(1, Math.max(0,
|
|
246
|
-
y: e.start.y + (e.end.y - e.start.y) * Math.min(1, Math.max(0,
|
|
245
|
+
x: e.start.x + (e.end.x - e.start.x) * Math.min(1, Math.max(0, s)),
|
|
246
|
+
y: e.start.y + (e.end.y - e.start.y) * Math.min(1, Math.max(0, s))
|
|
247
247
|
};
|
|
248
248
|
}
|
|
249
249
|
function Oe(e) {
|
|
@@ -252,42 +252,42 @@ function Oe(e) {
|
|
|
252
252
|
);
|
|
253
253
|
}
|
|
254
254
|
function Se(e, t, n) {
|
|
255
|
-
let
|
|
256
|
-
for (let
|
|
257
|
-
|
|
258
|
-
return
|
|
255
|
+
let s = 0;
|
|
256
|
+
for (let r = 0; r < t; r++)
|
|
257
|
+
s += e.segments[r].length;
|
|
258
|
+
return s += n, s;
|
|
259
259
|
}
|
|
260
260
|
function Ce(e, t) {
|
|
261
261
|
let n = 0;
|
|
262
|
-
for (let
|
|
263
|
-
const
|
|
262
|
+
for (let s = 0; s < e.segments.length; s++) {
|
|
263
|
+
const r = e.segments[s], c = n + r.length;
|
|
264
264
|
if (t < c)
|
|
265
265
|
return {
|
|
266
|
-
segmentIndex:
|
|
266
|
+
segmentIndex: s,
|
|
267
267
|
segmentDistance: t - n
|
|
268
268
|
};
|
|
269
269
|
if (t === c)
|
|
270
|
-
return
|
|
271
|
-
segmentIndex:
|
|
270
|
+
return s + 1 < e.segments.length ? {
|
|
271
|
+
segmentIndex: s + 1,
|
|
272
272
|
segmentDistance: 0
|
|
273
273
|
} : {
|
|
274
|
-
segmentIndex:
|
|
275
|
-
segmentDistance:
|
|
274
|
+
segmentIndex: s,
|
|
275
|
+
segmentDistance: r.length
|
|
276
276
|
};
|
|
277
|
-
n +=
|
|
277
|
+
n += r.length;
|
|
278
278
|
}
|
|
279
279
|
return null;
|
|
280
280
|
}
|
|
281
|
-
function te(e, t, n,
|
|
281
|
+
function te(e, t, n, s) {
|
|
282
282
|
const c = Se(
|
|
283
283
|
e,
|
|
284
284
|
t,
|
|
285
285
|
n
|
|
286
|
-
) +
|
|
286
|
+
) + s;
|
|
287
287
|
return Ce(e, c);
|
|
288
288
|
}
|
|
289
|
-
function
|
|
290
|
-
const
|
|
289
|
+
function me(e, t, n) {
|
|
290
|
+
const s = e.execution, r = n.vehicleQueues.get(e.vehicle.id), c = r?.[s.currentCommandIndex];
|
|
291
291
|
if (c && n.onCommandComplete && n.onCommandComplete({
|
|
292
292
|
vehicleId: e.vehicle.id,
|
|
293
293
|
command: c,
|
|
@@ -301,13 +301,13 @@ function ge(e, t, n) {
|
|
|
301
301
|
return {
|
|
302
302
|
handled: !0,
|
|
303
303
|
vehicle: { ...e.vehicle, state: "waiting" },
|
|
304
|
-
newExecution:
|
|
304
|
+
newExecution: s,
|
|
305
305
|
// Keep execution state for resume
|
|
306
306
|
isWaiting: !0
|
|
307
307
|
};
|
|
308
|
-
const
|
|
309
|
-
if (
|
|
310
|
-
const f =
|
|
308
|
+
const i = s.currentCommandIndex + 1;
|
|
309
|
+
if (r && i < r.length) {
|
|
310
|
+
const f = r[i], a = n.graphRef.current;
|
|
311
311
|
if (a) {
|
|
312
312
|
const u = {
|
|
313
313
|
graph: a,
|
|
@@ -320,28 +320,28 @@ function ge(e, t, n) {
|
|
|
320
320
|
u
|
|
321
321
|
);
|
|
322
322
|
if (d) {
|
|
323
|
-
const
|
|
323
|
+
const g = te(
|
|
324
324
|
d.path,
|
|
325
325
|
0,
|
|
326
326
|
t,
|
|
327
327
|
n.config.wheelbase
|
|
328
|
-
),
|
|
328
|
+
), v = {
|
|
329
329
|
path: d.path,
|
|
330
330
|
curveDataMap: d.curveDataMap,
|
|
331
|
-
currentCommandIndex:
|
|
331
|
+
currentCommandIndex: i,
|
|
332
332
|
rear: {
|
|
333
333
|
currentSegmentIndex: 0,
|
|
334
334
|
segmentDistance: t
|
|
335
335
|
},
|
|
336
|
-
front:
|
|
337
|
-
currentSegmentIndex:
|
|
338
|
-
segmentDistance:
|
|
336
|
+
front: g ? {
|
|
337
|
+
currentSegmentIndex: g.segmentIndex,
|
|
338
|
+
segmentDistance: g.segmentDistance
|
|
339
339
|
} : {
|
|
340
340
|
currentSegmentIndex: 0,
|
|
341
341
|
segmentDistance: t
|
|
342
342
|
}
|
|
343
343
|
};
|
|
344
|
-
return { handled: !0, vehicle: { ...e.vehicle, state: "moving" }, newExecution:
|
|
344
|
+
return { handled: !0, vehicle: { ...e.vehicle, state: "moving" }, newExecution: v };
|
|
345
345
|
}
|
|
346
346
|
}
|
|
347
347
|
}
|
|
@@ -352,23 +352,23 @@ function ge(e, t, n) {
|
|
|
352
352
|
}
|
|
353
353
|
function Ge(e, t) {
|
|
354
354
|
const n = e.execution;
|
|
355
|
-
return n ? n.rear.currentSegmentIndex >= n.path.segments.length ?
|
|
355
|
+
return n ? n.rear.currentSegmentIndex >= n.path.segments.length ? me(e, n.rear.segmentDistance, t) : { handled: !1, vehicle: e.vehicle } : { handled: !1, vehicle: e.vehicle };
|
|
356
356
|
}
|
|
357
357
|
function W(e, t) {
|
|
358
|
-
return { position:
|
|
358
|
+
return { position: ge(e, t), lineId: e.id, absoluteOffset: t };
|
|
359
359
|
}
|
|
360
360
|
function H(e, t) {
|
|
361
361
|
const n = ye(e.arcLengthTable, t);
|
|
362
362
|
return { position: ne(e.bezier, n) };
|
|
363
363
|
}
|
|
364
|
-
function
|
|
365
|
-
const
|
|
366
|
-
if (f >=
|
|
367
|
-
const u = f -
|
|
364
|
+
function re(e, t, n, s, r, c, i) {
|
|
365
|
+
const o = n.segments[t.currentSegmentIndex], f = t.segmentDistance + s;
|
|
366
|
+
if (f >= o.length) {
|
|
367
|
+
const u = f - o.length, d = t.currentSegmentIndex + 1;
|
|
368
368
|
if (d >= n.segments.length) {
|
|
369
|
-
if (
|
|
370
|
-
const l =
|
|
371
|
-
if (p <=
|
|
369
|
+
if (i !== void 0 && o.type === "line") {
|
|
370
|
+
const l = r.get(o.lineId), p = o.startOffset + f;
|
|
371
|
+
if (p <= i) {
|
|
372
372
|
const M = W(l, p);
|
|
373
373
|
return {
|
|
374
374
|
axleState: { ...e, ...M },
|
|
@@ -376,35 +376,35 @@ function se(e, t, n, r, s, c, o) {
|
|
|
376
376
|
completed: !1
|
|
377
377
|
};
|
|
378
378
|
}
|
|
379
|
-
const S = W(l,
|
|
379
|
+
const S = W(l, i);
|
|
380
380
|
return {
|
|
381
381
|
axleState: { ...e, ...S },
|
|
382
|
-
execution: { ...t, segmentDistance:
|
|
382
|
+
execution: { ...t, segmentDistance: i - o.startOffset },
|
|
383
383
|
completed: !0
|
|
384
384
|
};
|
|
385
385
|
}
|
|
386
|
-
const h =
|
|
387
|
-
|
|
388
|
-
|
|
386
|
+
const h = o.type === "line" ? W(
|
|
387
|
+
r.get(o.lineId),
|
|
388
|
+
o.endOffset
|
|
389
389
|
) : H(
|
|
390
|
-
c.get(
|
|
391
|
-
|
|
390
|
+
c.get(o.curveIndex),
|
|
391
|
+
o.length
|
|
392
392
|
);
|
|
393
393
|
return {
|
|
394
394
|
axleState: { ...e, ...h },
|
|
395
|
-
execution: { ...t, segmentDistance:
|
|
395
|
+
execution: { ...t, segmentDistance: o.length },
|
|
396
396
|
completed: !0
|
|
397
397
|
};
|
|
398
398
|
}
|
|
399
|
-
const
|
|
400
|
-
|
|
401
|
-
|
|
399
|
+
const g = n.segments[d], v = g.type === "line" ? W(
|
|
400
|
+
r.get(g.lineId),
|
|
401
|
+
g.startOffset + u
|
|
402
402
|
) : H(
|
|
403
|
-
c.get(
|
|
403
|
+
c.get(g.curveIndex),
|
|
404
404
|
u
|
|
405
405
|
);
|
|
406
406
|
return {
|
|
407
|
-
axleState: { ...e, ...
|
|
407
|
+
axleState: { ...e, ...v },
|
|
408
408
|
execution: {
|
|
409
409
|
currentSegmentIndex: d,
|
|
410
410
|
segmentDistance: u
|
|
@@ -412,11 +412,11 @@ function se(e, t, n, r, s, c, o) {
|
|
|
412
412
|
completed: !1
|
|
413
413
|
};
|
|
414
414
|
}
|
|
415
|
-
const a =
|
|
416
|
-
|
|
417
|
-
|
|
415
|
+
const a = o.type === "line" ? W(
|
|
416
|
+
r.get(o.lineId),
|
|
417
|
+
o.startOffset + f
|
|
418
418
|
) : H(
|
|
419
|
-
c.get(
|
|
419
|
+
c.get(o.curveIndex),
|
|
420
420
|
f
|
|
421
421
|
);
|
|
422
422
|
return {
|
|
@@ -425,20 +425,20 @@ function se(e, t, n, r, s, c, o) {
|
|
|
425
425
|
completed: !1
|
|
426
426
|
};
|
|
427
427
|
}
|
|
428
|
-
function
|
|
429
|
-
const
|
|
430
|
-
Math.pow(
|
|
428
|
+
function we(e, t, n, s) {
|
|
429
|
+
const r = Math.sqrt(
|
|
430
|
+
Math.pow(s.end.x - s.start.x, 2) + Math.pow(s.end.y - s.start.y, 2)
|
|
431
431
|
);
|
|
432
432
|
let c = t + n;
|
|
433
|
-
c = Math.min(c,
|
|
434
|
-
const
|
|
433
|
+
c = Math.min(c, r);
|
|
434
|
+
const i = ge(s, c);
|
|
435
435
|
return {
|
|
436
436
|
lineId: e,
|
|
437
|
-
position:
|
|
437
|
+
position: i,
|
|
438
438
|
absoluteOffset: c
|
|
439
439
|
};
|
|
440
440
|
}
|
|
441
|
-
function
|
|
441
|
+
function De(e, t) {
|
|
442
442
|
return {
|
|
443
443
|
...e,
|
|
444
444
|
state: "idle"
|
|
@@ -451,40 +451,40 @@ function Te(e) {
|
|
|
451
451
|
};
|
|
452
452
|
}
|
|
453
453
|
function oe(e, t) {
|
|
454
|
-
const n = [],
|
|
455
|
-
for (const
|
|
456
|
-
if (!t.get(
|
|
457
|
-
const
|
|
458
|
-
n.push(
|
|
459
|
-
const
|
|
460
|
-
|
|
454
|
+
const n = [], s = /* @__PURE__ */ new Map();
|
|
455
|
+
for (const r of e) {
|
|
456
|
+
if (!t.get(r.lineId)) continue;
|
|
457
|
+
const i = De(r);
|
|
458
|
+
n.push(i);
|
|
459
|
+
const o = Te(i);
|
|
460
|
+
s.set(r.id, o);
|
|
461
461
|
}
|
|
462
|
-
return { movingVehicles: n, stateMap:
|
|
462
|
+
return { movingVehicles: n, stateMap: s };
|
|
463
463
|
}
|
|
464
|
-
function Pe(e, t, n,
|
|
465
|
-
const
|
|
464
|
+
function Pe(e, t, n, s) {
|
|
465
|
+
const r = /* @__PURE__ */ new Map();
|
|
466
466
|
for (const c of e.segments)
|
|
467
467
|
if (c.type === "curve" && c.curveIndex !== void 0) {
|
|
468
|
-
const
|
|
469
|
-
if (
|
|
470
|
-
const
|
|
471
|
-
if (
|
|
468
|
+
const i = t[c.curveIndex];
|
|
469
|
+
if (i) {
|
|
470
|
+
const o = n.get(i.fromLineId), f = n.get(i.toLineId);
|
|
471
|
+
if (o && f) {
|
|
472
472
|
const a = fe(
|
|
473
|
-
|
|
474
|
-
|
|
475
|
-
|
|
473
|
+
o,
|
|
474
|
+
i.fromOffset,
|
|
475
|
+
i.fromIsPercentage,
|
|
476
476
|
100,
|
|
477
|
-
|
|
477
|
+
s.wheelbase
|
|
478
478
|
), u = le(
|
|
479
479
|
f,
|
|
480
|
-
|
|
481
|
-
|
|
480
|
+
i.toOffset,
|
|
481
|
+
i.toIsPercentage,
|
|
482
482
|
0,
|
|
483
|
-
|
|
483
|
+
s.wheelbase
|
|
484
484
|
), d = ue(
|
|
485
|
-
|
|
485
|
+
o,
|
|
486
486
|
f,
|
|
487
|
-
|
|
487
|
+
s,
|
|
488
488
|
!1,
|
|
489
489
|
// willFlip is always false now
|
|
490
490
|
{
|
|
@@ -495,120 +495,124 @@ function Pe(e, t, n, r) {
|
|
|
495
495
|
toIsPercentage: !1
|
|
496
496
|
// Already resolved to absolute
|
|
497
497
|
}
|
|
498
|
-
),
|
|
499
|
-
|
|
498
|
+
), g = xe(d);
|
|
499
|
+
r.set(c.curveIndex, { bezier: d, arcLengthTable: g });
|
|
500
500
|
}
|
|
501
501
|
}
|
|
502
502
|
}
|
|
503
|
-
return
|
|
503
|
+
return r;
|
|
504
504
|
}
|
|
505
505
|
function X(e, t, n) {
|
|
506
|
-
const { graph:
|
|
507
|
-
if (!
|
|
508
|
-
const a = Oe(
|
|
506
|
+
const { graph: s, linesMap: r, curves: c, config: i } = n, o = r.get(t.targetLineId);
|
|
507
|
+
if (!o) return null;
|
|
508
|
+
const a = Oe(o) - i.wheelbase;
|
|
509
509
|
if (a <= 0) return null;
|
|
510
510
|
const u = t.isPercentage ? t.targetOffset / 100 * a : Math.min(t.targetOffset, a), d = de(
|
|
511
|
-
|
|
512
|
-
{ lineId: e.lineId, offset: e.rear.absoluteOffset },
|
|
511
|
+
s,
|
|
512
|
+
{ lineId: e.rear.lineId, offset: e.rear.absoluteOffset },
|
|
513
513
|
t.targetLineId,
|
|
514
514
|
u,
|
|
515
515
|
!1
|
|
516
516
|
);
|
|
517
517
|
if (!d) return null;
|
|
518
|
-
const
|
|
519
|
-
return { path: d, curveDataMap:
|
|
518
|
+
const g = Pe(d, c, r, i);
|
|
519
|
+
return { path: d, curveDataMap: g };
|
|
520
520
|
}
|
|
521
521
|
function Ue({
|
|
522
522
|
vehicles: e,
|
|
523
523
|
lines: t,
|
|
524
524
|
vehicleQueues: n,
|
|
525
|
-
velocity:
|
|
526
|
-
wheelbase:
|
|
525
|
+
velocity: s,
|
|
526
|
+
wheelbase: r,
|
|
527
527
|
tangentMode: c,
|
|
528
|
-
curves:
|
|
529
|
-
eventEmitter:
|
|
528
|
+
curves: i,
|
|
529
|
+
eventEmitter: o
|
|
530
530
|
}) {
|
|
531
|
-
const [f, a] = L("stopped"), [u, d] = L([]),
|
|
532
|
-
wheelbase:
|
|
531
|
+
const [f, a] = L("stopped"), [u, d] = L([]), g = Z(() => ({
|
|
532
|
+
wheelbase: r,
|
|
533
533
|
tangentMode: c
|
|
534
|
-
}), [
|
|
535
|
-
() => new Map(t.map((
|
|
534
|
+
}), [r, c]), v = Z(
|
|
535
|
+
() => new Map(t.map((I) => [I.id, I])),
|
|
536
536
|
[t]
|
|
537
537
|
), h = P(null), l = P(/* @__PURE__ */ new Map());
|
|
538
538
|
b(() => {
|
|
539
|
-
const { movingVehicles:
|
|
539
|
+
const { movingVehicles: I, stateMap: y } = oe(e, v);
|
|
540
540
|
l.current = y;
|
|
541
541
|
const w = setTimeout(() => {
|
|
542
|
-
d(
|
|
542
|
+
d(I);
|
|
543
543
|
}, 0);
|
|
544
544
|
return () => clearTimeout(w);
|
|
545
|
-
}, [e,
|
|
545
|
+
}, [e, v]);
|
|
546
546
|
const p = P(null);
|
|
547
547
|
b(() => {
|
|
548
|
-
t.length > 0 && (p.current = Le(t,
|
|
549
|
-
}, [t,
|
|
548
|
+
t.length > 0 && (p.current = Le(t, i, g));
|
|
549
|
+
}, [t, i, g]);
|
|
550
550
|
const S = P(!1), M = P(() => {
|
|
551
|
-
}),
|
|
551
|
+
}), m = P(0), x = P(/* @__PURE__ */ new Set());
|
|
552
552
|
b(() => {
|
|
553
553
|
M.current = () => {
|
|
554
|
-
const
|
|
554
|
+
const I = s;
|
|
555
555
|
let y = !1;
|
|
556
556
|
for (const [, w] of l.current)
|
|
557
557
|
w.vehicle.state === "moving" && (y = !0);
|
|
558
558
|
if (!y) {
|
|
559
|
-
S.current = !1,
|
|
559
|
+
S.current = !1, m.current = 0;
|
|
560
560
|
return;
|
|
561
561
|
}
|
|
562
|
-
d((w) => w.map((
|
|
563
|
-
const T = l.current.get(
|
|
564
|
-
if (!T ||
|
|
565
|
-
return
|
|
562
|
+
d((w) => w.map((E) => {
|
|
563
|
+
const T = l.current.get(E.id);
|
|
564
|
+
if (!T || E.state !== "moving" || !T.execution)
|
|
565
|
+
return E;
|
|
566
566
|
const $ = T.execution;
|
|
567
567
|
let A;
|
|
568
568
|
if ($.front.currentSegmentIndex < $.path.segments.length) {
|
|
569
569
|
const N = $.path.segments[$.front.currentSegmentIndex];
|
|
570
570
|
if (N.type === "line") {
|
|
571
|
-
const V =
|
|
571
|
+
const V = v.get(N.lineId);
|
|
572
572
|
V && (A = Math.sqrt(
|
|
573
573
|
Math.pow(V.end.x - V.start.x, 2) + Math.pow(V.end.y - V.start.y, 2)
|
|
574
574
|
));
|
|
575
575
|
}
|
|
576
576
|
}
|
|
577
|
-
const F =
|
|
578
|
-
|
|
577
|
+
const F = re(
|
|
578
|
+
E.rear,
|
|
579
579
|
$.rear,
|
|
580
580
|
$.path,
|
|
581
|
-
x,
|
|
582
581
|
I,
|
|
582
|
+
v,
|
|
583
583
|
$.curveDataMap
|
|
584
|
-
), R =
|
|
585
|
-
|
|
584
|
+
), R = re(
|
|
585
|
+
E.front,
|
|
586
586
|
$.front,
|
|
587
587
|
$.path,
|
|
588
|
-
x,
|
|
589
588
|
I,
|
|
589
|
+
v,
|
|
590
590
|
$.curveDataMap,
|
|
591
591
|
A
|
|
592
592
|
);
|
|
593
593
|
if (F.completed) {
|
|
594
594
|
const N = {
|
|
595
|
-
linesMap:
|
|
596
|
-
config:
|
|
595
|
+
linesMap: v,
|
|
596
|
+
config: g,
|
|
597
597
|
vehicleQueues: n,
|
|
598
|
-
curves:
|
|
598
|
+
curves: i,
|
|
599
599
|
graphRef: p,
|
|
600
600
|
prepareCommandPath: X,
|
|
601
|
-
onCommandComplete:
|
|
601
|
+
onCommandComplete: o ? (K) => o.emit("commandComplete", K) : void 0
|
|
602
602
|
}, V = {
|
|
603
|
-
...
|
|
603
|
+
...E,
|
|
604
604
|
rear: F.axleState,
|
|
605
605
|
front: R.axleState
|
|
606
606
|
};
|
|
607
607
|
T.vehicle = V, T.execution.rear = F.execution, T.execution.front = R.execution;
|
|
608
|
-
const
|
|
609
|
-
if (T.vehicle = J.vehicle, J.newExecution !== void 0 && (T.execution = J.newExecution),
|
|
608
|
+
const se = F.execution.segmentDistance, J = me(T, se, N);
|
|
609
|
+
if (T.vehicle = J.vehicle, J.newExecution !== void 0 && (T.execution = J.newExecution), o && J.vehicle.state !== "moving" && o.emit("stateChange", {
|
|
610
|
+
vehicleId: E.id,
|
|
611
|
+
from: "moving",
|
|
612
|
+
to: J.vehicle.state
|
|
613
|
+
}), o) {
|
|
610
614
|
const K = J.vehicle.rear.position, U = J.vehicle.front.position;
|
|
611
|
-
|
|
615
|
+
o.emit("positionUpdate", {
|
|
612
616
|
vehicleId: J.vehicle.id,
|
|
613
617
|
rear: K,
|
|
614
618
|
front: U,
|
|
@@ -622,13 +626,13 @@ function Ue({
|
|
|
622
626
|
return J.vehicle;
|
|
623
627
|
}
|
|
624
628
|
const z = {
|
|
625
|
-
...
|
|
629
|
+
...E,
|
|
626
630
|
rear: F.axleState,
|
|
627
631
|
front: R.axleState
|
|
628
632
|
};
|
|
629
|
-
if (T.vehicle = z, T.execution.rear = F.execution, T.execution.front = R.execution,
|
|
633
|
+
if (T.vehicle = z, T.execution.rear = F.execution, T.execution.front = R.execution, o) {
|
|
630
634
|
const N = z.rear.position, V = z.front.position;
|
|
631
|
-
|
|
635
|
+
o.emit("positionUpdate", {
|
|
632
636
|
vehicleId: z.id,
|
|
633
637
|
rear: N,
|
|
634
638
|
front: V,
|
|
@@ -642,20 +646,20 @@ function Ue({
|
|
|
642
646
|
return z;
|
|
643
647
|
})), S.current && (h.current = requestAnimationFrame(() => M.current()));
|
|
644
648
|
};
|
|
645
|
-
}, [
|
|
649
|
+
}, [s, v, i, g, n, o]), b(() => (f === "running" ? (S.current = !0, h.current = requestAnimationFrame(() => M.current())) : S.current = !1, () => {
|
|
646
650
|
h.current && cancelAnimationFrame(h.current);
|
|
647
651
|
}), [f]);
|
|
648
652
|
const O = G(() => {
|
|
649
653
|
if (f === "running") return;
|
|
650
|
-
const
|
|
651
|
-
|
|
652
|
-
const
|
|
653
|
-
if (!
|
|
654
|
+
const I = p.current;
|
|
655
|
+
I && (m.current = 0, x.current.clear(), d((y) => y.map((w) => {
|
|
656
|
+
const E = n.get(w.id);
|
|
657
|
+
if (!E || E.length === 0)
|
|
654
658
|
return w;
|
|
655
|
-
const T =
|
|
659
|
+
const T = E[0], A = X(
|
|
656
660
|
w,
|
|
657
661
|
T,
|
|
658
|
-
{ graph:
|
|
662
|
+
{ graph: I, linesMap: v, curves: i, config: g }
|
|
659
663
|
);
|
|
660
664
|
if (!A)
|
|
661
665
|
return console.warn(`No path found for vehicle ${w.id}`), w;
|
|
@@ -665,7 +669,7 @@ function Ue({
|
|
|
665
669
|
A.path,
|
|
666
670
|
0,
|
|
667
671
|
0,
|
|
668
|
-
|
|
672
|
+
r
|
|
669
673
|
);
|
|
670
674
|
F.execution = {
|
|
671
675
|
path: A.path,
|
|
@@ -682,47 +686,59 @@ function Ue({
|
|
|
682
686
|
currentSegmentIndex: 0,
|
|
683
687
|
segmentDistance: 0
|
|
684
688
|
}
|
|
685
|
-
}, F.vehicle = { ...w, state: "moving" }
|
|
689
|
+
}, F.vehicle = { ...w, state: "moving" }, o && w.state !== "moving" && o.emit("stateChange", {
|
|
690
|
+
vehicleId: w.id,
|
|
691
|
+
from: w.state,
|
|
692
|
+
to: "moving"
|
|
693
|
+
});
|
|
686
694
|
}
|
|
687
695
|
return { ...w, state: "moving" };
|
|
688
696
|
})), a("running"));
|
|
689
|
-
}, [f,
|
|
697
|
+
}, [f, v, i, n, g, r, o]), C = G(() => {
|
|
690
698
|
h.current && (cancelAnimationFrame(h.current), h.current = null), a("paused");
|
|
691
|
-
}, []),
|
|
699
|
+
}, []), q = G(() => {
|
|
692
700
|
h.current && (cancelAnimationFrame(h.current), h.current = null);
|
|
693
|
-
const { movingVehicles:
|
|
694
|
-
l.current = y, d(
|
|
695
|
-
}, [e,
|
|
696
|
-
const y = l.current.get(
|
|
701
|
+
const { movingVehicles: I, stateMap: y } = oe(e, v);
|
|
702
|
+
l.current = y, d(I), a("stopped");
|
|
703
|
+
}, [e, v]), D = G((I) => {
|
|
704
|
+
const y = l.current.get(I);
|
|
697
705
|
if (!y || y.vehicle.state !== "waiting")
|
|
698
706
|
return !1;
|
|
699
|
-
const w = n.get(
|
|
700
|
-
if (!
|
|
701
|
-
const T =
|
|
707
|
+
const w = n.get(I), E = y.execution;
|
|
708
|
+
if (!E) return !1;
|
|
709
|
+
const T = E.currentCommandIndex + 1;
|
|
702
710
|
if (w && T < w.length) {
|
|
703
711
|
const $ = p.current;
|
|
704
712
|
if ($) {
|
|
705
|
-
const A = w[T], F = { graph: $, linesMap:
|
|
713
|
+
const A = w[T], F = { graph: $, linesMap: v, curves: i, config: g }, R = X(y.vehicle, A, F);
|
|
706
714
|
if (R) {
|
|
707
|
-
const z = te(R.path, 0, 0,
|
|
715
|
+
const z = te(R.path, 0, 0, r);
|
|
708
716
|
return y.execution = {
|
|
709
717
|
path: R.path,
|
|
710
718
|
curveDataMap: R.curveDataMap,
|
|
711
719
|
currentCommandIndex: T,
|
|
712
720
|
rear: { currentSegmentIndex: 0, segmentDistance: 0 },
|
|
713
721
|
front: z ? { currentSegmentIndex: z.segmentIndex, segmentDistance: z.segmentDistance } : { currentSegmentIndex: 0, segmentDistance: 0 }
|
|
714
|
-
}, y.vehicle = { ...y.vehicle, state: "moving" },
|
|
722
|
+
}, y.vehicle = { ...y.vehicle, state: "moving" }, o && o.emit("stateChange", {
|
|
723
|
+
vehicleId: I,
|
|
724
|
+
from: "waiting",
|
|
725
|
+
to: "moving"
|
|
726
|
+
}), d((N) => N.map((V) => V.id === I ? y.vehicle : V)), f !== "running" && a("running"), !0;
|
|
715
727
|
}
|
|
716
728
|
}
|
|
717
729
|
}
|
|
718
|
-
return y.vehicle = { ...y.vehicle, state: "idle" }, y.execution = null,
|
|
719
|
-
|
|
730
|
+
return y.vehicle = { ...y.vehicle, state: "idle" }, y.execution = null, o && o.emit("stateChange", {
|
|
731
|
+
vehicleId: I,
|
|
732
|
+
from: "waiting",
|
|
733
|
+
to: "idle"
|
|
734
|
+
}), d(($) => $.map((A) => A.id === I ? y.vehicle : A)), !0;
|
|
735
|
+
}, [n, v, i, g, r, f, o]);
|
|
720
736
|
return {
|
|
721
737
|
movingVehicles: u,
|
|
722
738
|
playbackState: f,
|
|
723
739
|
handleRun: O,
|
|
724
740
|
handlePause: C,
|
|
725
|
-
handleReset:
|
|
741
|
+
handleReset: q,
|
|
726
742
|
continueVehicle: D
|
|
727
743
|
};
|
|
728
744
|
}
|
|
@@ -745,11 +761,11 @@ class $e {
|
|
|
745
761
|
* @param data - The event data
|
|
746
762
|
*/
|
|
747
763
|
emit(t, n) {
|
|
748
|
-
this.listeners.get(t)?.forEach((
|
|
764
|
+
this.listeners.get(t)?.forEach((s) => {
|
|
749
765
|
try {
|
|
750
|
-
|
|
751
|
-
} catch (
|
|
752
|
-
console.error(`Error in event listener for "${t}":`,
|
|
766
|
+
s(n);
|
|
767
|
+
} catch (r) {
|
|
768
|
+
console.error(`Error in event listener for "${t}":`, r);
|
|
753
769
|
}
|
|
754
770
|
});
|
|
755
771
|
}
|
|
@@ -780,25 +796,25 @@ function We() {
|
|
|
780
796
|
return Z(() => new $e(), []);
|
|
781
797
|
}
|
|
782
798
|
function Be(e, t, n = []) {
|
|
783
|
-
const
|
|
784
|
-
b(() =>
|
|
799
|
+
const s = be();
|
|
800
|
+
b(() => s.on(e, t), [s, e, ...n]);
|
|
785
801
|
}
|
|
786
802
|
function ie(e) {
|
|
787
|
-
const t = [], n = [],
|
|
803
|
+
const t = [], n = [], s = [], r = e.trim().split(`
|
|
788
804
|
`);
|
|
789
|
-
for (const c of
|
|
790
|
-
const
|
|
791
|
-
if (!
|
|
792
|
-
const
|
|
793
|
-
if (
|
|
805
|
+
for (const c of r) {
|
|
806
|
+
const i = c.trim();
|
|
807
|
+
if (!i || i.startsWith("#")) continue;
|
|
808
|
+
const o = i.match(/^(\w+)\s*:\s*\((\d+),\s*(\d+)\)\s*->\s*\((\d+),\s*(\d+)\)/);
|
|
809
|
+
if (o) {
|
|
794
810
|
t.push({
|
|
795
|
-
id:
|
|
796
|
-
start: { x: parseInt(
|
|
797
|
-
end: { x: parseInt(
|
|
811
|
+
id: o[1],
|
|
812
|
+
start: { x: parseInt(o[2]), y: parseInt(o[3]) },
|
|
813
|
+
end: { x: parseInt(o[4]), y: parseInt(o[5]) }
|
|
798
814
|
});
|
|
799
815
|
continue;
|
|
800
816
|
}
|
|
801
|
-
const f =
|
|
817
|
+
const f = i.match(/^(\w+)(?:\s+(\d+(?:\.\d+)?)(%?))??\s*->\s*(\w+)(?:\s+(\d+(?:\.\d+)?)(%?))?/);
|
|
802
818
|
if (f) {
|
|
803
819
|
const u = {
|
|
804
820
|
fromLineId: f[1],
|
|
@@ -807,10 +823,10 @@ function ie(e) {
|
|
|
807
823
|
f[2] && (u.fromOffset = parseFloat(f[2]), u.fromIsPercentage = f[3] === "%"), f[5] && (u.toOffset = parseFloat(f[5]), u.toIsPercentage = f[6] === "%"), n.push(u);
|
|
808
824
|
continue;
|
|
809
825
|
}
|
|
810
|
-
const a =
|
|
826
|
+
const a = i.match(/^(\w+)\s+start\s+(\w+)\s+(\d+(?:\.\d+)?)(%?)/);
|
|
811
827
|
if (a) {
|
|
812
828
|
const u = parseFloat(a[3]), d = a[4] === "%";
|
|
813
|
-
|
|
829
|
+
s.push({
|
|
814
830
|
vehicleId: a[1],
|
|
815
831
|
lineId: a[2],
|
|
816
832
|
offset: u,
|
|
@@ -819,28 +835,28 @@ function ie(e) {
|
|
|
819
835
|
continue;
|
|
820
836
|
}
|
|
821
837
|
}
|
|
822
|
-
return { lines: t, curves: n, vehicles:
|
|
838
|
+
return { lines: t, curves: n, vehicles: s };
|
|
823
839
|
}
|
|
824
|
-
function
|
|
840
|
+
function qe(e) {
|
|
825
841
|
const t = [];
|
|
826
842
|
return e.lines.forEach((n) => {
|
|
827
843
|
t.push(`${n.id} : (${Math.round(n.start.x)}, ${Math.round(n.start.y)}) -> (${Math.round(n.end.x)}, ${Math.round(n.end.y)})`);
|
|
828
844
|
}), e.lines.length > 0 && e.curves.length > 0 && t.push(""), e.curves.forEach((n) => {
|
|
829
|
-
let
|
|
830
|
-
n.fromOffset !== void 0 && (
|
|
845
|
+
let s = `${n.fromLineId}`;
|
|
846
|
+
n.fromOffset !== void 0 && (s += ` ${n.fromOffset}${n.fromIsPercentage ? "%" : ""}`), s += " -> ", s += `${n.toLineId}`, n.toOffset !== void 0 && (s += ` ${n.toOffset}${n.toIsPercentage ? "%" : ""}`), t.push(s);
|
|
831
847
|
}), (e.lines.length > 0 || e.curves.length > 0) && e.vehicles.length > 0 && t.push(""), e.vehicles.forEach((n) => {
|
|
832
|
-
const
|
|
833
|
-
t.push(`${n.vehicleId} start ${n.lineId} ${
|
|
848
|
+
const s = n.isPercentage ? `${n.offset}%` : `${n.offset}`;
|
|
849
|
+
t.push(`${n.vehicleId} start ${n.lineId} ${s}`);
|
|
834
850
|
}), t.join(`
|
|
835
851
|
`);
|
|
836
852
|
}
|
|
837
853
|
function B(e) {
|
|
838
854
|
const t = [], n = e.trim().split(`
|
|
839
855
|
`);
|
|
840
|
-
for (const
|
|
841
|
-
const
|
|
842
|
-
if (!
|
|
843
|
-
const c =
|
|
856
|
+
for (const s of n) {
|
|
857
|
+
const r = s.trim();
|
|
858
|
+
if (!r || r.startsWith("#")) continue;
|
|
859
|
+
const c = r.match(/^(\w+)\s+start\s+(\w+)\s+(\d+(?:\.\d+)?)(%?)/);
|
|
844
860
|
c && t.push({
|
|
845
861
|
vehicleId: c[1],
|
|
846
862
|
lineId: c[2],
|
|
@@ -850,7 +866,7 @@ function B(e) {
|
|
|
850
866
|
}
|
|
851
867
|
return t;
|
|
852
868
|
}
|
|
853
|
-
function
|
|
869
|
+
function Ee(e) {
|
|
854
870
|
return e.map((t) => {
|
|
855
871
|
const n = t.isPercentage ? `${t.offset}%` : `${t.offset}`;
|
|
856
872
|
return `${t.vehicleId} start ${t.lineId} ${n}`;
|
|
@@ -860,14 +876,14 @@ function qe(e) {
|
|
|
860
876
|
function Y(e) {
|
|
861
877
|
const t = [], n = e.trim().split(`
|
|
862
878
|
`);
|
|
863
|
-
for (const
|
|
864
|
-
const
|
|
865
|
-
if (!
|
|
866
|
-
const c =
|
|
879
|
+
for (const s of n) {
|
|
880
|
+
const r = s.trim();
|
|
881
|
+
if (!r || r.startsWith("#")) continue;
|
|
882
|
+
const c = r.match(/^(\w+)\s+goto\s+(\w+)\s+(\d+(?:\.\d+)?)(%?)/);
|
|
867
883
|
if (c) {
|
|
868
|
-
const
|
|
884
|
+
const i = r.slice(c[0].length), o = i.includes("--wait");
|
|
869
885
|
let f;
|
|
870
|
-
const a =
|
|
886
|
+
const a = i.match(/--payload\s+(\{.*\})/);
|
|
871
887
|
if (a)
|
|
872
888
|
try {
|
|
873
889
|
f = JSON.parse(a[1]);
|
|
@@ -879,7 +895,7 @@ function Y(e) {
|
|
|
879
895
|
targetLineId: c[2],
|
|
880
896
|
targetOffset: parseFloat(c[3]),
|
|
881
897
|
isPercentage: c[4] === "%",
|
|
882
|
-
awaitConfirmation:
|
|
898
|
+
awaitConfirmation: o,
|
|
883
899
|
payload: f
|
|
884
900
|
});
|
|
885
901
|
}
|
|
@@ -888,240 +904,240 @@ function Y(e) {
|
|
|
888
904
|
}
|
|
889
905
|
function Re(e) {
|
|
890
906
|
return e.map((t) => {
|
|
891
|
-
const n = t.isPercentage ? `${t.targetOffset}%` : `${t.targetOffset}`,
|
|
892
|
-
return `${t.vehicleId} goto ${t.targetLineId} ${n}${
|
|
907
|
+
const n = t.isPercentage ? `${t.targetOffset}%` : `${t.targetOffset}`, s = t.awaitConfirmation ? " --wait" : "", r = t.payload !== void 0 ? ` --payload ${JSON.stringify(t.payload)}` : "";
|
|
908
|
+
return `${t.vehicleId} goto ${t.targetLineId} ${n}${s}${r}`;
|
|
893
909
|
}).join(`
|
|
894
910
|
`);
|
|
895
911
|
}
|
|
896
912
|
function ke() {
|
|
897
|
-
const [e, t] = L([]), [n,
|
|
913
|
+
const [e, t] = L([]), [n, s] = L([]), [r, c] = L(""), [i, o] = L(null), [f, a] = L(!1), [u, d] = L(0), g = P(!1), v = P("");
|
|
898
914
|
return b(() => {
|
|
899
|
-
|
|
900
|
-
}, [
|
|
901
|
-
if (
|
|
915
|
+
v.current = r;
|
|
916
|
+
}, [r]), b(() => {
|
|
917
|
+
if (g.current)
|
|
902
918
|
return;
|
|
903
|
-
const h = ie(
|
|
919
|
+
const h = ie(v.current), l = qe({
|
|
904
920
|
lines: e,
|
|
905
921
|
curves: n,
|
|
906
922
|
vehicles: h.vehicles
|
|
907
923
|
});
|
|
908
|
-
l !==
|
|
909
|
-
|
|
924
|
+
l !== v.current && (g.current = !0, c(l), setTimeout(() => {
|
|
925
|
+
g.current = !1;
|
|
910
926
|
}, 50));
|
|
911
927
|
}, [e, n]), b(() => {
|
|
912
|
-
if (
|
|
928
|
+
if (g.current)
|
|
913
929
|
return;
|
|
914
930
|
const h = setTimeout(() => {
|
|
915
931
|
a(!0), d((p) => p + 1);
|
|
916
932
|
}, 0), l = setTimeout(() => {
|
|
917
933
|
try {
|
|
918
|
-
const p = ie(
|
|
934
|
+
const p = ie(r);
|
|
919
935
|
a(!1);
|
|
920
936
|
const S = JSON.stringify(p.lines) !== JSON.stringify(e), M = JSON.stringify(p.curves) !== JSON.stringify(n);
|
|
921
|
-
(S || M) && (
|
|
922
|
-
|
|
923
|
-
}, 100)),
|
|
937
|
+
(S || M) && (g.current = !0, S && t(p.lines), M && s(p.curves), setTimeout(() => {
|
|
938
|
+
g.current = !1;
|
|
939
|
+
}, 100)), o(null);
|
|
924
940
|
} catch (p) {
|
|
925
|
-
a(!1),
|
|
941
|
+
a(!1), o(p instanceof Error ? p.message : "Invalid scene definition");
|
|
926
942
|
}
|
|
927
943
|
}, 2e3);
|
|
928
944
|
return () => {
|
|
929
945
|
clearTimeout(h), clearTimeout(l);
|
|
930
946
|
};
|
|
931
|
-
}, [
|
|
947
|
+
}, [r, e, n]), {
|
|
932
948
|
lines: e,
|
|
933
949
|
curves: n,
|
|
934
|
-
sceneDefinitionText:
|
|
935
|
-
sceneError:
|
|
950
|
+
sceneDefinitionText: r,
|
|
951
|
+
sceneError: i,
|
|
936
952
|
isDebouncing: f,
|
|
937
953
|
debounceKey: u,
|
|
938
954
|
setLines: t,
|
|
939
|
-
setCurves:
|
|
955
|
+
setCurves: s,
|
|
940
956
|
setSceneDefinitionText: c
|
|
941
957
|
};
|
|
942
958
|
}
|
|
943
959
|
function k(e, t, n = 0) {
|
|
944
|
-
const
|
|
945
|
-
for (const
|
|
946
|
-
if (c.has(
|
|
947
|
-
|
|
960
|
+
const s = [], r = [], c = /* @__PURE__ */ new Set();
|
|
961
|
+
for (const i of e) {
|
|
962
|
+
if (c.has(i.vehicleId)) {
|
|
963
|
+
r.push(`Duplicate vehicle ID: ${i.vehicleId}`);
|
|
948
964
|
continue;
|
|
949
965
|
}
|
|
950
|
-
c.add(
|
|
951
|
-
const
|
|
952
|
-
if (!
|
|
953
|
-
|
|
966
|
+
c.add(i.vehicleId);
|
|
967
|
+
const o = t.find((h) => h.id === i.lineId);
|
|
968
|
+
if (!o) {
|
|
969
|
+
r.push(`Vehicle ${i.vehicleId}: Line "${i.lineId}" not found`);
|
|
954
970
|
continue;
|
|
955
971
|
}
|
|
956
|
-
const f = j(
|
|
972
|
+
const f = j(o.start, o.end), a = Math.max(0, f - n);
|
|
957
973
|
let u;
|
|
958
|
-
if (
|
|
959
|
-
if (
|
|
960
|
-
|
|
974
|
+
if (i.isPercentage) {
|
|
975
|
+
if (i.offset < 0 || i.offset > 100) {
|
|
976
|
+
r.push(`Vehicle ${i.vehicleId}: Offset ${i.offset}% must be between 0% and 100%`);
|
|
961
977
|
continue;
|
|
962
978
|
}
|
|
963
|
-
u =
|
|
979
|
+
u = i.offset / 100 * a;
|
|
964
980
|
} else {
|
|
965
|
-
if (
|
|
966
|
-
|
|
981
|
+
if (i.offset < 0 || i.offset > f) {
|
|
982
|
+
r.push(`Vehicle ${i.vehicleId}: Offset ${i.offset} exceeds line length ${f.toFixed(2)}`);
|
|
967
983
|
continue;
|
|
968
984
|
}
|
|
969
|
-
u = Math.min(
|
|
985
|
+
u = Math.min(i.offset, a);
|
|
970
986
|
}
|
|
971
|
-
const d = ee(
|
|
972
|
-
lineId:
|
|
987
|
+
const d = ee(o, u, !1), g = {
|
|
988
|
+
lineId: i.lineId,
|
|
973
989
|
position: d,
|
|
974
990
|
absoluteOffset: u
|
|
975
|
-
},
|
|
976
|
-
|
|
991
|
+
}, v = we(
|
|
992
|
+
i.lineId,
|
|
977
993
|
u,
|
|
978
994
|
n,
|
|
979
|
-
|
|
995
|
+
o
|
|
980
996
|
);
|
|
981
|
-
|
|
982
|
-
id:
|
|
983
|
-
lineId:
|
|
984
|
-
offset:
|
|
985
|
-
isPercentage:
|
|
997
|
+
s.push({
|
|
998
|
+
id: i.vehicleId,
|
|
999
|
+
lineId: i.lineId,
|
|
1000
|
+
offset: i.offset,
|
|
1001
|
+
isPercentage: i.isPercentage,
|
|
986
1002
|
state: "idle",
|
|
987
|
-
rear:
|
|
988
|
-
front:
|
|
1003
|
+
rear: g,
|
|
1004
|
+
front: v
|
|
989
1005
|
});
|
|
990
1006
|
}
|
|
991
|
-
return { vehicles:
|
|
1007
|
+
return { vehicles: s, errors: r };
|
|
992
1008
|
}
|
|
993
1009
|
function Ae(e) {
|
|
994
|
-
const t = e.map((
|
|
995
|
-
const
|
|
996
|
-
return
|
|
997
|
-
}).filter((
|
|
1010
|
+
const t = e.map((s) => {
|
|
1011
|
+
const r = s.vehicleId.match(/^v(\d+)$/);
|
|
1012
|
+
return r ? parseInt(r[1]) : 0;
|
|
1013
|
+
}).filter((s) => s > 0);
|
|
998
1014
|
return `v${(t.length > 0 ? Math.max(...t) : 0) + 1}`;
|
|
999
1015
|
}
|
|
1000
1016
|
function _(e, t, n) {
|
|
1001
|
-
const
|
|
1017
|
+
const s = [], r = [], c = /* @__PURE__ */ new Map(), i = new Set(t.map((a) => a.id)), o = new Set(n.map((a) => a.id)), f = new Map(n.map((a) => {
|
|
1002
1018
|
const u = a.end.x - a.start.x, d = a.end.y - a.start.y;
|
|
1003
1019
|
return [a.id, Math.sqrt(u * u + d * d)];
|
|
1004
1020
|
}));
|
|
1005
1021
|
for (const a of e) {
|
|
1006
|
-
if (!
|
|
1007
|
-
|
|
1022
|
+
if (!i.has(a.vehicleId)) {
|
|
1023
|
+
s.push(`Vehicle "${a.vehicleId}" does not exist`);
|
|
1008
1024
|
continue;
|
|
1009
1025
|
}
|
|
1010
|
-
if (!
|
|
1011
|
-
|
|
1026
|
+
if (!o.has(a.targetLineId)) {
|
|
1027
|
+
s.push(`Line "${a.targetLineId}" does not exist`);
|
|
1012
1028
|
continue;
|
|
1013
1029
|
}
|
|
1014
1030
|
const u = f.get(a.targetLineId), d = a.isPercentage ? a.targetOffset / 100 * u : a.targetOffset;
|
|
1015
1031
|
if (d < 0 || d > u) {
|
|
1016
|
-
|
|
1032
|
+
s.push(`Offset ${a.targetOffset}${a.isPercentage ? "%" : ""} is out of bounds for ${a.targetLineId}`);
|
|
1017
1033
|
continue;
|
|
1018
1034
|
}
|
|
1019
|
-
|
|
1020
|
-
const
|
|
1021
|
-
|
|
1035
|
+
r.push(a);
|
|
1036
|
+
const g = c.get(a.vehicleId) || [];
|
|
1037
|
+
g.push(a), c.set(a.vehicleId, g);
|
|
1022
1038
|
}
|
|
1023
|
-
return { commands:
|
|
1039
|
+
return { commands: r, errors: s, vehicleQueues: c };
|
|
1024
1040
|
}
|
|
1025
1041
|
function Fe(e, t) {
|
|
1026
1042
|
if (t.length === 0) return null;
|
|
1027
1043
|
if (e.length === 0)
|
|
1028
1044
|
return t[0].id;
|
|
1029
1045
|
const n = /* @__PURE__ */ new Map();
|
|
1030
|
-
for (const
|
|
1031
|
-
n.set(
|
|
1032
|
-
for (const
|
|
1033
|
-
const
|
|
1034
|
-
n.set(
|
|
1046
|
+
for (const s of t)
|
|
1047
|
+
n.set(s.id, 0);
|
|
1048
|
+
for (const s of e) {
|
|
1049
|
+
const r = n.get(s.vehicleId) || 0;
|
|
1050
|
+
n.set(s.vehicleId, r + 1);
|
|
1035
1051
|
}
|
|
1036
1052
|
return t[0].id;
|
|
1037
1053
|
}
|
|
1038
1054
|
function Qe({ lines: e, wheelbase: t }) {
|
|
1039
|
-
const [n,
|
|
1055
|
+
const [n, s] = L([]), [r, c] = L(""), [i, o] = L(null), [f, a] = L(!1), [u, d] = L(0), g = P(!1), v = P(e), h = P(e), l = P(t), p = P(t);
|
|
1040
1056
|
b(() => {
|
|
1041
|
-
|
|
1057
|
+
v.current = e;
|
|
1042
1058
|
}, [e]), b(() => {
|
|
1043
1059
|
l.current = t;
|
|
1044
1060
|
}, [t]), b(() => {
|
|
1045
|
-
if (
|
|
1061
|
+
if (g.current)
|
|
1046
1062
|
return;
|
|
1047
1063
|
const M = setTimeout(() => {
|
|
1048
|
-
a(!0), d((
|
|
1049
|
-
}, 0),
|
|
1064
|
+
a(!0), d((x) => x + 1);
|
|
1065
|
+
}, 0), m = setTimeout(() => {
|
|
1050
1066
|
try {
|
|
1051
|
-
const
|
|
1052
|
-
|
|
1053
|
-
|
|
1067
|
+
const x = B(r), { vehicles: O, errors: C } = k(
|
|
1068
|
+
x,
|
|
1069
|
+
v.current,
|
|
1054
1070
|
l.current
|
|
1055
1071
|
);
|
|
1056
|
-
a(!1), C.length > 0 ? (
|
|
1057
|
-
`)),
|
|
1058
|
-
} catch (
|
|
1059
|
-
a(!1),
|
|
1072
|
+
a(!1), C.length > 0 ? (o(C.join(`
|
|
1073
|
+
`)), s(O)) : (o(null), s(O));
|
|
1074
|
+
} catch (x) {
|
|
1075
|
+
a(!1), o(x instanceof Error ? x.message : "Invalid initial movement"), s([]);
|
|
1060
1076
|
}
|
|
1061
1077
|
}, 2e3);
|
|
1062
1078
|
return () => {
|
|
1063
|
-
clearTimeout(M), clearTimeout(
|
|
1079
|
+
clearTimeout(M), clearTimeout(m);
|
|
1064
1080
|
};
|
|
1065
|
-
}, [
|
|
1066
|
-
if (!(JSON.stringify(h.current) !== JSON.stringify(e)) || (h.current = e,
|
|
1081
|
+
}, [r]), b(() => {
|
|
1082
|
+
if (!(JSON.stringify(h.current) !== JSON.stringify(e)) || (h.current = e, g.current || !r.trim()))
|
|
1067
1083
|
return;
|
|
1068
|
-
const
|
|
1084
|
+
const m = setTimeout(() => {
|
|
1069
1085
|
try {
|
|
1070
|
-
const
|
|
1071
|
-
|
|
1086
|
+
const x = B(r), { vehicles: O, errors: C } = k(
|
|
1087
|
+
x,
|
|
1072
1088
|
e,
|
|
1073
1089
|
l.current
|
|
1074
1090
|
);
|
|
1075
|
-
C.length > 0 ? (
|
|
1076
|
-
`)),
|
|
1077
|
-
} catch (
|
|
1078
|
-
|
|
1091
|
+
C.length > 0 ? (o(C.join(`
|
|
1092
|
+
`)), s(O)) : (o(null), s(O));
|
|
1093
|
+
} catch (x) {
|
|
1094
|
+
o(x instanceof Error ? x.message : "Invalid initial movement"), s([]);
|
|
1079
1095
|
}
|
|
1080
1096
|
}, 0);
|
|
1081
|
-
return () => clearTimeout(
|
|
1082
|
-
}, [e,
|
|
1083
|
-
if (p.current === t || (p.current = t,
|
|
1097
|
+
return () => clearTimeout(m);
|
|
1098
|
+
}, [e, r]), b(() => {
|
|
1099
|
+
if (p.current === t || (p.current = t, g.current || !r.trim()))
|
|
1084
1100
|
return;
|
|
1085
1101
|
const M = setTimeout(() => {
|
|
1086
1102
|
try {
|
|
1087
|
-
const
|
|
1088
|
-
|
|
1089
|
-
|
|
1103
|
+
const m = B(r), { vehicles: x, errors: O } = k(
|
|
1104
|
+
m,
|
|
1105
|
+
v.current,
|
|
1090
1106
|
t
|
|
1091
1107
|
);
|
|
1092
|
-
O.length > 0 ? (
|
|
1093
|
-
`)),
|
|
1094
|
-
} catch (
|
|
1095
|
-
|
|
1108
|
+
O.length > 0 ? (o(O.join(`
|
|
1109
|
+
`)), s(x)) : (o(null), s(x));
|
|
1110
|
+
} catch (m) {
|
|
1111
|
+
o(m instanceof Error ? m.message : "Invalid initial movement"), s([]);
|
|
1096
1112
|
}
|
|
1097
1113
|
}, 0);
|
|
1098
1114
|
return () => clearTimeout(M);
|
|
1099
|
-
}, [t,
|
|
1115
|
+
}, [t, r]);
|
|
1100
1116
|
const S = G(() => {
|
|
1101
|
-
const M = B(
|
|
1102
|
-
if (!
|
|
1103
|
-
|
|
1117
|
+
const M = B(r), m = Ae(M), x = e.length > 0 ? e[0] : null;
|
|
1118
|
+
if (!x) {
|
|
1119
|
+
o("No lines available. Please create at least one line first.");
|
|
1104
1120
|
return;
|
|
1105
1121
|
}
|
|
1106
1122
|
const O = {
|
|
1107
|
-
vehicleId:
|
|
1108
|
-
lineId:
|
|
1123
|
+
vehicleId: m,
|
|
1124
|
+
lineId: x.id,
|
|
1109
1125
|
offset: 0,
|
|
1110
1126
|
isPercentage: !1
|
|
1111
|
-
}, C = [...M, O],
|
|
1127
|
+
}, C = [...M, O], q = Ee(C), { vehicles: D, errors: I } = k(
|
|
1112
1128
|
C,
|
|
1113
1129
|
e,
|
|
1114
1130
|
t
|
|
1115
1131
|
);
|
|
1116
|
-
|
|
1117
|
-
`)) :
|
|
1118
|
-
|
|
1132
|
+
g.current = !0, c(q), I.length > 0 ? o(I.join(`
|
|
1133
|
+
`)) : o(null), s(D), setTimeout(() => {
|
|
1134
|
+
g.current = !1;
|
|
1119
1135
|
}, 50);
|
|
1120
|
-
}, [
|
|
1136
|
+
}, [r, e, t]);
|
|
1121
1137
|
return {
|
|
1122
1138
|
vehicles: n,
|
|
1123
|
-
initialMovementText:
|
|
1124
|
-
movementError:
|
|
1139
|
+
initialMovementText: r,
|
|
1140
|
+
movementError: i,
|
|
1125
1141
|
isDebouncing: f,
|
|
1126
1142
|
debounceKey: u,
|
|
1127
1143
|
setInitialMovementText: c,
|
|
@@ -1129,44 +1145,44 @@ function Qe({ lines: e, wheelbase: t }) {
|
|
|
1129
1145
|
};
|
|
1130
1146
|
}
|
|
1131
1147
|
function He({ lines: e, vehicles: t }) {
|
|
1132
|
-
const [n,
|
|
1148
|
+
const [n, s] = L(""), [r, c] = L([]), [i, o] = L(/* @__PURE__ */ new Map()), [f, a] = L(null), [u, d] = L(!1), [g, v] = L(0), h = P(!1), l = P(t), p = P(e);
|
|
1133
1149
|
b(() => {
|
|
1134
1150
|
l.current = t, p.current = e;
|
|
1135
1151
|
}, [t, e]), b(() => {
|
|
1136
1152
|
if (h.current)
|
|
1137
1153
|
return;
|
|
1138
1154
|
const M = setTimeout(() => {
|
|
1139
|
-
d(!0),
|
|
1140
|
-
}, 0),
|
|
1155
|
+
d(!0), v((x) => x + 1);
|
|
1156
|
+
}, 0), m = setTimeout(() => {
|
|
1141
1157
|
try {
|
|
1142
|
-
const
|
|
1143
|
-
|
|
1158
|
+
const x = Y(n), { commands: O, errors: C, vehicleQueues: q } = _(
|
|
1159
|
+
x,
|
|
1144
1160
|
l.current,
|
|
1145
1161
|
p.current
|
|
1146
1162
|
);
|
|
1147
1163
|
d(!1), C.length > 0 ? a(C.join(`
|
|
1148
|
-
`)) : a(null), c(O),
|
|
1149
|
-
} catch (
|
|
1150
|
-
d(!1), a(
|
|
1164
|
+
`)) : a(null), c(O), o(q);
|
|
1165
|
+
} catch (x) {
|
|
1166
|
+
d(!1), a(x instanceof Error ? x.message : "Invalid movement sequence"), c([]), o(/* @__PURE__ */ new Map());
|
|
1151
1167
|
}
|
|
1152
1168
|
}, 2e3);
|
|
1153
1169
|
return () => {
|
|
1154
|
-
clearTimeout(M), clearTimeout(
|
|
1170
|
+
clearTimeout(M), clearTimeout(m);
|
|
1155
1171
|
};
|
|
1156
1172
|
}, [n]), b(() => {
|
|
1157
1173
|
if (h.current || !n.trim())
|
|
1158
1174
|
return;
|
|
1159
1175
|
const M = setTimeout(() => {
|
|
1160
1176
|
try {
|
|
1161
|
-
const
|
|
1162
|
-
|
|
1177
|
+
const m = Y(n), { commands: x, errors: O, vehicleQueues: C } = _(
|
|
1178
|
+
m,
|
|
1163
1179
|
t,
|
|
1164
1180
|
e
|
|
1165
1181
|
);
|
|
1166
1182
|
O.length > 0 ? a(O.join(`
|
|
1167
|
-
`)) : a(null), c(
|
|
1168
|
-
} catch (
|
|
1169
|
-
a(
|
|
1183
|
+
`)) : a(null), c(x), o(C);
|
|
1184
|
+
} catch (m) {
|
|
1185
|
+
a(m instanceof Error ? m.message : "Invalid movement sequence"), c([]), o(/* @__PURE__ */ new Map());
|
|
1170
1186
|
}
|
|
1171
1187
|
}, 0);
|
|
1172
1188
|
return () => clearTimeout(M);
|
|
@@ -1180,51 +1196,51 @@ function He({ lines: e, vehicles: t }) {
|
|
|
1180
1196
|
a("No lines available. Please create at least one line first.");
|
|
1181
1197
|
return;
|
|
1182
1198
|
}
|
|
1183
|
-
const M = Y(n),
|
|
1184
|
-
if (!
|
|
1199
|
+
const M = Y(n), m = Fe(M, t);
|
|
1200
|
+
if (!m) {
|
|
1185
1201
|
a("No vehicles available.");
|
|
1186
1202
|
return;
|
|
1187
1203
|
}
|
|
1188
|
-
const
|
|
1189
|
-
vehicleId:
|
|
1190
|
-
targetLineId:
|
|
1204
|
+
const x = e[0], O = {
|
|
1205
|
+
vehicleId: m,
|
|
1206
|
+
targetLineId: x.id,
|
|
1191
1207
|
targetOffset: 100,
|
|
1192
1208
|
isPercentage: !0
|
|
1193
|
-
}, C = [...M, O],
|
|
1209
|
+
}, C = [...M, O], q = Re(C), { commands: D, errors: I, vehicleQueues: y } = _(
|
|
1194
1210
|
C,
|
|
1195
1211
|
t,
|
|
1196
1212
|
e
|
|
1197
1213
|
);
|
|
1198
|
-
h.current = !0,
|
|
1199
|
-
`)) : a(null), c(D),
|
|
1214
|
+
h.current = !0, s(q), I.length > 0 ? a(I.join(`
|
|
1215
|
+
`)) : a(null), c(D), o(y), setTimeout(() => {
|
|
1200
1216
|
h.current = !1;
|
|
1201
1217
|
}, 50);
|
|
1202
1218
|
}, [n, t, e]);
|
|
1203
1219
|
return {
|
|
1204
1220
|
movementSequenceText: n,
|
|
1205
|
-
gotoCommands:
|
|
1206
|
-
vehicleQueues:
|
|
1221
|
+
gotoCommands: r,
|
|
1222
|
+
vehicleQueues: i,
|
|
1207
1223
|
sequenceError: f,
|
|
1208
1224
|
isDebouncing: u,
|
|
1209
|
-
debounceKey:
|
|
1210
|
-
setMovementSequenceText:
|
|
1225
|
+
debounceKey: g,
|
|
1226
|
+
setMovementSequenceText: s,
|
|
1211
1227
|
handleAddGotoCommand: S
|
|
1212
1228
|
};
|
|
1213
1229
|
}
|
|
1214
1230
|
function ce(e, t, n) {
|
|
1215
1231
|
if (!t || !n) return { x: 0, y: 0 };
|
|
1216
|
-
const
|
|
1232
|
+
const s = t.getBoundingClientRect();
|
|
1217
1233
|
return {
|
|
1218
|
-
x: e.clientX -
|
|
1219
|
-
y: e.clientY -
|
|
1234
|
+
x: e.clientX - s.left,
|
|
1235
|
+
y: e.clientY - s.top
|
|
1220
1236
|
};
|
|
1221
1237
|
}
|
|
1222
1238
|
function ae(e, t, n = 10) {
|
|
1223
|
-
for (const
|
|
1224
|
-
if (j(e,
|
|
1225
|
-
return { lineId:
|
|
1226
|
-
if (j(e,
|
|
1227
|
-
return { lineId:
|
|
1239
|
+
for (const s of t) {
|
|
1240
|
+
if (j(e, s.start) < n)
|
|
1241
|
+
return { lineId: s.id, endpoint: "start" };
|
|
1242
|
+
if (j(e, s.end) < n)
|
|
1243
|
+
return { lineId: s.id, endpoint: "end" };
|
|
1228
1244
|
}
|
|
1229
1245
|
return null;
|
|
1230
1246
|
}
|
|
@@ -1232,64 +1248,64 @@ function Xe({
|
|
|
1232
1248
|
canvasRef: e,
|
|
1233
1249
|
containerRef: t,
|
|
1234
1250
|
drawMode: n,
|
|
1235
|
-
lines:
|
|
1236
|
-
curves:
|
|
1251
|
+
lines: s,
|
|
1252
|
+
curves: r,
|
|
1237
1253
|
setLines: c,
|
|
1238
|
-
setCurves:
|
|
1239
|
-
lineCounterRef:
|
|
1254
|
+
setCurves: i,
|
|
1255
|
+
lineCounterRef: o
|
|
1240
1256
|
}) {
|
|
1241
|
-
const [f, a] = L(!1), [u, d] = L(null), [
|
|
1257
|
+
const [f, a] = L(!1), [u, d] = L(null), [g, v] = L(null), [h, l] = L(null), [p, S] = L(null), [M, m] = L({ x: 0, y: 0 });
|
|
1242
1258
|
return {
|
|
1243
|
-
handleMouseDown: (
|
|
1244
|
-
const D = ce(
|
|
1259
|
+
handleMouseDown: (q) => {
|
|
1260
|
+
const D = ce(q, e.current, t.current), I = ae(D, s);
|
|
1245
1261
|
if (n === "line")
|
|
1246
|
-
|
|
1262
|
+
I || (a(!0), d({ start: D, current: D }));
|
|
1247
1263
|
else if (n === "drag")
|
|
1248
|
-
|
|
1264
|
+
I && l(I);
|
|
1249
1265
|
else if (n === "curve")
|
|
1250
|
-
if (
|
|
1266
|
+
if (I)
|
|
1251
1267
|
if (!p)
|
|
1252
|
-
S(
|
|
1268
|
+
S(I);
|
|
1253
1269
|
else {
|
|
1254
|
-
if (p.lineId !==
|
|
1270
|
+
if (p.lineId !== I.lineId) {
|
|
1255
1271
|
const y = {
|
|
1256
1272
|
fromLineId: p.lineId,
|
|
1257
|
-
toLineId:
|
|
1273
|
+
toLineId: I.lineId
|
|
1258
1274
|
};
|
|
1259
|
-
|
|
1275
|
+
i([...r, y]);
|
|
1260
1276
|
}
|
|
1261
1277
|
S(null);
|
|
1262
1278
|
}
|
|
1263
1279
|
else
|
|
1264
1280
|
p && S(null);
|
|
1265
1281
|
},
|
|
1266
|
-
handleMouseMove: (
|
|
1267
|
-
const D = ce(
|
|
1268
|
-
if (
|
|
1282
|
+
handleMouseMove: (q) => {
|
|
1283
|
+
const D = ce(q, e.current, t.current);
|
|
1284
|
+
if (m(D), f && u)
|
|
1269
1285
|
d({ ...u, current: D });
|
|
1270
1286
|
else if (h) {
|
|
1271
|
-
const
|
|
1272
|
-
c(
|
|
1287
|
+
const I = s.map((y) => y.id === h.lineId ? h.endpoint === "start" ? { ...y, start: D } : { ...y, end: D } : y);
|
|
1288
|
+
c(I);
|
|
1273
1289
|
} else {
|
|
1274
|
-
const
|
|
1275
|
-
I
|
|
1290
|
+
const I = ae(D, s);
|
|
1291
|
+
v(I);
|
|
1276
1292
|
}
|
|
1277
1293
|
},
|
|
1278
1294
|
handleMouseUp: () => {
|
|
1279
1295
|
if (f && u) {
|
|
1280
1296
|
if (j(u.start, u.current) > 20) {
|
|
1281
1297
|
const D = {
|
|
1282
|
-
id: `line${String(
|
|
1298
|
+
id: `line${String(o.current).padStart(3, "0")}`,
|
|
1283
1299
|
start: u.start,
|
|
1284
1300
|
end: u.current
|
|
1285
1301
|
};
|
|
1286
|
-
|
|
1302
|
+
o.current++, c([...s, D]);
|
|
1287
1303
|
}
|
|
1288
1304
|
d(null), a(!1);
|
|
1289
1305
|
} else h && l(null);
|
|
1290
1306
|
},
|
|
1291
1307
|
tempLine: u,
|
|
1292
|
-
hoveredEndpoint:
|
|
1308
|
+
hoveredEndpoint: g,
|
|
1293
1309
|
curveStart: p,
|
|
1294
1310
|
mousePos: M
|
|
1295
1311
|
};
|
|
@@ -1302,7 +1318,7 @@ export {
|
|
|
1302
1318
|
Le as buildGraph,
|
|
1303
1319
|
Me as calculateBezierArcLength,
|
|
1304
1320
|
te as calculateFrontAxlePosition,
|
|
1305
|
-
|
|
1321
|
+
we as calculateInitialFrontPosition,
|
|
1306
1322
|
H as calculatePositionOnCurve,
|
|
1307
1323
|
W as calculatePositionOnLine,
|
|
1308
1324
|
Je as canReachTarget,
|
|
@@ -1313,19 +1329,19 @@ export {
|
|
|
1313
1329
|
ye as distanceToT,
|
|
1314
1330
|
de as findPath,
|
|
1315
1331
|
Re as generateGotoCommands,
|
|
1316
|
-
|
|
1317
|
-
|
|
1332
|
+
qe as generateSceneDefinition,
|
|
1333
|
+
Ee as generateVehicleStarts,
|
|
1318
1334
|
je as getArcLength,
|
|
1319
1335
|
Se as getCumulativeArcLength,
|
|
1320
1336
|
Oe as getLineLength,
|
|
1321
1337
|
ne as getPointOnBezier,
|
|
1322
1338
|
ve as getPointOnLine,
|
|
1323
1339
|
ee as getPointOnLineByOffset,
|
|
1324
|
-
|
|
1340
|
+
ge as getPositionFromOffset,
|
|
1325
1341
|
Ke as getReachableCurves,
|
|
1326
|
-
|
|
1342
|
+
me as handleArrival,
|
|
1327
1343
|
oe as initializeAllVehicles,
|
|
1328
|
-
|
|
1344
|
+
De as initializeMovingVehicle,
|
|
1329
1345
|
Q as normalize,
|
|
1330
1346
|
Y as parseGotoCommands,
|
|
1331
1347
|
ie as parseSceneDefinition,
|
|
@@ -1334,7 +1350,7 @@ export {
|
|
|
1334
1350
|
fe as resolveFromLineOffset,
|
|
1335
1351
|
ze as resolveOffset,
|
|
1336
1352
|
le as resolveToLineOffset,
|
|
1337
|
-
|
|
1353
|
+
re as updateAxlePosition,
|
|
1338
1354
|
Xe as useCanvasInteraction,
|
|
1339
1355
|
We as useCreateVehicleEventEmitter,
|
|
1340
1356
|
Qe as useInitialMovement,
|