Apparel commands: piece table, marks and marker output
The Apparel add-on's commands that put numbers into the drawing or a file: the piece table, grain lines and buttonholes, automatic nesting on a marker and the marker's PDF.
How the precision is kept
The commands call the library files for the geometry and add unit factors and rounding of their own. The piece table rounds perimeters and areas to 2 decimals before they are printed or written to CSV. Marks picked in the drawing are stored at 6 decimals. Automatic nesting is run on a raster of the fabric width ÷ 750 with a time limit.
Open item. Write the piece table's CSV with the unrounded values and round only what is printed on the command line.
Calculations under this policy
11 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.
Sew and cut perimeter and area of every piece in every size, as printed and as exported to CSV.
perimeter → toFixed(2); area ÷ k → toFixed(2), k = 100 for mm² to cm², 1 for in²
The values are rounded to 2 decimals in this function, before both the command line and the CSV export, so the exported file carries the rounded numbers. 100 mm² per cm² is exact.
addons/apparel/main.js
lines 502 to 515
CadCraft 0.8.2
/** Every piece (or the selected ones) × its sizes. */
function tableRows(doc, only = null) {
const rows = [];
let u = 'mm';
for (const e of doc.all()) {
if (!isPiece(e) || (only && !only.has(e.id))) continue;
const d = api.objects.dataOf(e);
if (!d) continue;
u = d.u;
const k = d.u === 'in' ? 1 : 100; // mm² → cm²
for (const r of pieceRows(d)) rows.push({ style: d.style, piece: d.name, size: r.size, qty: d.qty ?? 1, sewPerimeter: +r.sewPerimeter.toFixed(2), cutPerimeter: +r.cutPerimeter.toFixed(2), sewArea: +(r.sewArea / k).toFixed(2), cutArea: +(r.cutArea / k).toFixed(2) });
}
return { rows, u };
}
Default grain line
64-bit
The grain line a new piece gets: through its centroid, up the page.
h = 0.3 × (maxY − minY); a = (cₓ, cᵧ − h); b = (cₓ, cᵧ + h); each → toFixed(6)
The centroid and box are those of the sampled outline. The two end points are rounded to 6 decimals when stored.
addons/apparel/main.js
lines 122 to 127
CadCraft 0.8.2
/** A grain line through the middle of the piece, up the page, 60 % of its height. */
function autoGrain(data, style = 'both') {
const { path } = sampled(ptsOf(data.pts), true);
const b = bounds(path), m = centroid(path), h = (b.maxY - b.minY) * 0.3;
return { a: [+m.x.toFixed(6), +(m.y - h).toFixed(6)], b: [+m.x.toFixed(6), +(m.y + h).toFixed(6)], s: ARROWS.includes(style) ? style : 'both' };
}
Buttonhole from two picked points
64-bit
The center, length and angle stored for a buttonhole.
center = (q + b) ÷ 2; L = |b − q|; angle = atan2(Δy, Δx) × 180 ÷ π
Center and length are rounded to 6 decimals and the angle to 4 decimals of a degree before they are stored. A length below 1e-9 is refused.
The marker's position is subtracted first and the difference is turned, so a marker far from the drawing origin does not cost digits in the turned values.
The length, used area, efficiency and piece count kept with a marker after every change to the drawing.
Only pieces that lie wholly on the fabric are counted. The numbers come from stats in marker.js and are stored with the marker when any of them changed.
The nesting engine (lib/nest/nest.js, not part of this review) is called with a raster cell of the fabric width ÷ 750 and a time limit of 3000 ms. The positions it returns are turned into the drawing with one 64-bit expression per coordinate and stored unrounded.
The text of a seam length or walk difference on the command line.
mm: 1 decimal, 0 below 0.05; inches: fractions to 1/16
Display rounding only: the measured value is not changed. A length is therefore shown no finer than 0.1 mm or 1/16 in.
addons/apparel/main.js
lines 1162 to 1163
CadCraft 0.8.2
/** A measured length: millimetres to one decimal, inches in fractions to 1/16 (CadCraft's units.js). */
export function fmtLen(v, u) { return u === 'in' ? formatLength(v, { lunits: 5, prec: 4 }) + ' in' : (Math.abs(v) < 0.05 ? '0' : Number(v).toFixed(1)) + ' mm'; }
In detail
Method
Inverse of the block reference's matrix for picked points; unit factors 100 (mm² to cm²) and 25.4 (inches to mm); rotation and translation of nested pieces into the drawing.
Number types
64-bit numbers.
Tolerances
Table values: 2 decimals. Stored marks: 6 decimals; buttonhole angle: 4 decimals of a degree. A buttonhole shorter than 1e-9 is refused. A walked notch counts as matching within 0.5 mm (1/32 in). Lengths shown: 0.1 mm or 1/16 in.
Limits
The nesting call is given a time limit of 3 seconds and a raster cell of the fabric width ÷ 750.
Approach: 64-bit, stated limit
The arithmetic is 64-bit, but the method or the data sets the accuracy: a solver tolerance, a mesh, a step size, a datum shift, a table. The limit is stated where the result is shown.