Resources Numerical accuracy Calculation policy

Stair family from a sketch

Writes a sketched stair as a family recipe with its width, tread, total rise, tread counts and riser height as parameters.

How the precision is kept

The sizes come from the stair layout (res-stair.js stairLayout) and are rounded when they become the family's parameters: width, height and gap to two decimals, tread and riser to four. The riser also carries the formula Height ÷ Steps, which works from the rounded height.

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.

stair-family.js BimCraft 0.8.1 64-bit 2 calculations Reviewed

Tests tools/bimcraft-test/r52-test.mjs

Stair parameters

64-bit

The sizes and counts the stair family is made with.

Width, Height, Gap = round(v × 100) ÷ 100; Tread, Rise = round(v × 1e4) ÷ 1e4; Rise = Height ÷ Steps

The sketch's values are rounded before they are stored as parameters: two decimals for width, height and gap, four for tread and riser. Rise also has the formula Height ÷ Steps, so the family's own value follows from the rounded Height.

  • stair-family.js
  • lines 30 to 40
  • BimCraft 0.8.1
const params = [
  { key: 'Width', kind: 'length', value: Math.round(spec.width * 100) / 100 },
  { key: 'Tread', kind: 'length', value: Math.round(L.tread * 1e4) / 1e4 },
  { key: 'Height', kind: 'length', value: Math.round(spec.height * 100) / 100 },
  { key: 'Thick', kind: 'length', value: 150 },
  { key: 'N1', kind: 'integer', value: n1, label: 'Treads in the first flight' },
];
if (spec.kind !== 'straight') params.push({ key: 'N2', kind: 'integer', value: n2, label: 'Treads in the second flight' });
if (spec.kind === 'u') params.push({ key: 'Gap', kind: 'length', value: Math.round((spec.gap ?? STAIR_DEFAULTS.gap) * 100) / 100 });
params.push({ key: 'Steps', kind: 'integer', value: L.n, formula: spec.kind === 'straight' ? '(N1 + 1)' : '(N1 + N2 + 2)', label: 'Risers' });
params.push({ key: 'Rise', kind: 'length', value: Math.round(L.riser * 1e4) / 1e4, formula: '(Height / Steps)', label: 'Riser height' });

Where the stair family is placed

64-bit

The insertion point and rotation that put the family on the sketch.

rot = ((angle mod 360) + 360) mod 360

The start point is passed on unchanged. The angle is folded into 0 to 360 degrees with two remainders.

  • stair-family.js
  • lines 64 to 65
  • BimCraft 0.8.1
/** Where the element goes: the stair's start, turned to its angle (the family's x is the first flight). */
export function stairFamilyPlace(spec) { return { x: spec.start[0], y: spec.start[1], rot: ((spec.angle || 0) % 360 + 360) % 360 }; }

In detail

Method
Steps = N1 + 1 for a straight stair, N1 + N2 + 2 for an L or U; Rise = Height ÷ Steps as a family formula; the treads of a flight are one box repeated with the step (Tread, Rise).
Number types
64-bit numbers; counts are integers; the solids are formula text evaluated by the family model.
Limits
Straight, L and U stairs only. The tread thickness is fixed at 150.

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