Resources Numerical accuracy Calculation policy

DWG and DXF views on screen

Draws a compiled drawing in the 2D view and in the 3D view.

How the precision is kept

The 3D view moves the geometry to the drawing's center, scales it so the largest extent is 100 units and stores it in Float32Array for the GPU; the file's header gives that as the reason drawings in state-plane or millimeter coordinates keep their precision in 32-bit floats. The 2D view draws the 64-bit compiled drawing through the canvas transform. These functions only draw and pick.

Calculations under this policy

3 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.

dwg-view3d.js BimCraft 0.8.1 32-bit, display only 2 calculations Reviewed

Tests tools/bimcraft-test/browser-3d.mjs

Drawing coordinates to scene coordinates

32-bit, display only

The positions sent to the GPU: centered on the drawing and scaled to about 100 units across.

scene = (p − center) × 100 ÷ largest extent

The subtraction and the scaling are done in 64-bit and the result is stored in a Float32Array. Because the center is taken off first, the 32-bit values hold the position within the drawing, not the full coordinate.

  • dwg-view3d.js
  • lines 117 to 121
  • BimCraft 0.8.1
const toScene = (src) => {
  const a = new Float32Array(src.length);
  for (let i = 0; i < src.length; i += 3) { a[i] = (src[i] - c[0]) * s; a[i + 1] = (src[i + 1] - c[1]) * s; a[i + 2] = (src[i + 2] - c[2]) * s; }
  return a;
};

Nearest line to the pointer

32-bit, display only

The distance in pixels from the pointer to a line, for picking.

t = clamp(((p − a) · (b − a)) ÷ |b − a|², 0, 1); d = |a + t·(b − a) − p|

Works on positions read from the 32-bit GPU array and projected to pixels. A line is picked within 6 pixels. The result is which entity is picked, not a measured value.

  • dwg-view3d.js
  • lines 237 to 239
  • BimCraft 0.8.1
const dx = b[0] - a[0], dy = b[1] - a[1], l2 = dx * dx + dy * dy;
const t = l2 > 0 ? Math.max(0, Math.min(1, ((x - a[0]) * dx + (y - a[1]) * dy) / l2)) : 0;
const d = Math.hypot(a[0] + t * dx - x, a[1] + t * dy - y);
dwg-view.js BimCraft 0.8.1 32-bit, display only 1 calculation Reviewed

Tests None found by the review

Zoom to the drawing

32-bit, display only

The zoom and center that show the whole drawing or sheet.

zoom = min(W ÷ w, H ÷ h) × 0.92; center = middle of the bounds

64-bit numbers that only set what the screen shows. A width or height below 1e-6 is taken as 1e-6 so the division is safe.

  • dwg-view.js
  • lines 129 to 141
  • BimCraft 0.8.1
/** Zoom to the drawing (model) or the sheet (layout). */
fit() {
  const s = this.space;
  if (!s) return this.render();
  const b = s.kind === 'paper' && s.paper ? s.paper : s.bounds;
  if (!Number.isFinite(b.minX)) { this.cx = 0; this.cy = 0; this.zoom = 1; return this.render(); }
  const w = Math.max(b.maxX - b.minX, 1e-6), h = Math.max(b.maxY - b.minY, 1e-6);
  const W = this.canvas.clientWidth || 1, H = this.canvas.clientHeight || 1;
  this.zoom = Math.min(W / w, H / h) * 0.92;
  this.cx = (b.minX + b.maxX) / 2;
  this.cy = (b.minY + b.maxY) / 2;
  this.render();
}

In detail

Method
3D: three.js buffers built from the compiled batches, centered and scaled. 2D: canvas paths under a world-to-pixel transform.
Number types
Float32Array for GPU positions; 64-bit numbers for the view center, zoom and transforms.

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