@rulecad/frames 0.1.7 → 0.1.8

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/beam.d.mts CHANGED
@@ -26,13 +26,16 @@ export function beamModel(profile: Profile | string | object, o?: {
26
26
  * A beam as a solid, lying along z from end a at z = 0. display: 'link' is a plain box of the section's envelope (a
27
27
  * round section a twelve-sided prism): 12 triangles, light enough for a link and an overlap check. 'preview' (the
28
28
  * default) is the true section, every slot, bore and hollow, run the whole length. Each operation is cut from it: a
29
- * mitre from the link too (its envelope changes), the holes, pockets and notches from the preview only.
29
+ * mitre from the link too (its envelope changes), the holes, pockets and notches from the preview only. tracks: a link
30
+ * with its V tracks cut along it (each slot with a track_width: its V mouth, and the opening under it to the cavity's
31
+ * depth), for an overlap check where V-wheels run in them: a rim in its track is clear of it, a rim out of it is not.
30
32
  * @param {Beam | Profile | string | object} m a beam's model, or a profile with { length } as beamModel takes
31
- * @param {{ display?: 'link' | 'preview', length?: number, ends?: any, material?: string, given?: object, cells?: number }} [o]
33
+ * @param {{ display?: 'link' | 'preview', tracks?: boolean, length?: number, ends?: any, material?: string, given?: object, cells?: number }} [o]
32
34
  * @returns {object} a JSCAD geom3, with .model holding beamModel's numbers (its anchors and mass)
33
35
  */
34
36
  export function beam(m: Beam | Profile | string | object, o?: {
35
37
  display?: "link" | "preview";
38
+ tracks?: boolean;
36
39
  length?: number;
37
40
  ends?: any;
38
41
  material?: string;
package/beam.mjs CHANGED
@@ -16,7 +16,7 @@ const mm = (x) => String(+Number(x).toFixed(2));
16
16
  const FACES = ['top', 'bottom', 'front', 'back'];
17
17
  const END_KINDS = ['cut', 'tapped'];
18
18
  const DISPLAYS = ['link', 'preview'];
19
- const OPTIONS = ['length', 'ends', 'ops', 'material', 'given', 'cells', 'display'];
19
+ const OPTIONS = ['length', 'ends', 'ops', 'material', 'given', 'cells', 'display', 'tracks'];
20
20
  const ROUND = ['round-tube', 'round-bar'];
21
21
 
22
22
  /**
@@ -128,9 +128,11 @@ export function beamModel(profile, o = {}) {
128
128
  * A beam as a solid, lying along z from end a at z = 0. display: 'link' is a plain box of the section's envelope (a
129
129
  * round section a twelve-sided prism): 12 triangles, light enough for a link and an overlap check. 'preview' (the
130
130
  * default) is the true section, every slot, bore and hollow, run the whole length. Each operation is cut from it: a
131
- * mitre from the link too (its envelope changes), the holes, pockets and notches from the preview only.
131
+ * mitre from the link too (its envelope changes), the holes, pockets and notches from the preview only. tracks: a link
132
+ * with its V tracks cut along it (each slot with a track_width: its V mouth, and the opening under it to the cavity's
133
+ * depth), for an overlap check where V-wheels run in them: a rim in its track is clear of it, a rim out of it is not.
132
134
  * @param {Beam | Profile | string | object} m a beam's model, or a profile with { length } as beamModel takes
133
- * @param {{ display?: 'link' | 'preview', length?: number, ends?: any, material?: string, given?: object, cells?: number }} [o]
135
+ * @param {{ display?: 'link' | 'preview', tracks?: boolean, length?: number, ends?: any, material?: string, given?: object, cells?: number }} [o]
134
136
  * @returns {object} a JSCAD geom3, with .model holding beamModel's numbers (its anchors and mass)
135
137
  */
136
138
  export function beam(m, o = {}) {
@@ -140,11 +142,28 @@ export function beam(m, o = {}) {
140
142
  let solid;
141
143
  if (display === 'link') solid = ROUND.includes(p.family) ? cylinder({ radius: p.width / 2, height: L, segments: 12, center: [0, 0, L / 2] }) : cuboid({ size: [p.width, p.height, L], center: [0, 0, L / 2] });
142
144
  else solid = extrudeLinear({ height: L }, polygon({ points: outline(p).loops }));
145
+ if (display === 'link' && o.tracks) { const tracks = trackCutters(p, L); if (tracks.length) solid = subtract(solid, ...tracks); }
143
146
  const cuts = opCutters(b, { envelope: display === 'link' }); // (a link keeps its box, cut only where an end is mitred)
144
147
  if (cuts.length) solid = subtract(solid, ...cuts);
145
148
  return Object.assign(solid, { model: b, display });
146
149
  }
147
150
 
151
+ // The free space of each V track along a beam, a little longer than it: the V from just outside the face (its sides
152
+ // carried on out) to the opening, then the opening's width down to the cavity's depth (the cavity is wider still)
153
+ function trackCutters(p, L) {
154
+ const out = [], RAD = Math.PI / 180;
155
+ for (const face of FACES) for (const q of p.faces[face] ?? []) {
156
+ const s = q.slot ? p.slots[q.slot] : null;
157
+ if (!(s?.trackWidth > 0)) continue;
158
+ const t = Math.tan((s.trackAngle / 2) * RAD), deep = (s.trackWidth - s.opening) / 2 / t, D = Math.max(s.cavityDepth, deep), e = 0.5;
159
+ const n = q.normal, u = [-n[1], n[0]], at = (w, v) => [q.at[0] + u[0] * w - n[0] * v, q.at[1] + u[1] * w - n[1] * v];
160
+ let loop = [[-(s.trackWidth / 2 + e * t), -e], [-s.opening / 2, deep], [-s.opening / 2, D], [s.opening / 2, D], [s.opening / 2, deep], [s.trackWidth / 2 + e * t, -e]].map(([w, v]) => at(w, v));
161
+ if (loop.reduce((a, P, i) => { const Q = loop[(i + 1) % loop.length]; return a + P[0] * Q[1] - Q[0] * P[1]; }, 0) < 0) loop = loop.reverse();
162
+ out.push(jscad.transforms.translate([0, 0, -1], extrudeLinear({ height: L + 2 }, polygon({ points: loop }))));
163
+ }
164
+ return out;
165
+ }
166
+
148
167
  /**
149
168
  * An anchor on a beam by its address: 'a' and 'b' are its ends, 'a.1' the first bore in end a, 'top' the first place on
150
169
  * its top face and 'top.2' the second, each with a distance after '@': 'top@120' is 120 mm from end a, 'top@-20' 20 mm
package/bought.d.mts ADDED
@@ -0,0 +1,60 @@
1
+ /**
2
+ * A bought fitting's set as numbers: what it is, the join kinds that take it, its screws and nuts and where each passes
3
+ * into beam a and beam b, the hole a beam needs for it, its sizes for a reference solid, its price, its stiffness with
4
+ * what that rests on, and (given the profiles it goes on) whether it fits them. Bad input is refused by name.
5
+ * @param {string | { name: string, part: string, rules: object }} which the set, by name or as read
6
+ * @param {{ given?: object, profile?: string | object, other?: string | object, join?: string }} [o] profile: b's
7
+ * (the beam a's end meets, or the beam an end cap or foot goes on), other: a's; join: the join kind it is asked for
8
+ * @returns {object} the model: kind 'fitting', bought true, fitting (bracket, plate, hidden, anchor, hinge, end-cap,
9
+ * levelling-foot), set, title, screws, holes, ops, cost, stiffness, findings
10
+ */
11
+ export function boughtFittingModel(which: string | {
12
+ name: string;
13
+ part: string;
14
+ rules: object;
15
+ }, o?: {
16
+ given?: object;
17
+ profile?: string | object;
18
+ other?: string | object;
19
+ join?: string;
20
+ }): object;
21
+ /**
22
+ * A bought fitting's reference solid, drawn from its set's figures in the printed fittings' frames (above): faint, for
23
+ * the picture and the fasten checks' holes, never printed.
24
+ * @param {object} m boughtFittingModel's @param {{ pose?: 'fit' }} [o]
25
+ */
26
+ export function boughtFitting(m: object, o?: {
27
+ pose?: "fit";
28
+ }): (jscad.geometries.geom2.Geom2 | jscad.geometries.geom3.Geom3) & {
29
+ model: any;
30
+ };
31
+ /**
32
+ * What a printed part costs in plastic beside a bought one's price: its grams times the material's cost per kilogram,
33
+ * where the material's set gives one (pla and petg do), else null. @param {number} grams @param {{ name?: string, rules: object }} material
34
+ * @returns {{ value: number, unit: string, rule: string, source: string } | null}
35
+ */
36
+ export function printedCost(grams: number, material: {
37
+ name?: string;
38
+ rules: object;
39
+ }): {
40
+ value: number;
41
+ unit: string;
42
+ rule: string;
43
+ source: string;
44
+ } | null;
45
+ /**
46
+ * The kinds of bought fitting, each with what it is, the join kinds that take it, and whether it goes on a beam's end
47
+ * as an item (an end cap, a foot) rather than in a join.
48
+ * @type {Record<string, { what: string, joins: string[], fitting: string }>}
49
+ */
50
+ export const BOUGHT_KINDS: Record<string, {
51
+ what: string;
52
+ joins: string[];
53
+ fitting: string;
54
+ }>;
55
+ export function boughtFittings(given?: {
56
+ sets?: object;
57
+ }): string[];
58
+ export { CHECKED as BOUGHT_CHECKED };
59
+ import jscad from '@jscad/modeling';
60
+ declare const CHECKED: "2026-11-17";
package/bought.mjs ADDED
@@ -0,0 +1,195 @@
1
+ // Bought fittings for a frame: a corner bracket, a joining plate, an inner connector, an anchor connector, a hinge, an
2
+ // end cap or a levelling foot, each a rule set (part "fitting") from its maker's drawing and shop page. A set says what
3
+ // the fitting mounts by: the screws, their slot nuts and where each passes into beam a and beam b (holes_a, holes_b), a
4
+ // hole a beam must have drilled for it (an anchor's pocket), its price where the seller lists one, and its stiffness,
5
+ // which no maker publishes, so every figure of it is an estimate until the joint rig (issue 264) measures it. A join or
6
+ // a mount chooses "printed" or a bought set's name; the list, the operations and the stiffness follow the choice.
7
+ //
8
+ // The frames the solids are drawn in are the printed fittings' (fitting.mjs), so one placement serves both: a corner
9
+ // bracket's or an inner connector's corner at the origin, b's face at y = 0 (b below it), a's face at x = 0 (a behind
10
+ // it), across the joint along z from its middle; a plate's joint middle at the origin, b along x, a along +y, the
11
+ // beams' faces at z = 0 and the plate above them; an anchor's where a's axis meets b's face, a along +z; an end cap's
12
+ // and a foot's the end's address frame (z out of the end); a hinge's pin along y at x = 0, its leaves on z = 0.
13
+ // Units: mm, N, N mm/rad, the currency its seller lists.
14
+ import jscad from '@jscad/modeling';
15
+ import { SETS } from './catalogue.mjs';
16
+ import { profileModel } from './profile.mjs';
17
+
18
+ const { cuboid, cylinder, cylinderElliptic, polygon } = jscad.primitives, { extrudeLinear } = jscad.extrusions, { union, subtract } = jscad.booleans;
19
+ const { translate, rotateX, rotateY } = jscad.transforms;
20
+ const CHECKED = '2026-11-17';
21
+ const isNum = (x) => typeof x === 'number' && Number.isFinite(x);
22
+ const shown = (v) => { const s = v === undefined ? 'nothing' : JSON.stringify(v) ?? String(v); return s.length > 80 ? `${s.slice(0, 77)}...` : s; };
23
+ const mm = (x) => String(+Number(x).toFixed(2));
24
+ const r3 = (x) => +x.toFixed(3);
25
+ const finding = (level, text, code, extra = {}) => ({ level, text, code, ...extra });
26
+ const find = (given) => (name) => given?.sets?.[name] ?? given?.load?.(name) ?? SETS[name];
27
+ const pairs = (flat) => (Array.isArray(flat) ? Array.from({ length: Math.floor(flat.length / 2) }, (_, i) => [flat[2 * i], flat[2 * i + 1]]) : []);
28
+ const box = (lo, hi) => cuboid({ size: hi.map((h, k) => h - lo[k]), center: hi.map((h, k) => (h + lo[k]) / 2) });
29
+
30
+ /**
31
+ * The kinds of bought fitting, each with what it is, the join kinds that take it, and whether it goes on a beam's end
32
+ * as an item (an end cap, a foot) rather than in a join.
33
+ * @type {Record<string, { what: string, joins: string[], fitting: string }>}
34
+ */
35
+ export const BOUGHT_KINDS = {
36
+ 'corner-bracket': { what: 'a corner bracket', joins: ['bracket'], fitting: 'bracket' },
37
+ 'joining-plate': { what: 'a joining plate', joins: ['gusset', 'splice'], fitting: 'plate' },
38
+ 'inner-connector': { what: 'an inner connector', joins: ['hidden'], fitting: 'hidden' },
39
+ 'anchor-connector': { what: 'an anchor connector', joins: ['anchor'], fitting: 'anchor' },
40
+ hinge: { what: 'a hinge', joins: [], fitting: 'hinge' },
41
+ 'end-cap': { what: 'an end cap', joins: [], fitting: 'end-cap' },
42
+ 'levelling-foot': { what: 'a levelling foot', joins: [], fitting: 'levelling-foot' },
43
+ };
44
+
45
+ /** @returns {string[]} the names of the bought fittings in the catalogue (and in given.sets) @param {{ sets?: object }} [given] */
46
+ export const boughtFittings = (given = {}) => [...new Set([...Object.values(SETS), ...Object.values(given.sets ?? {})].filter((s) => s?.part === 'fitting').map((s) => s.name))].sort();
47
+
48
+ /**
49
+ * A bought fitting's set as numbers: what it is, the join kinds that take it, its screws and nuts and where each passes
50
+ * into beam a and beam b, the hole a beam needs for it, its sizes for a reference solid, its price, its stiffness with
51
+ * what that rests on, and (given the profiles it goes on) whether it fits them. Bad input is refused by name.
52
+ * @param {string | { name: string, part: string, rules: object }} which the set, by name or as read
53
+ * @param {{ given?: object, profile?: string | object, other?: string | object, join?: string }} [o] profile: b's
54
+ * (the beam a's end meets, or the beam an end cap or foot goes on), other: a's; join: the join kind it is asked for
55
+ * @returns {object} the model: kind 'fitting', bought true, fitting (bracket, plate, hidden, anchor, hinge, end-cap,
56
+ * levelling-foot), set, title, screws, holes, ops, cost, stiffness, findings
57
+ */
58
+ export function boughtFittingModel(which, o = {}) {
59
+ const what = 'boughtFittingModel';
60
+ if (!o || typeof o !== 'object' || Array.isArray(o)) throw new Error(`${what}: the options are { given, profile, other, join } (got ${shown(o)})`);
61
+ for (const k of Object.keys(o)) if (!['given', 'profile', 'other', 'join'].includes(k)) throw new Error(`${what}: no option "${k}": it takes given, profile, other, join`);
62
+ const given = o.given ?? {}, set = typeof which === 'string' ? find(given)(which) : which;
63
+ const names = boughtFittings(given);
64
+ if (!set?.rules) throw new Error(`${what}: no bought fitting ${shown(which)}: there are ${names.join(', ')}`);
65
+ if (set.part !== 'fitting') throw new Error(`${what}: ${set.name} is ${set.part ? `a ${set.part}` : 'not a part'}, not a bought fitting: there are ${names.join(', ')}`);
66
+ const r = set.rules, v = (k) => r[k]?.value, num = (k) => (isNum(v(k)) ? v(k) : null);
67
+ const kind = v('fitting_kind'), spec = BOUGHT_KINDS[kind];
68
+ if (!spec) throw new Error(`${what}: ${set.name}'s fitting_kind is one of ${Object.keys(BOUGHT_KINDS).join(', ')} (got ${shown(kind)})`);
69
+ if (o.join != null && !spec.joins.includes(o.join)) {
70
+ const fit = Object.entries(BOUGHT_KINDS).filter(([, x]) => x.joins.includes(o.join)).map(([k]) => k);
71
+ throw new Error(`${what}: ${set.name} is ${spec.what}, and a ${o.join} join takes ${fit.length ? fit.map((k) => BOUGHT_KINDS[k].what).join(' or ') : 'no bought fitting'}${spec.joins.length ? `: ${set.name} goes in a ${spec.joins.join(' or ')} join` : `: ${set.name} goes on an item ("bought": "${set.name}")`}`);
72
+ }
73
+ const thread = typeof v('thread') === 'string' ? v('thread') : null, length = num('screw_length'), head = v('screw_form') ?? null;
74
+ const t = num('thickness') ?? 0, holes = { a: pairs(v('holes_a')), b: pairs(v('holes_b')) };
75
+ const m = {
76
+ kind: 'fitting', bought: true, set: set.name, fittingKind: kind, fitting: spec.fitting, what: spec.what, joins: spec.joins, name: set.name,
77
+ title: `${set.name}, ${spec.what} (bought)`, series: num('series'), slot: v('slot') ?? null, material: v('material') ?? null,
78
+ thread, head, length, nutKind: v('nut_kind') ?? null, count: num('screw_count') ?? 0, holes,
79
+ width: num('width'), leg: num('leg'), legA: num('leg_a') ?? num('leg'), thickness: t, hole: num('mount_hole_diameter'), shape: v('plate_shape') ?? null,
80
+ pocket: num('pocket_diameter') != null ? { diameter: num('pocket_diameter'), distance: num('pocket_distance') } : null,
81
+ pin: num('pin_diameter'), knuckle: num('knuckle_diameter'), stem: num('thread_length'), base: num('body_diameter'), baseHeight: num('body_length'), stand: num('stand_height'),
82
+ grams: num('mass') != null ? r3(num('mass') * 1000) : null, allowable: num('allowable_load'),
83
+ cost: r.cost ? { value: r.cost.value, unit: r.cost.unit, kind: r.cost.kind, rule: r.cost.rule, source: r.cost.source } : null,
84
+ stiffness: r.bending_stiffness ? { bending: r.bending_stiffness.value, twist: r.twist_stiffness?.value ?? null, kind: r.bending_stiffness.kind, rule: r.bending_stiffness.rule, source: r.bending_stiffness.source, measured: { bending: r.bending_stiffness.kind === 'measured' ? r.bending_stiffness.checked ?? null : null, twist: r.twist_stiffness?.kind === 'measured' ? r.twist_stiffness.checked ?? null : null }, rests: [r.bending_stiffness, ...(r.twist_stiffness ? [r.twist_stiffness] : [])].map((x, i) => ({ name: `${set.name}.${i ? 'twist' : 'bending'}_stiffness`, value: x.value, unit: x.unit, kind: x.kind, source: x.source })) } : null,
85
+ screws: [], ops: [], findings: [], rules: r,
86
+ };
87
+ // the screws in the printed fittings' frames (fitting.mjs), so cad's placement and fasten checks serve both
88
+ const screw = (leg, at, axis) => ({ leg, thread, head, length, grip: t, at, axis, nutKind: m.nutKind });
89
+ if (spec.fitting === 'bracket') { for (const [x, y] of holes.b) m.screws.push(screw('b', [x, t, y], [0, -1, 0])); for (const [x, y] of holes.a) m.screws.push(screw('a', [t, x, y], [-1, 0, 0])); m.screwAt = holes.b[0]?.[0] ?? null; }
90
+ if (spec.fitting === 'plate') { for (const [x, y] of holes.b) m.screws.push(screw('b', [x, y, t], [0, 0, -1])); for (const [x, y] of holes.a) m.screws.push(screw('a', [y, x, t], [0, 0, -1])); m.outline = plateOutline(m); m.arm = Math.max(...m.screws.map((q) => Math.hypot(q.at[0], q.at[1]))); }
91
+ if (spec.fitting === 'hinge') { for (const [x, y] of holes.b) m.screws.push(screw('b', [x, y, t], [0, 0, -1])); for (const [x, y] of holes.a) m.screws.push(screw('a', [-x, y, t], [0, 0, -1])); } // (the frame leaf's into b's slot, the door leaf's through the door)
92
+ if (spec.fitting === 'anchor' && m.pocket) m.ops.push({ op: 'drill', side: 'a', distance: m.pocket.distance, diameter: m.pocket.diameter, through: 'wall', why: `${set.name}'s guide` });
93
+ // what it costs, its stiffness and the maker's load, each saying what it rests on
94
+ if (m.cost) m.findings.push(finding('info', `${set.name} costs ${m.cost.value} ${m.cost.unit} each (${m.cost.kind}): ${m.cost.rule}`, 'fitting.cost', { values: { cost: m.cost.value, unit: m.cost.unit } }));
95
+ if (m.stiffness) {
96
+ // each figure as it rests: measured on the rig (and when), or the estimate's own sentence; one measured leaves the other an estimate
97
+ const st = m.stiffness, tw = r.twist_stiffness, est = (f) => `an ${f.kind}: ${f.rule} (issue 264) (${f.source})`, meas = (f) => `measured on the joint rig${f.checked ? ` on ${f.checked}` : ''} (${f.source})`;
98
+ const says = st.kind === 'measured' ? `bending ${meas(r.bending_stiffness)}${tw ? `; twist ${tw.kind === 'measured' ? meas(tw) : `${est(tw)}`}` : ''}`
99
+ : tw?.kind === 'measured' ? `bending ${est(r.bending_stiffness)}; twist ${meas(tw)}` : est(r.bending_stiffness);
100
+ m.findings.push(finding('info', `${set.name} holds a beam's end at ${st.bending} N mm/rad in bending${st.twist != null ? ` and ${st.twist} in twist` : ''}: ${says}`, 'fitting.stiffness', { values: { bending: st.bending, twist: st.twist }, refs: { kind_of_value: st.kind, ...(tw ? { twist_kind: tw.kind } : {}) } }));
101
+ }
102
+ if (m.allowable != null) m.findings.push(finding('info', `its maker allows ${m.allowable} N on it (${r.allowable_load.kind})`, 'fitting.load', { values: { allowable: m.allowable } }));
103
+ if (o.profile != null) m.findings.push(...fits(m, o.profile, o.other ?? o.profile, given));
104
+ return m;
105
+ }
106
+
107
+ // The plate's outline from its holes: the bar along b round b's holes, the stem (T) or arm (L) along a round a's, as
108
+ // wide as the series, the hole's edge distance its maker's (the bar's end beyond its last hole)
109
+ function plateOutline(m) {
110
+ const b = m.screws.filter((q) => q.leg === 'b').map((q) => q.at), a = m.screws.filter((q) => q.leg === 'a').map((q) => q.at), s = m.series ?? 20;
111
+ const xs = b.map((p) => p[0]), lo = Math.min(...xs), hi = Math.max(...xs), edge = m.width != null ? (m.width - (hi - lo)) / 2 : s / 2;
112
+ const top = a.length ? Math.max(...a.map((p) => p[1])) + edge : s / 2, band = [-edge, s - edge];
113
+ if (m.shape === 'straight' || !a.length) return [[lo - edge, band[0]], [hi + edge, band[0]], [hi + edge, band[1]], [lo - edge, band[1]]];
114
+ if (m.shape === 'L') return [[lo - edge, band[0]], [hi + edge, band[0]], [hi + edge, band[1]], [s / 2, top], [-s / 2, top], [-s / 2, band[1]]].map(([x, y]) => [r3(x), r3(y)]);
115
+ return [[lo - edge, band[0]], [hi + edge, band[0]], [hi + edge, band[1]], [s / 2, top], [-s / 2, top], [lo - edge, band[1]]].map(([x, y]) => [r3(x), r3(y)]);
116
+ }
117
+
118
+ // Whether a fitting fits the profiles it is put on: their size, the slot family its lugs or nuts are made for, and for
119
+ // a foot the thread of the end's bore. Each a finding, a fail where it would not go on
120
+ function fits(m, profileB, profileA, given) {
121
+ const out = [], seen = new Set();
122
+ for (const [side, profile] of [['b', profileB], ['a', profileA]]) {
123
+ const p = profile?.kind === 'profile' ? profile : profileModel(profile, {}, given);
124
+ if (seen.has(p.name)) continue; seen.add(p.name);
125
+ const size = Math.min(p.width, p.height), short = p.name.replace(/^profile-/, '');
126
+ if (m.series != null && Math.abs(size - m.series) > 1e-6) out.push(finding('fail', `${m.set} is made for ${m.series} mm profiles, and ${short} is ${mm(size)} mm: choose a fitting made for it, or "fitting": "printed"`, 'fitting.fit', { values: { series: m.series, size }, refs: { set: m.set, profile: p.name, side } }));
127
+ if (m.slot) {
128
+ const family = (n) => { const s = find(given)(n); return s?.part === 'slot' ? String(s.rules.nut_family?.value ?? n) : n; };
129
+ const want = family(m.slot), have = [...new Set(Object.keys(p.slots ?? {}))], ok = have.some((n) => n === m.slot || family(n) === want);
130
+ if (!have.length) out.push(finding('fail', `${m.set} keys into a slot (${m.slot}), and ${short} has none`, 'fitting.fit', { refs: { set: m.set, profile: p.name, side } }));
131
+ else if (!ok) out.push(finding('fail', `${m.set} is made for ${m.slot} (nut family ${want}), and ${short}'s slots are ${have.join(', ')} (${[...new Set(have.map(family))].join(', ')}): its lugs and nuts are not promised to fit. Choose a fitting made for ${have[0]}, or "fitting": "printed"`, 'fitting.fit', { values: { family: want }, refs: { set: m.set, profile: p.name, side, slots: have } }));
132
+ }
133
+ if (m.fitting === 'levelling-foot' && m.thread) {
134
+ const bore = p.bores?.[0]?.thread ?? null;
135
+ if (bore !== m.thread) out.push(finding('fail', `${m.set}'s stem is ${m.thread}, and ${short}'s end bore ${bore ? `is tapped ${bore}` : 'takes no thread'}: ${bore ? `choose a foot with an ${bore} stem` : 'it has nothing to screw into'}`, 'fitting.fit', { values: { thread: m.thread, bore }, refs: { set: m.set, profile: p.name } }));
136
+ }
137
+ }
138
+ if (!out.length) out.push(finding('pass', `${m.set} fits ${[...seen].map((n) => n.replace(/^profile-/, '')).join(' and ')}: made for ${m.series} mm profiles${m.slot ? ` with ${m.slot}'s slot` : ''}${m.fitting === 'levelling-foot' ? `, its ${m.thread} stem into the end's bore` : ''}`, 'fitting.fit', { refs: { set: m.set, profiles: [...seen] } }));
139
+ return out;
140
+ }
141
+
142
+ /**
143
+ * A bought fitting's reference solid, drawn from its set's figures in the printed fittings' frames (above): faint, for
144
+ * the picture and the fasten checks' holes, never printed.
145
+ * @param {object} m boughtFittingModel's @param {{ pose?: 'fit' }} [o]
146
+ */
147
+ export function boughtFitting(m, o = {}) {
148
+ if (!m?.bought) throw new Error(`boughtFitting: give a bought fitting's model (boughtFittingModel), not ${shown(m)}`);
149
+ if (o.pose != null && o.pose !== 'fit') throw new Error(`boughtFitting: a bought fitting is drawn as fitted: pose is fit (got ${shown(o.pose)})`);
150
+ const t = m.thickness, r = (m.hole ?? 0) / 2, w = m.width ?? m.series ?? 20;
151
+ const holeAt = (q) => { const [x, y, z] = q.at, h = 3 * t + 2; return q.axis[1] ? translate([x, y - t / 2, z], rotateX(Math.PI / 2, cylinder({ radius: r, height: h, segments: 24 }))) : q.axis[0] ? translate([x - t / 2, y, z], rotateY(Math.PI / 2, cylinder({ radius: r, height: h, segments: 24 }))) : translate([x, y, t / 2], cylinder({ radius: r, height: h, segments: 24 })); };
152
+ let g;
153
+ if (m.fitting === 'bracket') {
154
+ const L = m.leg, La = m.legA ?? L;
155
+ g = union(box([0, 0, -w / 2], [L, t, w / 2]), box([0, 0, -w / 2], [t, La, w / 2]));
156
+ if (r > 0) g = subtract(g, ...m.screws.map(holeAt));
157
+ } else if (m.fitting === 'plate') {
158
+ g = extrudeLinear({ height: t }, polygon({ points: m.outline }));
159
+ if (r > 0) g = subtract(g, ...m.screws.map(holeAt));
160
+ } else if (m.fitting === 'hidden') {
161
+ // in the slots under the lips: b's leg along x below b's face, a's along y behind a's
162
+ const d = t, half = w / 2;
163
+ g = union(box([-d, -d, -half], [m.leg, 0, half]), box([-d, -d, -half], [0, m.legA, half]));
164
+ } else if (m.fitting === 'anchor') {
165
+ // the post along a's axis from under b's lips, its head in b's slot; the guide across a at its pocket
166
+ const head = m.width ?? 10, post = m.leg ?? 20;
167
+ g = union(box([-head / 2, -head / 2, -5], [head / 2, head / 2, -2]), translate([0, 0, (post - 5) / 2 - 2.5], cylinder({ radius: 2, height: post - 5, segments: 24 })));
168
+ if (m.pocket) g = union(g, translate([0, 0, m.pocket.distance], rotateY(Math.PI / 2, cylinder({ radius: m.pocket.diameter / 2 - 0.1, height: (m.series ?? 20) / 2, center: [0, 0, (m.series ?? 20) / 4], segments: 24 }))));
169
+ } else if (m.fitting === 'hinge') {
170
+ const half = (m.width ?? 39) / 2, L = m.leg ?? 30, k = (m.knuckle ?? 8) / 2;
171
+ g = union(box([-half, -L / 2, 0], [half, L / 2, t]), translate([0, 0, k], rotateX(Math.PI / 2, cylinder({ radius: k, height: L, segments: 24 }))));
172
+ if (r > 0) g = subtract(g, ...[...m.holes.b.map(([x, y]) => [x, y]), ...m.holes.a.map(([x, y]) => [-x, y])].map(([x, y]) => translate([x, y, t / 2], cylinder({ radius: r, height: 2 * t + 2, segments: 24 }))));
173
+ } else if (m.fitting === 'end-cap') {
174
+ g = box([-w / 2, -w / 2, 0], [w / 2, w / 2, t || 2]);
175
+ } else {
176
+ // a levelling foot screwed fully home: the nut on the end's face, the base under it, the stem between
177
+ const base = (m.base ?? 19) / 2, bh = m.baseHeight ?? 10, stand = m.stand ?? bh + 6, nut = 5;
178
+ g = union(translate([0, 0, nut / 2], cylinder({ radius: 5.7, height: nut, segments: 6 })), translate([0, 0, (stand - bh) / 2], cylinder({ radius: 3, height: stand - bh, segments: 24 })),
179
+ translate([0, 0, stand - bh / 2], cylinderElliptic({ height: bh, startRadius: [base * 0.84, base * 0.84], endRadius: [base, base], segments: 32 })));
180
+ }
181
+ return Object.assign(g, { model: m });
182
+ }
183
+
184
+ /**
185
+ * What a printed part costs in plastic beside a bought one's price: its grams times the material's cost per kilogram,
186
+ * where the material's set gives one (pla and petg do), else null. @param {number} grams @param {{ name?: string, rules: object }} material
187
+ * @returns {{ value: number, unit: string, rule: string, source: string } | null}
188
+ */
189
+ export function printedCost(grams, material) {
190
+ const c = material?.rules?.cost;
191
+ if (!isNum(grams) || !c || !isNum(c.value)) return null;
192
+ const unit = String(c.unit ?? '').replace(/\/kg$/, '');
193
+ return { value: +((grams / 1000) * c.value).toFixed(3), unit, rule: `${mm(grams)} g of ${material.name ?? 'plastic'} at ${c.value} ${c.unit}: the plastic alone, not the printer's time or power`, source: c.source, kind: 'derived' };
194
+ }
195
+ export { CHECKED as BOUGHT_CHECKED };
package/catalogue.mjs CHANGED
@@ -1,4 +1,4 @@
1
- // The rule sets @rulecad/frames reads, by name: every profile, slot family and slot nut in @rulecad/rules, the threads
1
+ // The rule sets @rulecad/frames reads, by name: every profile, slot family, slot nut, bought fitting, rail, V-wheel and eccentric spacer in @rulecad/rules (and the bearings the wheels run on), the rods, linear bearings, lead screws and nuts, couplers, motors and switches a rod guide and its drive read, the threads
2
2
  // their bores tap to, the materials they name and the outlines the kit draws itself. Generated from the rules package (one import per set, so a bundler
3
3
  // can see them): after adding a set there, add its line here. A test holds the two together.
4
4
  import s_al6000_item from '@rulecad/rules/al6000-item.json' with { type: 'json' };
@@ -7,6 +7,13 @@ import s_al6060_rexroth from '@rulecad/rules/al6060-rexroth.json' with { type: '
7
7
  import s_al6063_t5 from '@rulecad/rules/al6063-t5.json' with { type: 'json' };
8
8
  import s_al6063_t66 from '@rulecad/rules/al6063-t66.json' with { type: 'json' };
9
9
  import s_al6n01_t5 from '@rulecad/rules/al6n01-t5.json' with { type: 'json' };
10
+ import s_fitting_misumi_hmj5 from '@rulecad/rules/fitting-misumi-hmj5.json' with { type: 'json' };
11
+ import s_fitting_motedis_bracket_20_b6 from '@rulecad/rules/fitting-motedis-bracket-20-b6.json' with { type: 'json' };
12
+ import s_fitting_motedis_end_cap_20_b6 from '@rulecad/rules/fitting-motedis-end-cap-20-b6.json' with { type: 'json' };
13
+ import s_fitting_motedis_foot_m6_d19 from '@rulecad/rules/fitting-motedis-foot-m6-d19.json' with { type: 'json' };
14
+ import s_fitting_motedis_hinge_20 from '@rulecad/rules/fitting-motedis-hinge-20.json' with { type: 'json' };
15
+ import s_fitting_motedis_inner_20_b6 from '@rulecad/rules/fitting-motedis-inner-20-b6.json' with { type: 'json' };
16
+ import s_fitting_motedis_plate_t_20 from '@rulecad/rules/fitting-motedis-plate-t-20.json' with { type: 'json' };
10
17
  import s_m10 from '@rulecad/rules/m10.json' with { type: 'json' };
11
18
  import s_m12 from '@rulecad/rules/m12.json' with { type: 'json' };
12
19
  import s_m1_6 from '@rulecad/rules/m1_6.json' with { type: 'json' };
@@ -17,6 +24,16 @@ import s_m4 from '@rulecad/rules/m4.json' with { type: 'json' };
17
24
  import s_m5 from '@rulecad/rules/m5.json' with { type: 'json' };
18
25
  import s_m6 from '@rulecad/rules/m6.json' with { type: 'json' };
19
26
  import s_m8 from '@rulecad/rules/m8.json' with { type: 'json' };
27
+ import s_rail_mgn7 from '@rulecad/rules/rail-mgn7.json' with { type: 'json' };
28
+ import s_rail_mgn9 from '@rulecad/rules/rail-mgn9.json' with { type: 'json' };
29
+ import s_rail_mgn12 from '@rulecad/rules/rail-mgn12.json' with { type: 'json' };
30
+ import s_rail_mgn15 from '@rulecad/rules/rail-mgn15.json' with { type: 'json' };
31
+ import s_v_wheel_solid from '@rulecad/rules/v-wheel-solid.json' with { type: 'json' };
32
+ import s_v_wheel_mini from '@rulecad/rules/v-wheel-mini.json' with { type: 'json' };
33
+ import s_eccentric_6_openbuilds from '@rulecad/rules/eccentric-6-openbuilds.json' with { type: 'json' };
34
+ import s_eccentric_mini_6_openbuilds from '@rulecad/rules/eccentric-mini-6-openbuilds.json' with { type: 'json' };
35
+ import s_bearing_625 from '@rulecad/rules/bearing-625.json' with { type: 'json' };
36
+ import s_bearing_mr105 from '@rulecad/rules/bearing-mr105.json' with { type: 'json' };
20
37
  import s_profile_1010_8020 from '@rulecad/rules/profile-1010-8020.json' with { type: 'json' };
21
38
  import s_profile_1010_makerbeam from '@rulecad/rules/profile-1010-makerbeam.json' with { type: 'json' };
22
39
  import s_profile_1020_8020 from '@rulecad/rules/profile-1020-8020.json' with { type: 'json' };
@@ -188,6 +205,17 @@ import s_unc_5_16_18 from '@rulecad/rules/unc_5_16_18.json' with { type: 'json'
188
205
  import s_unc_6_32 from '@rulecad/rules/unc_6_32.json' with { type: 'json' };
189
206
  import s_unc_8_32 from '@rulecad/rules/unc_8_32.json' with { type: 'json' };
190
207
  import s_unf_10_32 from '@rulecad/rules/unf_10_32.json' with { type: 'json' };
208
+ import s_rod_8 from '@rulecad/rules/rod-8.json' with { type: 'json' };
209
+ import s_lm8uu from '@rulecad/rules/lm8uu.json' with { type: 'json' };
210
+ import s_lm8luu from '@rulecad/rules/lm8luu.json' with { type: 'json' };
211
+ import s_t8_nut from '@rulecad/rules/t8-nut.json' with { type: 'json' };
212
+ import s_t8_screw from '@rulecad/rules/t8-screw.json' with { type: 'json' };
213
+ import s_bearing_608 from '@rulecad/rules/bearing-608.json' with { type: 'json' };
214
+ import s_coupler_5_8 from '@rulecad/rules/coupler-5-8.json' with { type: 'json' };
215
+ import s_endstop_10t85 from '@rulecad/rules/endstop-10t85.json' with { type: 'json' };
216
+ import s_28byj48 from '@rulecad/rules/28byj48.json' with { type: 'json' };
217
+ import s_nema14 from '@rulecad/rules/nema14.json' with { type: 'json' };
218
+ import s_nema17 from '@rulecad/rules/nema17.json' with { type: 'json' };
191
219
  import o_profile_custom from '@rulecad/rules/outlines/profile-custom.json' with { type: 'json' };
192
220
  import vocabulary from '@rulecad/rules/vocabulary.json' with { type: 'json' };
193
221
 
@@ -195,7 +223,8 @@ import vocabulary from '@rulecad/rules/vocabulary.json' with { type: 'json' };
195
223
  export const FIELDS = vocabulary.fields;
196
224
  /** Every rule set frames knows, by its name. @type {Record<string, { name: string, part?: string, rules: Record<string, any> }>} */
197
225
  export const SETS = Object.fromEntries([
198
- s_al6000_item, s_al6005a_8020, s_al6060_rexroth, s_al6063_t5, s_al6063_t66, s_al6n01_t5, s_m10, s_m12,
226
+ s_al6000_item, s_al6005a_8020, s_fitting_misumi_hmj5, s_fitting_motedis_bracket_20_b6, s_fitting_motedis_end_cap_20_b6, s_fitting_motedis_foot_m6_d19, s_fitting_motedis_hinge_20, s_fitting_motedis_inner_20_b6, s_fitting_motedis_plate_t_20,
227
+ s_al6060_rexroth, s_al6063_t5, s_al6063_t66, s_al6n01_t5, s_m10, s_m12,
199
228
  s_m1_6, s_m2, s_m2_5, s_m3, s_m4, s_m5, s_m6, s_m8, s_profile_1010_8020, s_profile_1010_makerbeam, s_profile_1020_8020,
200
229
  s_profile_1515_8020, s_profile_1515_makerbeam_xl, s_profile_1515_openbeam, s_profile_1530_8020, s_profile_2020_bosch,
201
230
  s_profile_2020_generic, s_profile_2020_item_5, s_profile_2020_misumi_hfs5, s_profile_2020_motedis_b6,
@@ -212,7 +241,7 @@ export const SETS = Object.fromEntries([
212
241
  s_profile_custom, s_profile_round_bar_al_10, s_profile_round_bar_steel_10, s_profile_round_bar, s_profile_round_tube_al_25x2,
213
242
  s_profile_round_tube_steel_25x2, s_profile_round_tube, s_profile_tube_al_20x20x2, s_profile_tube_al_25x25x2,
214
243
  s_profile_tube_al_40x20x2, s_profile_tube_steel_25x25x2, s_profile_tube_steel_40x40x2, s_profile_tube,
215
- s_s275, s_slot_10_bosch_45l, s_slot_10_bosch, s_slot_10_misumi_45, s_slot_10_misumi, s_slot_10_motedis,
244
+ s_rail_mgn7, s_rail_mgn9, s_rail_mgn12, s_rail_mgn15, s_v_wheel_solid, s_v_wheel_mini, s_eccentric_6_openbuilds, s_eccentric_mini_6_openbuilds, s_bearing_625, s_bearing_mr105, s_rod_8, s_lm8uu, s_lm8luu, s_t8_nut, s_t8_screw, s_bearing_608, s_coupler_5_8, s_endstop_10t85, s_28byj48, s_nema14, s_nema17, s_s275, s_slot_10_bosch_45l, s_slot_10_bosch, s_slot_10_misumi_45, s_slot_10_misumi, s_slot_10_motedis,
216
245
  s_slot_10, s_slot_3_makerbeam_xl, s_slot_3_makerbeam, s_slot_3_openbeam, s_slot_5_item, s_slot_5_motedis,
217
246
  s_slot_6_8020, s_slot_6_bosch, s_slot_6_item_light, s_slot_6_item, s_slot_6_misumi, s_slot_6_motedis_i,
218
247
  s_slot_6_motedis, s_slot_6_openbuilds, s_slot_6, s_slot_8_8020, s_slot_8_bosch, s_slot_8_i, s_slot_8_item_light,
package/door.d.mts ADDED
@@ -0,0 +1,127 @@
1
+ /**
2
+ * A printed hinge for a door over a bay: the frame's leaf lies on the hinge beam's face, two screws into slot nuts on
3
+ * its slot, its two knuckles risen over the beam's outer edge; the door's leaf lies on the door's outer face, its knuckle
4
+ * between them, two screws through the door into nuts; a bought cap screw is the pin. The door stands off the face by
5
+ * the frame leaf, a head and the clearance, so it passes over the heads; its edge on the hinge side stops a knuckle and
6
+ * the clearance from the axis. Sized from a named load across the pin by beam formulas to about twice the margin. The
7
+ * frame's leaf prints as it lies, the door's leaf face down; the pin's hole lies as a teardrop.
8
+ * @param {string | object} profile the hinge beam's @param {{ sheet: number, face?: string, thread?: string, nut?: string, pin?: string, screw?: string, load?: number, printer?: object, material?: string | object, given?: object }} o
9
+ * sheet: the door's thickness; pin: the pin's thread (default M3); screw: the thread through the door (default M3)
10
+ * @returns {object} its model: standoff (the door's inner face over the beam's), axis [y, z], edge (the door's hinge-side edge, y), screws, hardware, grams, margin
11
+ */
12
+ export function hingeModel(profile: string | object, o?: {
13
+ sheet: number;
14
+ face?: string;
15
+ thread?: string;
16
+ nut?: string;
17
+ pin?: string;
18
+ screw?: string;
19
+ load?: number;
20
+ printer?: object;
21
+ material?: string | object;
22
+ given?: object;
23
+ }): object;
24
+ /**
25
+ * A hinge's leaves: part 'frame' (as it prints, which is as it lies) or 'door' (face down to print); pose 'fit' puts
26
+ * the door's leaf where it sits with the door closed. @param {object} m @param {{ part?: 'frame' | 'door', pose?: 'print' | 'fit', printer?: object, ops?: object }} [o] @returns {object}
27
+ */
28
+ export function hinge(m: object, o?: {
29
+ part?: "frame" | "door";
30
+ pose?: "print" | "fit";
31
+ printer?: object;
32
+ ops?: object;
33
+ }): object;
34
+ /**
35
+ * A printed pull handle for a door: a grip between two feet, screwed from inside the door into a pilot in each foot,
36
+ * room under the grip for the fingers. Sized from a named pull by beam formulas to about twice the margin. It prints
37
+ * on its side, its outline the first layer, its pilots lying as teardrops.
38
+ * @param {{ sheet: number, thread?: string, span?: number, load?: number, printer?: object, material?: string | object }} o
39
+ * sheet: the door's thickness, for the screws' length; span: between the screws (default 64)
40
+ * @returns {object} its model
41
+ */
42
+ export function handleModel(o?: {
43
+ sheet: number;
44
+ thread?: string;
45
+ span?: number;
46
+ load?: number;
47
+ printer?: object;
48
+ material?: string | object;
49
+ }): object;
50
+ /** A handle's solid: on its side to print, or fitted (pose 'fit', its feet on the door at z = 0). @param {object} m @param {{ pose?: 'print' | 'fit', printer?: object, ops?: object }} [o] @returns {object} */
51
+ export function handle(m: object, o?: {
52
+ pose?: "print" | "fit";
53
+ printer?: object;
54
+ ops?: object;
55
+ }): object;
56
+ /**
57
+ * A printed turn-button latch: a post on the latch beam's face, screwed into a slot nut through its middle, with a tab
58
+ * on top that turns over the door's edge to hold it shut. Shown at rest, turned over the door. It prints tab down.
59
+ * @param {string | object} profile @param {{ sheet: number, standoff: number, edge?: number, face?: string, thread?: string, nut?: string, load?: number, printer?: object, material?: string | object, given?: object }} o
60
+ * standoff: the door's inner face over the beam's (a hinge's); edge: the door's edge, from the slot's line (default a clip's)
61
+ * @returns {object} its model
62
+ */
63
+ export function latchModel(profile: string | object, o?: {
64
+ sheet: number;
65
+ standoff: number;
66
+ edge?: number;
67
+ face?: string;
68
+ thread?: string;
69
+ nut?: string;
70
+ load?: number;
71
+ printer?: object;
72
+ material?: string | object;
73
+ given?: object;
74
+ }): object;
75
+ /** A latch's solid: tab down to print, or fitted and turned over the door (pose 'fit'). @param {object} m @param {{ pose?: 'print' | 'fit', printer?: object, ops?: object }} [o] @returns {object} */
76
+ export function latch(m: object, o?: {
77
+ pose?: "print" | "fit";
78
+ printer?: object;
79
+ ops?: object;
80
+ }): object;
81
+ /**
82
+ * A printed magnet catch: a block on a beam's face under the door's edge, screwed into a slot nut on a step lower than
83
+ * its tower, a disc magnet pressed into the tower's top; a steel washer stuck to the door's inner face over it is the
84
+ * strike. The tower's top stops the washer's thickness and a half millimetre under the door. It prints on its side.
85
+ * @param {string | object} profile @param {{ standoff: number, edge?: number, magnet?: number[], face?: string, thread?: string, nut?: string, printer?: object, material?: string | object, given?: object }} o
86
+ * standoff: the door's (a hinge's); edge: the door's edge from the slot's line (default the head's room); magnet: [diameter, thickness]
87
+ * @returns {object} its model
88
+ */
89
+ export function magnetCatchModel(profile: string | object, o?: {
90
+ standoff: number;
91
+ edge?: number;
92
+ magnet?: number[];
93
+ face?: string;
94
+ thread?: string;
95
+ nut?: string;
96
+ printer?: object;
97
+ material?: string | object;
98
+ given?: object;
99
+ }): object;
100
+ /** A magnet catch's solid: on its side to print, or fitted. @param {object} m @param {{ pose?: 'print' | 'fit', tongues?: boolean, printer?: object, ops?: object }} [o] @returns {object} */
101
+ export function magnetCatch(m: object, o?: {
102
+ pose?: "print" | "fit";
103
+ tongues?: boolean;
104
+ printer?: object;
105
+ ops?: object;
106
+ }): object;
107
+ export namespace DOOR_DEFAULTS {
108
+ namespace pin {
109
+ export { text as rule };
110
+ export { kind };
111
+ export { source };
112
+ export { CHECKED as checked };
113
+ export { unit };
114
+ export { value };
115
+ }
116
+ namespace door { }
117
+ namespace load { }
118
+ namespace knuckles { }
119
+ namespace clear { }
120
+ namespace pull { }
121
+ namespace span { }
122
+ namespace finger { }
123
+ namespace magnet { }
124
+ namespace open { }
125
+ }
126
+ declare const CHECKED: "2026-11-17";
127
+ export {};