@rulecad/frames 0.0.1 → 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/CHANGELOG.md +23 -0
- package/README.md +1182 -21
- package/beam.d.mts +145 -0
- package/beam.mjs +201 -0
- package/bought.d.mts +60 -0
- package/bought.mjs +195 -0
- package/catalogue.d.mts +20 -0
- package/catalogue.mjs +268 -0
- package/cutlist.d.mts +88 -0
- package/cutlist.mjs +199 -0
- package/cutsheet.d.mts +23 -0
- package/cutsheet.mjs +118 -0
- package/door.d.mts +127 -0
- package/door.mjs +254 -0
- package/ends.d.mts +130 -0
- package/ends.mjs +290 -0
- package/fitting.d.mts +262 -0
- package/fitting.mjs +535 -0
- package/frames.d.mts +18 -9
- package/frames.mjs +43 -10
- package/guide.d.mts +140 -0
- package/guide.mjs +269 -0
- package/jig.d.mts +146 -0
- package/jig.mjs +332 -0
- package/join.d.mts +244 -0
- package/join.mjs +257 -0
- package/ops.d.mts +44 -0
- package/ops.mjs +324 -0
- package/package.json +75 -8
- package/panel.d.mts +225 -0
- package/panel.mjs +374 -0
- package/profile.d.mts +268 -0
- package/profile.mjs +462 -0
- package/rods.d.mts +195 -0
- package/rods.mjs +475 -0
- package/section.d.mts +43 -0
- package/section.mjs +140 -0
- package/services.d.mts +335 -0
- package/services.mjs +486 -0
- package/slotnut.d.mts +210 -0
- package/slotnut.mjs +394 -0
- package/square.d.mts +23 -0
- package/square.mjs +42 -0
- package/wheels.d.mts +141 -0
- package/wheels.mjs +337 -0
package/beam.d.mts
ADDED
|
@@ -0,0 +1,145 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* A beam as numbers: a length of a profile, its mass and centre of mass from the section and the alloy, the figures to
|
|
3
|
+
* design it with, and its anchors. A beam is bought: it is cut from stock, and its supply is checked.
|
|
4
|
+
* @param {Profile | string | object} profile a profile's model, or what profileModel takes ('2040-misumi-hfs5', or a rule set)
|
|
5
|
+
* @param {{ length: number, ends?: 'cut' | 'tapped' | ['cut' | 'tapped', 'cut' | 'tapped'] | { a?: 'cut' | 'tapped', b?: 'cut' | 'tapped' },
|
|
6
|
+
* ops?: object[], material?: string, given?: object, cells?: number }} o length: mm, end a to end b (on the long side where
|
|
7
|
+
* an end is mitred); ends: each end cut square (the default), or tapped (a tap op at that end, in the profile's bore_thread);
|
|
8
|
+
* ops: operations, each { op, at, ... } as OPS lists (cut, mitre, tap, access, drill, counterbore, pocket, notch,
|
|
9
|
+
* deburr), placed by an address on the beam (a, a.1, top@120); the model's ops are them worked out, dimensioned from end a; material: a material set's name in place of the profile's
|
|
10
|
+
* alloy (so a frame can be weighed in another metal or a plastic); given: profileModel's third argument; cells: raster
|
|
11
|
+
* cells for the torsion constant where the sheet gives none
|
|
12
|
+
* @returns {Beam}
|
|
13
|
+
*/
|
|
14
|
+
export function beamModel(profile: Profile | string | object, o?: {
|
|
15
|
+
length: number;
|
|
16
|
+
ends?: "cut" | "tapped" | ["cut" | "tapped", "cut" | "tapped"] | {
|
|
17
|
+
a?: "cut" | "tapped";
|
|
18
|
+
b?: "cut" | "tapped";
|
|
19
|
+
};
|
|
20
|
+
ops?: object[];
|
|
21
|
+
material?: string;
|
|
22
|
+
given?: object;
|
|
23
|
+
cells?: number;
|
|
24
|
+
}): Beam;
|
|
25
|
+
/**
|
|
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
|
+
* round section a twelve-sided prism): 12 triangles, light enough for a link and an overlap check. 'preview' (the
|
|
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. 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.
|
|
32
|
+
* @param {Beam | Profile | string | object} m a beam's model, or a profile with { length } as beamModel takes
|
|
33
|
+
* @param {{ display?: 'link' | 'preview', tracks?: boolean, length?: number, ends?: any, material?: string, given?: object, cells?: number }} [o]
|
|
34
|
+
* @returns {object} a JSCAD geom3, with .model holding beamModel's numbers (its anchors and mass)
|
|
35
|
+
*/
|
|
36
|
+
export function beam(m: Beam | Profile | string | object, o?: {
|
|
37
|
+
display?: "link" | "preview";
|
|
38
|
+
tracks?: boolean;
|
|
39
|
+
length?: number;
|
|
40
|
+
ends?: any;
|
|
41
|
+
material?: string;
|
|
42
|
+
given?: object;
|
|
43
|
+
cells?: number;
|
|
44
|
+
}): object;
|
|
45
|
+
/**
|
|
46
|
+
* 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
|
|
47
|
+
* 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
|
|
48
|
+
* from end b, 'top@50%' the middle. A face's place with no distance is at the middle.
|
|
49
|
+
* @param {Beam} b a beam's model @param {string} address
|
|
50
|
+
* @returns {Anchor & { name: string, distance: number | null }}
|
|
51
|
+
*/
|
|
52
|
+
export function beamAnchor(b: Beam, address: string): Anchor & {
|
|
53
|
+
name: string;
|
|
54
|
+
distance: number | null;
|
|
55
|
+
};
|
|
56
|
+
/**
|
|
57
|
+
* What a printer can make of it, as findings. A beam of a profile is bought and cut from stock, and so is a profile:
|
|
58
|
+
* both fail. Printed beams are a later release.
|
|
59
|
+
* @param {Beam | Profile | object} x a beam's or a profile's model, or a solid beam() made
|
|
60
|
+
* @returns {{ level: 'fail', code: string, text: string }[]}
|
|
61
|
+
*/
|
|
62
|
+
export function printable(x: Beam | Profile | object): {
|
|
63
|
+
level: "fail";
|
|
64
|
+
code: string;
|
|
65
|
+
text: string;
|
|
66
|
+
}[];
|
|
67
|
+
export type Profile = import("./profile.mjs").Profile;
|
|
68
|
+
/**
|
|
69
|
+
* a point, the direction out of the beam there, and
|
|
70
|
+
* a direction square to it that fixes the turn about it: at an end, the beam's up (+y); on a face, along the beam toward end b
|
|
71
|
+
*/
|
|
72
|
+
export type Anchor = {
|
|
73
|
+
origin: number[];
|
|
74
|
+
axis: number[];
|
|
75
|
+
ref: number[];
|
|
76
|
+
};
|
|
77
|
+
/**
|
|
78
|
+
* a place a face offers along the whole beam: its slot family (null where the face is closed there), where it meets
|
|
79
|
+
* the face in the section, and how far the slot goes in (0 for a closed face)
|
|
80
|
+
*/
|
|
81
|
+
export type Place = {
|
|
82
|
+
name: string;
|
|
83
|
+
face: "top" | "bottom" | "front" | "back";
|
|
84
|
+
index: number;
|
|
85
|
+
slot: string | null;
|
|
86
|
+
at: [number, number];
|
|
87
|
+
normal: [number, number];
|
|
88
|
+
along: [number, number];
|
|
89
|
+
depth: number;
|
|
90
|
+
};
|
|
91
|
+
export type EndBore = {
|
|
92
|
+
name: string;
|
|
93
|
+
end: "a" | "b";
|
|
94
|
+
at: [number, number];
|
|
95
|
+
diameter: number;
|
|
96
|
+
thread: string | null;
|
|
97
|
+
tapped: boolean;
|
|
98
|
+
};
|
|
99
|
+
export type Beam = {
|
|
100
|
+
kind: "beam";
|
|
101
|
+
name: string;
|
|
102
|
+
title: string;
|
|
103
|
+
profile: Profile;
|
|
104
|
+
length: number;
|
|
105
|
+
ends: {
|
|
106
|
+
a: {
|
|
107
|
+
kind: "cut" | "tapped";
|
|
108
|
+
thread: string | null;
|
|
109
|
+
};
|
|
110
|
+
b: {
|
|
111
|
+
kind: "cut" | "tapped";
|
|
112
|
+
thread: string | null;
|
|
113
|
+
};
|
|
114
|
+
};
|
|
115
|
+
material: {
|
|
116
|
+
name: string;
|
|
117
|
+
density: number | null;
|
|
118
|
+
modulus: number | null;
|
|
119
|
+
given: boolean;
|
|
120
|
+
} | null;
|
|
121
|
+
area: number;
|
|
122
|
+
centroid: [number, number];
|
|
123
|
+
mass: number | null;
|
|
124
|
+
centreOfMass: [number, number, number];
|
|
125
|
+
weight: {
|
|
126
|
+
computed: number | null;
|
|
127
|
+
sheet: number | null;
|
|
128
|
+
difference: number | null;
|
|
129
|
+
};
|
|
130
|
+
figures: Record<string, {
|
|
131
|
+
value: number | null;
|
|
132
|
+
unit: string;
|
|
133
|
+
kind: string;
|
|
134
|
+
source: string;
|
|
135
|
+
from: "sheet" | "outline";
|
|
136
|
+
}>;
|
|
137
|
+
places: Place[];
|
|
138
|
+
bores: EndBore[];
|
|
139
|
+
anchors: Record<string, Anchor>;
|
|
140
|
+
ops: object[];
|
|
141
|
+
bought: true;
|
|
142
|
+
printed: false;
|
|
143
|
+
rests: object[];
|
|
144
|
+
findings: object[];
|
|
145
|
+
};
|
package/beam.mjs
ADDED
|
@@ -0,0 +1,201 @@
|
|
|
1
|
+
// A beam: a length of a profile. Its model holds what the length is worth (mass and centre of mass from the section
|
|
2
|
+
// and the alloy, the figures to design it with), what it is cut from, and the anchors an assembly places it and
|
|
3
|
+
// anything on it by: its two ends, the bores in each end, and every place a face offers (a slot, or a closed face).
|
|
4
|
+
// Its solid comes at two display levels: a plain box for a link, the true section for a preview.
|
|
5
|
+
//
|
|
6
|
+
// A beam lies along z: end a at z = 0, end b at z = length, the section in x and y as profileModel draws it (the
|
|
7
|
+
// middle of its envelope on the z axis, top +y, bottom -y, front -x, back +x). Units: mm, grams, degrees.
|
|
8
|
+
import jscad from '@jscad/modeling';
|
|
9
|
+
import { profileModel, section, beamFigures, outline, DEFAULTS } from './profile.mjs';
|
|
10
|
+
import { opsOf, opCutters } from './ops.mjs';
|
|
11
|
+
|
|
12
|
+
const { cuboid, cylinder, polygon } = jscad.primitives, { extrudeLinear } = jscad.extrusions, { subtract } = jscad.booleans;
|
|
13
|
+
const isNum = (x) => typeof x === 'number' && Number.isFinite(x);
|
|
14
|
+
const shown = (v) => { const s = v === undefined ? 'nothing' : JSON.stringify(v) ?? String(v); return s.length > 80 ? `${s.slice(0, 77)}...` : s; };
|
|
15
|
+
const mm = (x) => String(+Number(x).toFixed(2));
|
|
16
|
+
const FACES = ['top', 'bottom', 'front', 'back'];
|
|
17
|
+
const END_KINDS = ['cut', 'tapped'];
|
|
18
|
+
const DISPLAYS = ['link', 'preview'];
|
|
19
|
+
const OPTIONS = ['length', 'ends', 'ops', 'material', 'given', 'cells', 'display', 'tracks'];
|
|
20
|
+
const ROUND = ['round-tube', 'round-bar'];
|
|
21
|
+
|
|
22
|
+
/**
|
|
23
|
+
* @typedef {import('./profile.mjs').Profile} Profile
|
|
24
|
+
* @typedef {{ origin: number[], axis: number[], ref: number[] }} Anchor a point, the direction out of the beam there, and
|
|
25
|
+
* a direction square to it that fixes the turn about it: at an end, the beam's up (+y); on a face, along the beam toward end b
|
|
26
|
+
* @typedef {{ name: string, face: 'top' | 'bottom' | 'front' | 'back', index: number, slot: string | null, at: [number, number], normal: [number, number], along: [number, number], depth: number }} Place
|
|
27
|
+
* a place a face offers along the whole beam: its slot family (null where the face is closed there), where it meets
|
|
28
|
+
* the face in the section, and how far the slot goes in (0 for a closed face)
|
|
29
|
+
* @typedef {{ name: string, end: 'a' | 'b', at: [number, number], diameter: number, thread: string | null, tapped: boolean }} EndBore
|
|
30
|
+
* @typedef {{ kind: 'beam', name: string, title: string, profile: Profile, length: number,
|
|
31
|
+
* ends: { a: { kind: 'cut' | 'tapped', thread: string | null }, b: { kind: 'cut' | 'tapped', thread: string | null } },
|
|
32
|
+
* material: { name: string, density: number | null, modulus: number | null, given: boolean } | null,
|
|
33
|
+
* area: number, centroid: [number, number], mass: number | null, centreOfMass: [number, number, number],
|
|
34
|
+
* weight: { computed: number | null, sheet: number | null, difference: number | null },
|
|
35
|
+
* figures: Record<string, { value: number | null, unit: string, kind: string, source: string, from: 'sheet' | 'outline' }>,
|
|
36
|
+
* places: Place[], bores: EndBore[], anchors: Record<string, Anchor>, ops: object[], bought: true, printed: false,
|
|
37
|
+
* rests: object[], findings: object[] }} Beam
|
|
38
|
+
*/
|
|
39
|
+
|
|
40
|
+
// ends: one kind for both, [a, b], or { a, b }
|
|
41
|
+
function endsOf(what, ends, m) {
|
|
42
|
+
const pair = ends == null ? ['cut', 'cut'] : typeof ends === 'string' ? [ends, ends] : Array.isArray(ends) ? ends : typeof ends === 'object' ? [ends.a ?? 'cut', ends.b ?? 'cut'] : null;
|
|
43
|
+
if (!pair || pair.length !== 2) throw new Error(`${what}: ends is ${END_KINDS.join(' or ')} for both ends, [a, b], or { a, b } (got ${shown(ends)})`);
|
|
44
|
+
if (ends && typeof ends === 'object' && !Array.isArray(ends)) for (const k of Object.keys(ends)) if (!['a', 'b'].includes(k)) throw new Error(`${what}: ends names end a and end b (got "${k}")`);
|
|
45
|
+
const threaded = m.bores.filter((b) => b.thread != null);
|
|
46
|
+
return Object.fromEntries(pair.map((k, i) => {
|
|
47
|
+
const end = 'ab'[i];
|
|
48
|
+
if (!END_KINDS.includes(k)) throw new Error(`${what}: end ${end} is ${END_KINDS.join(' or ')} (got ${shown(k)}). A mitre, a drilled hole and the rest are operations: { ops: [{ op: 'mitre', at: 'a', angle: 45, about: 'top' }] }`);
|
|
49
|
+
if (k === 'tapped' && !threaded.length) throw new Error(`${what}: end ${end} is tapped, and ${m.name} has no bore with a thread to tap (bore_thread): leave it cut, or give the profile a bore_thread`);
|
|
50
|
+
return [end, { kind: k, thread: k === 'tapped' ? threaded[0].thread : null }];
|
|
51
|
+
}));
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
/**
|
|
55
|
+
* A beam as numbers: a length of a profile, its mass and centre of mass from the section and the alloy, the figures to
|
|
56
|
+
* design it with, and its anchors. A beam is bought: it is cut from stock, and its supply is checked.
|
|
57
|
+
* @param {Profile | string | object} profile a profile's model, or what profileModel takes ('2040-misumi-hfs5', or a rule set)
|
|
58
|
+
* @param {{ length: number, ends?: 'cut' | 'tapped' | ['cut' | 'tapped', 'cut' | 'tapped'] | { a?: 'cut' | 'tapped', b?: 'cut' | 'tapped' },
|
|
59
|
+
* ops?: object[], material?: string, given?: object, cells?: number }} o length: mm, end a to end b (on the long side where
|
|
60
|
+
* an end is mitred); ends: each end cut square (the default), or tapped (a tap op at that end, in the profile's bore_thread);
|
|
61
|
+
* ops: operations, each { op, at, ... } as OPS lists (cut, mitre, tap, access, drill, counterbore, pocket, notch,
|
|
62
|
+
* deburr), placed by an address on the beam (a, a.1, top@120); the model's ops are them worked out, dimensioned from end a; material: a material set's name in place of the profile's
|
|
63
|
+
* alloy (so a frame can be weighed in another metal or a plastic); given: profileModel's third argument; cells: raster
|
|
64
|
+
* cells for the torsion constant where the sheet gives none
|
|
65
|
+
* @returns {Beam}
|
|
66
|
+
*/
|
|
67
|
+
export function beamModel(profile, o = {}) {
|
|
68
|
+
const what = 'beamModel';
|
|
69
|
+
if (!o || typeof o !== 'object' || Array.isArray(o)) throw new Error(`${what}: the second argument is { length, ends, material } (got ${shown(o)})`);
|
|
70
|
+
for (const k of Object.keys(o)) if (!OPTIONS.includes(k)) throw new Error(`${what}: no option "${k}": it takes ${OPTIONS.join(', ')}`);
|
|
71
|
+
if (!(isNum(o.length) && o.length > 0)) throw new Error(`${what}: length is a number above 0, in mm from end a to end b (got ${shown(o.length)})`);
|
|
72
|
+
const given = o.given ?? {};
|
|
73
|
+
const base = profile?.kind === 'profile' ? profile : profileModel(profile, {}, given);
|
|
74
|
+
let m = base;
|
|
75
|
+
const changed = o.material != null && o.material !== base.material?.name;
|
|
76
|
+
if (changed) {
|
|
77
|
+
if (typeof o.material !== 'string') throw new Error(`${what}: material is a material set's name, such as al6063-t5 (got ${shown(o.material)})`);
|
|
78
|
+
// the same profile in another material: its own figures, the material changed, and the measured outline kept
|
|
79
|
+
m = profileModel({ name: m.name, part: 'profile', rules: m.figures }, { material: o.material }, { ...given, ...(m.measured ? { outline: m.measured } : {}) });
|
|
80
|
+
}
|
|
81
|
+
const L = o.length, ends = endsOf(what, o.ends, m), s = section(m, { torsion: false }), fig = beamFigures(m, { cells: o.cells });
|
|
82
|
+
if (changed) fig.massPerMetre = { value: s.massPerMetre, unit: 'kg/m', kind: 'derived', source: `worked out from the ${s.measured ? 'measured' : 'drawn'} outline of ${m.name} and the density of ${m.material?.name}`, from: 'outline' };
|
|
83
|
+
const density = m.material?.density ?? null, mass = density != null ? (s.area * L * density) / 1000 : null; // mm² x mm x g/cm³ / 1000 = g
|
|
84
|
+
const sheetMass = !changed && m.sheet.massPerMetre != null ? m.sheet.massPerMetre * L : null; // kg/m x mm = g
|
|
85
|
+
const weight = { computed: mass, sheet: sheetMass, difference: mass != null && sheetMass != null ? mass / sheetMass - 1 : null };
|
|
86
|
+
const centreOfMass = [+s.centroid[0].toFixed(6), +s.centroid[1].toFixed(6), L / 2]; // (to a millionth: a symmetric section's centroid is a rounding error off 0)
|
|
87
|
+
// the places a face offers, numbered along each face (top.1, top.2), with top alone for the first
|
|
88
|
+
const places = [];
|
|
89
|
+
for (const face of FACES) {
|
|
90
|
+
const list = [...m.faces[face]].sort((p, q) => p.index - q.index || (q.at[0] * p.normal[0] + q.at[1] * p.normal[1]) - (p.at[0] * p.normal[0] + p.at[1] * p.normal[1]));
|
|
91
|
+
list.forEach((p, i) => places.push({ name: `${face}.${i + 1}`, face, index: p.index, slot: p.slot, at: [...p.at], normal: [...p.normal], along: [...p.along], depth: p.slot ? m.slots[p.slot].cavityDepth : 0 }));
|
|
92
|
+
}
|
|
93
|
+
const bores = ['a', 'b'].flatMap((end) => m.bores.map((b, i) => ({ name: `${end}.${i + 1}`, end, at: [...b.at], diameter: b.diameter, thread: b.thread, tapped: ends[end].kind === 'tapped' && b.thread != null })));
|
|
94
|
+
const up = [0, 1, 0], anchors = { a: { origin: [0, 0, 0], axis: [0, 0, -1], ref: up }, b: { origin: [0, 0, L], axis: [0, 0, 1], ref: up } };
|
|
95
|
+
for (const b of bores) anchors[b.name] = { origin: [b.at[0], b.at[1], b.end === 'a' ? 0 : L], axis: [0, 0, b.end === 'a' ? -1 : 1], ref: up };
|
|
96
|
+
for (const p of places) {
|
|
97
|
+
const a = { origin: [p.at[0], p.at[1], L / 2], axis: [p.normal[0], p.normal[1], 0], ref: [0, 0, 1] };
|
|
98
|
+
anchors[p.name] = a; if (p.name.endsWith('.1')) anchors[p.face] = a;
|
|
99
|
+
}
|
|
100
|
+
// what to know: the mass beside the sheet's, and the length beside what the profile is sold and cut in
|
|
101
|
+
const findings = [], title = `${m.title}, ${mm(L)} mm`, name = `${m.name} x ${mm(L)}`;
|
|
102
|
+
if (mass == null) findings.push({ level: 'warn', code: 'beam.mass', text: `${name}: ${m.name} names no material with a density, so the beam has no mass: give one ({ material: 'al6063-t5' })`, rule: 'material' });
|
|
103
|
+
else {
|
|
104
|
+
findings.push({ level: 'info', code: 'beam.mass', text: `${name}: ${mm(mass)} g, from the ${s.measured ? 'measured' : 'drawn'} section's ${mm(s.area)} mm² and ${m.material.name}'s density ${density} g/cm³${sheetMass != null ? `; the sheet's ${m.sheet.massPerMetre} kg/m gives ${mm(sheetMass)} g (${weight.difference > 0 ? '+' : ''}${(weight.difference * 100).toFixed(1)}%)` : ''}`, values: { mass, ...(sheetMass != null ? { sheet: sheetMass } : {}) }, refs: { material: m.material.name } });
|
|
105
|
+
if (weight.difference != null && Math.abs(weight.difference) > DEFAULTS.section.value) findings.push({ level: 'warn', code: 'beam.mass', text: `${name}: the section weighs ${weight.difference > 0 ? '+' : ''}${(weight.difference * 100).toFixed(1)}% from the sheet's mass per metre, past the ${DEFAULTS.section.value * 100}% a drawn outline is held to: the drawn section is not the maker's (a hollow or a hooked lip it does not describe), so weigh it by the sheet's ${mm(sheetMass)} g`, rule: 'mass_per_metre', values: { mass, sheet: sheetMass, difference: weight.difference } });
|
|
106
|
+
}
|
|
107
|
+
const { lengths, cutMin, cutMax } = m.supply, longest = Math.max(cutMax ?? 0, ...lengths.filter(isNum));
|
|
108
|
+
if (longest > 0 && L > longest + 1e-9) findings.push({ level: 'warn', code: 'beam.length', text: `${name}: ${mm(L)} mm is longer than ${m.name} is sold or cut in (${mm(longest)} mm): it needs a joint along its length`, rule: cutMax != null ? 'cut_length_max' : 'lengths', values: { length: L, longest } });
|
|
109
|
+
if (cutMin != null && L < cutMin - 1e-9) findings.push({ level: 'warn', code: 'beam.length', text: `${name}: ${mm(L)} mm is shorter than the ${mm(cutMin)} mm the maker cuts ${m.name} to: cut it yourself, or ask`, rule: 'cut_length_min', values: { length: L, cutMin } });
|
|
110
|
+
const rests = [m.figures.area, m.figures.mass_per_metre, ...(m.material ? [m.material.figures.density] : [])].filter(Boolean).map((f) => ({ value: f.value, ...(f.unit ? { unit: f.unit } : {}), kind: f.kind, source: f.source }));
|
|
111
|
+
const b = { kind: 'beam', name, title, profile: m, length: L, ends,
|
|
112
|
+
material: m.material ? { name: m.material.name, density, modulus: m.material.modulus, given: changed } : null,
|
|
113
|
+
area: s.area, centroid: s.centroid, mass, centreOfMass, weight, figures: fig, places, bores, anchors, ops: [], bought: true, printed: false, rests, findings };
|
|
114
|
+
// operations: those given, a tap for an end said to be tapped, and a square cut at an end with no cut of its own
|
|
115
|
+
const given_ = o.ops ?? [];
|
|
116
|
+
if (!Array.isArray(given_)) throw new Error(`${what}: ops is a list of operations, [{ op: 'tap', at: 'a' }] (got ${shown(o.ops)})`);
|
|
117
|
+
const list = [...given_];
|
|
118
|
+
for (const e of ['a', 'b']) if (ends[e].kind === 'tapped' && !list.some((x) => x?.op === 'tap' && String(x.at ?? '').trim()[0] === e)) list.push({ op: 'tap', at: e });
|
|
119
|
+
let done;
|
|
120
|
+
try { done = opsOf(b, list, beamAnchor); } catch (e) { throw new Error(`${what}: ${String(e.message).replace(/^beamAnchor: /, '')}`); }
|
|
121
|
+
for (const x of done.ops) if (x.op === 'tap') { ends[x.end] = { kind: 'tapped', thread: x.thread }; for (const bo of bores) if (x.bores.includes(bo.name)) bo.tapped = true; }
|
|
122
|
+
for (const e of ['a', 'b']) if (!done.ops.some((x) => x.end === e && (x.op === 'cut' || x.op === 'mitre'))) done.ops.push({ op: 'cut', at: e, end: e, face: null, place: null, distance: e === 'a' ? 0 : L, line: `cut end ${e} square`, implied: true });
|
|
123
|
+
b.ops = done.ops.sort((p, q) => p.distance - q.distance); b.findings.push(...done.findings);
|
|
124
|
+
return b;
|
|
125
|
+
}
|
|
126
|
+
|
|
127
|
+
/**
|
|
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
|
+
* round section a twelve-sided prism): 12 triangles, light enough for a link and an overlap check. 'preview' (the
|
|
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. 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.
|
|
134
|
+
* @param {Beam | Profile | string | object} m a beam's model, or a profile with { length } as beamModel takes
|
|
135
|
+
* @param {{ display?: 'link' | 'preview', tracks?: boolean, length?: number, ends?: any, material?: string, given?: object, cells?: number }} [o]
|
|
136
|
+
* @returns {object} a JSCAD geom3, with .model holding beamModel's numbers (its anchors and mass)
|
|
137
|
+
*/
|
|
138
|
+
export function beam(m, o = {}) {
|
|
139
|
+
const what = 'beam', display = o.display ?? 'preview';
|
|
140
|
+
if (!DISPLAYS.includes(display)) throw new Error(`${what}: display is ${DISPLAYS.join(' or ')} (got ${shown(display)})`);
|
|
141
|
+
const b = m?.kind === 'beam' ? m : beamModel(m, o), p = b.profile, L = b.length;
|
|
142
|
+
let solid;
|
|
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] });
|
|
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); }
|
|
146
|
+
const cuts = opCutters(b, { envelope: display === 'link' }); // (a link keeps its box, cut only where an end is mitred)
|
|
147
|
+
if (cuts.length) solid = subtract(solid, ...cuts);
|
|
148
|
+
return Object.assign(solid, { model: b, display });
|
|
149
|
+
}
|
|
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
|
+
|
|
167
|
+
/**
|
|
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
|
|
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
|
|
170
|
+
* from end b, 'top@50%' the middle. A face's place with no distance is at the middle.
|
|
171
|
+
* @param {Beam} b a beam's model @param {string} address
|
|
172
|
+
* @returns {Anchor & { name: string, distance: number | null }}
|
|
173
|
+
*/
|
|
174
|
+
export function beamAnchor(b, address) {
|
|
175
|
+
const what = 'beamAnchor';
|
|
176
|
+
if (b?.kind !== 'beam') throw new Error(`${what}: give a beam's model (beamModel), not ${shown(b)}`);
|
|
177
|
+
if (typeof address !== 'string') throw new Error(`${what}: an address is a string such as 'a', 'a.1', 'top@120', 'top.2@-20' or 'top@50%' (got ${shown(address)})`);
|
|
178
|
+
const [name, at, ...more] = address.trim().split('@');
|
|
179
|
+
const a = b.anchors[name];
|
|
180
|
+
if (!a || more.length) throw new Error(`${what}: ${b.name} has no "${address}": it has ${Object.keys(b.anchors).join(', ')}, and a face's place takes a distance after @ (top@120, top@-20, top@50%)`);
|
|
181
|
+
if (at == null) return { name, ...a, origin: [...a.origin], distance: null };
|
|
182
|
+
if (/^[ab](\.|$)/.test(name)) throw new Error(`${what}: "${address}": an end is where it is, so it takes no distance; a face does (top@120)`);
|
|
183
|
+
const t = at.trim(), share = /^(-?\d+(?:\.\d+)?)%$/.exec(t), L = b.length;
|
|
184
|
+
if (!share && !/^-?\d+(\.\d+)?$/.test(t)) throw new Error(`${what}: "${address}": the distance is in mm from end a (120), from end b when negative (-20), or a share of the length (50%)`);
|
|
185
|
+
const z = share ? (Number(share[1]) / 100) * L : t.startsWith('-') ? L + Number(t) : Number(t);
|
|
186
|
+
if (!(z >= -1e-9 && z <= L + 1e-9)) throw new Error(`${what}: "${address}" is past the end of ${b.name}: it is ${mm(L)} mm long, so a distance is from 0 to ${mm(L)} mm, -${mm(L)} to -0 from end b, or 0% to 100%`);
|
|
187
|
+
return { name, origin: [a.origin[0], a.origin[1], z], axis: [...a.axis], ref: [...a.ref], distance: z };
|
|
188
|
+
}
|
|
189
|
+
|
|
190
|
+
/**
|
|
191
|
+
* What a printer can make of it, as findings. A beam of a profile is bought and cut from stock, and so is a profile:
|
|
192
|
+
* both fail. Printed beams are a later release.
|
|
193
|
+
* @param {Beam | Profile | object} x a beam's or a profile's model, or a solid beam() made
|
|
194
|
+
* @returns {{ level: 'fail', code: string, text: string }[]}
|
|
195
|
+
*/
|
|
196
|
+
export function printable(x) {
|
|
197
|
+
const m = x?.model?.kind === 'beam' ? x.model : x;
|
|
198
|
+
if (m?.kind === 'beam') return [{ level: 'fail', code: 'beam.printable', text: `${m.name} is a bought beam: cut from ${m.profile.name} stock and fitted, not printed. What prints is the parts that fasten to it` }];
|
|
199
|
+
if (m?.kind === 'profile') return [{ level: 'fail', code: 'beam.printable', text: `${m.name} is a bought profile: beams of it are cut from stock, not printed` }];
|
|
200
|
+
throw new Error(`printable: give a beam's model (beamModel), a profile's (profileModel), or a solid beam() made, not ${shown(x)}`);
|
|
201
|
+
}
|
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.d.mts
ADDED
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
/** The names a profile, a slot and a slot nut are written in: the fields of vocabulary.json. @type {Record<string, { unit?: string, choice?: string[], list?: boolean, says: string }>} */
|
|
2
|
+
export const FIELDS: Record<string, {
|
|
3
|
+
unit?: string;
|
|
4
|
+
choice?: string[];
|
|
5
|
+
list?: boolean;
|
|
6
|
+
says: string;
|
|
7
|
+
}>;
|
|
8
|
+
/** Every rule set frames knows, by its name. @type {Record<string, { name: string, part?: string, rules: Record<string, any> }>} */
|
|
9
|
+
export const SETS: Record<string, {
|
|
10
|
+
name: string;
|
|
11
|
+
part?: string;
|
|
12
|
+
rules: Record<string, any>;
|
|
13
|
+
}>;
|
|
14
|
+
/** The kit's own outlines, by the name of the set each belongs to (rules/outlines/<name>.json). @type {Record<string, { name?: string, source: string, licence: string, loops: number[][][] }>} */
|
|
15
|
+
export const OUTLINES: Record<string, {
|
|
16
|
+
name?: string;
|
|
17
|
+
source: string;
|
|
18
|
+
licence: string;
|
|
19
|
+
loops: number[][][];
|
|
20
|
+
}>;
|