Resources Numerical accuracy Calculation policy

Rendered picture size

Works out the width and height in pixels of a picture an assistant asks the Render dialog for.

How the precision is kept

One side given: the other follows the view's shape by a 64-bit proportion rounded to whole pixels. A picture over the largest allowed side is scaled down by one factor and rounded again.

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.

render-tools.js BimCraft 0.8.1 64-bit 1 calculation Reviewed

Tests bin/test-agents.mjs

Width and height in pixels

64-bit

The pixel size of the picture.

h = round(w × vh ÷ vw); k = min(1, MAX ÷ w, MAX ÷ h)

The proportion is multiplied before it is divided, then rounded once; a scale-down rounds a second time, so the shape can change by up to one pixel.

  • render-tools.js
  • lines 38 to 48
  • BimCraft 0.8.1
/** The picture's size: width and height as given (one of them: the view's shape), else the dialog's size setting. */
export function renderSize(settings, view, a = {}) {
  const vw = Math.max(1, view?.w || 1), vh = Math.max(1, view?.h || 1);
  let w, h;
  if (a.width && a.height) { w = a.width; h = a.height; }
  else if (a.width) { w = a.width; h = Math.round((a.width * vh) / vw); }
  else if (a.height) { h = a.height; w = Math.round((a.height * vw) / vh); }
  else return sizeFor(settings, vw, vh);
  const k = Math.min(1, MAX_SIDE / w, MAX_SIDE / h);
  return { w: Math.max(1, Math.round(w * k)), h: Math.max(1, Math.round(h * k)) };
}

In detail

Method
h = round(w × viewH ÷ viewW) when only the width is given, w = round(h × viewW ÷ viewH) when only the height is; then both × min(1, MAX_SIDE ÷ w, MAX_SIDE ÷ h), rounded, at least 1.
Number types
64-bit numbers; pixel counts are whole numbers.
Limits
The view's shape is taken from its pixel size, with 1 for a missing side. The default size comes from sizeFor in render/looks.js, which was not part of this review.

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