Resources Numerical accuracy

Calculations

Every calculation under our calculation policies: what it works out, its formula and the precision it runs at. Open one to see its code as it is in the released app.

  • 6,917 calculations in 1,248 source files
  • 143 exact
  • 6,286 in 64-bit
  • 335 with a 32-bit step
  • Last reviewed

Calculations

  • Page box and rotation matrix

    The matrix from PDF user space to the page as displayed: origin at the lower-left corner, y up, the page's rotation applied.

    0°: [1 0 0 1 −x₀ −y₀]; 90°: [0 −1 1 0 −y₀ W + x₀]; 180°: [−1 0 0 −1 W + x₀ H + y₀]; 270°: [0 1 −1 0 H + y₀ −x₀]

    PDF page vectors and snapping to them pdf-vector.js
    • CadCraft
    • BimCraft
    64-bit
  • Matrix product

    Combines the current matrix with one the page's content applies.

    [a b c d e f] = m · k for 2 × 3 affine matrices

    PDF page vectors and snapping to them pdf-vector.js
    • CadCraft
    • BimCraft
    64-bit
  • Path points

    Each move, line and curve point of a path, taken through the current matrix into displayed-page points.

    x′ = a·x + c·y + e; y′ = b·x + d·y + f; quadratic to cubic: c₁ = p + ⅔(q − p), c₂ = x + ⅔(q − x)

    PDF page vectors and snapping to them pdf-vector.js
    • CadCraft
    • BimCraft
    32-bit in part
  • Text position, height and angle

    Where each run of text starts, how tall it is, its angle and its width, in displayed-page points.

    height = |M·(t₂, t₃)|; angle = atan2 of M·(t₀, t₁); width = |w| × |(m₀, m₁)|

    PDF page vectors and snapping to them pdf-vector.js
    • CadCraft
    • BimCraft
    64-bit
  • Flattening curves to segments

    Turns every line and curve of the page into straight segments for snapping.

    B(t) = u³p₀ + 3u²t·c₁ + 3u·t²·c₂ + t³p₃, u = 1 − t, t = 1⁄8 … 8⁄8

    PDF page vectors and snapping to them pdf-vector.js
    • CadCraft
    • BimCraft
    32-bit in part
  • Nearest point on a segment

    The point of a segment closest to the pointer.

    t = ((p − a)·(b − a)) ÷ |b − a|², held to [0, 1]; q = a + t(b − a)

    PDF page vectors and snapping to them pdf-snap.js
    • CadCraft
    • BimCraft
    32-bit in part
  • Crossing of two segments

    The point where two segments of the page cross, or nothing when they are parallel, apart, or only meet end to end.

    den = r × s; u = ((c − a) × s) ÷ den; v = ((c − a) × r) ÷ den; point = a + u·r

    PDF page vectors and snapping to them pdf-snap.js
    • CadCraft
    • BimCraft
    32-bit in part
  • Choosing the snap point

    Picks the end, crossing, middle or nearest point within the snap distance of the pointer.

    midpoint = (a + b) ÷ 2; candidate kept when |candidate − p| ≤ tol

    PDF page vectors and snapping to them pdf-snap.js
    • CadCraft
    • BimCraft
    32-bit in part
  • Drawing units per PDF point

    The scale that makes a PDF page its true size in the drawing's units.

    1 pt = 1⁄72 in; inches: 1 ÷ 72; feet: (1 ÷ 72) ÷ 12; millimeters: 25.4 ÷ 72; meters: 0.0254 ÷ 72

    PDF underlay placement and PDF import pdfmodel.js
    • CadCraft
    64-bit
  • Underlay scale and rotation for saving

    The insertion point, x and y scale and rotation of an underlay as a DWG stores them.

    sx = |(m₀, m₁)|; sy = |(m₂, m₃)| × sign(det); rotation = atan2(m₁, m₀)

    PDF underlay placement and PDF import pdfmodel.js
    • CadCraft
    64-bit
  • Underlay read from a file

    Builds the underlay block and its placing reference from a file's PDF underlay record.

    PDF underlay placement and PDF import pdfmodel.js
    • CadCraft
    64-bit
  • Scale typed when attaching

    The scale an attached page gets: its true size, or the number typed.

    PDF underlay placement and PDF import pdfunder.js
    • CadCraft
    64-bit
  • Inverse of a placement

    Takes clip points picked in the drawing back into the page's own points.

    det = a·d − b·c; inverse = [d −b −c a (c·f − d·e) (b·e − a·f)] ÷ det

    PDF underlay placement and PDF import pdfunder.js
    • CadCraft
    64-bit
  • Is this curve a circular arc

    Decides whether one cubic curve of the page is an arc of a circle, and if so gives its center, radius and angles.

    circle through B(0), B(½), B(1); arc when | |B(t) − c| − r | ≤ 0.002·r at t = 0.25, 0.75, 0.1, 0.9

    PDF underlay placement and PDF import pdfunder.js
    • CadCraft
    32-bit in part
  • Circle through three points

    Center and radius of the circle through three points.

    d = 2(aₓ(b_y − c_y) + bₓ(c_y − a_y) + cₓ(a_y − b_y)); center from |a|², |b|², |c|² ÷ d

    PDF underlay placement and PDF import pdfunder.js
    • CadCraft
    64-bit
  • Outline points of an imported shape

    The vertices of each imported path in drawing coordinates, with curves replaced by straight pieces.

    B(t) at t = 0.1 … 1.0, then (x, y) → placement matrix

    PDF underlay placement and PDF import pdfunder.js
    • CadCraft
    32-bit in part
  • Stroke width kept on imported objects

    The line width stored on each imported line, arc and polyline.

    lw = round(width × scale × 100) ÷ 100

    PDF underlay placement and PDF import pdfunder.js
    • CadCraft
    64-bit
  • Arcs and circles from curves

    Turns a path made only of circular curves into a circle or an arc object.

    same circle when |rᵢ − r₀| < 1e-3·r₀ and |cᵢ − c₀| < 1e-3·r₀; circle when Σ sweep = 2π within 1e-3

    PDF underlay placement and PDF import pdfunder.js
    • CadCraft
    32-bit in part
  • Imported text

    Position, height and angle of each imported text.

    h = PDF height × scale ÷ FONT_EM; angle = (PDF angle + placement rotation) mod 2π

    PDF underlay placement and PDF import pdfunder.js
    • CadCraft
    64-bit
  • Scale from two points and a real distance

    Rescales an imported page so that two picked points are a stated distance apart.

    f = real ÷ |p₂ − p₁|

    PDF underlay placement and PDF import pdfunder.js
    • CadCraft
    64-bit
  • Scaling an object about a point

    Moves and resizes one imported object by the factor f about the insertion point.

    x′ = aₓ + (x − aₓ)·f; r′ = r·f; h′ = h·f

    PDF underlay placement and PDF import pdfunder.js
    • CadCraft
    64-bit
  • Picture corners

    The four corners of a picture in its block's coordinates.

    W = u × w; H = v × h; corners = p, p + W, p + W + H, p + H

    Pictures: size, placement and clip pictures.js
    • CadCraft
    64-bit
  • Picture placement and clip for saving

    The insertion point, pixel vectors and clip boundary a DWG image record holds.

    det = u × v; a = (d × v) ÷ det; b = (u × d) ÷ det; pixel = (a − 0.5, h − 0.5 − b)

    Pictures: size, placement and clip pictures.js
    • CadCraft
    64-bit
  • Pixel size of a picture in a PDF

    How many pixels a PNG keeps when a plot caps its resolution.

    w₂ = round(maxDpi × mm ÷ 25.4), at least 1

    Pictures: size, placement and clip pictures.js
    • CadCraft
    64-bit
  • Pixel size when attaching

    The size of one pixel in drawing units from the width typed for the picture.

    px = W ÷ pixel width

    Pictures: size, placement and clip pictures-cmd.js
    • CadCraft
    64-bit
  • Inverse of a placement

    Takes clip points picked in the drawing back into the picture block's coordinates.

    det = a·d − b·c; inverse = [d −b −c a (c·f − d·e) (b·e − a·f)] ÷ det

    Pictures: size, placement and clip pictures-cmd.js
    • CadCraft
    64-bit
  • Rescaling a pasted area by two points

    Resizes a pasted picture so two picked points are a stated distance apart.

    f = wanted ÷ |b − a|; sx′ = sx·f; sy′ = sy·f

    Pictures: size, placement and clip pictures-cmd.js
    • CadCraft
    64-bit
  • Finding the paper

    The four corners of the sheet of paper in the photo.

    corner = (pixel + 0.5) × k on a copy reduced by the whole factor k; fill = bright pixels inside ÷ outline area

    Sketch photo to drawing photosketch.js
    • CadCraft
    64-bit
  • Perspective matrix from four corners

    The 3 × 3 matrix that takes the straight sheet's corners to the corners found in the photo.

    8 equations in h₁ … h₈ with h₉ = 1, solved by Gauss–Jordan elimination

    Sketch photo to drawing photosketch.js
    • CadCraft
    64-bit
  • Applying the perspective matrix

    Where a point of the straight sheet lies in the photo.

    w = h₇x + h₈y + h₉; x′ = (h₁x + h₂y + h₃) ÷ w; y′ = (h₄x + h₅y + h₆) ÷ w

    Sketch photo to drawing photosketch.js
    • CadCraft
    64-bit
  • Sheet proportions

    The long-to-short side ratio of the straightened sheet.

    w = mean of top and bottom; h = mean of left and right; ratio = max ÷ min

    Sketch photo to drawing photosketch.js
    • CadCraft
    64-bit
  • Drawing units per pixel

    The size of one pixel of the straightened sheet in drawing units.

    units per px = long side (mm) ÷ long side (px) × scale ÷ mm per unit

    Sketch photo to drawing photosketch.js
    • CadCraft
    64-bit
  • Traced arcs and circles

    Turns each traced arc into a circle or an arc object in drawing units.

    r = r(px) × units per px; arc through start, middle and end

    Sketch photo to drawing photosketch.js
    • CadCraft
    64-bit
  • Layout sheet in millimeters

    The matrix that takes a layout and its viewports to millimeters on the sheet.

    toMm = [k 0 0 k −x₀k −y₀k], k = mm per paper unit; view matrix = toMm · viewport matrix

    Plotting: sheet scale, PDF, SVG and PNG output plot.js
    • CadCraft
    64-bit
  • Model plot scale and placement

    The scale and offset that put a window of the model on a paper size, fitted or at 1:n.

    fit: s = min((W − 10) ÷ w, (H − 10) ÷ h); offset = (W ÷ 2 − cₓs, H ÷ 2 − c_y·s)

    Plotting: sheet scale, PDF, SVG and PNG output plot.js
    • CadCraft
    64-bit
  • Millimeters to points in the page

    The factor that lets the rest of the PDF page be written in millimeters.

    72 ÷ 25.4 = 2.834645669 (9 decimals)

    Plotting: sheet scale, PDF, SVG and PNG output plot.js
    • CadCraft
    64-bit
  • Numbers written to the PDF and SVG

    Turns a coordinate, width or size into the text that goes into the file.

    text = v.toFixed(4), trailing zeros dropped; |v| < 0.00005 → 0

    Plotting: sheet scale, PDF, SVG and PNG output plot.js
    • CadCraft
    64-bit
  • Arcs as cubic Béziers

    The Bézier pieces that draw an arc in the PDF.

    n = ⌈|sweep| ÷ 90°⌉; d = sweep ÷ n; k = 4⁄3 · tan(d ÷ 4); handles at r·k along the tangents

    Plotting: sheet scale, PDF, SVG and PNG output plot.js
    • CadCraft
    64-bit
  • Lines and arcs in the page

    Writes each line and arc of a stroke group as PDF path operators.

    arc start = c + r(cos a, sin a)

    Plotting: sheet scale, PDF, SVG and PNG output plot.js
    • CadCraft
    64-bit
  • Text placement in the PDF

    The text matrix of each line of text: size, width factor, rotation, lean and position.

    size = h × FONT_EM; width = advance ÷ 1000 × size × wf; lean = size × tan(oblique)

    Plotting: sheet scale, PDF, SVG and PNG output plot.js
    • CadCraft
    64-bit
  • Page size in points

    The PDF page's width and height from the sheet's millimeters.

    pt = mm × 72 ÷ 25.4, written with 4 decimals

    Plotting: sheet scale, PDF, SVG and PNG output plot.js
    • CadCraft
    64-bit
  • Lines and arcs in the SVG

    Writes each line and arc of a stroke group as SVG path data.

    arc pieces of at most 90°: A r r 0 0 flag x y

    Plotting: sheet scale, PDF, SVG and PNG output plot.js
    • CadCraft
    64-bit
  • Paper size from a printer's paper name

    The size in millimeters of a named paper such as A3, Letter or 24 x 36 in.

    A-series: start 841 × 1189, each step (w, h) → (⌊h ÷ 2⌋, w); inches × 25.4

    Plotting: sheet scale, PDF, SVG and PNG output plot.js
    • CadCraft
    64-bit
  • Matching a sheet to a printer paper

    Finds the printer paper that is the sheet's size.

    |short − a| ≤ 2 mm and |long − b| ≤ 2 mm

    Plotting: sheet scale, PDF, SVG and PNG output plot.js
    • CadCraft
    64-bit
  • PNG size in pixels

    The pixel width and height of a sheet at a resolution, held under what a canvas can make.

    px = round(mm ÷ 25.4 × dpi), at least 1; while too big: dpi = ⌊dpi × 0.9⌋

    Plotting: sheet scale, PDF, SVG and PNG output plot.js
    • CadCraft
    64-bit
  • Plot extents of the model

    The box round everything the model would plot.

    Plotting: sheet scale, PDF, SVG and PNG output plot.js
    • CadCraft
    64-bit
  • Zero-size test

    Says whether a line has no length or a circle or arc no radius.

    line: |p₂ − p₁| ≤ 1e-9; circle or arc: r ≤ 1e-9

    Drawing audit: zero-size and duplicate objects problems-cadcraft.js
    • CadCraft
    64-bit
  • Duplicate test

    A text key that two objects share only when they are the same shape on the same layer.

    Drawing audit: zero-size and duplicate objects problems-cadcraft.js
    • CadCraft
    Exact
  • Unit sizes

    Builds each unit's row: its fraction of the base unit and the factor used for quick conversion.

    factor = n ÷ d (× π for degrees and gons)

    Unit table: reading and writing values unit-table.js Every app
    Exact
  • Numbers and fractions

    Reads 6, 6.5, 6 1/2, 6-1/2 or 1/2 as a number.

    whole + numerator ÷ denominator

    Unit table: reading and writing values unit-table.js Every app
    64-bit

A calculation is added only after its source was read. Each statement can be checked in the code shown on its policy's page; the app repositories are public. When a release changes a calculation, its page says so until it has been read again.