fix: Using floating point math for arcs.#173
Merged
ooxi merged 1 commit intogerbv:mainfrom May 25, 2023
Merged
Conversation
Arcs and lines don't always line up when the image is zoomed out because gdk expects integers so we do a lot of integer math. For example, under a lot of zoom out, we might be looking at arcs circles with a diameter of 5. When dividing by 2 to compute the radius, this causes a problem. The solution is to do as much floating-point math as possible and only convert to integer at the very end, when we call the GDK functions to draw. In testing, this fixed gerbv#167.
Collaborator
Author
|
To test, download the files from #167 and then compile and run gerbv like this: Go to rendering mode "Fast, with XOR". Then, click on the "-" in the menu bar 6 times. If I zoom out even further than I get some more artifacts but this is at least better than what we had before. The best solution would be to do all math in floating-point and only convert to integer when necessary. |
Contributor
|
Thank you! I'll finish the release of 2.9.7 and then merge this |
rampageservices
added a commit
to SourceParts/gerbv
that referenced
this pull request
Mar 10, 2026
Replace integer-truncating division (/ 2, >> 1) with round(... / 2.0) when computing top-left coordinates for circles, macro primitives (prim1, prim6, prim7), rectangles, and ovals in the GDK renderer. Integer truncation causes off-by-one positioning of concentric apertures (e.g. pad + hole) at low zoom levels, making them appear misaligned. This extends the fix from PR gerbv#173 (which addressed arcs only) to all remaining shape primitives. Fixes gerbv#167
This was referenced Mar 10, 2026
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.


Arcs and lines don't always line up when the image is zoomed out because gdk expects integers so we do a lot of integer math. For example, under a lot of zoom out, we might be looking at arcs circles with a diameter of 5. When dividing by 2 to compute the radius, this causes a problem.
The solution is to do as much floating-point math as possible and only convert to integer at the very end, when we call the GDK functions to draw. In testing, this fixed #167.