Bevy shapes - #25302
Conversation
f10b34d to
4ea8710
Compare
Smerom
left a comment
There was a problem hiding this comment.
Looks to be a clean move of the primitive shapes out of the math crate.
4ea8710 to
5dae0b8
Compare
| /// The shape prelude. | ||
| /// | ||
| /// This includes all primitive shape types in this crate, re-exported for your convenience. | ||
| pub mod prelude { | ||
| // just re-export everything, it's just shape definitions anyways | ||
| #[doc(hidden)] | ||
| pub use crate::*; | ||
| } |
There was a problem hiding this comment.
let me know if we should be more specific here
| impl Primitive2d for bevy_math::Dir2 {} | ||
| impl Primitive3d for bevy_math::Dir3 {} | ||
| impl Primitive3d for bevy_math::Dir3A {} |
There was a problem hiding this comment.
These impls are super weird to me, why do we have them?
Regardless, they're not the fault of this PR, it just keeps them as they were.
There was a problem hiding this comment.
I think this is for rendering the structs with gizmos. They have special rendering (arrows) when rendered via the primitives gizmos API.
| fn xy_order(a: Vec2, b: Vec2) -> Ordering { | ||
| a.x.total_cmp(&b.x).then_with(|| a.y.total_cmp(&b.y)) | ||
| } | ||
|
|
||
| /// The event queue holds an ordered list of all events the [`SweepLine`] will encounter when checking the current polygon. | ||
| #[cfg(feature = "alloc")] |
There was a problem hiding this comment.
Why drop the feature gates?
There was a problem hiding this comment.
Everything in the module was feature gated with alloc. The only thing that wasn't was marked as dead code. I thought that this is a bit silly so I just feature gated the whole module instead.
See latest state on main without the changes for a clearer picture:
|
Gave it a quick skim, seems generally good, with a few minor things. Will 100% need a migration guide for users to switch imports to the new crate. |
5dae0b8 to
64966ed
Compare
64966ed to
36e3af3
Compare
Based-A
left a comment
There was a problem hiding this comment.
Couple questions, but otherwise everything looks good from my perspective :)
| let [a, b, c] = [vertices[0], vertices[1], vertices[2]]; | ||
| let triangle_area = | ||
| ops::abs(a.x * (b.y - c.y) + b.x * (c.y - a.y) + c.x * (a.y - b.y)) / 2.0; | ||
| return triangle_area > 0.0; |
There was a problem hiding this comment.
Is using a Triange2d here not preferred anymore?
There was a problem hiding this comment.
It's due to a dependency reason. This PR is a shorter version of the one mentioned in the description. The area method on Triangle2d is a trait method.
@NiseVoid proposed moving the Bounding-related traits out into yet another crate.
In my last attempt, this other crate bevy_geometry (working-crate-name, not final) had a dependency on bevy_shape because it was making use of the Circle and Sphere structs for bounding volumes and it was also containing the implementations of all its traits for the bevy_shapes.
Importing the Bounding trait here to make use of the area method would lead to a circular dependency. So in the end this is for decoupling reasons.
I don't mind reverting it if it is a thorn in your eyes.
There was a problem hiding this comment.
Gotcha, that makes sense. No need to revert from my perspective
| use bevy::{ | ||
| color::palettes::css::{BLUE, GRAY, RED}, | ||
| math::{ | ||
| bounding::{Bounded2d, BoundingVolume}, |
There was a problem hiding this comment.
I'm guessing these shapes/primitives are included in the prelude now?
There was a problem hiding this comment.
These are traits that were previously not included in the math prelude for some odd not-documented reason. At this point I'm just guessing it is an oversight.
When asking on discord, noone responded except @Jondolf :
I don't think there's any particular reason, I'd be fine with adding all the common bounding types and traits to the prelude
So this is why there are changes like this all over the place.
There was a problem hiding this comment.
Nice, yeah just double checking.
|
Added the migration guide. Now also up for review |
Smerom
left a comment
There was a problem hiding this comment.
Couple proofread comments on the migration, but otherwise looks good!
70ff10e to
6e15856
Compare
|
Thanks @Smerom, I applied the suggestions |
|
@JasmineLowen Could you merge main? |
6e15856 to
724b681
Compare
| pub mod prelude { | ||
| // just re-export everything, it's just shape definitions anyways | ||
| #[doc(hidden)] | ||
| pub use crate::*; | ||
| } |
There was a problem hiding this comment.
This was a mistake btw, this lead to:
https://github.com/bevyengine/bevy/actions/runs/33535695284/job/99949477868?pr=25380
I'm going to fix it up in:
# Objective - the bevy_curve / bevy_shape split (bevyengine#25380 / bevyengine#25302) had a few issues - missing licenses files - tool generating images didn't update path - bevy_animation needs bevy_curve/reflect - some alloc gates in bevy_curve seem wrong - dependencies are not specified in the same order as other crates ## Solution - fix them
Objective
bevy_mathintobevy_shapeandbevy_geometry#25047, supersedes itbevy_mathintobevy_mathandbevy_shape(geometry focused)Solution
bevy_shapedepends onbevy_mathbevy_shapealso includes other primitive related things like rays and primitive related traitsTesting
Todos
maybe improve prelude?