Skip to content

Bevy shapes - #25302

Merged
alice-i-cecile merged 5 commits into
bevyengine:mainfrom
JasmineLowen:bevy-shapes
Aug 31, 2026
Merged

Bevy shapes#25302
alice-i-cecile merged 5 commits into
bevyengine:mainfrom
JasmineLowen:bevy-shapes

Conversation

@JasmineLowen

@JasmineLowen JasmineLowen commented Aug 5, 2026

Copy link
Copy Markdown
Contributor

Objective

Solution

  • Mainly move over all the primitives and related structs
  • bevy_shape depends on bevy_math
  • bevy_shape also includes other primitive related things like rays and primitive related traits

Testing

  • CI is green except for some weird failures that are unrelated to the PR itself
  • Run tests & co

Todos

  • migration guide
  • maybe improve prelude?

@JasmineLowen
JasmineLowen force-pushed the bevy-shapes branch 2 times, most recently from f10b34d to 4ea8710 Compare August 6, 2026 15:10
@JaySpruce JaySpruce added C-Usability A targeted quality-of-life change that makes Bevy easier to use A-Math Fundamental domain-agnostic mathematical operations S-Waiting-on-Author The author needs to make changes or address concerns before this can be merged labels Aug 6, 2026
@JasmineLowen
JasmineLowen marked this pull request as ready for review August 6, 2026 18:16
@JaySpruce JaySpruce added S-Needs-Review Needs reviewer attention (from anyone!) to move forward and removed S-Waiting-on-Author The author needs to make changes or address concerns before this can be merged labels Aug 6, 2026

@Smerom Smerom left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks to be a clean move of the primitive shapes out of the math crate.

Comment thread crates/bevy_math/Cargo.toml
Comment thread crates/bevy_math/src/sampling/standard.rs
Comment on lines +92 to +99
/// 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::*;
}

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

let me know if we should be more specific here

@IQuick143 IQuick143 added C-Code-Quality A section of code that is hard to understand or change D-Straightforward Simple bug fixes and API improvements, docs, test and examples labels Aug 11, 2026
Comment thread crates/bevy_gizmos/src/primitives/dim3.rs Outdated
Comment thread crates/bevy_gizmos/src/primitives/mod.rs Outdated
Comment on lines +55 to +57
impl Primitive2d for bevy_math::Dir2 {}
impl Primitive3d for bevy_math::Dir3 {}
impl Primitive3d for bevy_math::Dir3A {}

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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")]

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why drop the feature gates?

@JasmineLowen JasmineLowen Aug 11, 2026

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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:

https://github.com/bevyengine/bevy/blob/1f7cbb6674148bee59e353d9763c11ba02c6a5dd/crates/bevy_math/src/primitives/polygon.rs

@IQuick143 IQuick143 added the M-Migration-Guide A breaking change to Bevy's public API that needs to be noted in a migration guide label Aug 11, 2026
@IQuick143

Copy link
Copy Markdown
Contributor

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.

@Based-A Based-A left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Couple questions, but otherwise everything looks good from my perspective :)

Comment on lines +264 to +267
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;

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is using a Triange2d here not preferred anymore?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Gotcha, that makes sense. No need to revert from my perspective

use bevy::{
color::palettes::css::{BLUE, GRAY, RED},
math::{
bounding::{Bounded2d, BoundingVolume},

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm guessing these shapes/primitives are included in the prelude now?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice, yeah just double checking.

@JasmineLowen
JasmineLowen requested a review from Based-A August 12, 2026 06:33
@JasmineLowen

JasmineLowen commented Aug 12, 2026

Copy link
Copy Markdown
Contributor Author

Added the migration guide. Now also up for review

Comment thread _release-content/migration-guides/bevy_shape.md Outdated
Comment thread _release-content/migration-guides/bevy_shape.md Outdated

@Smerom Smerom left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Couple proofread comments on the migration, but otherwise looks good!

@JasmineLowen

Copy link
Copy Markdown
Contributor Author

Thanks @Smerom, I applied the suggestions

@Zeophlite Zeophlite added S-Merge-Conflicts Merge conflicts :( Add this label on top of other S- labels. S-Ready-For-Final-Review This PR has been approved by the community. It's ready for a maintainer to consider merging it and removed S-Needs-Review Needs reviewer attention (from anyone!) to move forward labels Aug 22, 2026
@Zeophlite

Copy link
Copy Markdown
Contributor

@JasmineLowen Could you merge main?

@JaySpruce JaySpruce removed the S-Merge-Conflicts Merge conflicts :( Add this label on top of other S- labels. label Aug 25, 2026
@alice-i-cecile alice-i-cecile added the X-Blessed Has a large architectural impact or tradeoffs, but the design has been endorsed by decision makers label Aug 31, 2026
@alice-i-cecile
alice-i-cecile added this pull request to the merge queue Aug 31, 2026
Merged via the queue into bevyengine:main with commit 5ccb729 Aug 31, 2026
44 checks passed
@JasmineLowen
JasmineLowen deleted the bevy-shapes branch September 1, 2026 06:21
Comment on lines +98 to +102
pub mod prelude {
// just re-export everything, it's just shape definitions anyways
#[doc(hidden)]
pub use crate::*;
}

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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:

#25380

ickshonpe pushed a commit to ickshonpe/bevy that referenced this pull request Sep 2, 2026
# 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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

A-Math Fundamental domain-agnostic mathematical operations C-Code-Quality A section of code that is hard to understand or change C-Usability A targeted quality-of-life change that makes Bevy easier to use D-Straightforward Simple bug fixes and API improvements, docs, test and examples M-Migration-Guide A breaking change to Bevy's public API that needs to be noted in a migration guide S-Ready-For-Final-Review This PR has been approved by the community. It's ready for a maintainer to consider merging it X-Blessed Has a large architectural impact or tradeoffs, but the design has been endorsed by decision makers

Projects

None yet

Development

Successfully merging this pull request may close these issues.

7 participants