@rulecad/cad 0.8.0 → 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 +24 -10
- package/CHANGELOG.md +404 -0
- package/EXAMPLES.md +40 -38
- package/README.md +193 -67
- package/TUTORIAL.md +2 -2
- package/bin/cad.mjs +2250 -512
- package/lib/animate.mjs +173 -49
- package/lib/assembly.mjs +1847 -434
- 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 +649 -121
- package/lib/drive.mjs +187 -63
- package/lib/edit.mjs +899 -191
- package/lib/errors.mjs +16 -3
- package/lib/explain.mjs +62 -13
- package/lib/fasten.mjs +2702 -507
- package/lib/fittings.mjs +715 -121
- package/lib/fixings.mjs +21 -9
- package/lib/framebuild.mjs +790 -175
- 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 +123 -21
- 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 +2 -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 +1021 -213
- package/lib/motorsvg.mjs +114 -32
- package/lib/names.mjs +3 -1
- package/lib/optimise.mjs +978 -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 +223 -35
- 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 +15 -5
- package/lib/sandbox-hooks.mjs +77 -19
- package/lib/sandbox-run.mjs +117 -18
- package/lib/sandbox.mjs +509 -60
- package/lib/schema.mjs +42 -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 +22 -4
- package/lib/task.mjs +376 -79
- package/lib/versions.mjs +111 -28
- package/lib/wires.mjs +228 -45
- package/lib/workspace.mjs +197 -12
- package/package.json +19 -19
- package/schemas/assembly.schema.json +2 -2
package/lib/schema.mjs
CHANGED
|
@@ -15,7 +15,8 @@ export function schema(name) {
|
|
|
15
15
|
}
|
|
16
16
|
|
|
17
17
|
const typeOf = (v) => (v === null ? 'null' : Array.isArray(v) ? 'array' : Number.isInteger(v) ? 'integer' : typeof v);
|
|
18
|
-
const fits = (v, t) =>
|
|
18
|
+
const fits = (v, t) =>
|
|
19
|
+
t === typeOf(v) || (t === 'number' && typeof v === 'number') || (t === 'integer' && Number.isInteger(v));
|
|
19
20
|
|
|
20
21
|
/**
|
|
21
22
|
* Problems with a value against a schema: [{ path, message }], empty when it's valid.
|
|
@@ -23,8 +24,19 @@ const fits = (v, t) => t === typeOf(v) || (t === 'number' && typeof v === 'numbe
|
|
|
23
24
|
* @returns {{ path: string, message: string }[]}
|
|
24
25
|
*/
|
|
25
26
|
export function validate(value, s, root = s, at = '') {
|
|
26
|
-
const out = [],
|
|
27
|
-
|
|
27
|
+
const out = [],
|
|
28
|
+
here = at || '(top)',
|
|
29
|
+
p = (k) => (at ? `${at}.${k}` : String(k));
|
|
30
|
+
if (s.$ref)
|
|
31
|
+
return validate(
|
|
32
|
+
value,
|
|
33
|
+
s.$ref
|
|
34
|
+
.replace('#/$defs/', '')
|
|
35
|
+
.split('/')
|
|
36
|
+
.reduce((o, k) => o[k], root.$defs),
|
|
37
|
+
root,
|
|
38
|
+
at,
|
|
39
|
+
);
|
|
28
40
|
if (s.anyOf) {
|
|
29
41
|
const each = s.anyOf.map((x) => validate(value, x, root, at));
|
|
30
42
|
// Report the alternative that got furthest (the fewest problems), so a near miss says what's wrong with it
|
|
@@ -34,23 +46,37 @@ export function validate(value, s, root = s, at = '') {
|
|
|
34
46
|
}
|
|
35
47
|
if (s.type) {
|
|
36
48
|
const types = [].concat(s.type);
|
|
37
|
-
if (!types.some((t) => fits(value, t)))
|
|
49
|
+
if (!types.some((t) => fits(value, t)))
|
|
50
|
+
return [{ path: here, message: `should be ${types.join(' or ')}, not ${typeOf(value)}` }];
|
|
38
51
|
}
|
|
39
|
-
if (s.enum && !s.enum.includes(value))
|
|
52
|
+
if (s.enum && !s.enum.includes(value))
|
|
53
|
+
out.push({
|
|
54
|
+
path: here,
|
|
55
|
+
message: `should be one of ${s.enum.map((x) => JSON.stringify(x)).join(', ')} (got ${JSON.stringify(value)})`,
|
|
56
|
+
});
|
|
40
57
|
// (a pattern with a description says what it wants in words; one without, the pattern itself)
|
|
41
|
-
if (s.pattern && typeof value === 'string' && !new RegExp(s.pattern).test(value))
|
|
58
|
+
if (s.pattern && typeof value === 'string' && !new RegExp(s.pattern).test(value))
|
|
59
|
+
out.push({ path: here, message: `"${value}" isn't in the expected form: ${s.description || s.pattern}` });
|
|
42
60
|
if (typeOf(value) === 'object') {
|
|
43
61
|
for (const k of s.required || []) if (!(k in value)) out.push({ path: here, message: `needs "${k}"` });
|
|
44
62
|
const props = s.properties || {};
|
|
45
63
|
for (const [k, v] of Object.entries(value)) {
|
|
46
64
|
if (props[k]) out.push(...validate(v, props[k], root, p(k)));
|
|
47
|
-
else if (s.additionalProperties === false) {
|
|
48
|
-
|
|
65
|
+
else if (s.additionalProperties === false) {
|
|
66
|
+
const guess = near(k, Object.keys(props));
|
|
67
|
+
out.push({
|
|
68
|
+
path: p(k),
|
|
69
|
+
message: `not allowed here${guess ? ` (did you mean "${guess}"?)` : ` (allowed: ${Object.keys(props).join(', ')})`}`,
|
|
70
|
+
});
|
|
71
|
+
} else if (s.additionalProperties && typeof s.additionalProperties === 'object')
|
|
72
|
+
out.push(...validate(v, s.additionalProperties, root, p(k)));
|
|
49
73
|
}
|
|
50
74
|
}
|
|
51
75
|
if (Array.isArray(value)) {
|
|
52
|
-
if (s.minItems != null && value.length < s.minItems)
|
|
53
|
-
|
|
76
|
+
if (s.minItems != null && value.length < s.minItems)
|
|
77
|
+
out.push({ path: here, message: `needs at least ${s.minItems} entries` });
|
|
78
|
+
if (s.maxItems != null && value.length > s.maxItems)
|
|
79
|
+
out.push({ path: here, message: `takes at most ${s.maxItems} entries` });
|
|
54
80
|
value.forEach((v, i) => {
|
|
55
81
|
const item = s.prefixItems?.[i] || s.items;
|
|
56
82
|
if (item) out.push(...validate(v, item, root, `${at}[${i}]`));
|
|
@@ -61,5 +87,10 @@ export function validate(value, s, root = s, at = '') {
|
|
|
61
87
|
|
|
62
88
|
/** Problems with a file's JSON as findings (code schema), for cad check. @param {any} json @param {'object' | 'assembly' | 'project' | 'rules' | 'layout' | 'problem'} kind @param {string} file */
|
|
63
89
|
export function schemaFindings(json, kind, file) {
|
|
64
|
-
return validate(json, schema(kind)).map((x) => ({
|
|
90
|
+
return validate(json, schema(kind)).map((x) => ({
|
|
91
|
+
level: 'fail',
|
|
92
|
+
text: `${file}: ${x.path}: ${x.message}`,
|
|
93
|
+
code: 'schema',
|
|
94
|
+
refs: { file, path: x.path },
|
|
95
|
+
}));
|
|
65
96
|
}
|
package/lib/seats.mjs
CHANGED
|
@@ -4,125 +4,303 @@ import { createRequire } from 'node:module';
|
|
|
4
4
|
|
|
5
5
|
const require = createRequire(import.meta.url);
|
|
6
6
|
const n3 = (x, d = 3) => String(Number(x.toFixed(d)));
|
|
7
|
-
const sub = (a, b) => [a[0] - b[0], a[1] - b[1], a[2] - b[2]],
|
|
7
|
+
const sub = (a, b) => [a[0] - b[0], a[1] - b[1], a[2] - b[2]],
|
|
8
|
+
dot = (a, b) => a[0] * b[0] + a[1] * b[1] + a[2] * b[2];
|
|
8
9
|
const cross = (a, b) => [a[1] * b[2] - a[2] * b[1], a[2] * b[0] - a[0] * b[2], a[0] * b[1] - a[1] * b[0]];
|
|
9
|
-
const unit = (v) => {
|
|
10
|
+
const unit = (v) => {
|
|
11
|
+
const l = Math.hypot(...v);
|
|
12
|
+
return v.map((c) => c / l);
|
|
13
|
+
};
|
|
10
14
|
|
|
11
15
|
// Coordinates about an axis: z along it from O, x and y across it
|
|
12
16
|
export function axisFrame(O, Z) {
|
|
13
|
-
const z = unit(Z),
|
|
14
|
-
|
|
17
|
+
const z = unit(Z),
|
|
18
|
+
seed = Math.abs(z[0]) < 0.9 ? [1, 0, 0] : [0, 1, 0],
|
|
19
|
+
x = unit(cross(seed, z)),
|
|
20
|
+
y = cross(z, x);
|
|
21
|
+
return (p) => {
|
|
22
|
+
const q = sub(p, O);
|
|
23
|
+
return [dot(q, x), dot(q, y), dot(q, z)];
|
|
24
|
+
};
|
|
15
25
|
}
|
|
16
26
|
// A slice across the axis at z, as 2D segments
|
|
17
27
|
export function sliceAt(tris, z) {
|
|
18
28
|
const segs = [];
|
|
19
29
|
for (const t of tris) {
|
|
20
30
|
const c = [];
|
|
21
|
-
for (let i = 0; i < 3; i++) {
|
|
31
|
+
for (let i = 0; i < 3; i++) {
|
|
32
|
+
const a = t[i],
|
|
33
|
+
b = t[(i + 1) % 3];
|
|
34
|
+
if ((a[2] - z) * (b[2] - z) < 0) {
|
|
35
|
+
const u = (z - a[2]) / (b[2] - a[2]);
|
|
36
|
+
c.push([a[0] + u * (b[0] - a[0]), a[1] + u * (b[1] - a[1])]);
|
|
37
|
+
}
|
|
38
|
+
}
|
|
22
39
|
if (c.length === 2) segs.push(c);
|
|
23
40
|
}
|
|
24
41
|
return segs;
|
|
25
42
|
}
|
|
26
43
|
// How far out from the axis a ray crosses the slice's walls
|
|
27
44
|
export function rayHits(segs, ang) {
|
|
28
|
-
const dx = Math.cos(ang),
|
|
45
|
+
const dx = Math.cos(ang),
|
|
46
|
+
dy = Math.sin(ang),
|
|
47
|
+
out = [];
|
|
29
48
|
for (const [p, q] of segs) {
|
|
30
|
-
const ex = q[0] - p[0],
|
|
49
|
+
const ex = q[0] - p[0],
|
|
50
|
+
ey = q[1] - p[1],
|
|
51
|
+
den = dx * ey - dy * ex;
|
|
31
52
|
if (Math.abs(den) < 1e-12) continue;
|
|
32
|
-
const t = (p[0] * ey - p[1] * ex) / den,
|
|
53
|
+
const t = (p[0] * ey - p[1] * ex) / den,
|
|
54
|
+
u = (p[0] * dy - p[1] * dx) / den;
|
|
33
55
|
if (t > 1e-6 && u >= 0 && u < 1) out.push(t);
|
|
34
56
|
}
|
|
35
57
|
return out.sort((a, b) => a - b);
|
|
36
58
|
}
|
|
37
|
-
const RAYS = 48,
|
|
59
|
+
const RAYS = 48,
|
|
60
|
+
FACETS = 0.02; // mm: what a round drawn in facets is short of its true size
|
|
38
61
|
// At one slice: is the axis in solid (a pin) or in a space (a bore), and the first wall out, each way round
|
|
39
62
|
function round(segs) {
|
|
40
63
|
if (segs.length < 3) return null;
|
|
41
|
-
let solid = 0,
|
|
42
|
-
|
|
64
|
+
let solid = 0,
|
|
65
|
+
bore = 0;
|
|
66
|
+
const first = [];
|
|
67
|
+
for (let k = 0; k < RAYS; k++) {
|
|
68
|
+
const h = rayHits(segs, ((k + 0.37) * 2 * Math.PI) / RAYS);
|
|
69
|
+
if (!h.length) return null;
|
|
70
|
+
h.length % 2 ? solid++ : bore++;
|
|
71
|
+
first.push(h[0]);
|
|
72
|
+
}
|
|
43
73
|
return { pin: solid > bore, first };
|
|
44
74
|
}
|
|
45
|
-
const span = (tris, r) => {
|
|
75
|
+
const span = (tris, r) => {
|
|
76
|
+
let lo = Infinity,
|
|
77
|
+
hi = -Infinity;
|
|
78
|
+
for (const t of tris)
|
|
79
|
+
for (const p of t)
|
|
80
|
+
if (Math.hypot(p[0], p[1]) < r) {
|
|
81
|
+
lo = Math.min(lo, p[2]);
|
|
82
|
+
hi = Math.max(hi, p[2]);
|
|
83
|
+
}
|
|
84
|
+
return [lo, hi];
|
|
85
|
+
};
|
|
46
86
|
|
|
47
87
|
// The running gap of a revolute: where one side is a pin and the other a bore round it, the least gap each side as drawn
|
|
48
88
|
// (over a few slices along the length they share) and how far along it runs. null: nothing there turns on a pin
|
|
49
89
|
export function runningGap(aTris, bTris) {
|
|
50
|
-
const reach = 40,
|
|
90
|
+
const reach = 40,
|
|
91
|
+
[la, ha] = span(aTris, reach),
|
|
92
|
+
[lb, hb] = span(bTris, reach),
|
|
93
|
+
lo = Math.max(la, lb),
|
|
94
|
+
hi = Math.min(ha, hb);
|
|
51
95
|
if (!(hi - lo > 0.2)) return null;
|
|
52
|
-
let least = null,
|
|
96
|
+
let least = null,
|
|
97
|
+
along = 0,
|
|
98
|
+
step = (hi - lo) / 8;
|
|
53
99
|
for (let k = 0; k < 8; k++) {
|
|
54
|
-
const z = lo + step * (k + 0.5),
|
|
100
|
+
const z = lo + step * (k + 0.5),
|
|
101
|
+
A = round(sliceAt(aTris, z)),
|
|
102
|
+
B = round(sliceAt(bTris, z));
|
|
55
103
|
if (!A || !B || A.pin === B.pin) continue;
|
|
56
|
-
const pin = A.pin ? A : B,
|
|
104
|
+
const pin = A.pin ? A : B,
|
|
105
|
+
bore = A.pin ? B : A;
|
|
57
106
|
// A real pin is round about the axis: the widest and narrowest of it agree
|
|
58
107
|
if (Math.max(...pin.first) - Math.min(...pin.first) > 0.5) continue;
|
|
59
108
|
const gap = Math.min(...bore.first.map((r, i) => r - pin.first[i]));
|
|
60
109
|
if (gap > 2) continue; // room, not a running fit
|
|
61
110
|
along += step;
|
|
62
|
-
if (least == null || gap < least.gap)
|
|
111
|
+
if (least == null || gap < least.gap)
|
|
112
|
+
least = { gap, z, pin: Math.max(...pin.first), bore: Math.min(...bore.first), pinOn: A.pin ? 'a' : 'b' };
|
|
63
113
|
}
|
|
64
114
|
return least && { ...least, length: along };
|
|
65
115
|
}
|
|
66
116
|
|
|
67
117
|
// What the project prints on, for the fits to hold a gap against: a rule set the assembly reads, or the kit's default
|
|
68
118
|
export function printerRules(s) {
|
|
69
|
-
const pick = (name) => {
|
|
119
|
+
const pick = (name) => {
|
|
120
|
+
try {
|
|
121
|
+
return Object.fromEntries(
|
|
122
|
+
Object.entries(require(`@rulecad/rules/${name}.json`).rules).map(([k, r]) => [k, r.value]),
|
|
123
|
+
);
|
|
124
|
+
} catch {
|
|
125
|
+
return null;
|
|
126
|
+
}
|
|
127
|
+
};
|
|
70
128
|
return { ...pick('x1c'), ...(s.values?.x1c && typeof s.values.x1c === 'object' ? s.values.x1c : {}) };
|
|
71
129
|
}
|
|
72
130
|
|
|
73
131
|
// joint.running: for each revolute, the gap where its child turns on a pin or in a bore. A printed bore comes out
|
|
74
132
|
// hole_comp smaller across, so half of that comes off the gap each side; what's left is held against the printer's fit
|
|
75
133
|
export function runningChecks(s, f, { axisOf, placeItems, jointValues, mul }) {
|
|
76
|
-
const motion = s.motion;
|
|
77
|
-
|
|
78
|
-
const
|
|
134
|
+
const motion = s.motion;
|
|
135
|
+
if (!motion?.joints?.length) return;
|
|
136
|
+
const worlds = placeItems(motion, s.jointValues ?? jointValues(motion, motion.pose ?? undefined)),
|
|
137
|
+
ids = motion.items.map((x) => x[0]);
|
|
138
|
+
const P = printerRules(s),
|
|
139
|
+
fit = P.fit ?? 0.2,
|
|
140
|
+
comp = P.hole_comp ?? 0.1;
|
|
79
141
|
const refs = new Set(s.objects.filter((o) => o.role === 'reference').map((o) => String(o.id).split('.')[0]));
|
|
80
142
|
const partsOf = (id) => s.parts.filter((p) => p.item === id || p.leaf === id);
|
|
81
143
|
for (const j of motion.joints) {
|
|
82
144
|
if (j.type !== 'revolute' || j.parent < 0) continue;
|
|
83
|
-
const a = ids[j.parent],
|
|
145
|
+
const a = ids[j.parent],
|
|
146
|
+
b = ids[j.child];
|
|
84
147
|
if (refs.has(a) || refs.has(b)) continue; // a bought part's seat is fit.seat's business
|
|
85
|
-
const pa = partsOf(a),
|
|
148
|
+
const pa = partsOf(a),
|
|
149
|
+
pb = partsOf(b);
|
|
86
150
|
if (!pa.length || !pb.length) continue;
|
|
87
|
-
const { O, Z } = axisOf(motion, worlds, j, mul),
|
|
151
|
+
const { O, Z } = axisOf(motion, worlds, j, mul),
|
|
152
|
+
to = axisFrame(O, Z),
|
|
153
|
+
g = runningGap(
|
|
154
|
+
pa.flatMap((p) => p.triangles).map((t) => t.map(to)),
|
|
155
|
+
pb.flatMap((p) => p.triangles).map((t) => t.map(to)),
|
|
156
|
+
);
|
|
88
157
|
if (!g) continue;
|
|
89
|
-
const printed = g.gap - comp / 2,
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
158
|
+
const printed = g.gap - comp / 2,
|
|
159
|
+
at = O.map((c, i) => c + unit(Z)[i] * g.z),
|
|
160
|
+
pin = g.pinOn === 'a' ? a : b,
|
|
161
|
+
bore = g.pinOn === 'a' ? b : a,
|
|
162
|
+
refsOut = { joint: j.id, pin, bore };
|
|
163
|
+
const values = { drawn: g.gap, printed, fit, length: g.length },
|
|
164
|
+
words = `${bore} on ${pin}'s ${n3(g.pin * 2, 2)} mm pin: ${n3(g.gap)} mm each side as drawn, about ${n3(printed)} mm printed`;
|
|
165
|
+
if (printed <= 0)
|
|
166
|
+
f(
|
|
167
|
+
'fail',
|
|
168
|
+
`${j.id}: ${words} (a printed bore comes out ${comp} mm small across): it won't turn. The bore wants ${n3(2 * (g.pin + fit) + comp, 2)} mm`,
|
|
169
|
+
`${j.id}: no running gap`,
|
|
170
|
+
{ code: 'joint.running', at, refs: refsOut, values },
|
|
171
|
+
);
|
|
172
|
+
else if (printed < fit - FACETS)
|
|
173
|
+
f(
|
|
174
|
+
'warn',
|
|
175
|
+
`${j.id}: ${words}, under the printer's ${fit} mm fit: expect it to bind. The bore wants ${n3(2 * (g.pin + fit) + comp, 2)} mm`,
|
|
176
|
+
`${j.id}: tight on its pin`,
|
|
177
|
+
{ code: 'joint.running', at, refs: refsOut, values },
|
|
178
|
+
);
|
|
93
179
|
else f('pass', `${j.id}: ${words}`, null, { code: 'joint.running', at, refs: refsOut, values });
|
|
94
180
|
}
|
|
95
181
|
}
|
|
96
182
|
|
|
97
183
|
// fit.seat: a printed pocket against the bought bearing in it, read from the part as drawn, so a pocket drawn by hand is
|
|
98
184
|
// caught as well as one from bearingSeat. { "a": "b1", "b": "housing", "seat": "press" | "slip" | clearance in mm }
|
|
99
|
-
export function seatFit(x, s, f, { placeItems, jointValues,
|
|
100
|
-
const top = (n) => String(n).split(/[.@]/)[0],
|
|
101
|
-
|
|
102
|
-
|
|
185
|
+
export function seatFit(x, s, f, { placeItems, jointValues, seatSize }) {
|
|
186
|
+
const top = (n) => String(n).split(/[.@]/)[0],
|
|
187
|
+
o = s.objects.find((y) => y.bought?.part === 'bearing' && (y.id === top(x.a) || y.id === top(x.b))),
|
|
188
|
+
label = x.note || `${x.a} in ${x.b}`,
|
|
189
|
+
code = 'fit.seat';
|
|
190
|
+
if (!o)
|
|
191
|
+
return f(
|
|
192
|
+
'fail',
|
|
193
|
+
`${label}: a seat holds a bought bearing, and neither ${x.a} nor ${x.b} is one`,
|
|
194
|
+
`${label}: no bearing`,
|
|
195
|
+
{ code },
|
|
196
|
+
);
|
|
197
|
+
const other = top(x.a) === o.id ? top(x.b) : top(x.a),
|
|
198
|
+
parts = s.parts.filter((p) => p.item === other || p.leaf === other);
|
|
103
199
|
if (!parts.length) return f('fail', `${label}: no part "${other}"`, null, { code });
|
|
104
|
-
const motion = s.motion,
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
const
|
|
108
|
-
|
|
200
|
+
const motion = s.motion,
|
|
201
|
+
ids = motion.items.map((y) => y[0]),
|
|
202
|
+
W = placeItems(motion, s.jointValues ?? jointValues(motion, motion.pose ?? undefined))[ids.indexOf(o.id)];
|
|
203
|
+
const inv = (p) => {
|
|
204
|
+
const q = [p[0] - W[3], p[1] - W[7], p[2] - W[11]];
|
|
205
|
+
return [
|
|
206
|
+
W[0] * q[0] + W[4] * q[1] + W[8] * q[2],
|
|
207
|
+
W[1] * q[0] + W[5] * q[1] + W[9] * q[2],
|
|
208
|
+
W[2] * q[0] + W[6] * q[1] + W[10] * q[2],
|
|
209
|
+
];
|
|
210
|
+
};
|
|
211
|
+
const tris = parts.flatMap((p) => p.triangles).map((t) => t.map(inv)),
|
|
212
|
+
v = o.built.values,
|
|
213
|
+
w = v.width,
|
|
214
|
+
R = v.outer_diameter / 2,
|
|
215
|
+
r = v.bore / 2;
|
|
216
|
+
const printer = printerRules(s),
|
|
217
|
+
want = seatSize(v, { fit: x.seat === true ? 'press' : x.seat, printer }),
|
|
218
|
+
refs = { item: o.id, part: other };
|
|
219
|
+
const firstWall = (z) => {
|
|
220
|
+
const segs = sliceAt(tris, z);
|
|
221
|
+
if (segs.length < 3) return null;
|
|
222
|
+
const h = [];
|
|
223
|
+
for (let k = 0; k < RAYS; k++) {
|
|
224
|
+
const a = rayHits(segs, ((k + 0.37) * 2 * Math.PI) / RAYS);
|
|
225
|
+
if (!a.length) return null;
|
|
226
|
+
h.push(a[0]);
|
|
227
|
+
}
|
|
228
|
+
return h;
|
|
229
|
+
};
|
|
109
230
|
const mid = firstWall(w / 2);
|
|
110
|
-
if (!mid)
|
|
111
|
-
|
|
231
|
+
if (!mid)
|
|
232
|
+
return f('fail', `${label}: halfway along ${o.bought.set}, ${other} doesn't go round it`, `${label}: no seat`, {
|
|
233
|
+
code,
|
|
234
|
+
refs,
|
|
235
|
+
});
|
|
236
|
+
const drawn = 2 * Math.max(...mid),
|
|
237
|
+
diff = drawn - want.pocket,
|
|
238
|
+
values = { drawn, wanted: want.pocket, difference: diff, comp: want.comp, clearance: want.clearance };
|
|
112
239
|
const inMaterial = 2 * Math.min(...mid) < 2 * r + 0.1;
|
|
113
|
-
if (inMaterial)
|
|
240
|
+
if (inMaterial)
|
|
241
|
+
return f(
|
|
242
|
+
'fail',
|
|
243
|
+
`${label}: ${other} is solid where the bearing goes (the wall is ${n3(Math.min(...mid), 2)} mm from its axis, inside the ${v.bore} mm bore)`,
|
|
244
|
+
`${label}: no pocket`,
|
|
245
|
+
{ code, refs, values },
|
|
246
|
+
);
|
|
114
247
|
const say = `${o.bought.set} (${n3(2 * R, 2)} mm) in a pocket drawn ${n3(drawn, 3)} mm`;
|
|
115
|
-
if (Math.abs(diff) > 0.15)
|
|
116
|
-
|
|
117
|
-
|
|
248
|
+
if (Math.abs(diff) > 0.15)
|
|
249
|
+
f(
|
|
250
|
+
'fail',
|
|
251
|
+
`${label}: ${say}, and a ${typeof want.fit === 'string' ? want.fit : `${want.fit} mm`} fit on this printer wants ${n3(want.pocket, 3)} mm: ${n3(Math.abs(diff), 2)} mm too ${diff < 0 ? 'small: it will not press in' : 'big: it will rattle'}`,
|
|
252
|
+
`${label}: seat ${diff < 0 ? 'small' : 'big'}`,
|
|
253
|
+
{ code, refs, values },
|
|
254
|
+
);
|
|
255
|
+
else if (Math.abs(diff) > 0.05)
|
|
256
|
+
f(
|
|
257
|
+
'warn',
|
|
258
|
+
`${label}: ${say}, ${n3(diff, 3)} mm from the ${n3(want.pocket, 3)} mm a ${typeof want.fit === 'string' ? want.fit : `${want.fit} mm`} fit wants`,
|
|
259
|
+
`${label}: seat off`,
|
|
260
|
+
{ code, refs, values },
|
|
261
|
+
);
|
|
262
|
+
else
|
|
263
|
+
f(
|
|
264
|
+
'pass',
|
|
265
|
+
`${label}: ${say}, a ${typeof want.fit === 'string' ? want.fit : `${want.fit} mm`} fit (printed about ${n3(want.clearance, 3)} mm)`,
|
|
266
|
+
null,
|
|
267
|
+
{ code, refs, values },
|
|
268
|
+
);
|
|
118
269
|
// How much of the race the wall holds, and what stops it
|
|
119
|
-
const levels = 9,
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
270
|
+
const levels = 9,
|
|
271
|
+
held =
|
|
272
|
+
Array.from({ length: levels }, (_, k) => firstWall((w * (k + 0.5)) / levels)).filter(
|
|
273
|
+
(h) => h && Math.min(...h) < R + 0.5,
|
|
274
|
+
).length / levels;
|
|
275
|
+
if (held < 0.8)
|
|
276
|
+
f(
|
|
277
|
+
'warn',
|
|
278
|
+
`${label}: the pocket holds only ${n3(held * w, 1)} mm of the ${w} mm race: the bearing can tip`,
|
|
279
|
+
`${label}: shallow`,
|
|
280
|
+
{ code: 'fit.seat', refs, values: { held: held * w, width: w } },
|
|
281
|
+
);
|
|
282
|
+
const ledges = [firstWall(-0.3), firstWall(w + 0.3)]
|
|
283
|
+
.map((h) => (h ? Math.min(...h) : null))
|
|
284
|
+
.filter((h) => h != null && h < R - 0.1);
|
|
285
|
+
if (!ledges.length)
|
|
286
|
+
f('warn', `${label}: nothing stops the bearing at either face: draw a lip`, `${label}: no lip`, {
|
|
287
|
+
code: 'fit.seat',
|
|
288
|
+
refs,
|
|
289
|
+
});
|
|
123
290
|
else {
|
|
124
291
|
const lip = Math.max(...ledges);
|
|
125
|
-
if (lip < r + (R - r) / 2)
|
|
126
|
-
|
|
292
|
+
if (lip < r + (R - r) / 2)
|
|
293
|
+
f(
|
|
294
|
+
'fail',
|
|
295
|
+
`${label}: the lip comes in to ${n3(2 * lip, 2)} mm across, onto the inner race (which turns): it wants ${n3(2 * r + (R - r), 2)} mm or more`,
|
|
296
|
+
`${label}: lip on inner race`,
|
|
297
|
+
{ code: 'fit.seat', refs, values: { lip: 2 * lip } },
|
|
298
|
+
);
|
|
299
|
+
else
|
|
300
|
+
f('pass', `${label}: a ${n3(R - lip, 2)} mm lip stops the outer race and clears the inner`, null, {
|
|
301
|
+
code: 'fit.seat',
|
|
302
|
+
refs,
|
|
303
|
+
values: { lip: 2 * lip },
|
|
304
|
+
});
|
|
127
305
|
}
|
|
128
306
|
}
|