Writes drawings to a PDF file: the page size, the millimeter scale, lines, circles and text positions.
How the precision is kept
Coordinates arrive in millimeters as 64-bit numbers and are written as decimal text with at most 4 decimals. The page content is scaled from millimeters to points by one matrix whose factor 72 ÷ 25.4 is also written with 4 decimals, as 2.8346. Circles are drawn as four cubic Bézier curves.
Open item. Write the millimeter-to-point scale with full precision instead of the 4-decimal value 2.8346.
Calculations under this policy
6 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.
Every coordinate, line width and matrix entry is rounded to 4 decimals when it is written. A value that is not finite is written as 0.
pdf.js
lines 19 to 23
BimCraft 0.8.1
export function num(v) {
if (!Number.isFinite(v)) return '0';
const s = (Math.abs(v) < 5e-5 ? 0 : v).toFixed(4);
return s.includes('.') ? s.replace(/0+$/, '').replace(/\.$/, '') : s;
}
Millimeters to points
Exact
The factor between millimeters and PDF points.
K = 72 ÷ 25.4
Both numbers are exact by definition and the quotient is the nearest 64-bit number to 2.834645669…
pdf.js
line 17
BimCraft 0.8.1
const K = 72 / 25.4;
Page scale matrix
64-bit
The matrix that lets the rest of the page be written in millimeters.
[K 0 0 K 0 0] with K written as num(K) = 2.8346
K passes through the 4-decimal number format, so the file holds 2.8346 instead of 2.834645669. That is a relative error of 1.6e-5 applied to every length on the page.
The sheet size is multiplied by the unrounded factor and then written with 4 decimals, so the page box does not carry the scale matrix's error.
pdf.js
line 109
BimCraft 0.8.1
const pt = (mm) => num(mm * K);
Circle as four curves
64-bit
A circle written as four cubic Bézier curves.
control distance k = 0.5522847498 × r
The constant is 4 ÷ 3 × (√2 − 1) written to 10 digits. The curves pass through the four quarter points exactly and bulge slightly outside the circle between them.
Centered and right-aligned text is moved back along its own direction by half or all of its width. The width comes from the Helvetica advance table in font.js, with bold taken as 5 % wider rather than measured.
PDF 1.4 content stream: a scale matrix, then path and text operators with numbers printed by toFixed(4) with trailing zeros removed.
Number types
64-bit numbers formatted to 4 decimals; values smaller than 5e-5 in size are written as 0.
Tolerances
No comparisons. Number format step 0.0001 (millimeters inside the page, points for the page box).
Limits
The scale written is 2.8346, while 72 ÷ 25.4 is 2.83464567; every length on the page is therefore about 0.0016 % short (0.016 mm per meter of paper). The page box is computed with the unrounded factor. A four-curve circle differs from a true circle by up to about 0.03 % of its radius.
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.