Resources Numerical accuracy Calculation policy

Cabinets as 3D viewport bodies

Turns the cabinet job into boxes and meshes for the 3D viewport: every panel, the floor and the walls with their openings (CabinetCraft add-on).

How the precision is kept

The bodies are made for display only (the file's header says so). Coordinates are computed in 64-bit numbers, converted to millimeters and to the viewport's axes, and handed to the host's viewport as plain arrays. Curved walls are drawn as flat facets of at most 7.5 degrees.

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/bodies3d.js CadCraft 0.8.2 32-bit, display only 2 calculations Reviewed

Tests None found by the review

Triangles of a panel outline

32-bit, display only

Cuts a panel's outline into triangles for drawing.

ear when (b − a) × (c − a) > 1e-9 and no other point is inside the triangle

Ear clipping with fixed limits of 1e-9 on cross products in the job's unit squared. It returns index triples only; no coordinate is changed.

  • addons/cabinetcraft/lib/bodies3d.js
  • lines 33 to 53
  • CadCraft 0.8.2
/** Ear clipping of a simple polygon, counter-clockwise. */
export function triangulate(pts) {
  const n = pts.length, idx = pts.map((_, i) => i), out = [];
  const cross = (a, b, c) => (b[0] - a[0]) * (c[1] - a[1]) - (b[1] - a[1]) * (c[0] - a[0]);
  const inTri = (p, a, b, c) => cross(a, b, p) >= -1e-9 && cross(b, c, p) >= -1e-9 && cross(c, a, p) >= -1e-9;
  let guard = n * n + 10;
  while (idx.length > 3 && guard-- > 0) {
    let cut = false;
    for (let k = 0; k < idx.length; k++) {
      const i0 = idx[(k + idx.length - 1) % idx.length], i1 = idx[k], i2 = idx[(k + 1) % idx.length];
      const a = pts[i0], b = pts[i1], c = pts[i2];
      if (cross(a, b, c) <= 1e-9) continue;
      if (idx.some((j) => j !== i0 && j !== i1 && j !== i2 && inTri(pts[j], a, b, c))) continue;
      out.push([i0, i1, i2]); idx.splice(k, 1); cut = true; break;
    }
    if (!cut) break;
  }
  if (idx.length === 3) out.push([idx[0], idx[1], idx[2]]);
  void n;
  return out;
}

Room coordinates to viewport coordinates

32-bit, display only

A point of the room in the viewport's axes and millimeters.

k = 25.4 (inch job) or 1; (x, y, z) → (x·k, z·k, −y·k)

One multiplication per coordinate by 1 or by 25.4, the exact number of millimeters in an inch, and a swap of axes.

  • addons/cabinetcraft/lib/bodies3d.js
  • lines 67 to 68
  • CadCraft 0.8.2
const k = project.unit === 'in' ? 25.4 : 1;
const W = (x, y, z) => [x * k, z * k, -y * k];   // room → PartCraft world

In detail

Method
Ear clipping for prism caps; room (x, y, z) to viewport (x, z, −y) in millimeters.
Number types
64-bit numbers in plain arrays; the host's viewport decides what the graphics card receives.
Tolerances
Ear clipping accepts a corner when its cross product is above 1e-9 and treats points within −1e-9 as inside. Wall pieces shorter or lower than 1e-6 are left out.
Limits
A curved wall is shown as chords. Nothing here is written to the drawing or a file.

Approach: Display only

Computed to draw the screen, often in 32-bit on the graphics processor. No number a person reads, saves or exports comes from it.

Every policy that takes this approach