@rulecad/frames 0.0.0-stage → 0.1.7
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/LICENSE +21 -0
- package/README.md +573 -2
- package/beam.d.mts +142 -0
- package/beam.mjs +182 -0
- package/catalogue.d.mts +20 -0
- package/catalogue.mjs +239 -0
- package/cutlist.d.mts +88 -0
- package/cutlist.mjs +199 -0
- package/cutsheet.d.mts +23 -0
- package/cutsheet.mjs +118 -0
- package/frames.d.mts +6 -0
- package/frames.mjs +16 -0
- package/ops.d.mts +44 -0
- package/ops.mjs +319 -0
- package/package.json +58 -4
- package/profile.d.mts +268 -0
- package/profile.mjs +462 -0
- package/section.d.mts +43 -0
- package/section.mjs +140 -0
- package/slotnut.d.mts +207 -0
- package/slotnut.mjs +389 -0
package/cutlist.d.mts
ADDED
|
@@ -0,0 +1,88 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The beams by mark: beams that are the same (one profile, one material, one length and the same operations at the
|
|
3
|
+
* same places) share one, A, B, C and on, in order of profile and then the longest first.
|
|
4
|
+
* @param {object[]} beams beams' models (beamModel), or { id, beam } with an item's name
|
|
5
|
+
* @returns {{ mark: string, beam: object, items: string[], count: number }[]}
|
|
6
|
+
*/
|
|
7
|
+
export function beamMarks(beams: object[]): {
|
|
8
|
+
mark: string;
|
|
9
|
+
beam: object;
|
|
10
|
+
items: string[];
|
|
11
|
+
count: number;
|
|
12
|
+
}[];
|
|
13
|
+
/**
|
|
14
|
+
* Pieces packed into bars of the lengths sold, first-fit decreasing: every cut takes a kerf (the last one too, which
|
|
15
|
+
* parts the piece from the offcut), and the first end of each bar is trimmed square. A piece longer than a bar can give
|
|
16
|
+
* is left out, in unpacked.
|
|
17
|
+
* @param {{ length: number }[]} pieces each with its length, and anything else to keep (its mark, its item)
|
|
18
|
+
* @param {number[]} lengths the lengths sold, mm
|
|
19
|
+
* @param {{ kerf?: number, trim?: number }} [o] mm (CUT_DEFAULTS' kerf and trim where left out)
|
|
20
|
+
* @returns {{ bars: { length: number, cuts: object[], offcut: number }[], buy: { length: number, count: number }[], unpacked: object[], bought: number, offcut: number }}
|
|
21
|
+
* each cut carries at, where it starts from the bar's trimmed end (mm from the bar's first end)
|
|
22
|
+
*/
|
|
23
|
+
export function packBars(pieces: {
|
|
24
|
+
length: number;
|
|
25
|
+
}[], lengths: number[], o?: {
|
|
26
|
+
kerf?: number;
|
|
27
|
+
trim?: number;
|
|
28
|
+
}): {
|
|
29
|
+
bars: {
|
|
30
|
+
length: number;
|
|
31
|
+
cuts: object[];
|
|
32
|
+
offcut: number;
|
|
33
|
+
}[];
|
|
34
|
+
buy: {
|
|
35
|
+
length: number;
|
|
36
|
+
count: number;
|
|
37
|
+
}[];
|
|
38
|
+
unpacked: object[];
|
|
39
|
+
bought: number;
|
|
40
|
+
offcut: number;
|
|
41
|
+
};
|
|
42
|
+
/**
|
|
43
|
+
* A frame's cut list: each mark (beams that are the same) with its count, mass and operations, and for each profile the
|
|
44
|
+
* bars to buy, the cut order on each and its offcut, with the checks frame.cut makes (a beam longer than any sold length,
|
|
45
|
+
* lengths the cut tolerance cannot hold apart, beams that must match). Weighed by the maker's sheet where it gives a mass
|
|
46
|
+
* per metre, else by the drawn section.
|
|
47
|
+
* @param {object[]} beams beams' models (beamModel), or { id, beam } with an item's name
|
|
48
|
+
* @param {{ kerf?: number, trim?: number, tolerance?: number, stock?: number }} [o] mm, a workshop's own; CUT_DEFAULTS' where left out
|
|
49
|
+
* stock: each profile's { profile, supply ('sold', 'cut' by the maker, or 'assumed'), lengths, cuts (each length to cut and how
|
|
50
|
+
* many), bars, buy, unpacked, bought, offcut, kerf, trim, tolerance }
|
|
51
|
+
* @returns {{ marks: object[], stock: object[], rules: object, totals: { beams: number, grams: number, bars: number, bought: number, offcut: number }, findings: object[] }}
|
|
52
|
+
*/
|
|
53
|
+
export function cutList(beams: object[], o?: {
|
|
54
|
+
kerf?: number;
|
|
55
|
+
trim?: number;
|
|
56
|
+
tolerance?: number;
|
|
57
|
+
stock?: number;
|
|
58
|
+
}): {
|
|
59
|
+
marks: object[];
|
|
60
|
+
stock: object[];
|
|
61
|
+
rules: object;
|
|
62
|
+
totals: {
|
|
63
|
+
beams: number;
|
|
64
|
+
grams: number;
|
|
65
|
+
bars: number;
|
|
66
|
+
bought: number;
|
|
67
|
+
offcut: number;
|
|
68
|
+
};
|
|
69
|
+
findings: object[];
|
|
70
|
+
};
|
|
71
|
+
/**
|
|
72
|
+
* The cut list as lines of text: the marks, then each profile's bars to buy and the cuts on each.
|
|
73
|
+
* @param {ReturnType<typeof cutList>} c @returns {string[]}
|
|
74
|
+
*/
|
|
75
|
+
export function cutListText(c: ReturnType<typeof cutList>): string[];
|
|
76
|
+
/**
|
|
77
|
+
* The rules the cut list packs and checks by, each with what it rests on. A workshop that knows its own saw gives its
|
|
78
|
+
* own: cutList(beams, { kerf: 2.4, trim: 5 }).
|
|
79
|
+
* @type {Record<'kerf' | 'trim' | 'tolerance' | 'stock', { value: number, unit: string, rule: string, kind: string, source: string, checked: string }>}
|
|
80
|
+
*/
|
|
81
|
+
export const CUT_DEFAULTS: Record<"kerf" | "trim" | "tolerance" | "stock", {
|
|
82
|
+
value: number;
|
|
83
|
+
unit: string;
|
|
84
|
+
rule: string;
|
|
85
|
+
kind: string;
|
|
86
|
+
source: string;
|
|
87
|
+
checked: string;
|
|
88
|
+
}>;
|
package/cutlist.mjs
ADDED
|
@@ -0,0 +1,199 @@
|
|
|
1
|
+
// The cut list: a frame's beams by profile and length, each kind of beam with its mark, and the bars to buy. Beams that
|
|
2
|
+
// are the same (one profile, one material, one length and the same operations at the same places) share a mark, A, B,
|
|
3
|
+
// C and on, and one cut-and-drill sheet. Each profile's beams are packed into the lengths it is sold in, with the saw's
|
|
4
|
+
// kerf taken at every cut and a trim allowance off the first end of every bar: the bars to buy, the cut order on each,
|
|
5
|
+
// and what is left of each, the offcut.
|
|
6
|
+
//
|
|
7
|
+
// The packing is first-fit decreasing, a simple rule that is not always the fewest bars: the longest beam first, each on
|
|
8
|
+
// the first bar with room for it, else on a new bar. It is run with each sold length as the length of a new bar (and
|
|
9
|
+
// once with the shortest that holds the beam), each bar then cut down to the shortest sold length that holds what is on
|
|
10
|
+
// it, and the plan that buys the least metal kept (then the fewest bars). Units: mm, grams.
|
|
11
|
+
|
|
12
|
+
const isNum = (x) => typeof x === 'number' && Number.isFinite(x);
|
|
13
|
+
const shown = (v) => { const s = v === undefined ? 'nothing' : JSON.stringify(v) ?? String(v); return s.length > 80 ? `${s.slice(0, 77)}...` : s; };
|
|
14
|
+
const mm = (x) => String(+Number(x).toFixed(2));
|
|
15
|
+
const d1 = (x) => Number(x).toFixed(1);
|
|
16
|
+
const EPS = 1e-9;
|
|
17
|
+
const CHECKED = '2026-11-15';
|
|
18
|
+
|
|
19
|
+
/**
|
|
20
|
+
* The rules the cut list packs and checks by, each with what it rests on. A workshop that knows its own saw gives its
|
|
21
|
+
* own: cutList(beams, { kerf: 2.4, trim: 5 }).
|
|
22
|
+
* @type {Record<'kerf' | 'trim' | 'tolerance' | 'stock', { value: number, unit: string, rule: string, kind: string, source: string, checked: string }>}
|
|
23
|
+
*/
|
|
24
|
+
export const CUT_DEFAULTS = {
|
|
25
|
+
kerf: { value: 3, unit: 'mm', rule: 'The width of metal a cut takes, taken at every cut on a bar: a 250 mm carbide blade for aluminium and other non-ferrous metals (80 teeth, 30 mm bore) cuts 3.0 mm on a 2.2 mm plate. A mitre or chop saw for aluminium extrusion commonly takes a blade of this size; give your own saw\'s', kind: 'default', source: 'Popular Tools NF2503080 non-ferrous saw blade, 250 mm x 80T TCG, sold by Carbide Processors, https://carbideprocessors.com/non-ferrous-cutting-saw-blade-250mm-x-80t-tcg-popular-tools-nf2503080', checked: CHECKED },
|
|
26
|
+
trim: { value: 10, unit: 'mm', rule: 'Cut off the first end of every bar to square it before the first beam is measured: a mill end can be bruised, burred or out of square from the extruder\'s saw. A working allowance, not taken from a supplier: no figure for it was found', kind: 'estimate', source: 'workshop practice, not checked against a supplier', checked: CHECKED },
|
|
27
|
+
tolerance: { value: 0.5, unit: 'mm', rule: 'How far a cut length may be from the length asked, either way, where the profile\'s set gives no cut_tolerance: MISUMI\'s for its cut lengths of extrusion, taken for any saw cut against a stop. A hand saw to a pencil line does worse', kind: 'estimate', source: 'MISUMI FA Mechanical Standard Components catalogue 2014, page 2-527, https://my.misumi-ec.com/pdf/fa/2014/p2_527.pdf ("L Dimension Tolerance ±0.5mm"), taken for other saws without a check', checked: CHECKED },
|
|
28
|
+
stock: { value: 6000, unit: 'mm', rule: 'The bar length a profile is packed into where its set gives no lengths and no cut-to-length range: 6 m, the length Bosch Rexroth and item sell their profiles in (their sets in @rulecad/rules). Taken for a generic section without a check: ask your supplier', kind: 'estimate', source: 'the lengths rules of profile-2020-bosch and profile-2020-item-5 in @rulecad/rules, taken for other profiles without a check', checked: CHECKED },
|
|
29
|
+
};
|
|
30
|
+
|
|
31
|
+
const OPTIONS = ['kerf', 'trim', 'tolerance', 'stock'];
|
|
32
|
+
|
|
33
|
+
// The rules as used: the defaults, or what was given (a workshop's own, so kind measured)
|
|
34
|
+
function rulesOf(o, what) {
|
|
35
|
+
if (!o || typeof o !== 'object' || Array.isArray(o)) throw new Error(`${what}: the options are { ${OPTIONS.join(', ')} }, each a number in mm (got ${shown(o)})`);
|
|
36
|
+
for (const k of Object.keys(o)) if (!OPTIONS.includes(k)) throw new Error(`${what}: no option "${k}": it takes ${OPTIONS.join(', ')}, each a number in mm`);
|
|
37
|
+
return Object.fromEntries(OPTIONS.map((k) => {
|
|
38
|
+
if (o[k] == null) return [k, { ...CUT_DEFAULTS[k] }];
|
|
39
|
+
const v = o[k], min = k === 'stock' ? EPS : 0;
|
|
40
|
+
if (!(isNum(v) && v >= min)) throw new Error(`${what}: ${k} is a number in mm, ${k === 'stock' ? 'above' : 'at least'} 0 (got ${shown(v)})`);
|
|
41
|
+
return [k, { value: v, unit: 'mm', rule: `${CUT_DEFAULTS[k].rule.split(':')[0]}: given`, kind: 'measured', source: 'given to cutList', checked: CHECKED }];
|
|
42
|
+
}));
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
// The beams as { id, beam }: a list of those, or of beam models (named 1, 2, 3 in order)
|
|
46
|
+
function beamsOf(list, what) {
|
|
47
|
+
if (!Array.isArray(list)) throw new Error(`${what}: give a list of beams, each a beam's model (beamModel) or { id, beam } (got ${shown(list)})`);
|
|
48
|
+
return list.map((x, i) => {
|
|
49
|
+
const b = x?.kind === 'beam' ? x : x?.beam, id = x?.kind === 'beam' ? String(i + 1) : x?.id;
|
|
50
|
+
if (b?.kind !== 'beam') throw new Error(`${what}: beams[${i}] is a beam's model (beamModel) or { id, beam } (got ${shown(x)})`);
|
|
51
|
+
if (typeof id !== 'string' || !id) throw new Error(`${what}: beams[${i}]'s id is a name, such as x1 (got ${shown(id)})`);
|
|
52
|
+
return { id, beam: b };
|
|
53
|
+
});
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
// A, B, ... Z, AA, AB, ...
|
|
57
|
+
const letters = (n) => { let s = ''; for (let k = n + 1; k > 0; k = Math.floor((k - 1) / 26)) s = String.fromCharCode(65 + ((k - 1) % 26)) + s; return s; };
|
|
58
|
+
// What makes two beams the same: profile, material, length and every operation's line (each says where and how big)
|
|
59
|
+
const keyOf = (b) => JSON.stringify([b.profile.name, b.material?.name ?? null, +b.length.toFixed(2), b.ops.map((o) => o.line)]);
|
|
60
|
+
|
|
61
|
+
/**
|
|
62
|
+
* The beams by mark: beams that are the same (one profile, one material, one length and the same operations at the
|
|
63
|
+
* same places) share one, A, B, C and on, in order of profile and then the longest first.
|
|
64
|
+
* @param {object[]} beams beams' models (beamModel), or { id, beam } with an item's name
|
|
65
|
+
* @returns {{ mark: string, beam: object, items: string[], count: number }[]}
|
|
66
|
+
*/
|
|
67
|
+
export function beamMarks(beams) {
|
|
68
|
+
const list = beamsOf(beams, 'beamMarks'), by = new Map();
|
|
69
|
+
for (const { id, beam } of list) { const k = keyOf(beam), g = by.get(k) ?? { beam, items: [], key: k }; g.items.push(id); by.set(k, g); }
|
|
70
|
+
return [...by.values()].sort((p, q) => p.beam.profile.name.localeCompare(q.beam.profile.name) || q.beam.length - p.beam.length || p.key.localeCompare(q.key))
|
|
71
|
+
.map((g, i) => ({ mark: letters(i), beam: g.beam, items: g.items, count: g.items.length }));
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
// One plan: first-fit decreasing, new bars of open(piece) long, each then cut down to the shortest sold length that holds it
|
|
75
|
+
function firstFit(pieces, sold, open, kerf, trim) {
|
|
76
|
+
const bars = [];
|
|
77
|
+
for (const p of pieces) {
|
|
78
|
+
const need = p.length + kerf;
|
|
79
|
+
let bar = bars.find((b) => b.free >= need - EPS);
|
|
80
|
+
if (!bar) { const L = open(p); bar = { length: L, free: L - trim, cuts: [] }; bars.push(bar); }
|
|
81
|
+
bar.cuts.push(p); bar.free -= need;
|
|
82
|
+
}
|
|
83
|
+
for (const b of bars) { const used = b.length - b.free, L = sold.find((s) => s >= used - EPS); b.free += L - b.length; b.length = L; }
|
|
84
|
+
return bars;
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
/**
|
|
88
|
+
* Pieces packed into bars of the lengths sold, first-fit decreasing: every cut takes a kerf (the last one too, which
|
|
89
|
+
* parts the piece from the offcut), and the first end of each bar is trimmed square. A piece longer than a bar can give
|
|
90
|
+
* is left out, in unpacked.
|
|
91
|
+
* @param {{ length: number }[]} pieces each with its length, and anything else to keep (its mark, its item)
|
|
92
|
+
* @param {number[]} lengths the lengths sold, mm
|
|
93
|
+
* @param {{ kerf?: number, trim?: number }} [o] mm (CUT_DEFAULTS' kerf and trim where left out)
|
|
94
|
+
* @returns {{ bars: { length: number, cuts: object[], offcut: number }[], buy: { length: number, count: number }[], unpacked: object[], bought: number, offcut: number }}
|
|
95
|
+
* each cut carries at, where it starts from the bar's trimmed end (mm from the bar's first end)
|
|
96
|
+
*/
|
|
97
|
+
export function packBars(pieces, lengths, o = {}) {
|
|
98
|
+
const what = 'packBars';
|
|
99
|
+
if (!Array.isArray(pieces) || pieces.some((p) => !(isNum(p?.length) && p.length > 0))) throw new Error(`${what}: pieces is a list of { length }, each above 0 mm (got ${shown(pieces)})`);
|
|
100
|
+
if (!Array.isArray(lengths) || !lengths.length || lengths.some((l) => !(isNum(l) && l > 0))) throw new Error(`${what}: lengths is a list of the lengths sold, each above 0 mm (got ${shown(lengths)})`);
|
|
101
|
+
const r = rulesOf({ ...(o.kerf != null ? { kerf: o.kerf } : {}), ...(o.trim != null ? { trim: o.trim } : {}) }, what), kerf = r.kerf.value, trim = r.trim.value;
|
|
102
|
+
const sold = [...new Set(lengths)].sort((a, b) => a - b), longest = sold.at(-1), room = longest - trim;
|
|
103
|
+
const sorted = [...pieces].sort((a, b) => b.length - a.length), fits = sorted.filter((p) => p.length + kerf <= room + EPS), unpacked = sorted.filter((p) => p.length + kerf > room + EPS);
|
|
104
|
+
let best = [];
|
|
105
|
+
if (fits.length) {
|
|
106
|
+
const opens = [(p) => sold.find((s) => s - trim >= p.length + kerf - EPS), ...sold.map((s) => (p) => (s - trim >= p.length + kerf - EPS ? s : longest))];
|
|
107
|
+
const plans = opens.map((open) => firstFit(fits, sold, open, kerf, trim)), total = (bars) => bars.reduce((t, b) => t + b.length, 0);
|
|
108
|
+
best = plans.reduce((a, b) => (total(b) < total(a) - EPS || (Math.abs(total(b) - total(a)) <= EPS && b.length < a.length) ? b : a));
|
|
109
|
+
}
|
|
110
|
+
// each bar's cut order: the trim, then the longest first, as packed
|
|
111
|
+
const bars = best.sort((a, b) => b.length - a.length || b.cuts.length - a.cuts.length).map((b) => {
|
|
112
|
+
let at = trim;
|
|
113
|
+
const cuts = b.cuts.map((p) => { const c = { ...p, at: +at.toFixed(6) }; at += p.length + kerf; return c; });
|
|
114
|
+
return { length: b.length, cuts, offcut: +(b.length - at).toFixed(6) };
|
|
115
|
+
});
|
|
116
|
+
const buy = sold.map((l) => ({ length: l, count: bars.filter((b) => b.length === l).length })).filter((x) => x.count).reverse();
|
|
117
|
+
return { bars, buy, unpacked, bought: bars.reduce((t, b) => t + b.length, 0), offcut: +bars.reduce((t, b) => t + b.offcut, 0).toFixed(6), kerf, trim };
|
|
118
|
+
}
|
|
119
|
+
|
|
120
|
+
// An operation in a few words for the list
|
|
121
|
+
function opWords(o) {
|
|
122
|
+
const at = o.end ? `at ${o.end}` : `at ${o.place}@${d1(o.distance)}`;
|
|
123
|
+
if (o.op === 'mitre') return `mitre ${mm(o.angle)}° about ${o.about} ${at}`;
|
|
124
|
+
if (o.op === 'tap') return `tap ${o.thread} x ${mm(o.depth)} ${at}`;
|
|
125
|
+
if (o.op === 'access' || o.op === 'drill') return `${o.op} ${o.thread && o.kind === 'tap' ? o.thread : `Ø${mm(o.diameter)}`} ${at}`;
|
|
126
|
+
if (o.op === 'counterbore') return `counterbore Ø${mm(o.seat.diameter)} ${at}`;
|
|
127
|
+
if (o.op === 'pocket') return `pocket ${o.size ? `${mm(o.size[0])} x ${mm(o.size[1])}` : 'by outline'} ${at}`;
|
|
128
|
+
if (o.op === 'notch') return `notch ${mm(o.length)} ${at}`;
|
|
129
|
+
return `${o.op} ${at}`;
|
|
130
|
+
}
|
|
131
|
+
|
|
132
|
+
/**
|
|
133
|
+
* A frame's cut list: each mark (beams that are the same) with its count, mass and operations, and for each profile the
|
|
134
|
+
* bars to buy, the cut order on each and its offcut, with the checks frame.cut makes (a beam longer than any sold length,
|
|
135
|
+
* lengths the cut tolerance cannot hold apart, beams that must match). Weighed by the maker's sheet where it gives a mass
|
|
136
|
+
* per metre, else by the drawn section.
|
|
137
|
+
* @param {object[]} beams beams' models (beamModel), or { id, beam } with an item's name
|
|
138
|
+
* @param {{ kerf?: number, trim?: number, tolerance?: number, stock?: number }} [o] mm, a workshop's own; CUT_DEFAULTS' where left out
|
|
139
|
+
* stock: each profile's { profile, supply ('sold', 'cut' by the maker, or 'assumed'), lengths, cuts (each length to cut and how
|
|
140
|
+
* many), bars, buy, unpacked, bought, offcut, kerf, trim, tolerance }
|
|
141
|
+
* @returns {{ marks: object[], stock: object[], rules: object, totals: { beams: number, grams: number, bars: number, bought: number, offcut: number }, findings: object[] }}
|
|
142
|
+
*/
|
|
143
|
+
export function cutList(beams, o = {}) {
|
|
144
|
+
const what = 'cutList', rules = rulesOf(o, what), marks = beamMarks(beamsOf(beams, what)), findings = [];
|
|
145
|
+
const kerf = rules.kerf.value, trim = rules.trim.value;
|
|
146
|
+
const lines = marks.map(({ mark, beam: b, items, count }) => {
|
|
147
|
+
const mitre = b.ops.find((x) => x.op === 'mitre' && x.shortLength != null), grams = b.weight?.sheet ?? b.mass;
|
|
148
|
+
return { mark, profile: b.profile.name, material: b.material?.name ?? null, length: b.length, ...(mitre ? { shortLength: Math.min(...b.ops.filter((x) => x.op === 'mitre').map((x) => x.shortLength)) } : {}),
|
|
149
|
+
count, items, grams: grams != null ? +grams.toFixed(1) : null, weighedBy: b.weight?.sheet != null ? 'sheet' : b.mass != null ? 'section' : null,
|
|
150
|
+
ops: b.ops.filter((x) => !x.implied).map(opWords), beam: b };
|
|
151
|
+
});
|
|
152
|
+
const profiles = [...new Set(lines.map((l) => l.profile))], stock = [];
|
|
153
|
+
for (const name of profiles) {
|
|
154
|
+
const ls = lines.filter((l) => l.profile === name), p = ls[0].beam.profile, s = p.supply, tol = s.cutTolerance ?? rules.tolerance.value;
|
|
155
|
+
const tolRule = s.cutTolerance != null ? 'cut_tolerance' : 'cut tolerance (CUT_DEFAULTS)';
|
|
156
|
+
const pieces = ls.flatMap((l) => l.items.map((item) => ({ mark: l.mark, item, length: l.length })));
|
|
157
|
+
let entry;
|
|
158
|
+
if (s.lengths.length || s.cutMax == null) {
|
|
159
|
+
const sold = s.lengths.length ? s.lengths : [rules.stock.value], r = packBars(pieces, sold, { kerf, trim });
|
|
160
|
+
entry = { profile: name, supply: s.lengths.length ? 'sold' : 'assumed', lengths: [...sold].sort((a, b) => a - b), tolerance: tol, ...r };
|
|
161
|
+
const room = Math.max(...sold) - trim - kerf;
|
|
162
|
+
for (const u of r.unpacked) findings.push({ level: 'fail', code: 'frame.cut', text: `${u.item}: ${mm(u.length)} mm of ${name} is longer than any length it is ${s.lengths.length ? 'sold' : 'taken to come'} in (${entry.lengths.map(mm).join(', ')} mm): a bar gives ${mm(room)} mm after a ${mm(trim)} mm trim and a ${mm(kerf)} mm cut. Join two lengths along it, or buy it cut to length`, values: { length: u.length, room }, refs: { item: u.item, mark: u.mark, profile: name, rule: s.lengths.length ? 'lengths' : 'stock' } });
|
|
163
|
+
} else {
|
|
164
|
+
// no sold lengths, but the maker cuts to length: each beam is bought at its length, no saw of ours
|
|
165
|
+
const bars = pieces.filter((x) => x.length <= s.cutMax + EPS).map((x) => ({ length: x.length, cuts: [{ ...x, at: 0 }], offcut: 0 })), unpacked = pieces.filter((x) => x.length > s.cutMax + EPS);
|
|
166
|
+
const buy = [...new Set(bars.map((b) => b.length))].sort((a, b) => b - a).map((l) => ({ length: l, count: bars.filter((b) => b.length === l).length }));
|
|
167
|
+
entry = { profile: name, supply: 'cut', lengths: [], cutMin: s.cutMin, cutMax: s.cutMax, tolerance: tol, bars, buy, unpacked, bought: bars.reduce((t, b) => t + b.length, 0), offcut: 0, kerf: 0, trim: 0 };
|
|
168
|
+
for (const u of unpacked) findings.push({ level: 'fail', code: 'frame.cut', text: `${u.item}: ${mm(u.length)} mm of ${name} is longer than the ${mm(s.cutMax)} mm the maker cuts it to: join two lengths along it`, values: { length: u.length, cutMax: s.cutMax }, refs: { item: u.item, mark: u.mark, profile: name, rule: 'cut_length_max' } });
|
|
169
|
+
}
|
|
170
|
+
// the lengths to cut, longest first, however many marks share one
|
|
171
|
+
entry.cuts = [...new Set(pieces.map((x) => +x.length.toFixed(2)))].sort((a, b) => b - a).map((l) => ({ length: l, count: pieces.filter((x) => Math.abs(x.length - l) < 0.005).length }));
|
|
172
|
+
stock.push(entry);
|
|
173
|
+
// lengths the cut tolerance cannot hold apart: two marks nearer than two cuts' tolerance
|
|
174
|
+
const byLength = [...ls].sort((a, b) => a.length - b.length);
|
|
175
|
+
for (let i = 0; i + 1 < byLength.length; i++) {
|
|
176
|
+
const a = byLength[i], b = byLength[i + 1], gap = b.length - a.length;
|
|
177
|
+
if (gap > 1e-6 && gap < 2 * tol - EPS) findings.push({ level: 'warn', code: 'frame.cut', text: `${name}: mark ${a.mark} (${a.items.join(', ')}) at ${mm(a.length)} mm and mark ${b.mark} (${b.items.join(', ')}) at ${mm(b.length)} mm differ by ${mm(gap)} mm, less than two cuts at ±${mm(tol)} mm can hold apart: make them one length if they should match, or cut them against one stop`, values: { a: a.length, b: b.length, gap, tolerance: tol }, refs: { marks: [a.mark, b.mark], profile: name, rule: tolRule } });
|
|
178
|
+
}
|
|
179
|
+
for (const l of ls) if (l.count > 1 && tol > 0) findings.push({ level: 'info', code: 'frame.cut', text: `mark ${l.mark} (${l.items.join(', ')}): ${l.count} beams of ${mm(l.length)} mm, each cut to ±${mm(tol)} mm, may differ by up to ${mm(2 * tol)} mm: where they must match (opposite sides of a frame), cut them against one stop`, values: { length: l.length, count: l.count, tolerance: tol }, refs: { mark: l.mark, items: l.items, profile: name, rule: tolRule } });
|
|
180
|
+
}
|
|
181
|
+
const totals = { beams: lines.reduce((t, l) => t + l.count, 0), grams: +lines.reduce((t, l) => t + (l.grams ?? 0) * l.count, 0).toFixed(1), bars: stock.reduce((t, s) => t + s.bars.length, 0), bought: stock.reduce((t, s) => t + s.bought, 0), offcut: +stock.reduce((t, s) => t + s.offcut, 0).toFixed(3) };
|
|
182
|
+
return { marks: lines, stock, rules, totals, findings };
|
|
183
|
+
}
|
|
184
|
+
|
|
185
|
+
/**
|
|
186
|
+
* The cut list as lines of text: the marks, then each profile's bars to buy and the cuts on each.
|
|
187
|
+
* @param {ReturnType<typeof cutList>} c @returns {string[]}
|
|
188
|
+
*/
|
|
189
|
+
export function cutListText(c) {
|
|
190
|
+
const out = [];
|
|
191
|
+
for (const l of c.marks) out.push([` ${l.mark.padEnd(3)}${String(l.count).padStart(3)} ×`, `${l.profile} x ${mm(l.length)} mm${l.shortLength != null ? ` (short side ${mm(l.shortLength)})` : ''}`, l.grams != null ? `${mm(l.grams)} g each` : 'mass not given', l.ops.length ? l.ops.join('; ') : 'cut square', l.items.join(', ')].join(' '));
|
|
192
|
+
for (const s of c.stock) {
|
|
193
|
+
out.push(` ${s.profile}: ${s.cuts.length} length${s.cuts.length === 1 ? '' : 's'}, ${s.cuts.map((x) => `${x.count} × ${mm(x.length)}`).join(', ')} mm`);
|
|
194
|
+
if (s.supply === 'cut') { out.push(` ${s.profile}: cut to length by the maker (${mm(s.cutMin ?? 0)} to ${mm(s.cutMax)} mm): ${s.buy.map((b) => `${b.count} × ${mm(b.length)} mm`).join(', ')}`); continue; }
|
|
195
|
+
out.push(` ${s.profile}: buy ${s.buy.map((b) => `${b.count} × ${mm(b.length)} mm`).join(', ')}${s.supply === 'assumed' ? ` (no sold length in its set: ${mm(s.lengths[0])} mm assumed)` : ''}; kerf ${mm(s.kerf)}, trim ${mm(s.trim)}; ${mm(s.offcut)} mm left over`);
|
|
196
|
+
s.bars.forEach((b, i) => out.push(` bar ${i + 1}, ${mm(b.length)} mm: trim ${mm(s.trim)}, ${b.cuts.map((x) => `${x.mark} ${mm(x.length)} (${x.item})`).join(', ')}; offcut ${mm(b.offcut)}`));
|
|
197
|
+
}
|
|
198
|
+
return out;
|
|
199
|
+
}
|
package/cutsheet.d.mts
ADDED
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* A beam's cut-and-drill sheet, to scale: its section from end a with the faces named, a view of each face with work
|
|
3
|
+
* on it (that face up), each operation dimensioned from end a to 0.1 mm, and the operations listed in order, each tap
|
|
4
|
+
* with its thread and depth.
|
|
5
|
+
* @param {object} b a beam's model (beamModel)
|
|
6
|
+
* @param {{ mark?: string, items?: string[], grams?: number | null }} [o] the beam's mark on the cut list, the items it is, its mass each
|
|
7
|
+
* @returns {{ svg: string, scale: number, faces: string[], dimensions: { op: number, distance: number, text: string }[] }}
|
|
8
|
+
* scale: the beam is drawn 1:scale; faces: the views drawn; dimensions: each operation's figure from end a, as on the sheet
|
|
9
|
+
*/
|
|
10
|
+
export function beamSheet(b: object, o?: {
|
|
11
|
+
mark?: string;
|
|
12
|
+
items?: string[];
|
|
13
|
+
grams?: number | null;
|
|
14
|
+
}): {
|
|
15
|
+
svg: string;
|
|
16
|
+
scale: number;
|
|
17
|
+
faces: string[];
|
|
18
|
+
dimensions: {
|
|
19
|
+
op: number;
|
|
20
|
+
distance: number;
|
|
21
|
+
text: string;
|
|
22
|
+
}[];
|
|
23
|
+
};
|
package/cutsheet.mjs
ADDED
|
@@ -0,0 +1,118 @@
|
|
|
1
|
+
// A beam's cut-and-drill sheet, as SVG: what a person at the saw and the drill needs, to scale. The section seen from
|
|
2
|
+
// end a, each face named and the tapped bores marked; a view of each face that has work on it, that face up, end a on
|
|
3
|
+
// the left; every operation dimensioned from end a to 0.1 mm; and a numbered list of the operations, each tap with its
|
|
4
|
+
// thread and depth. Units: mm, the sheet drawn in mm too (it prints to scale at 100%).
|
|
5
|
+
import { outline } from './profile.mjs';
|
|
6
|
+
import { CUT_DEFAULTS } from './cutlist.mjs';
|
|
7
|
+
|
|
8
|
+
const mm = (x) => String(+Number(x).toFixed(2));
|
|
9
|
+
const d1 = (x) => Number(x).toFixed(1);
|
|
10
|
+
const f = (x) => String(+Number(x).toFixed(3));
|
|
11
|
+
const esc = (s) => String(s).replace(/&/g, '&').replace(/</g, '<').replace(/>/g, '>').replace(/"/g, '"');
|
|
12
|
+
const INK = '#1a1a1a', THIN = '#666', METAL = '#dde3ea', CUT = '#c03a2b';
|
|
13
|
+
const SCALES = [1, 2, 5, 10, 20, 50, 100];
|
|
14
|
+
// Each face's view: looking at it from outside, end a on the left, and which way in the section is up the page
|
|
15
|
+
// (the face frame's y: top +x, bottom -x, front +y, back -y), and how wide the face is
|
|
16
|
+
const FACE_VIEW = { top: { up: [1, 0], wide: 'width' }, bottom: { up: [-1, 0], wide: 'width' }, front: { up: [0, 1], wide: 'height' }, back: { up: [0, -1], wide: 'height' } };
|
|
17
|
+
const OPPOSITE = { top: 'bottom', bottom: 'top', front: 'back', back: 'front' };
|
|
18
|
+
const DIR = { top: [0, 1], bottom: [0, -1], front: [-1, 0], back: [1, 0] };
|
|
19
|
+
|
|
20
|
+
function pen() {
|
|
21
|
+
const out = [];
|
|
22
|
+
return {
|
|
23
|
+
out,
|
|
24
|
+
line: (a, b, c, d, s = INK, w = 0.25, dash = '') => out.push(`<line x1="${f(a)}" y1="${f(b)}" x2="${f(c)}" y2="${f(d)}" stroke="${s}" stroke-width="${w}"${dash ? ` stroke-dasharray="${dash}"` : ''}/>`),
|
|
25
|
+
circle: (x, y, r, s = INK, fill = 'none') => out.push(`<circle cx="${f(x)}" cy="${f(y)}" r="${f(r)}" fill="${fill}" stroke="${s}" stroke-width="0.25"/>`),
|
|
26
|
+
path: (d, fill = 'none', s = INK, w = 0.25) => out.push(`<path d="${d}" fill="${fill}" fill-rule="evenodd" stroke="${s}" stroke-width="${w}" stroke-linejoin="round"/>`),
|
|
27
|
+
text: (x, y, t, { anchor = 'start', size = 3, turn = 0, weight = '' } = {}) => out.push(`<text x="${f(x)}" y="${f(y)}"${turn ? ` transform="rotate(${turn} ${f(x)} ${f(y)})"` : ''} text-anchor="${anchor}" font-size="${size}"${weight ? ` font-weight="${weight}"` : ''} font-family="system-ui, sans-serif" fill="${INK}">${esc(t)}</text>`),
|
|
28
|
+
};
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
/**
|
|
32
|
+
* A beam's cut-and-drill sheet, to scale: its section from end a with the faces named, a view of each face with work
|
|
33
|
+
* on it (that face up), each operation dimensioned from end a to 0.1 mm, and the operations listed in order, each tap
|
|
34
|
+
* with its thread and depth.
|
|
35
|
+
* @param {object} b a beam's model (beamModel)
|
|
36
|
+
* @param {{ mark?: string, items?: string[], grams?: number | null }} [o] the beam's mark on the cut list, the items it is, its mass each
|
|
37
|
+
* @returns {{ svg: string, scale: number, faces: string[], dimensions: { op: number, distance: number, text: string }[] }}
|
|
38
|
+
* scale: the beam is drawn 1:scale; faces: the views drawn; dimensions: each operation's figure from end a, as on the sheet
|
|
39
|
+
*/
|
|
40
|
+
export function beamSheet(b, o = {}) {
|
|
41
|
+
if (b?.kind !== 'beam') throw new Error(`beamSheet: give a beam's model (beamModel) (got ${b === undefined ? 'nothing' : typeof b})`);
|
|
42
|
+
const p = b.profile, L = b.length, mark = o.mark ?? null, items = o.items ?? [], grams = o.grams ?? b.weight?.sheet ?? b.mass;
|
|
43
|
+
const ops = b.ops.map((x, i) => ({ ...x, n: i + 1 }));
|
|
44
|
+
// the views: each face with work on it or a mitre seen from it, else the top
|
|
45
|
+
const faces = Object.keys(FACE_VIEW).filter((k) => ops.some((x) => x.face === k || (x.op === 'mitre' && x.about === k)));
|
|
46
|
+
if (!faces.length) faces.push('top');
|
|
47
|
+
const k = SCALES.find((s) => L / s <= 200) ?? Math.ceil(L / 200), s = 1 / k; // the beam's scale, 1:k
|
|
48
|
+
const big = Math.max(p.width, p.height), ks = [4, 2, 1].find((z) => big * z <= 44) ?? 0.5; // the section's, ks:1
|
|
49
|
+
const x0 = 78, W = Math.max(297, x0 + L * s + 24), { out, line, circle, path, text } = pen();
|
|
50
|
+
// heading
|
|
51
|
+
text(10, 12, `${mark ? `Mark ${mark}: ` : ''}${p.name} x ${d1(L)} mm`, { size: 5, weight: 'bold' });
|
|
52
|
+
text(10, 18.5, [items.length ? `${items.length} off: ${items.join(', ')}` : null, p.title, grams != null ? `${mm(grams)} g each` : null, b.material?.name].filter(Boolean).join(' · '), { size: 3 });
|
|
53
|
+
text(10, 23.5, `Beam 1:${k}, section ${ks >= 1 ? `${ks}:1` : `1:${1 / ks}`}. All in mm, measured from end a. Cut to ±${mm(p.supply.cutTolerance ?? CUT_DEFAULTS.tolerance.value)}.`, { size: 3 });
|
|
54
|
+
// the section from end a: top up, front on the right (looking from a toward b)
|
|
55
|
+
const cx = 38, cy = 58, X = (x) => cx - x * ks, Y = (y) => cy - y * ks, loops = outline(p).loops;
|
|
56
|
+
path(loops.map((l) => `M ${l.map(([x, y]) => `${f(X(x))} ${f(Y(y))}`).join(' L ')} Z`).join(' '), METAL);
|
|
57
|
+
text(cx, Y(p.height / 2) - 2, 'top', { anchor: 'middle', size: 2.6 }); text(cx, Y(-p.height / 2) + 4.5, 'bottom', { anchor: 'middle', size: 2.6 });
|
|
58
|
+
text(X(p.width / 2) - 1.5, cy + 1, 'back', { anchor: 'end', size: 2.6 }); text(X(-p.width / 2) + 1.5, cy + 1, 'front', { anchor: 'start', size: 2.6 });
|
|
59
|
+
text(cx, cy + big * ks / 2 + 11, 'section at end a,', { anchor: 'middle', size: 2.6 }); text(cx, cy + big * ks / 2 + 14.5, 'seen from a, top up', { anchor: 'middle', size: 2.6 });
|
|
60
|
+
let ty = cy + big * ks / 2 + 20;
|
|
61
|
+
for (const t of ops.filter((x) => x.op === 'tap')) for (const bn of t.bores) {
|
|
62
|
+
const bo = b.bores.find((x) => x.name === bn); if (!bo) continue;
|
|
63
|
+
if (t.end === 'a') circle(X(bo.at[0]), Y(bo.at[1]), (t.major / 2) * ks, CUT);
|
|
64
|
+
text(cx, ty, `(${t.n}) ${bn}: tap ${t.thread} x ${mm(t.depth)} deep`, { anchor: 'middle', size: 2.6 }); ty += 4;
|
|
65
|
+
}
|
|
66
|
+
// each face's view
|
|
67
|
+
const dimensions = [];
|
|
68
|
+
let y = 40;
|
|
69
|
+
for (const face of faces) {
|
|
70
|
+
const v = FACE_VIEW[face], w = p[v.wide], h = w * s < 6 ? 6 / s : w, top = y, mid = y + (h * s) / 2, U = (pt) => mid - ((pt[0] * v.up[0] + pt[1] * v.up[1]) * h / w) * s, Z = (z) => x0 + z * s;
|
|
71
|
+
text(x0, top - 3, `${face} face up: seen from the ${face}, end a on the left${h !== w ? ` (across drawn ${mm(h / w)} times its size)` : ''}`, { size: 3, weight: 'bold' });
|
|
72
|
+
// the outline, with any mitre seen
|
|
73
|
+
const corner = (end, side) => { // where the outline's edge on this side (+1 the upper, -1 the lower) meets the end
|
|
74
|
+
const m = ops.find((x) => x.op === 'mitre' && x.end === end);
|
|
75
|
+
if (!m) return end === 'a' ? 0 : L;
|
|
76
|
+
const seen = m.about === face || m.about === OPPOSITE[face], u = DIR[m.long][0] * v.up[0] + DIR[m.long][1] * v.up[1];
|
|
77
|
+
const c = seen ? ((u > 0) === (side > 0) ? 0 : m.cut) : face === m.long ? 0 : m.cut;
|
|
78
|
+
return end === 'a' ? c : L - c;
|
|
79
|
+
};
|
|
80
|
+
const yT = top, yB = top + h * s, poly = [[corner('a', 1), yT], [corner('b', 1), yT], [corner('b', -1), yB], [corner('a', -1), yB]];
|
|
81
|
+
path(`M ${poly.map(([z, yy]) => `${f(Z(z))} ${f(yy)}`).join(' L ')} Z`, METAL);
|
|
82
|
+
for (const pl of b.places.filter((q) => q.face === face && q.slot)) line(Z(0) - 3, U(pl.at), Z(L) + 3, U(pl.at), THIN, 0.18, '4 1 1 1');
|
|
83
|
+
text(Z(0) - 2, mid + 1, 'a', { anchor: 'end', size: 3.2, weight: 'bold' }); text(Z(L) + 2, mid + 1, 'b', { size: 3.2, weight: 'bold' });
|
|
84
|
+
// the work on this face
|
|
85
|
+
const here = ops.filter((x) => x.face === face);
|
|
86
|
+
for (const x of here) {
|
|
87
|
+
const zc = Z(x.distance), uc = U(x.anchor.origin);
|
|
88
|
+
if (x.op === 'access' || x.op === 'drill') circle(zc, uc, Math.max((x.diameter / 2) * s, 0.4), CUT);
|
|
89
|
+
if (x.op === 'counterbore') { circle(zc, uc, Math.max((x.seat.diameter / 2) * s, 0.6), CUT); circle(zc, uc, Math.max((x.diameter / 2) * s, 0.4), CUT); }
|
|
90
|
+
if (x.op === 'pocket' && x.size) path(`M ${f(zc - x.size[0] * s / 2)} ${f(uc - x.size[1] * s / 2)} h ${f(x.size[0] * s)} v ${f(x.size[1] * s)} h ${f(-x.size[0] * s)} Z`, 'none', CUT);
|
|
91
|
+
if (x.op === 'pocket' && x.outline) path(`M ${x.outline.map(([a, c]) => `${f(zc + a * s)} ${f(uc - c * s)}`).join(' L ')} Z`, 'none', CUT);
|
|
92
|
+
if (x.op === 'notch') path(`M ${f(zc - x.length * s / 2)} ${f(uc - x.width * s / 2)} h ${f(x.length * s)} v ${f(x.width * s)} h ${f(-x.length * s)} Z`, 'none', CUT);
|
|
93
|
+
text(zc + 1, uc - Math.max((x.diameter ?? 2) / 2 * s, 0.6) - 0.8, `(${x.n})`, { size: 2.2 });
|
|
94
|
+
}
|
|
95
|
+
// dimensions from end a: a leader down from each, its figure turned to read up the page, the length last
|
|
96
|
+
const yd = yB + 3, marks = [...here.map((x) => ({ n: x.n, z: x.distance, from: U(x.anchor.origin) })), { n: null, z: Math.max(corner('b', 1), corner('b', -1)), from: yB }];
|
|
97
|
+
line(Z(0), yB, Z(0), yd + 3, THIN, 0.18); text(Z(0) + 1, yd + 3.5, '0', { size: 2.6, turn: 90 });
|
|
98
|
+
let last = Z(0);
|
|
99
|
+
for (const m of marks.sort((a, c) => a.z - c.z)) {
|
|
100
|
+
const at = Math.max(Z(m.z), last + 3.2); last = at;
|
|
101
|
+
line(Z(m.z), m.from, Z(m.z), yd, THIN, 0.18, m.n ? '1 0.6' : ''); line(Z(m.z), yd, at, yd + 2, THIN, 0.18); line(at, yd + 2, at, yd + 3, THIN, 0.18);
|
|
102
|
+
const t = d1(m.z); text(at + 1, yd + 3.5, t, { size: 2.6, turn: 90 });
|
|
103
|
+
if (m.n) dimensions.push({ op: m.n, distance: m.z, text: t });
|
|
104
|
+
}
|
|
105
|
+
y = yd + 26;
|
|
106
|
+
}
|
|
107
|
+
// the operations, in order from end a
|
|
108
|
+
y = Math.max(y, ty + 4);
|
|
109
|
+
text(10, y, 'Operations, in order from end a', { size: 3.4, weight: 'bold' }); y += 5.5;
|
|
110
|
+
for (const x of ops) {
|
|
111
|
+
const where = x.end ? `end ${x.end}` : `${x.place ?? x.face}, ${d1(x.distance)} from a`;
|
|
112
|
+
text(10, y, `${x.n}.`, { size: 3 }); text(17, y, `${x.op} · ${where}`, { size: 3, weight: 'bold' }); text(80, y, x.line, { size: 3 }); y += 5;
|
|
113
|
+
}
|
|
114
|
+
text(10, y + 3, 'Deburr every cut and hole. Check each length against its figure before drilling.', { size: 2.6 });
|
|
115
|
+
const H = y + 10;
|
|
116
|
+
const svg = `<svg xmlns="http://www.w3.org/2000/svg" width="${f(W)}mm" height="${f(H)}mm" viewBox="0 0 ${f(W)} ${f(H)}"><rect width="100%" height="100%" fill="#fff"/>${out.join('')}</svg>\n`;
|
|
117
|
+
return { svg, scale: k, faces, dimensions };
|
|
118
|
+
}
|
package/frames.d.mts
ADDED
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
export * from "./profile.mjs";
|
|
2
|
+
export { beamSheet } from "./cutsheet.mjs";
|
|
3
|
+
export { beamModel, beam, beamAnchor, printable } from "./beam.mjs";
|
|
4
|
+
export { OPS, OP_DEFAULTS } from "./ops.mjs";
|
|
5
|
+
export { CUT_DEFAULTS, beamMarks, packBars, cutList, cutListText } from "./cutlist.mjs";
|
|
6
|
+
export { slotNutModel, nutFit, slotNut, nutFor, carrierModel, carrier, CARRIER_DEFAULTS } from "./slotnut.mjs";
|
package/frames.mjs
ADDED
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
// @rulecad/frames: structures from beams, of any profile. This release reads a profile (a beam's constant section, as
|
|
2
|
+
// a model from its rule set, its outline, and what that outline is worth beside the maker's sheet) and makes beams of
|
|
3
|
+
// it: a length with its mass, its anchors, the operations on it (cut, mitre, tap, holes, pockets, notches) and its solid;
|
|
4
|
+
// and a frame's cut list (the bars to buy and the cuts on each) and a cut-and-drill sheet for each kind of beam. Beams in assemblies, joins, fittings and guides follow: the
|
|
5
|
+
// plan is https://github.com/JoniBach/rulecad/issues/240.
|
|
6
|
+
//
|
|
7
|
+
// Every profile, slot family and slot nut is a rule set in @rulecad/rules, so the numbers are open data and live
|
|
8
|
+
// there. A section is drawn in x (across, its width) and y (up, its height), with the middle of its envelope at the
|
|
9
|
+
// origin; a beam runs along z from end a at z = 0. Its faces are top (+y), bottom (-y), front (-x) and back (+x).
|
|
10
|
+
// Units: mm, grams, degrees.
|
|
11
|
+
export * from './profile.mjs';
|
|
12
|
+
export { beamModel, beam, beamAnchor, printable } from './beam.mjs';
|
|
13
|
+
export { OPS, OP_DEFAULTS } from './ops.mjs';
|
|
14
|
+
export { CUT_DEFAULTS, beamMarks, packBars, cutList, cutListText } from './cutlist.mjs';
|
|
15
|
+
export { beamSheet } from './cutsheet.mjs';
|
|
16
|
+
export { slotNutModel, nutFit, slotNut, nutFor, carrierModel, carrier, CARRIER_DEFAULTS } from './slotnut.mjs';
|
package/ops.d.mts
ADDED
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* A beam's operations, each checked and worked out: where it is (its distance from end a, its frame), its sizes (from
|
|
3
|
+
* @rulecad/fixings where a thread names it), its line on the sheet, and what to know about it. Bad input is refused
|
|
4
|
+
* by name.
|
|
5
|
+
* @param {object} b a beam's model, before its ops (beamModel calls this)
|
|
6
|
+
* @param {object[]} list the operations: { op, at, ... } as OPS lists
|
|
7
|
+
* @param {(b: object, address: string) => object} anchorOf beamAnchor
|
|
8
|
+
* @returns {{ ops: object[], findings: object[] }}
|
|
9
|
+
*/
|
|
10
|
+
export function opsOf(b: object, list: object[], anchorOf: (b: object, address: string) => object): {
|
|
11
|
+
ops: object[];
|
|
12
|
+
findings: object[];
|
|
13
|
+
};
|
|
14
|
+
/**
|
|
15
|
+
* The cutters a beam's operations take out of its solid, in the beam's frame. Mitres alone where only the envelope
|
|
16
|
+
* matters (a link's box); every hole, pocket and notch for a preview.
|
|
17
|
+
* @param {object} b a beam's model, with its ops @param {{ envelope?: boolean }} [o]
|
|
18
|
+
* @returns {object[]} JSCAD geom3s to subtract
|
|
19
|
+
*/
|
|
20
|
+
export function opCutters(b: object, { envelope }?: {
|
|
21
|
+
envelope?: boolean;
|
|
22
|
+
}): object[];
|
|
23
|
+
/**
|
|
24
|
+
* The operations a beam takes, each with the keys it takes besides op and at. at is an address on the beam: an end
|
|
25
|
+
* (a, b), an end's bore (a.1), or a face's place with a distance from end a (top@120, top@-20 from end b, top@50%).
|
|
26
|
+
* @type {Record<string, { what: string, at: 'end' | 'bore' | 'face', keys: string[] }>}
|
|
27
|
+
*/
|
|
28
|
+
export const OPS: Record<string, {
|
|
29
|
+
what: string;
|
|
30
|
+
at: "end" | "bore" | "face";
|
|
31
|
+
keys: string[];
|
|
32
|
+
}>;
|
|
33
|
+
/**
|
|
34
|
+
* The rules operations are checked and sized by, each with what it rests on.
|
|
35
|
+
* @type {Record<string, { value: number, unit: string, rule: string, kind: string, source: string, checked: string }>}
|
|
36
|
+
*/
|
|
37
|
+
export const OP_DEFAULTS: Record<string, {
|
|
38
|
+
value: number;
|
|
39
|
+
unit: string;
|
|
40
|
+
rule: string;
|
|
41
|
+
kind: string;
|
|
42
|
+
source: string;
|
|
43
|
+
checked: string;
|
|
44
|
+
}>;
|