Resources Numerical accuracy Calculation policy

Add-on solids placed on the 3D tab

Converts the faces an add-on hands over from drawing units into the 3D model's units and places them.

How the precision is kept

Face corners arrive as 64-bit numbers in drawing units. They are taken relative to the first corner of the first face and multiplied by k, the meters per drawing unit of the 3D model (model3d.js). The first corner times k becomes the placement's translation.

Calculations under this policy

1 calculation 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/cadcraft-api.js CadCraft 0.8.2 64-bit 1 calculation Reviewed

Tests bin/test-cadcraft-addons.mjs

Face corners in model units

64-bit

The corners of an add-on's solid in the 3D model's units, and where the solid is placed.

local = (q − o) × k; translation = o × k

Each corner is one subtraction and one multiplication in 64-bit. The mesh is stored relative to its first corner, and that corner × k is the placement's translation, so a placed corner is (q − o) × k + o × k rather than q × k computed in one step.

  • addons/cadcraft-api.js
  • lines 202 to 210
  • CadCraft 0.8.2
const polys = spec && Array.isArray(spec.polys) ? spec.polys.filter((p) => Array.isArray(p) && p.length >= 3 && p.every((q) => Array.isArray(q) && q.length === 3 && q.every(Number.isFinite))) : [];
if (!polys.length) continue;
const o = polys[0][0];
const P = polys.map((p) => p.map((q) => [(q[0] - o[0]) * k, (q[1] - o[1]) * k, (q[2] - o[2]) * k]));
const name = String(spec.name || addon.manifest?.name || addon.id).replace(/[\u0000-\u001f]/g, ' ').slice(0, 60);
const d = meshDef(M, P, M.uniqueName(name));
if (!d.faces.size) { M.defs.delete(d.id); continue; }
if (Number(spec.smooth) > 0) softenEdges(d, [...d.edges.keys()], Math.min(60, Number(spec.smooth)));   // round surfaces shade smooth
const iid = M.place(M.root, d.id, translation([o[0] * k, o[1] * k, o[2] * k]));

In detail

Method
local corner = (q − o) × k; translation = o × k, with o the first corner of the first face.
Number types
64-bit numbers.
Limits
A face with fewer than 3 corners, or with a corner that is not three finite numbers, is left out.

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