Writes a drawing sheet's lines, circles, fills and text into a DWG model or a DXF R12 file at 1 unit = 1 mm on paper.
How the precision is kept
Sheet coordinates are 64-bit paper millimeters. Every coordinate, radius and text height is rounded to six decimals (0.000001 mm) before it is written, in both formats. A filled circle becomes a 48-sided polygon under a true circle. Text height is the font size times 0.718, a two-figure approximation of the font's capital height.
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.
The rounding applied to every number written to the file.
round(v × 10⁶) ÷ 10⁶
Math.round on the value times one million, then a division. The result is the nearest 64-bit number to a six-decimal value.
dwgout.js
line 28
DetailCraft 0.8.1
const r6 = (v) => Math.round(v * 1e6) / 1e6;
Text position and height
64-bit
Where a line of text sits and how tall it is in the DWG model.
height = size × 0.718
Position and height are rounded to six decimals. 0.718 is written in the file as the capital height of Helvetica or Arial per unit of size. The rotation is passed on as stored.
The polygon used as the boundary of a filled circle.
(c_x + r·cos(2π·i ÷ 48), c_y + r·sin(2π·i ÷ 48))
A 48-sided polygon inside the circle, with each vertex rounded to six decimals. The circle itself is also written as a true circle with its exact center and radius.
dwgout.js
lines 91 to 95
DetailCraft 0.8.1
function circlePts(it, n = 48) {
const out = [];
for (let i = 0; i < n; i++) { const a = 2 * Math.PI * i / n; out.push({ x: r6(it.c[0] + it.r * Math.cos(a)), y: r6(it.c[1] + it.r * Math.sin(a)) }); }
return out;
}
A number in the DXF text
64-bit
How each coordinate is printed in the DXF file.
The value is rounded to six decimals and printed by String, so trailing zeros are dropped; a whole number is printed with one decimal place.
The line weight written for a layer, in hundredths of a millimeter.
round(w × 100)
The pen width in millimeters is rounded to a whole number of hundredths, which is how the format stores line weights.
dwgout.js
lines 30 to 38
DetailCraft 0.8.1
/** The pen of an item → { name, w, dash, lt } (lineweight in 1/100 mm). */
export function penOf(it) {
const w = it.w ?? 0.25, dash = it.dash && it.dash.length ? it.dash : null;
if (!dash) { const k = KNOWN.find((p) => !p.dash && w >= p.min); return { name: k.name, w: Math.round(w * 100), dash: null, lt: 'CONTINUOUS' }; }
const k = KNOWN.find((p) => sameDash(p.dash, dash));
if (k) return { name: k.name, w: Math.round(w * 100), dash, lt: k.lt };
const key = 'DC_DASH_' + dash.map((v) => String(r6(v)).replace('.', 'p')).join('_');
return { name: key.replace(/_/g, '-'), w: Math.round(w * 100), dash, lt: key };
}
In detail
Method
One entity per display-list item; coordinates copied after rounding.
Number types
64-bit numbers rounded to 6 decimals; DXF numbers as decimal text.
Tolerances
Dash patterns matched to the known pens within 1e-9.
Limits
Six decimals on a sheet up to about a meter wide keeps about ten significant digits. The values are paper coordinates of a drawing, not model geometry. DXF R12 carries no fills and no line weights.
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.