Fix inch-unit conversion for coordinates and extrusion - #500
Merged
Conversation
|
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 |
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
approved these changes
Sep 10, 2026
sophiedeziel
left a comment
Collaborator
There was a problem hiding this comment.
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.
18 tasks
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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
Assisted by OpenAI Codex (GPT-6).