Resources Numerical accuracy Calculation policy

Cabinet job totals: linear stock and sheet count

Adds up the hardwood to buy by length and counts the sheets a nested job uses.

How the precision is kept

The linear total is a sum of quantity times length in 64-bit numbers, added in the order of the parts and rounded to six decimals once at the end. The sheet count is a sum of whole numbers. The nesting itself is in the nest module and is recorded there.

Calculations under this policy

2 calculations in 1 source file. The code is read from the released app when this page loads. It is the calculation people run, not a copy kept for this page.

addons/cabinetcraft/lib/sheets.js CadCraft 0.8.2 64-bit 2 calculations Reviewed

Tests None found by the review

Linear stock to buy

64-bit

The number of pieces and the total length of each hardwood section in the job.

length = Σ qty × length; pieces = Σ qty

The products are added in part order and the total is rounded to six decimals once, after the sum. Groups are keyed by the exact width and thickness, so two widths that differ in the last digit are listed separately. No cutting allowance is added.

  • addons/cabinetcraft/lib/sheets.js
  • lines 91 to 100
  • CadCraft 0.8.2
export function linearList(linear) {
  const g = new Map();
  for (const p of linear.map(cleanPart).filter(Boolean)) {
    const k = p.material + '|' + p.thickness + '|' + p.width;
    if (!g.has(k)) g.set(k, { material: p.material, thickness: p.thickness, width: p.width, pieces: 0, length: 0 });
    const e = g.get(k);
    e.pieces += p.qty; e.length += p.qty * p.length;
  }
  return [...g.values()].map((e) => ({ ...e, length: r6(e.length) })).sort((a, b) => a.material.localeCompare(b.material) || a.width - b.width);
}

Sheets used by a nested job

Exact

The total number of sheets over all materials, with each material's own count and efficiency.

sheets = Σ sheets per material

A sum of whole numbers. The efficiency of each material is copied from the nest result without change.

  • addons/cabinetcraft/lib/sheets.js
  • lines 45 to 50
  • CadCraft 0.8.2
/** The pieces of a nest put together (also what the worker's answer is joined into). */
export function nestJoin(done, margin) {
  const mats = done.map((d) => d.mat), seq = done.flatMap((d) => d.seq), unplaced = done.flatMap((d) => d.unplaced);
  const sheets = mats.reduce((n, m) => n + m.result.sheets.length, 0);
  return { mats, seq, sheets, unplaced, margin, efficiency: mats.map((m) => ({ material: m.material, thickness: m.thickness, sheets: m.result.sheets.length, efficiency: m.result.efficiency, sheet: m.sheet })) };
}

In detail

Method
Parts cut by length are grouped by material, thickness and width; each group's pieces and total length are summed.
Number types
64-bit numbers; counts are whole numbers.
Tolerances
The total length is rounded to 1e-6 job units.

Approach: 64-bit, direct

Every value is a 64-bit number from input to result. Formulas are closed form or a direct solve, and every comparison uses a stated tolerance.

Every policy that takes this approach