Skip to content
CADCAMFUN
Docs

Documentation

Tolerance and tessellation

How one chord-height tolerance decides segment counts, display decimals and curve tessellation across the CAD kernels.

One tolerance, every curve

A tolerance is the largest distance the model may be from the true shape, in millimetres. For a circle drawn as a polygon that distance is the chord's sagitta r(1 − cos(π/n)), so the number of segments follows from the tolerance. packages/core/src/cad/tolerance.ts (39 lines) holds that rule; the editor's renderer, the assistant's element catalogue, the entity tessellator and the tests all use it.

Ø20 circle at three tolerances Drag to orbit · scroll to zoom · right-drag to pan
The same radius-10 circle as segmentsFor gives it: 10 segments at 0.5 mm (chord error 0.489), 23 at 0.1 mm (0.093) and 71 at the 0.01 mm default (0.0098). Each polygon is extruded 2 mm.

Constants

NameValueMeaning
TOLERANCE_PRESETS0.1, 0.05, 0.01, 0.005, 0.002, 0.001, 0.0005what the UI offers, coarse to fine
DEFAULT_TOLERANCE0.01editor and tessellation default
MIN_TOLERANCE0.0001below this isTolerance is false
MAX_TOLERANCE10above this isTolerance is false
MIN_CURVE_SEGMENTS8fewest segments of a circle
MAX_CURVE_SEGMENTS2048default cap of segmentsFor
MAX_SEGMENTS (tessellate.ts)65 536hard cap per entity in the entity tessellator
MIN_TOLERANCE (tessellate.ts)1e-6floor so a zero tolerance cannot produce unbounded counts
tolerance.ts
export const isTolerance: (value: unknown) => value is number      // finite, in [0.0001, 10]
/** Smallest n ≥ 8 with r(1 − cos(π/n)) ≤ tolerance, capped. */
export const segmentsFor: (radius: number, tolerance: number, cap?: number /* 2048 */) => number
export const chordError: (radius: number, segments: number) => number   // r(1 − cos(π/n))
/** 0.001 → 3, 0.05 → 2, 0.5 → 1; at most 6. */
export const decimalsForTolerance: (tolerance: number) => number

Presets in numbers

Real segmentsFor, chordError and decimalsForTolerance output for each preset:

Tolerance, mmsegments r 10chord error r 10decimalssegments r 50
0.1239.314e-2150
0.05324.815e-2271
0.01 (default)719.788e-32158
0.0051004.934e-33223
0.0021581.977e-33352
0.0012239.923e-43497
0.00053154.973e-44703

Edge cases, also real: segmentsFor(1000, 0.0001) = 2048 (the cap), segmentsFor(2, 5) = 8 (tolerance ≥ radius), isTolerance(0.00005) = false, isTolerance(10) = true, decimalsForTolerance(0.0001) = 4.

Tessellating drawing entities

tessellate(entity, tolerance) in tessellate.ts turns any drawing entity into polylines within the chord tolerance. That polyline is what the CAM layer offsets and what the viewport renders. A closed shape returns a ring whose first and last points differ; the closing segment is implicit.
EntityRule
Lineits two end points
Circle, Arcarc segment count from radius, sweep and tolerance, capped at 65 536
Ellipseuniform parameter step h = √(8·tol / a), a the larger radius, at least 8 segments
Splineanalytic bound of splinePolyline
Polylinebulged segments as arcs
Rectanglefour corners
Text, Dimensionno outline: empty list

For an ellipse with radii 20 and 10, ellipseSegmentCount gives 100 segments at 0.01 mm and 32 at 0.1 mm.

Where tolerances meet

KernelTolerance parameterDefault
Sketch profilessketchProfiles(sketch, tolerance)0.01 mm
Mesh primitivesmeshOf(solid, tolerance)0.1 mm
CSG coincidenceCsgOptions.tolerance1e-7 × extent
B-rep tessellationTessellateOptions.chordToldiagonal / 2000, in [0.001, 0.05]
B-rep Boolean coincidenceBooleanOptions.tol1e-8 × size, ≥ 1e-7
Helix chordsstepsPerTurn0.01 mm

Display tolerance is not machining tolerance

The drawing tolerance controls how curves are approximated. CAM verification and G-code arc fitting carry their own tolerances; see the CAM kernel.

Troubleshooting

SymptomCauseFix
circles look polygonaltolerance 0.1 on a large radiuschoose a finer preset; segments grow with √r
viewport slow on a large drawingvery fine tolerance on many curves0.01 is enough for display; keep finer values for export
length shows too many decimalsdecimals follow the tolerancedecimalsForTolerance(0.01) = 2
a value is rejected as toleranceoutside [0.0001, 10]use a preset