SI value of a file unit
64-bitMeters per file length unit and radians per file angle unit.
SI unit: 10^prefix; conversion-based unit: factor × factor of its base unit; by name: degree π ÷ 180, inch 0.0254, foot 0.3048
The prefix factors are powers of ten and the inch and foot factors are exact. A conversion factor in the file is multiplied in as written. The name fallback is used only when the unit carries no usable factor, and it returns the length factor for any unit whose name contains INCH, FOOT or FEET.
/** The SI value of one of `u` (SI base unit with prefix, or a conversion-based unit through its factor). */
unitFactor(u, base, depth = 0) {
if (depth > 8 || u === null) return null;
const t = this.t(u);
if (t === 'IFCSIUNIT') {
const p = this.enm(this.a(u, 'Prefix'));
return p ? PREFIX[p] ?? 1 : 1;
}
if (t === 'IFCCONVERSIONBASEDUNIT' || t === 'IFCCONVERSIONBASEDUNITWITHOFFSET') {
const m = this.ref(this.a(u, 'ConversionFactor'));
if (m !== null) {
const v = this.num(this.a(m, 'ValueComponent'));
const inner = this.unitFactor(this.ref(this.a(m, 'UnitComponent')), base, depth + 1) ?? 1;
if (v && Number.isFinite(v)) return v * inner;
}
const n = String(this.str(this.a(u, 'Name')) || '').toUpperCase();
if (base === 'RADIAN' && n.includes('DEGREE')) return Math.PI / 180;
if (n.includes('INCH')) return 0.0254;
if (n.includes('FOOT') || n.includes('FEET')) return 0.3048;
}
return null;
}