Skip to content

fix: support A (radius) parameter for Excellon G02/G03 arcs#345

Open
rampageservices wants to merge 1 commit intogerbv:developfrom
SourceParts:fix/excellon-g02-g03-radius-arcs
Open

fix: support A (radius) parameter for Excellon G02/G03 arcs#345
rampageservices wants to merge 1 commit intogerbv:developfrom
SourceParts:fix/excellon-g02-g03-radius-arcs

Conversation

@rampageservices
Copy link
Copy Markdown
Contributor

Summary

Adds support for the A (radius) parameter in Excellon G02/G03 arc routing commands. PR #298 added G02/G03 support but only for I/J center-offset arcs. The A radius format is used by some CAM tools (e.g. the file in #297's latest comment) and was completely unhandled — when the parser encountered A, it broke out of the coordinate loop and ignored the arc radius.

Format:

G02X194478Y14182A2542    ; CW arc, radius 2.542mm
G03X174898Y6404A7778     ; CCW arc, radius 7.778mm

Changes

Parsingdrill_parse_coordinate() now recognizes the A parameter alongside X/Y/I/J and stores it in new arc_radius / found_arc_radius fields on drill_state_t.

Geometrydrill_add_arc_segment() converts radius to center offsets (delta_cp) when found_arc_radius is set, using chord geometry:

  1. Midpoint of start→end chord
  2. Perpendicular distance from midpoint to center: h = sqrt(r² - (d/2)²)
  3. CW/CCW selects which side of the chord the center falls on

After conversion, the existing cirseg calculation works unchanged — it receives center offsets regardless of whether they came from I/J or were derived from A.

Edge cases:

  • Start == end (full circle): center offset perpendicular to X axis by radius
  • Chord > diameter: clamps to semicircle with a warning message

State resetfound_arc_radius is cleared alongside delta_cp_x/y after tool-up repositions and after arc segment creation.

Test

New from-scratch test file test-drill-arc-radius.exc with:

  • CW 90° arc via A parameter
  • CCW 90° arc via A parameter
  • Rounded rectangle contour (mixed G01 linear + G02 radius arcs with 0.1" corner radii)

Test suite: 96 passed (was 95), 0 skipped (was 1), 10 pre-existing failures unchanged.

Fixes the rendering bug reported by FrankOnGit in #297.

PR gerbv#298 added G02/G03 support but only for I/J center-offset arcs.
The A radius format (e.g. G02X194478Y14182A2542) is used by some CAM
tools and was completely unhandled — the parser broke out of the
coordinate loop on encountering A, ignoring the arc radius.

Parse the A parameter in drill_parse_coordinate(), store it in new
arc_radius/found_arc_radius fields on drill_state_t, and convert
radius to center offsets in drill_add_arc_segment() using chord
geometry before the existing cirseg calculation.

Fixes the rendering bug reported in gerbv#297.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant