Resources Numerical accuracy Calculation policy

Drawing the 3D check view and CAD sheets on screen

Draws the 3D check view with three.js and a DWG or DXF sheet on the canvas.

How the precision is kept

This code only draws. The 3D view hands its vertex lists to the graphics card as 32-bit floats; the canvas draws a CAD sheet's lines relative to a point near the data. No length, area, count or exported value comes from here.

Calculations under this policy

2 calculations in 2 source files. 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.

view3d.js TakeoffCraft 0.8.1 32-bit, display only 1 calculation Reviewed

Tests bin/test-takeoffcraft.mjs

Vertex buffers for the 3D view

32-bit, display only

Copies an object's triangles into a buffer for the graphics card.

THREE.Float32BufferAttribute converts the 64-bit vertex list to 32-bit for drawing. The object's reported quantities are not read from this buffer.

  • view3d.js
  • lines 225 to 226
  • TakeoffCraft 0.8.1
g.setAttribute('position', new THREE.Float32BufferAttribute(o.tris, 3));
g.computeVertexNormals();
cadset.js TakeoffCraft 0.8.1 32-bit, display only 1 calculation Reviewed

Tests bin/test-takeoffcraft-cad.mjs

Canvas paths for a CAD sheet

32-bit, display only

Builds the canvas paths of one batch of lines and fills.

Coordinates are written relative to the first point of the batch and the offset is put back in the canvas transform, which keeps the path's numbers small when the view is zoomed in. Screen only.

  • cadset.js
  • lines 399 to 421
  • TakeoffCraft 0.8.1
/** Path2D for a batch, relative to an origin near its data (keeps float precision when zoomed in). */
function pathsFor(page, b) {
  let p = page.paths.get(b);
  if (p) return p;
  const first = b.lines[0] || b.fills[0]?.rings[0] || [0, 0];
  const ox = first[0] || 0, oy = first[1] || 0;
  let lines = null;
  if (b.lines.length) {
    lines = new Path2D();
    for (const pl of b.lines) {
      lines.moveTo(pl[0] - ox, pl[1] - oy);
      for (let i = 2; i < pl.length; i += 2) lines.lineTo(pl[i] - ox, pl[i + 1] - oy);
    }
  }
  const fills = b.fills.map((f) => {
    const path = new Path2D();
    for (const r of f.rings) { path.moveTo(r[0] - ox, r[1] - oy); for (let i = 2; i < r.length; i += 2) path.lineTo(r[i] - ox, r[i + 1] - oy); path.closePath(); }
    return { path, pattern: f.pattern };
  });
  p = { origin: [ox, oy], lines, fills };
  page.paths.set(b, p);
  return p;
}

In detail

Method
three.js buffer geometry for the 3D view; Canvas 2D paths for CAD sheets.
Number types
Float32 buffers for the graphics card; 64-bit numbers handed to the canvas.
Limits
Picking in the 3D view selects a mark; the numbers shown for it are the 64-bit ones computed in scene3d.js.

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