Skip to content

Fix inch-unit conversion for coordinates and extrusion - #500

Merged
remcoder merged 4 commits into
developfrom
codex/497-inch-units
Sep 11, 2026
Merged

Fix inch-unit conversion for coordinates and extrusion#500
remcoder merged 4 commits into
developfrom
codex/497-inch-units

Conversation

@remcoder

@remcoder remcoder commented Sep 10, 2026

Copy link
Copy Markdown
Member

Problem

Fixes #497. Inch-based G-code rendered 25.4 times too small and reported incorrect filament lengths.

Cause and fix

G20 changed the units flag but handlers used command values directly. Distance words now become millimeters before coordinate shifts or extrusion deltas are calculated: distance_mm = distance_in × 25.4. Omitted words preserve existing state; G20/G21 only change interpretation of subsequent commands. G92 uses the same conversion, so its logical coordinates and stored physical offsets agree.

Arc endpoints, I/J offsets and R are normalized together. The tessellator now receives millimeters exclusively, so its chord tolerance uses the physical radius directly. Probe targets use the same conversion and retain Z0 contact behavior. Slicer width/height comments remain millimeters.

Behavior changes

Inch files now produce correctly sized paths, bounding boxes and extrusion lengths. Millimeter files retain their existing behavior. State position documentation specifies millimeters; the internal ArcTessellator no longer accepts a units argument.

Checks

  • 992 tests passed; 100% statement, branch, function and line coverage.
  • Typecheck, lint and production build passed.
  • Pipeline regressions cover M82/M83, E-only moves, G92, unit switches, I/J and R helical arcs (including equal geometry and segment counts), probes, and slicer dimensions.
  • Straight-move equivalence now checks geometry, path types, bounds, and filament length in both M82/M83. Inch E-only retract/prime pairs check each intermediate E position, unchanged geometry, and correct subsequent extrusion without a G92 reset.
  • All four new regression cases fail when inch extrusion conversion is temporarily removed and pass with the fix restored.
  • Browser verification left to the maintainer as requested.

Assisted by OpenAI Codex (GPT-6).

@remcoder remcoder added bug Something isn't working 3.0 Targeted for the 3.0 release interpreter Related to the G-code interpreter / state machine labels Sep 10, 2026
@github-actions

github-actions Bot commented Sep 10, 2026

Copy link
Copy Markdown

Visit the preview URL for this PR (updated for commit e9d33f0):

https://gcode-preview--pr500-codex-497-inch-units-hjuycwks.web.app

(expires Sun, 11 Oct 2026 07:09:04 GMT)

🔥 via Firebase Hosting GitHub Action 🌎

Sign: 59bd114ae4847b32c2bba0b68620b9069a3e3531

Comment thread src/state.ts Outdated
State tracked units but converting them is a units concern, not state.
toMillimeters(value, units) now lives in units.ts and the command handlers
call it with state.units.

@sophiedeziel sophiedeziel left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I like that everything is normalized early.

I worry that bugs are easily introduced by forgetting to normalize units whenever a new command is introduced, but that's not in scope of this PR.

Let's think a little bit about the safeguards to add.

@remcoder
remcoder merged commit 4fd8b83 into develop Sep 11, 2026
7 checks passed
@remcoder
remcoder deleted the codex/497-inch-units branch September 11, 2026 07:10
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

3.0 Targeted for the 3.0 release bug Something isn't working interpreter Related to the G-code interpreter / state machine

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Inch-based G-code is drawn 25.4 times too small

2 participants