-
-
Notifications
You must be signed in to change notification settings - Fork 88
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Fix arc sector bounding box #441
base: master
Are you sure you want to change the base?
Conversation
a190165
to
a034f04
Compare
a034f04
to
b9537ca
Compare
b9537ca
to
b74b6a7
Compare
b74b6a7
to
926d1b5
Compare
I'm getting my ass kicked by something that I'm sure has a simple solution: more off-by-one errors. I've tried various things but as a baseline I have this code in let radius = Real::from(self.diameter) / 2.into();
Point::new(
i32::from(angle.cos() * radius),
-i32::from(angle.sin() * radius),
) + Size::new_equal(radius.into()) The sin/cos stuff is fine, but as far as I can see the final point rarely lies on the actual arc (or circle, same thing) because the point is transformed not from the true center of the arc but somewhere near it (+/- 1) due to rounding. @rfuest you've done some magic with circles in the same vein as this, so could you offer some guidance perhaps? |
I did take a very brief look at this and I think that at least part of the problem is in the existing code. I would expect an 90 degree arc starting at 0 degrees to exactly draw one quadrant of a full circle. But in my test this only worked correctly for arcs with odd diameters. Arcs with even diameters were missing one row of pixels at the bottom. The circle code internally uses coordinates that are scaled by a factor of 2 (e.g. in |
Hi! Thank you for helping out with Embedded Graphics development! Please:
CHANGELOG.md
entry in the Unreleased section under the appropriate heading (Added, Fixed, etc) and appropriate crate (embedded-graphics
,simulator
,tinytga
,tinybmp
) if your changes affect the public APIrustfmt
on the projectjust build
(Linux/macOS only) and make sure it passes. If you use Windows, check that CI passes once you've opened the PR.PR description
Fix Arc/Sector bounding boxes.
TODO
Off-by-one on right/bottom edges of Arc bounding box:
Unit tests
Note that there are some errors around stroke widths as can be seen on the right side here:
Due to stroke corners lying outside the bounding box. IMO this should be fixed, but later. Perhaps once thick polylines is merged so the
Line::extents()
method can be reused.Closes #405