Resources Numerical accuracy Calculation policy

Part labels on label sheets

Places a label for every piece on a printable label sheet and sizes its bar code.

How the precision is kept

Label positions come from the template's margins, label size and gaps in millimeters, in 64-bit numbers. Every coordinate written into the SVG is rounded to 0.001 mm. The inch templates are entered as millimeter values that are exact multiples of 25.4.

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/cutlist/labels.js CadCraft 0.8.2 64-bit 2 calculations Reviewed

Tests None found by the review

Label position on the sheet

64-bit

Where each label is printed on the page, so that it lands on the die-cut label.

x = left + col × (label width + gap x); y = top + row × (label height + gap y)

The position is computed in 64-bit numbers and written rounded to 0.001 mm. The 10-label letter template's left margin of 3.96875 mm is therefore written as 3.969 mm.

  • addons/cabinetcraft/lib/cutlist/labels.js
  • lines 104 to 126
  • CadCraft 0.8.2
export function labelSheets(items, template, { startAt = 0, module = 0.33 } = {}) {
  const T = typeof template === 'string' ? TEMPLATES[template] : template;
  if (!T) throw new Error('labels: no template ' + template);   // i18n-ignore (for developers)
  const per = T.cols * T.rows, pages = [], warnings = [];
  let slots = [];
  const flush = () => {
    if (!slots.length) return;
    pages.push(`<svg xmlns="http://www.w3.org/2000/svg" width="${T.page.w}mm" height="${T.page.h}mm" viewBox="0 0 ${T.page.w} ${T.page.h}" font-family="Arial, Helvetica, sans-serif" data-page="${pages.length + 1}"><rect width="${T.page.w}" height="${T.page.h}" fill="#fff"/>${slots.join('')}</svg>`);
    slots = [];
  };
  let pos = Math.max(0, Math.min(per - 1, Math.floor(startAt) || 0));
  for (const it of items) {
    const c = pos % T.cols, r = Math.floor(pos / T.cols);
    const x = T.left + c * (T.label.w + T.gapX), y = T.top + r * (T.label.h + T.gapY);
    const { svg, warn } = labelSvg(it, x, y, T.label, { module });
    slots.push(svg);
    if (warn) warnings.push({ code: warn, id: it.id });
    pos++;
    if (pos >= per) { flush(); pos = 0; }
  }
  flush();
  return { pages, perPage: per, count: items.length, warnings };
}

Bar code module width

64-bit

The width of the narrowest bar of a label's Code 128 bar code, fitted to the space beside the id text.

module = min(0.33 mm, room ÷ (code width + 20))

The module shrinks to fit the label and the code is left out below 0.19 mm. The 20 added modules are the two quiet zones of 10 modules each.

  • addons/cabinetcraft/lib/cutlist/labels.js
  • lines 88 to 93
  • CadCraft 0.8.2
const enc = encode(it.id);
const idW = Math.min(W * 0.4, fs2 * 0.6 * it.id.length + p);
const room = W - 2 * p - idW;
const m = Math.min(module || 0.33, room / (enc.width + 20));
if (it.id && m >= 0.19) body += barsSvg(it.id, { x: p, y: barTop, h: barH, module: m, quiet: 10 });
else if (it.id) warn = 'barcode_too_small';

In detail

Method
Slot n sits in column n mod cols and row ⌊n ÷ cols⌋; its corner is the margin plus whole steps of label size and gap.
Number types
64-bit numbers, written as decimal text with three decimals.
Tolerances
A bar code is drawn only when its narrowest bar is at least 0.19 mm wide; otherwise the label carries the id as text and a warning is returned.
Limits
The sizes printed on a label are formatted by the caller; this file does not round them.

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