📚 Encyclopedia

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

2.5-D CNC design-to-G-code (distance-field offsetting, independent verification)

cnccamoffsettingdistance-fieldsvgdxffontsgrbl

The "Create" mode of cncfileoptimizer.com (2026-10) lets a user draw or import a 2D design on the stock, choose 2.5-D operations, and download verified GRBL G-code. Lessons from building the offsetter, the planner and the safety model.

Offsetting as a distance field

Instead of an analytic polygon offsetter, compute a signed distance field over the design and extract contours with marching squares. Three details were proven necessary by failing tests: 1. Seed the distance transform with exact sub-cell distances, not 0, for cells the outline crosses. 2. Bisect outline crossings when classifying buried edges (in both the planner and the verifier). 3. Return the stored float32 distance so every caller sees the same value; mixing float64 recomputation with float32 storage gave inconsistent decisions. Lazy exact refinement plus chain descent and a neighbor polish recover accuracy near the boundary.

Operations

Profile (outside or inside, with tabs and ramp entry), pocket (rings at R + k * stepover, inside-out, linked), follow-path (engraving), peck drilling, facing. Output either one file per bit (GRBL has no tool changer) or a single file with M0 pauses.

Coordinate conventions

Millimeters; X0 Y0 at the front-left stock corner; Z0 at the stock top. Sideways rapids at the machine's safe Z; rapids stop 1 mm above the stock (only a peck re-entry goes lower, down its own hole).

Safety model

Every plan must pass an independent verifier: kept material at most 0.03 mm, path following, depth, tabs, rapids and machine envelope; plus a round trip that parses the generated G-code back and checks it. The UI asks before downloading a red result. The verifier shares no geometry code with the planner; keep it that way, or a shared bug passes both.

Inputs

Known limits worth designing for

No V-carve, no dogbone corner relief (box joints need it), tabs evenly spaced and may land on corners, gaps narrower than the bit silently stay uncut, no tiling for jobs larger than the travel.

See also

Linked from

Sources: cnc memory (MEMORY.md, architecture.md, pending.md, machine-profile.md), tldr posts #1744, #1745