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