@rulecad/cad 0.7.97 → 0.9.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/AGENTS.md +26 -10
- package/CHANGELOG.md +442 -2
- package/EXAMPLES.md +48 -42
- package/README.md +226 -73
- package/TUTORIAL.md +2 -2
- package/bin/cad.mjs +2253 -514
- package/lib/animate.mjs +173 -49
- package/lib/assembly.mjs +1854 -437
- package/lib/beams.mjs +256 -52
- package/lib/belts.mjs +66 -15
- package/lib/board-work.mjs +12 -0
- package/lib/bought.mjs +309 -53
- package/lib/buildpage.mjs +179 -29
- package/lib/carried.mjs +201 -0
- package/lib/clone.mjs +194 -42
- package/lib/design.mjs +734 -113
- package/lib/drive.mjs +187 -63
- package/lib/edit.mjs +900 -191
- package/lib/errors.mjs +16 -3
- package/lib/explain.mjs +62 -13
- package/lib/fasten.mjs +2710 -502
- package/lib/fittings.mjs +715 -121
- package/lib/fixings.mjs +21 -9
- package/lib/framebuild.mjs +792 -176
- package/lib/framecheck.mjs +1901 -368
- package/lib/framegen.mjs +100 -22
- package/lib/frameheat.mjs +225 -42
- package/lib/frameprint.mjs +513 -108
- package/lib/frames.mjs +81 -17
- package/lib/framesize.mjs +792 -120
- package/lib/frametip.mjs +235 -0
- package/lib/gait.mjs +135 -23
- package/lib/grip.mjs +62 -13
- package/lib/guides.mjs +1403 -230
- package/lib/host.mjs +149 -18
- package/lib/inplace.mjs +171 -36
- package/lib/jigs.mjs +360 -78
- package/lib/joins.mjs +697 -118
- package/lib/jsonedit.mjs +88 -26
- package/lib/kept.mjs +84 -0
- package/lib/kit.mjs +438 -68
- package/lib/layout.mjs +3 -1
- package/lib/links.mjs +149 -42
- package/lib/list.mjs +326 -64
- package/lib/live-guard.mjs +68 -0
- package/lib/live-shape.mjs +96 -24
- package/lib/live.mjs +189 -59
- package/lib/loads.mjs +579 -130
- package/lib/machine.mjs +372 -74
- package/lib/magnets.mjs +162 -44
- package/lib/measured.mjs +417 -94
- package/lib/mesh.mjs +526 -119
- package/lib/meshcmd.mjs +215 -60
- package/lib/motors.mjs +1022 -212
- package/lib/motorsvg.mjs +114 -32
- package/lib/names.mjs +41 -0
- package/lib/optimise.mjs +979 -283
- package/lib/order.mjs +519 -112
- package/lib/panels.mjs +482 -94
- package/lib/parts.mjs +78 -23
- package/lib/pins.mjs +163 -44
- package/lib/plates.mjs +224 -36
- package/lib/player.mjs +37 -9
- package/lib/power.mjs +64 -13
- package/lib/preview.mjs +83 -16
- package/lib/profilemeasure.mjs +572 -129
- package/lib/rules.mjs +38 -4
- package/lib/sandbox-hooks.mjs +154 -12
- package/lib/sandbox-preload.mjs +2 -2
- package/lib/sandbox-run.mjs +127 -12
- package/lib/sandbox.mjs +632 -35
- package/lib/schema.mjs +43 -11
- package/lib/seats.mjs +227 -49
- package/lib/services.mjs +261 -52
- package/lib/sheet.mjs +851 -178
- package/lib/slotnuts.mjs +213 -34
- package/lib/targets/gist.mjs +4 -1
- package/lib/targets.mjs +42 -6
- package/lib/task.mjs +376 -79
- package/lib/versions.mjs +113 -28
- package/lib/wires.mjs +228 -45
- package/lib/workspace.mjs +216 -17
- package/package.json +19 -19
- package/schemas/assembly.schema.json +2 -2
- package/schemas/object.schema.json +1 -1
- package/schemas/project.schema.json +1 -1
package/lib/animate.mjs
CHANGED
|
@@ -9,7 +9,8 @@ const STEP = 0.06; // seconds a frame
|
|
|
9
9
|
|
|
10
10
|
const fmt = (n) => +n.toFixed(2);
|
|
11
11
|
const pathOf = (outlines) => outlines.map((o) => `M${o.map(([x, y]) => `${fmt(x)} ${fmt(-y)}`).join('L')}Z`).join('');
|
|
12
|
-
const escape = (s) =>
|
|
12
|
+
const escape = (s) =>
|
|
13
|
+
String(s).replace(/[<>&"]/g, (c) => ({ '<': '<', '>': '>', '&': '&', '"': '"' })[c]);
|
|
13
14
|
|
|
14
15
|
/**
|
|
15
16
|
* @param {{ frames: { from: string, to: string, t: number, parts: Record<string, number[][][]> }[], joints: Record<string, object> }} mechanism
|
|
@@ -19,48 +20,112 @@ const escape = (s) => String(s).replace(/[<>&"]/g, (c) => ({ '<': '<', '>': '
|
|
|
19
20
|
export function sequenceSvg(mechanism, { title = '' } = {}) {
|
|
20
21
|
const frames = mechanism.frames || [];
|
|
21
22
|
if (!frames.length) throw new Error('the mechanism has no sequence to animate: give its lamina a sequence of states');
|
|
22
|
-
const flexures = new Set(Object.keys(mechanism.joints || {})),
|
|
23
|
+
const flexures = new Set(Object.keys(mechanism.joints || {})),
|
|
24
|
+
kind = (n) => (n === 'ground' ? 'ground' : flexures.has(n) ? 'flexure' : 'body');
|
|
23
25
|
// The view: everything every frame reaches, with a margin and a line for the caption
|
|
24
|
-
let lo = [Infinity, Infinity],
|
|
25
|
-
|
|
26
|
-
|
|
26
|
+
let lo = [Infinity, Infinity],
|
|
27
|
+
hi = [-Infinity, -Infinity];
|
|
28
|
+
for (const fr of frames)
|
|
29
|
+
for (const outs of Object.values(fr.parts))
|
|
30
|
+
for (const o of outs)
|
|
31
|
+
for (const [x, y] of o) {
|
|
32
|
+
lo = [Math.min(lo[0], x), Math.min(lo[1], -y)];
|
|
33
|
+
hi = [Math.max(hi[0], x), Math.max(hi[1], -y)];
|
|
34
|
+
}
|
|
35
|
+
const pad = Math.max(hi[0] - lo[0], hi[1] - lo[1]) * 0.05,
|
|
36
|
+
caption = pad * 2;
|
|
27
37
|
// The force curves of the steps a hand drives, a chart each, in a row under the drawing
|
|
28
|
-
const charts = (mechanism.curves || []).flatMap((tr) =>
|
|
38
|
+
const charts = (mechanism.curves || []).flatMap((tr) =>
|
|
39
|
+
tr.curve.filter((c) => c.points.length > 1).map((c) => ({ from: tr.from, to: tr.to, ...c })),
|
|
40
|
+
);
|
|
29
41
|
const chartH = charts.length ? (hi[1] - lo[1]) * 0.35 : 0;
|
|
30
|
-
const vb = [
|
|
42
|
+
const vb = [
|
|
43
|
+
lo[0] - pad,
|
|
44
|
+
lo[1] - pad - caption,
|
|
45
|
+
hi[0] - lo[0] + 2 * pad,
|
|
46
|
+
hi[1] - lo[1] + 2 * pad + caption * 2 + (chartH ? chartH + caption * 1.5 : 0),
|
|
47
|
+
]; // a band above for the key, below for the step and the charts
|
|
31
48
|
// Timing: each frame its share; a state (the first frame of each step, and the last) held longer
|
|
32
|
-
const weights = frames.map((fr, i) => (fr.t === 0 || i === frames.length - 1 ? HOLD : 1)),
|
|
33
|
-
|
|
49
|
+
const weights = frames.map((fr, i) => (fr.t === 0 || i === frames.length - 1 ? HOLD : 1)),
|
|
50
|
+
total = weights.reduce((a, b) => a + b, 0);
|
|
51
|
+
const starts = [];
|
|
52
|
+
weights.reduce((at, w) => {
|
|
53
|
+
starts.push(at / total);
|
|
54
|
+
return at + w;
|
|
55
|
+
}, 0);
|
|
34
56
|
const dur = `${fmt(total * STEP)}s`;
|
|
35
|
-
const show = (i) => {
|
|
36
|
-
|
|
37
|
-
const
|
|
57
|
+
const show = (i) => {
|
|
58
|
+
// visible only during frame i
|
|
59
|
+
const a = fmt(starts[i]),
|
|
60
|
+
b = fmt(i + 1 < frames.length ? starts[i + 1] : 1);
|
|
61
|
+
const keys = [...new Set([0, a, b, 1])].sort((x, y) => x - y),
|
|
62
|
+
values = keys.map((k) => (k >= a && k < b ? 'inline' : 'none'));
|
|
38
63
|
if (i === frames.length - 1) values[values.length - 1] = 'inline';
|
|
39
64
|
return `<animate attributeName="display" values="${values.join(';')}" keyTimes="${keys.join(';')}" dur="${dur}" calcMode="discrete" repeatCount="indefinite"/>`;
|
|
40
65
|
};
|
|
41
|
-
const ground = frames[0].parts.ground
|
|
42
|
-
|
|
66
|
+
const ground = frames[0].parts.ground
|
|
67
|
+
? `<path d="${pathOf(frames[0].parts.ground)}" fill="${COLOURS.ground}" fill-rule="evenodd"/>`
|
|
68
|
+
: '';
|
|
69
|
+
const size = fmt(caption * 0.45),
|
|
70
|
+
textY = fmt(hi[1] + pad + caption * 0.65),
|
|
71
|
+
keyY = fmt(vb[1] + caption * 0.65);
|
|
43
72
|
// Each chart: its box, the curve, and where frame i sits on it (if frame i is in its step)
|
|
44
|
-
const chartTop = hi[1] + pad + caption * 1.5,
|
|
73
|
+
const chartTop = hi[1] + pad + caption * 1.5,
|
|
74
|
+
cw = vb[2] / Math.max(1, charts.length),
|
|
75
|
+
inner = (k) => ({
|
|
76
|
+
x0: vb[0] + k * cw + pad * 1.5,
|
|
77
|
+
x1: vb[0] + (k + 1) * cw - pad * 0.5,
|
|
78
|
+
y0: chartTop + caption * 0.6,
|
|
79
|
+
y1: chartTop + chartH,
|
|
80
|
+
});
|
|
45
81
|
const scaled = charts.map((c, k) => {
|
|
46
|
-
const b = inner(k),
|
|
47
|
-
|
|
82
|
+
const b = inner(k),
|
|
83
|
+
xs = c.points.map(([x]) => Math.abs(x)),
|
|
84
|
+
fs = c.points.map(([, F]) => F),
|
|
85
|
+
xm = Math.max(1e-9, ...xs),
|
|
86
|
+
fmin = Math.min(0, ...fs),
|
|
87
|
+
fmax = Math.max(1e-9, ...fs);
|
|
88
|
+
const at = ([x, F]) => [
|
|
89
|
+
b.x0 + (Math.abs(x) / xm) * (b.x1 - b.x0),
|
|
90
|
+
b.y1 - ((F - fmin) / (fmax - fmin)) * (b.y1 - b.y0),
|
|
91
|
+
];
|
|
48
92
|
return { ...c, b, at, fmax, xm };
|
|
49
93
|
});
|
|
50
|
-
const chartArt = scaled
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
94
|
+
const chartArt = scaled
|
|
95
|
+
.map((c) => {
|
|
96
|
+
const pts = c.points.map(c.at),
|
|
97
|
+
zero = c.at([0, 0])[1];
|
|
98
|
+
const small = fmt(Math.min(size * 0.6, (c.b.x1 - c.b.x0) / 22)); // two short lines, sized to fit the chart's width
|
|
99
|
+
return `<g font-family="system-ui, sans-serif" fill="#555"><text x="${fmt(c.b.x0)}" y="${fmt(c.b.y0 - caption * 0.45)}" font-size="${small}">${escape(`${c.from} to ${c.to}, ${c.joint}`)}</text><text x="${fmt(c.b.x0)}" y="${fmt(c.b.y0 - caption * 0.1)}" font-size="${small}">${escape(`up to ${c.fmax.toFixed(1)} N over ${c.xm.toFixed(1)} mm`)}</text>
|
|
54
100
|
<line x1="${fmt(c.b.x0)}" y1="${fmt(zero)}" x2="${fmt(c.b.x1)}" y2="${fmt(zero)}" stroke="#ccc" stroke-width="${fmt(size * 0.04)}"/><line x1="${fmt(c.b.x0)}" y1="${fmt(c.b.y0)}" x2="${fmt(c.b.x0)}" y2="${fmt(c.b.y1)}" stroke="#ccc" stroke-width="${fmt(size * 0.04)}"/>
|
|
55
101
|
<polyline points="${pts.map(([x, y]) => `${fmt(x)},${fmt(y)}`).join(' ')}" fill="none" stroke="#2f6fb3" stroke-width="${fmt(size * 0.08)}"/></g>`;
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
const
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
102
|
+
})
|
|
103
|
+
.join('\n');
|
|
104
|
+
const markerOf = (fr) =>
|
|
105
|
+
scaled
|
|
106
|
+
.filter((c) => c.from === fr.from && c.to === fr.to)
|
|
107
|
+
.map((c) => {
|
|
108
|
+
const p = c.at(c.points[Math.min(c.points.length - 1, Math.round(fr.t * (c.points.length - 1)))]);
|
|
109
|
+
return `<circle cx="${fmt(p[0])}" cy="${fmt(p[1])}" r="${fmt(size * 0.25)}" fill="#e07a1f"/>`;
|
|
110
|
+
})
|
|
111
|
+
.join('');
|
|
112
|
+
const body = frames
|
|
113
|
+
.map((fr, i) => {
|
|
114
|
+
const label =
|
|
115
|
+
fr.label || (fr.t === 0 && fr.from === fr.to ? fr.from : fr.t === 0 ? fr.from : `${fr.from} to ${fr.to}`);
|
|
116
|
+
const shapes = Object.entries(fr.parts)
|
|
117
|
+
.filter(([n]) => n !== 'ground')
|
|
118
|
+
.map(([n, o]) => `<path d="${pathOf(o)}" fill="${COLOURS[kind(n)]}" fill-rule="evenodd"/>`)
|
|
119
|
+
.join('');
|
|
120
|
+
return `<g display="${i ? 'none' : 'inline'}">${show(i)}${shapes}${markerOf(fr)}<text x="${fmt(vb[0] + pad)}" y="${textY}" font-size="${size}" font-family="system-ui, sans-serif" fill="#333">${escape(label)}</text></g>`;
|
|
121
|
+
})
|
|
122
|
+
.join('\n');
|
|
123
|
+
const key = Object.entries(COLOURS)
|
|
124
|
+
.map(
|
|
125
|
+
([k, c], i) =>
|
|
126
|
+
`<rect x="${fmt(vb[0] + pad + i * size * 5)}" y="${fmt(keyY - size * 0.8)}" width="${size}" height="${size}" fill="${c}"/><text x="${fmt(vb[0] + pad + i * size * 5 + size * 1.3)}" y="${keyY}" font-size="${fmt(size * 0.8)}" font-family="system-ui, sans-serif" fill="#555">${{ ground: 'frame', body: 'moves', flexure: 'bends' }[k]}</text>`,
|
|
127
|
+
)
|
|
128
|
+
.join('');
|
|
64
129
|
return `<svg xmlns="http://www.w3.org/2000/svg" viewBox="${vb.map(fmt).join(' ')}" width="900">
|
|
65
130
|
<title>${escape(title)}</title>
|
|
66
131
|
<rect x="${fmt(vb[0])}" y="${fmt(vb[1])}" width="${fmt(vb[2])}" height="${fmt(vb[3])}" fill="#fff"/>
|
|
@@ -75,28 +140,79 @@ ${key}
|
|
|
75
140
|
// A gait as one animated SVG: the side view (x, z) with each leg's hip, knee and foot drawn as sticks and the ground, and
|
|
76
141
|
// under it the plan (x, y) with the feet in contact and the support they make. Self-contained, as the lamina sequence is.
|
|
77
142
|
export function gaitData(s, r) {
|
|
78
|
-
return {
|
|
143
|
+
return {
|
|
144
|
+
title: s.a.title || s.name,
|
|
145
|
+
pattern: s.a.gait.pattern,
|
|
146
|
+
period: s.gait.period,
|
|
147
|
+
height: s.gait.height,
|
|
148
|
+
legs: s.gait.legs.map((l) => l.name),
|
|
149
|
+
frames: r.frames.map((f) => ({
|
|
150
|
+
t: f.t,
|
|
151
|
+
margin: Number.isFinite(f.margin) ? Number(f.margin.toFixed(3)) : null,
|
|
152
|
+
feet: f.feet.map((e) => ({ leg: e.leg, stance: e.stance, foot: e.foot, q: e.q, load: e.load })),
|
|
153
|
+
})),
|
|
154
|
+
};
|
|
79
155
|
}
|
|
80
156
|
|
|
81
157
|
export function gaitSvg(s, r, { title = '' } = {}) {
|
|
82
|
-
const gait = s.gait,
|
|
83
|
-
|
|
84
|
-
|
|
158
|
+
const gait = s.gait,
|
|
159
|
+
joints = (l, q) => {
|
|
160
|
+
const c = fk(l.chain, q);
|
|
161
|
+
return [c.frames[0].at, c.frames[1].at, c.position];
|
|
162
|
+
};
|
|
163
|
+
const frames = r.frames.map((f) => ({
|
|
164
|
+
...f,
|
|
165
|
+
sticks: f.feet.map((e) => {
|
|
166
|
+
const l = gait.legs.find((x) => x.name === e.leg);
|
|
167
|
+
return { ...e, pts: joints(l, e.q) };
|
|
168
|
+
}),
|
|
169
|
+
}));
|
|
170
|
+
const xs = frames.flatMap((f) => f.sticks.flatMap((e) => e.pts.map((p) => p[0]))),
|
|
171
|
+
zs = frames.flatMap((f) => f.sticks.flatMap((e) => e.pts.map((p) => p[2])));
|
|
85
172
|
const ys = frames.flatMap((f) => f.sticks.map((e) => e.foot[1]));
|
|
86
|
-
const [x0, x1] = [Math.min(...xs) - 40, Math.max(...xs) + 40],
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
const
|
|
173
|
+
const [x0, x1] = [Math.min(...xs) - 40, Math.max(...xs) + 40],
|
|
174
|
+
[z0, z1] = [Math.min(...zs, -gait.height) - 40, Math.max(...zs, 0) + 40],
|
|
175
|
+
[y0, y1] = [Math.min(...ys) - 40, Math.max(...ys) + 40];
|
|
176
|
+
const side = { w: x1 - x0, h: z1 - z0 },
|
|
177
|
+
plan = { w: x1 - x0, h: y1 - y0 },
|
|
178
|
+
pad = Math.max(side.w, side.h) * 0.04,
|
|
179
|
+
cap = pad * 1.6;
|
|
180
|
+
const W = side.w + 2 * pad,
|
|
181
|
+
H = side.h + plan.h + 3 * pad + cap,
|
|
182
|
+
fx = (x) => fmt(x - x0 + pad),
|
|
183
|
+
fz = (z) => fmt(z1 - z + pad + cap),
|
|
184
|
+
fy = (y) => fmt(y - y0 + side.h + 2 * pad + cap);
|
|
185
|
+
const hold = 1 / frames.length,
|
|
186
|
+
dur = `${fmt(gait.period)}s`;
|
|
90
187
|
const stroke = Math.max(side.w, side.h) * 0.012;
|
|
91
|
-
const body = frames
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
188
|
+
const body = frames
|
|
189
|
+
.map((f, i) => {
|
|
190
|
+
const a = fmt(i * hold),
|
|
191
|
+
b = fmt((i + 1) * hold),
|
|
192
|
+
keys = [...new Set([0, a, b, 1])].sort((p, q) => p - q),
|
|
193
|
+
vals = keys.map((k) => (k >= a && k < b ? 'inline' : 'none'));
|
|
194
|
+
const sticks = f.sticks
|
|
195
|
+
.map(
|
|
196
|
+
(e) =>
|
|
197
|
+
`<polyline points="${e.pts.map((p) => `${fx(p[0])},${fz(p[2])}`).join(' ')}" fill="none" stroke="${e.stance ? '#2f6fb3' : '#e07a1f'}" stroke-width="${fmt(stroke)}" stroke-linecap="round" stroke-linejoin="round"/><circle cx="${fx(e.pts[2][0])}" cy="${fz(e.pts[2][2])}" r="${fmt(stroke * 1.1)}" fill="${e.stance ? '#2f6fb3' : '#e07a1f'}"/>`,
|
|
198
|
+
)
|
|
199
|
+
.join('');
|
|
200
|
+
const down = f.sticks.filter((e) => e.stance).map((e) => e.foot),
|
|
201
|
+
pts = hull2D(down.map((p) => [p[0], p[1]]));
|
|
202
|
+
const support =
|
|
203
|
+
pts.length > 1
|
|
204
|
+
? `<polygon points="${pts.map(([x, y]) => `${fx(x)},${fy(y)}`).join(' ')}" fill="#2f6fb333" stroke="#2f6fb3" stroke-width="${fmt(stroke / 2)}"/>`
|
|
205
|
+
: '';
|
|
206
|
+
const feet = f.sticks
|
|
207
|
+
.map(
|
|
208
|
+
(e) =>
|
|
209
|
+
`<circle cx="${fx(e.foot[0])}" cy="${fy(e.foot[1])}" r="${fmt(stroke)}" fill="${e.stance ? '#2f6fb3' : '#e07a1f'}"/>`,
|
|
210
|
+
)
|
|
211
|
+
.join('');
|
|
212
|
+
const text = `${fmt(f.time)} s of ${fmt(gait.period)} s${Number.isFinite(f.margin) ? `, ${fmt(f.margin)} mm of balance to spare` : ''}`;
|
|
213
|
+
return `<g display="${i ? 'none' : 'inline'}"><animate attributeName="display" values="${vals.join(';')}" keyTimes="${keys.join(';')}" dur="${dur}" calcMode="discrete" repeatCount="indefinite"/>${sticks}${support}${feet}<text x="${fmt(pad)}" y="${fmt(cap * 0.6)}" font-family="system-ui, sans-serif" font-size="${fmt(pad * 0.7)}" fill="#333">${escape(text)}</text></g>`;
|
|
214
|
+
})
|
|
215
|
+
.join('\n');
|
|
100
216
|
const ground = `<line x1="${fmt(pad)}" y1="${fz(-gait.height)}" x2="${fmt(W - pad)}" y2="${fz(-gait.height)}" stroke="#555" stroke-width="${fmt(stroke / 2)}"/>`;
|
|
101
217
|
const tag = `<text x="${fmt(pad)}" y="${fmt(side.h + pad + cap * 1.3)}" font-family="system-ui, sans-serif" font-size="${fmt(pad * 0.7)}" fill="#555">Plan: feet in blue are down, orange in swing; quasi-static, so no momentum is counted</text>`;
|
|
102
218
|
return `<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 ${fmt(W)} ${fmt(H)}" width="900">\n<title>${escape(title)}</title>\n<rect width="${fmt(W)}" height="${fmt(H)}" fill="#fff"/>\n${ground}\n${tag}\n${body}\n</svg>\n`;
|
|
@@ -105,8 +221,16 @@ export function gaitSvg(s, r, { title = '' } = {}) {
|
|
|
105
221
|
const hull2D = (points) => {
|
|
106
222
|
const p = [...points].sort((a, b) => a[0] - b[0] || a[1] - b[1]);
|
|
107
223
|
if (p.length < 3) return p;
|
|
108
|
-
const cross = (o, a, b) => (a[0] - o[0]) * (b[1] - o[1]) - (a[1] - o[1]) * (b[0] - o[0]),
|
|
109
|
-
|
|
110
|
-
|
|
224
|
+
const cross = (o, a, b) => (a[0] - o[0]) * (b[1] - o[1]) - (a[1] - o[1]) * (b[0] - o[0]),
|
|
225
|
+
lo = [],
|
|
226
|
+
hi = [];
|
|
227
|
+
for (const x of p) {
|
|
228
|
+
while (lo.length >= 2 && cross(lo.at(-2), lo.at(-1), x) <= 0) lo.pop();
|
|
229
|
+
lo.push(x);
|
|
230
|
+
}
|
|
231
|
+
for (const x of [...p].reverse()) {
|
|
232
|
+
while (hi.length >= 2 && cross(hi.at(-2), hi.at(-1), x) <= 0) hi.pop();
|
|
233
|
+
hi.push(x);
|
|
234
|
+
}
|
|
111
235
|
return [...lo.slice(0, -1), ...hi.slice(0, -1)];
|
|
112
236
|
};
|