Resources Numerical accuracy Calculation policy

Shared feature lines: units and geometry

Sends a feature line to the team and takes one back, converting between feet and meters when the two drawings differ.

How the precision is kept

Points are sent as 64-bit numbers in JSON. A line made in the other unit is scaled by 0.3048 or by 1 ÷ 0.3048, a factor computed once and rounded to 64 bits. Arcs are sent as chords made by flatten in featureline.js.

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.

team-lines.js CivilCraft 0.8.1 64-bit 2 calculations Reviewed

Tests bin/test-civilcraft-teamlines.mjs

Line taken from the team

64-bit

Turns shared geometry into feature line points in the drawing's unit.

k = 1 (same unit), 0.3048 (ft → m) or 1 ÷ 0.3048 (m → ft); p′ = p × k

Each coordinate is one 64-bit product. The meters to feet factor is the reciprocal of 0.3048 computed once, so a coordinate can differ by one unit in the last place from a division by 0.3048. A missing z is taken as 0.

  • team-lines.js
  • lines 42 to 53
  • CivilCraft 0.8.1
/** Geometry from the site → { pts, closed }, in `units` (a line made in the other unit is scaled). null when it is not usable. */
export function fromGeometry(geo, units = 'ft') {
  if (!geo || !Array.isArray(geo.points) || geo.points.length < 2) return null;
  const from = /units=(ft|m)\b/.exec(String(geo.style || ''))?.[1] || units;
  const k = from === units ? 1 : from === 'm' ? 1 / FT : FT;
  const pts = [];
  for (const p of geo.points) {
    if (!Array.isArray(p) || p.length < 2 || !p.every((v) => Number.isFinite(v))) return null;
    pts.push({ x: p[0] * k, y: p[1] * k, z: (p[2] || 0) * k });
  }
  return { pts, closed: !!geo.closed && pts.length >= 3 };
}

Line sent to the team

64-bit

Turns a feature line into the points that are shared.

Points are copied as [x, y, z] without arithmetic. A line with arcs is first turned into chords by flatten in featureline.js, and the result says so in chords.

  • team-lines.js
  • lines 35 to 40
  • CivilCraft 0.8.1
/** The feature line as the site's `cc-feature-line` geometry. Arcs become chords (within 0.01). → { geometry, chords } */
export function toGeometry(f, units = 'ft') {
  const arcs = f.pts.some((p) => p.b);
  const pts = arcs ? flatten(f) : f.pts;
  return { geometry: { points: pts.map((p) => [p.x, p.y, p.z]), closed: !!f.closed, style: 'units=' + (units === 'm' ? 'm' : 'ft') }, chords: arcs };
}

In detail

Method
Points [x, y, z] with the unit carried in the geometry's style text; one scale factor on the way in.
Number types
64-bit numbers.
Limits
Meters to feet multiplies by the rounded reciprocal 1 ÷ 0.3048, which can differ in the last digit from dividing by 0.3048. The foot here is 0.3048 m; this file has no US survey foot. Arcs become chords.

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