📚 Encyclopedia

3D Printing & CAD · updated 2026-10-13

Optimizing CNC G-code safely (arc fitting, simplification, self-checks)

cncgcodearc-fittingdouglas-peuckeroptimizationverification

cncfileoptimizer.com rewrites CNC G-code to be smaller and faster without changing what gets cut, entirely in the browser. The techniques are standard; the lessons are about guaranteeing the output is still the same part.

Techniques

The self-check (every result must pass)

Arc-fitting lesson

Fitted arcs strayed up to 2x the tolerance on coarse polylines and failed the tool's own Path check. Fix: re-center each fitted arc on the perpendicular bisector of its end points (so it passes exactly through both) and fit at 0.85 x the tolerance to leave margin.

Performance notes

Architecture (reusable for browser tools)

Pure DOM-free ES modules for the engine (also run under Node for tests and benchmarks), heavy work in a module Web Worker, a hand-written WebGL toolpath viewer, and a settings UI generated from the engine's DEFAULTS object. See Offline-first browser tools (module workers, precache lists, no build step).

See also

Linked from

Sources: cnc memory (MEMORY.md, architecture.md, pending.md), tldr posts #1662, #1745