New circular primitives: Arc2d, CircularSector, CircularSegment#11748
New circular primitives: Arc2d, CircularSector, CircularSegment#11748spectria-limina wants to merge 23 commits intobevyengine:mainfrom
Arc2d, CircularSector, CircularSegment#11748Conversation
|
Welcome, new contributor! Please make sure you've read our contributing guide and we look forward to reviewing your pull request shortly ✨ |
2179bba to
271f299
Compare
Jondolf
left a comment
There was a problem hiding this comment.
I didn't take a super in-depth look at all of the math and the bounding implementation yet, but everything seems correct at a glance. Code quality overall is great!
I mainly left some documentation and naming suggestions and typo fixes.
As for the unresolved questions:
- I think the origin should probably be at the circle's center for all three shapes for the sake of consistency. I can't think of another origin that would make much sence, except maybe for the circular segment, but I think I prefer consistency here. Whatever is chosen, the important thing is that it is documented (and it already is).
- Option 1 (the current one) is a good default. We can add option 2 as a configuration option in a follow-up.
- I agree, a half-angle in radians extending symmetrically in both directions from the vertical (i.e. the "top" of the circle) might be more intuitive and easier to work with. Starting from the right and going counterclockwise might be more conventional mathematically (though I'm not sure if arcs specifically have a convention for this), but I feel like that wouldn't be a very useful default from a practical standpoint. I don't have a strong opinion on this though, so other peoples' thoughts on the topic would be useful.
|
Thanks for the review! I've made the changes plus a few more things. I'll update the first comment to reflect the current state of things. |
Arc, CircularSector, CircularSegmentArc2d, CircularSector, CircularSegment
|
The generated |
This required adding a parameterizable angle for the UV mapping. It's in an enum to reduce the amount of churn if/when we add additional modes.
Change the default angle to a third of a circle, because a quarter leads to too thin of a segment. Also formatting changes in 2d_shapes.rs.
668137d to
5847618
Compare
There were bugs.
Jondolf
left a comment
There was a problem hiding this comment.
I love the tests and overall code quality, and the examples looks great. Large PR though!
I left a ton of tweaks and suggestions regarding names, docs, and some other things. I tried to be pretty thorough, so apologies if some things are overly nitpicky :)
Co-authored-by: Joona Aalto <jondolf.dev@gmail.com> Co-authored-by: Alice Cecile <alice.i.cecile@gmail.com>
|
You added a new example but didn't add metadata for it. Please update the root Cargo.toml file. |
Jondolf
left a comment
There was a problem hiding this comment.
Alright, once the example metadata is fixed, I think this LGTM! Thanks for the patience :)
|
I've now updated the PR and got it as close to working as I can, but #12729 is preventing all tests from passing and I can't figure out a fix locally. |
|
The generated |
|
There also seems to be a failing wasm build that isn't related to my PR. |
That has been fixed #12730 |
There was a problem hiding this comment.
I have a couple of minor nits, but I would like for this to get merged. I wish I had realized this needed another review earlier; I'm sorry that this PR has been neglected somewhat.
Overall, I am very happy with the documentation, testing, and examples.
|
|
||
| let segment = CircularSegment::from_turns(40.0, fraction); | ||
| // For the circular segment, we will draw Bevy charging forward, which requires rotating the | ||
| // shape and texture by 90 degrees. |
There was a problem hiding this comment.
I don't really get what this means, since to me it just looks like Bevy is upside-down in the CircularSegment part of the example.
| } | ||
| } | ||
|
|
||
| /// Create a new [`Arc2d`] from a `radius` and a number of `turns` of a circle. |
There was a problem hiding this comment.
| /// Create a new [`Arc2d`] from a `radius` and a number of `turns` of a circle. | |
| /// Create a new [`Arc2d`] from a `radius` and a `fraction` of a single turn. |
This is a great convenience API; it looks like the documentation is just slightly out of date.
|
@spectria-limina I'm happy to merge this as is: let me know if you're able to resolve merge conflicts? |
…#13482) # Objective Adopted #11748 ## Solution I've rebased on main to fix the merge conflicts. ~~Not quite ready to merge yet~~ * Clippy is happy and the tests are passing, but... * ~~The new shapes in `examples/2d/2d_shapes.rs` don't look right at all~~ Never mind, looks like radians and degrees just got mixed up at some point? * I have updated one doc comment based on a review in the original PR. --------- Co-authored-by: Alexis "spectria" Horizon <spectria.limina@gmail.com> Co-authored-by: Alexis "spectria" Horizon <118812919+spectria-limina@users.noreply.github.com> Co-authored-by: Joona Aalto <jondolf.dev@gmail.com> Co-authored-by: Alice Cecile <alice.i.cecile@gmail.com> Co-authored-by: Ben Harper <ben@tukom.org>
Objective
There are no 2d primitives available for the common shapes of an arc or a circular sector (pie slice).
Solution
This PR introduces three new types to the existing math primitives:
Arc2d: a portion of a (hollow) circleCircularSector: the area between an arc and the centre of the circleCircularSegment: the convex hull of an arcRun
cargo run --example 2d_shapesto see examples of theCircularSectorandCircularSegmenttype.Design decisions
What should the arc type be named?
Answer:
Arc2d, becauseArcis already taken by the standard library.What should the origin point of these shapes be?
Answer: This PR puts the origin of all three shapes in the center, prioritizing consistency,
What should the UV-mapping of
CircularSectorandCircularSegmentlook like? There are two reasonable options:Answer: This PR chooses option 1 as the default, but puts UV-mapping configuration in a
CircularMeshUvModeenum, as futureproofing for later adding option 2.How should the angle of these shapes be expressed?
Answer: This PR chooses option 2, because it leads to better defaults and better ergonomics when reasoning about how to rotate the shape.
TODO
CircularSectorandCircularSegmentthat avoid needing to explicitly access thearcfield.Future Work
For after this PR is merged:
Gizmosas in Drawing Primitives with Gizmos #11072.MeshBuildertypes.math/primitivesexample.Changelog
Arc2d,CircularSector, andCircularSegmentprimitives to [bevy::math::primitives].