Resources Numerical accuracy Calculation policy

Drawing placed on a map grid

Describes where the drawing's own coordinates sit on a projected map system: scale, rotation and one matching pair of points.

How the precision is kept

The placement is a scale (the ratio of two unit factors), a rotation in degrees and two points, all copied or divided once in 64-bit numbers. The conversion itself is done by crs.js with this record.

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.

maplayers.js CadCraft 0.8.2 64-bit 1 calculation Reviewed

Tests bin/test-maplayers.mjs

Local placement record

64-bit

The scale, rotation and point pair that tie drawing coordinates to grid coordinates.

scale = m per drawing unit ÷ m per grid unit; from = (x, y); to = (e, n)

The scale is one division of the two unit factors handed in; the placement's point, grid point and rotation are copied unchanged. When the scale is within 1e-12 of 1 and the placement is all zeros, the function returns nothing and the drawing's numbers are used as grid coordinates.

  • maplayers.js
  • lines 629 to 639
  • CadCraft 0.8.2
/**
 * The drawing's own coordinates in a projected system: `place` {x, y (a drawing point), e, n (where it is on the map grid),
 * rot (degrees: the drawing's X axis turned from the grid's east)} and the drawing's metres per unit → a crs.js `local`.
 * With drawing units equal to the system's and no placement, null (the drawing's numbers are grid coordinates).
 */
export function drawingLocal(entry, place, mPerUnit, METRES_PER) {
  const k = mPerUnit && METRES_PER[entry.unit] ? mPerUnit / METRES_PER[entry.unit] : 1;
  const p = place || { x: 0, y: 0, e: 0, n: 0, rot: 0 };
  if (Math.abs(k - 1) < 1e-12 && !p.x && !p.y && !p.e && !p.n && !p.rot) return null;
  return { scale: k, rotation: p.rot || 0, from: [p.x || 0, p.y || 0], to: [p.e || 0, p.n || 0] };
}

In detail

Method
scale = meters per drawing unit ÷ meters per grid unit.
Number types
64-bit numbers.
Tolerances
A scale within 1e-12 of 1 with no offset and no rotation means no local transform at all.

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