-
Notifications
You must be signed in to change notification settings - Fork 72
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
Allow independent corner radii for RoundedRect #166
Allow independent corner radii for RoundedRect #166
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Generally this looks pretty good to me. I'm a little worried about all the edge cases (radii adding up to more than the rectangle side), but overall this looks like a careful job.
I don't believe this is possible.
let radii = radii.abs().clamp(shortest_side_length / 2.0);
|
I'll address the remaining comments next time I work on this. |
Ok, I think it means nothing can go wrong, but it's also more conservative than it needs to be. For example, in a w x h rectangle, radii of (w, w, 0, 0) are possible, and this is a useful shape to draw. The logic to enforce that is not trivial, and there may not be an unambiguous "correct" solution as in the case of a single radius. |
I think enforcing would not be a big issue. It may either mean panicking:
Or clamping in a different way, arbitrarily giving priority to some corner over others:
However allowing the radii to go past the half dimensions will make several other calculations invalid, this is where it will not be trivial anymore. |
I believe I've addressed all the review comments. Please let me know if I can add or change anything else. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think this looks good, and I think the API is the right choice; I had initially thought it would make more sense to have separate methods for the non-uniform radii case, but this feels good.
I'll look into doing a kurbo release shortly. |
Closes #138.
This PR allows
RoundedRect
to be created with four radius values instead of one, and updates theShape
impl accordingly.All functions that take a
f64
radius value now take animpl Into<RoundedRectRadii>
value.RoundedRectRadii
implements thefrom
trait forf64
, so existing code should not need to change in most cases.Supporting this in Piet is not trivial as best I can tell. I took a cursory look at the breaking changes and noticed that, while Direct2D supports rounded rectangles, it only supports them with a single radius for all corners. I haven't looked at other platforms.
I am taking the existing unit test for
to_path
as evidence of correctness, but I'd like to ask my reviewer(s) to double-check the ordering of the corners in that function. If I messed up the ordering, then I believe the unit test would still pass.Please let me know if there's anything I can fix or improve!