Resources Numerical accuracy Calculation policy

Building masses as IFC

Writes building masses as an IFC4 file: footprints, storey levels, heights and areas.

How the precision is kept

Values are computed in 64-bit and written as text with 9 decimal places, except the unit factor, which has 16. Footprints are written relative to an origin rounded to 10 units. Areas are converted to square meters with the exact or fractional foot.

Calculations under this policy

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

ifc-massing.js CivilCraft 0.8.1 64-bit 6 calculations Reviewed

Tests bin/test-civilcraft-massing.mjs

A real number as IFC text

64-bit

Formats every number this file writes.

text = v.toFixed(d) with trailing zeros removed; d = 9 unless stated

Rounded to 9 decimal places by default; a value below half of the last place, or one that is not finite, is written as 0.

  • ifc-massing.js
  • line 30
  • CivilCraft 0.8.1
const R = (v, d = 9) => { if (!Number.isFinite(v)) return '0.'; let s = (Math.abs(v) < 0.5 * 10 ** -d ? 0 : v).toFixed(d).replace(/(\.\d*?)0+$/, '$1'); if (!s.includes('.')) s += '.'; return s === '-0.' ? '0.' : s; };

US survey foot

Exact

Meters in a US survey foot, shared with the project IFC export.

1200 ÷ 3937

Formed as the defining fraction by one division, so it is the nearest 64-bit number to the exact value.

  • ifc-massing.js
  • line 29
  • CivilCraft 0.8.1
export const FT_US_M = 1200 / 3937;   // metres in a US survey foot

Latitude and longitude

64-bit

Writes an angle as degrees, minutes, seconds and millionths of a second.

Whole degrees, minutes and seconds by Math.floor; the rest rounded to a millionth of an arc second, the resolution of the IFC compound angle.

  • ifc-massing.js
  • lines 42 to 45
  • CivilCraft 0.8.1
const angle = (deg) => {   // IfcCompoundPlaneAngleMeasure: degrees, minutes, seconds, millionths of a second, all with the sign
  const sg = deg < 0 ? -1 : 1, a = Math.abs(deg), d = Math.floor(a), m = Math.floor((a - d) * 60), sc = ((a - d) * 60 - m) * 60, s = Math.floor(sc), u = Math.round((sc - s) * 1e6);
  return '(' + [sg * d, sg * m, sg * s, sg * u].join(',') + ')';
};

Footprint area

64-bit

The signed area of a mass outline; its sign sets the direction the outline is written in.

A = Σ (x_i·y_j − x_j·y_i) ÷ 2

The shoelace sum on absolute project coordinates, with no shift to a local origin, so large coordinates cost digits in the area.

  • ifc-massing.js
  • line 46
  • CivilCraft 0.8.1
const signedArea = (P) => { let a = 0; for (let i = 0; i < P.length; i++) { const p = P[i], q = P[(i + 1) % P.length]; a += p.x * q.y - q.x * p.y; } return a / 2; };

File origin

Exact

The origin footprints are written from: the middle of the masses rounded to 10 units, at the lowest ground floor level.

origin = round((min + max) ÷ 20) × 10

The plan origin is a whole multiple of 10. The z origin is the lowest ground floor level as it is, not rounded.

  • ifc-massing.js
  • lines 54 to 58
  • CivilCraft 0.8.1
export function defaultOrigin(masses) {
  let x0 = Infinity, y0 = Infinity, x1 = -Infinity, y1 = -Infinity, z = Infinity;
  for (const m of masses) { for (const p of m.pts) { x0 = Math.min(x0, p.x); y0 = Math.min(y0, p.y); x1 = Math.max(x1, p.x); y1 = Math.max(y1, p.y); } z = Math.min(z, m.z0); }
  return masses.length ? { x: Math.round((x0 + x1) / 20) * 10, y: Math.round((y0 + y1) / 20) * 10, z: Number.isFinite(z) ? z : 0 } : { x: 0, y: 0, z: 0 };
}

Height and areas of a mass

64-bit

The height, footprint area and gross floor area written in the mass's properties.

H = floors × floor height; footprint (m²) = A × um²; gross = A × floors × um²

um is 1, 0.3048 or 1200 ÷ 3937. Storey elevations are z₀ + k × floor height from the whole-number storey index, not a running sum. All are written with 9 decimals.

  • ifc-massing.js
  • line 67
  • CivilCraft 0.8.1
const um = unit === 'm' ? 1 : unit === 'ft' ? 0.3048 : FT_US_M, area = (a) => a * um * um;   // sq project units → m²

In detail

Method
ISO 10303-21 text; reals through toFixed(9) with trailing zeros removed; shoelace footprint area.
Number types
64-bit numbers, written as text with 9 decimal places.
Tolerances
Values below 0.5e-9 are written as 0.
Limits
9 decimals is an absolute resolution of one billionth of a file unit. Latitude and longitude carry a millionth of an arc second, the IFC format's own resolution. The footprint area is summed from absolute project coordinates.

Approach: 64-bit, stated limit

The arithmetic is 64-bit, but the method or the data sets the accuracy: a solver tolerance, a mesh, a step size, a datum shift, a table. The limit is stated where the result is shown.

Every policy that takes this approach