@rulecad/cad 0.7.36 → 0.7.37
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/EXAMPLES.md +3 -1
- package/README.md +4 -0
- package/lib/assembly.mjs +24 -0
- package/package.json +1 -1
- package/schemas/assembly.schema.json +2 -0
package/EXAMPLES.md
CHANGED
|
@@ -520,6 +520,7 @@ gap, and says whether the axle is where the gears need it.
|
|
|
520
520
|
{ "id": "slide", "type": "prismatic", "parent": "rail.track", "child": "rack.slide", "min": -100, "max": 100,
|
|
521
521
|
"mesh": { "with": "knob", "module": "pinion.module", "teeth": ["pinion.teeth", "rack.teeth"], "shift": ["pinion.shift", 0] } }
|
|
522
522
|
],
|
|
523
|
+
"fits": [{ "a": "pinion", "b": "rail", "engage": "pinion.width", "note": "The pinion down its axle" }],
|
|
523
524
|
"poses": { "home": { "knob": 0 }, "out": { "knob": 150 } }
|
|
524
525
|
}
|
|
525
526
|
```
|
|
@@ -803,7 +804,8 @@ are built with Manifold's booleans (`"engine": "manifold"`): closed solids, so t
|
|
|
803
804
|
"module": "ring.module", "teeth": ["sun.teeth", "p0.teeth", "ring.teeth"] }
|
|
804
805
|
],
|
|
805
806
|
"fits": [{ "a": "handle", "b": "carrier", "min": "0 - carrier.fit * 2", "note": "The handle's peg pressed into the arm" },
|
|
806
|
-
{ "a": "ring", "b": "case", "fastens": true, "note": "The ring held still on the case by its two push pins" }
|
|
807
|
+
{ "a": "ring", "b": "case", "fastens": true, "note": "The ring held still on the case by its two push pins" },
|
|
808
|
+
{ "a": "handle", "b": "carrier", "engage": "carrier.t", "note": "The handle's peg through the arm" }],
|
|
807
809
|
"poses": { "rest": { "crank": 0 }, "quarter": { "crank": 90 } }
|
|
808
810
|
}
|
|
809
811
|
```
|
package/README.md
CHANGED
|
@@ -385,6 +385,10 @@ then y, then z, as `rotate` does.
|
|
|
385
385
|
fastened to the first through fits with `"fastens": true` (the pins, screws or press that do it, named in the fit's
|
|
386
386
|
note): `{ "a": "ring", "b": "case", "fastens": true, "note": "Two push pins" }`. A part only placed somewhere is
|
|
387
387
|
said (`assembly.loose`): a ring gear resting on its case would turn with its planets.
|
|
388
|
+
- **Onto a shaft:** `{ "a": "arm", "b": "crank", "engage": "arm.thick" }` checks that a part slid onto a shaft, a pin or a
|
|
389
|
+
peg goes that far onto it along the joint between them (`fit.engage`), not just against its end: an arm resting on
|
|
390
|
+
a shaft's end touches it face to face, as a seated one does, and nothing overlaps either way, so only this tells
|
|
391
|
+
them apart. It looks within `radius` (10 mm) of the joint's axis.
|
|
388
392
|
- **Loops:** each item has one joint to its parent. Where parts join in a ring (two links between the same two
|
|
389
393
|
parts), let joints place every part, then name the meeting that closes the ring in `loops`. The check measures it
|
|
390
394
|
in every pose: `"loops": [{ "a": "link_l.top", "b": "mount_l.axis", "label": "Left pivot lines up" }]`. Its anchors
|
package/lib/assembly.mjs
CHANGED
|
@@ -696,6 +696,7 @@ export function checkAssembly(s) {
|
|
|
696
696
|
for (const x of s.fits) {
|
|
697
697
|
if (x.poses && !x.poses.includes(s.pose)) continue; // a fit for some poses only: the folded screen over the keys
|
|
698
698
|
if (x.holes) { holesFit(x); continue; }
|
|
699
|
+
if (x.engage != null) { engageFit(x); continue; }
|
|
699
700
|
const A = pickIn(x.a, x), key = x.note || `${x.a} / ${x.b}`;
|
|
700
701
|
const lo = x.min != null ? x.num(x.min) : -Infinity, hi = x.max != null ? x.num(x.max) : Infinity;
|
|
701
702
|
const reach = Math.max(2, ...[lo, hi].filter(Number.isFinite)) + 1; // look past the range, so a gap near it is measured
|
|
@@ -729,6 +730,29 @@ export function checkAssembly(s) {
|
|
|
729
730
|
{ code: 'fit', values: { ...(worst.gap < 0 ? { overlap: -worst.gap } : { gap: worst.gap }), min: lo, max: hi, inRange: results.filter((r) => r.ok).length, copies: results.length },
|
|
730
731
|
refs: { a: x.a, b: x.b, label: x.label, ...(s.pose ? { pose: s.pose } : {}), outOfRange: results.filter((r) => !r.ok).map((r) => r.id), ...where }, ...(worst.at ? { at: { lo: worst.at, hi: worst.at } } : {}) });
|
|
731
732
|
}
|
|
733
|
+
// Engage fits: a part slid onto a shaft, a pin or a peg goes onto it, not just against its end. Along the axis of the
|
|
734
|
+
// joint between them, each part's material near the axis (within radius, 10 mm) spans a stretch; how far the two
|
|
735
|
+
// stretches overlap is how far one is on the other. An arm resting on a shaft's end touches it face to face, as a
|
|
736
|
+
// seated one does, and nothing overlaps either way: only this tells them apart.
|
|
737
|
+
function engageFit(x) {
|
|
738
|
+
const top = (n) => String(n).split(/[.@]/)[0], ids = s.motion?.items.map((i) => i[0]) || [], a = top(x.a), b = top(x.b), label = x.note || `${x.a} onto ${x.b}`;
|
|
739
|
+
const j = (s.motion?.joints || []).find((jt) => { const pair = [ids[jt.child], jt.parent < 0 ? null : ids[jt.parent]]; return pair.includes(a) && pair.includes(b); });
|
|
740
|
+
if (!j) return f('fail', `${label}: no joint between ${a} and ${b} to measure along (engage measures along the joint that holds one on the other)`, null, { code: 'fit.engage', refs: { a: x.a, b: x.b } });
|
|
741
|
+
const worlds = placeItems(s.motion, s.jointValues), P = mul(j.parent < 0 ? [1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0] : worlds[j.parent], j.a);
|
|
742
|
+
const O = [P[3], P[7], P[11]], Z = [P[2], P[6], P[10]], r = x.radius != null ? x.num(x.radius) : 10, need = x.num(x.engage);
|
|
743
|
+
const span = (parts) => {
|
|
744
|
+
let lo = Infinity, hi = -Infinity;
|
|
745
|
+
for (const p of parts) for (const t of p.triangles) for (const v of t) {
|
|
746
|
+
const d = [v[0] - O[0], v[1] - O[1], v[2] - O[2]], along = d[0] * Z[0] + d[1] * Z[1] + d[2] * Z[2];
|
|
747
|
+
if (Math.hypot(d[0] - along * Z[0], d[1] - along * Z[1], d[2] - along * Z[2]) <= r) { lo = Math.min(lo, along); hi = Math.max(hi, along); }
|
|
748
|
+
}
|
|
749
|
+
return [lo, hi];
|
|
750
|
+
};
|
|
751
|
+
const [la, ha] = span(pickIn(x.a, x)), [lb, hb] = span(pickIn(x.b, x)), on = Math.max(0, Math.min(ha, hb) - Math.max(la, lb));
|
|
752
|
+
const ok = on >= need - 1e-3; // (flush is on: a hair under, in the floating point, is not short)
|
|
753
|
+
f(ok ? 'pass' : 'fail', `${label}: ${on > 1e-3 ? `${mm(on)} mm on` : `not on at all (${Math.max(la, lb) - Math.min(ha, hb) < 1e-3 ? 'end to end' : 'apart'})`} along their joint${ok ? '' : `, where it should go ${mm(need)} mm on: its anchor is on the wrong face, or the shaft too short`}`, ok ? null : `${a}: not on ${b}`, { code: 'fit.engage', values: { engaged: on, need }, refs: { a: x.a, b: x.b, joint: j.id } });
|
|
754
|
+
}
|
|
755
|
+
|
|
732
756
|
// Holes fits: each mounting hole's screw path, clear into a hole, with material round it
|
|
733
757
|
function holesFit(x) {
|
|
734
758
|
const A = pick(x.a), B = pick(x.b), label = x.label || `${x.a} into ${x.b}`;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@rulecad/cad",
|
|
3
|
-
"version": "0.7.
|
|
3
|
+
"version": "0.7.37",
|
|
4
4
|
"description": "The cad command: JSCAD designs from traceable rules, checked for printing and fit, versioned by what fits, shared as links and exported as Bambu 3MF.",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"bin": {
|
|
@@ -64,6 +64,8 @@
|
|
|
64
64
|
"properties": {
|
|
65
65
|
"a": { "$ref": "#/$defs/names" },
|
|
66
66
|
"b": { "$ref": "#/$defs/names" },
|
|
67
|
+
"engage": { "$ref": "#/$defs/expr", "description": "a goes at least this far (mm) onto b along the joint between them: a part slid onto a shaft or a pin, not resting on its end" },
|
|
68
|
+
"radius": { "$ref": "#/$defs/expr", "description": "With engage: how near the joint's axis to look (mm, default 10)" },
|
|
67
69
|
"fastens": { "type": "boolean", "description": "a and b are fastened together (pins, screws, a press): what holds a part that has no joint" },
|
|
68
70
|
"min": { "$ref": "#/$defs/expr" },
|
|
69
71
|
"max": { "$ref": "#/$defs/expr" },
|