Skip to content

Put math primitives in bevy_shapes crate#25003

Closed
JasmineLowen wants to merge 17 commits into
bevyengine:mainfrom
JasmineLowen:bevy-shapes
Closed

Put math primitives in bevy_shapes crate#25003
JasmineLowen wants to merge 17 commits into
bevyengine:mainfrom
JasmineLowen:bevy-shapes

Conversation

@JasmineLowen

Copy link
Copy Markdown
Contributor

Objective

The math library contains so called primitives. They are mostly just really high level features for users to draw some quick shapes on the screen or to debug things. Additionally there were a few very simple use cases in the engine. On closer inspection, those use cases don't really require the primitives and all of the features they are coming with.

This PR tries to move all of the mentioned primitives into a new crate bevy_shapes. There we consolidate all of the features primitives currently support in one place. Opposed to this those mentioned features were spread throughout a lot of bevy crates previously (bevy_mesh, bevy_gizmos, bevy_math).

Pros:

  • The new crate makes implementing new primitives more straightforward, as it is easier to discover which things and traits have to be implemented
  • The primitives features are opt-out now via feature flags on the bevy_shapes crate

Cons:

  • Some implementation details had to be shifted somewhere else. An example is the quad mesh which is actually one of the few in engine use cases. In this case, the solution was to implement a quad_mesh constructor on the Mesh struct and use that for the in-engine use cases as well as the Meshable implementation of the Rectangle primitive

Testing

  • Tests were also migrated and are all green
  • cargo clippy successfully runs without showing any further errors

@IQuick143 IQuick143 added C-Code-Quality A section of code that is hard to understand or change A-Math Fundamental domain-agnostic mathematical operations M-Migration-Guide A breaking change to Bevy's public API that needs to be noted in a migration guide X-Needs-SME This type of work requires an SME to approve it. D-Straightforward Simple bug fixes and API improvements, docs, test and examples S-Waiting-on-Author The author needs to make changes or address concerns before this can be merged labels Jul 16, 2026
@JasmineLowen

Copy link
Copy Markdown
Contributor Author

@rparrett I saw you reacted with a 'confused' emoji. Mind sharing your concerns? I'm genuinely interested

@JasmineLowen

Copy link
Copy Markdown
Contributor Author

Someone behind the discord wall suggested that we change the crate name from bevy_shapes to bevy_shape. That's a good point as only the latter is reserved by cart on crates.io, see

https://crates.io/search?q=bevy_shape

@JasmineLowen

Copy link
Copy Markdown
Contributor Author

After work I will also try to fix all of the Cargo.toml changes that my auto-formatter made with my personal preference configs

@JasmineLowen

Copy link
Copy Markdown
Contributor Author

Also we need to discuss what's reasonable to have in the prelude

@rparrett

rparrett commented Jul 16, 2026

Copy link
Copy Markdown
Contributor

I saw you reacted with a 'confused' emoji. Mind sharing your concerns? I'm genuinely interested

Yeah, of course.

I am confused about what motivated this PR. I was later able to dig a small amount of context out of #24849 and #math-dev, but I can no longer process the entire Bevy firehouse of information.

It's not self-evident to me that this new organization scheme is better, and it doesn't seem to address the motivations for the current scheme, as laid out in https://github.com/bevyengine/rfcs/blob/main/rfcs/12-primitive-shapes.md.

@JasmineLowen

JasmineLowen commented Jul 16, 2026

Copy link
Copy Markdown
Contributor Author

Thank you!

I am confused about what motivated this PR. I was later able to dig a small amount of context out of #24849 and #math-dev, but I can no longer process the entire Bevy firehouse of information.

Initially I just wanted to make some progress on the primitives tracking issue and implemented another primitive that was listed there.

Alice asked the question mentioned in #24849. She said that we should further define what a primitive is and maybe put them in a separate crate before adding new ones.

I kind of agreed. Implementing the new primitive felt weird because the traits are scattered all over the place and it was easy to miss one. In a following analysis I suggested two disjunct purposes for primitives: high level for users and low level for in-engine use. Unfortunately I didn't have the RFC in mind and picked the wrong route (the former suggestion). (Thanks for the reminder about the RFC btw!)

I might start a second attempt with the RFC in mind and just scratch this PR here if people are not completely opposed to the idea.

It's not self-evident to me that this new organization scheme is better

Mainly to improve the scattering of the implementations and to increase discoverability in general.
Edit: I guess also to not clutter primitives too much with new shapes. That seems to be one of the original ideas behind alice's comment. I.e. we have some base shapes that are used quiet often and then maybe have other shapes that are more niche behind feature flags.

@github-actions

Copy link
Copy Markdown
Contributor

You added a new example but didn't add metadata for it. Please update the root Cargo.toml file.

@JasmineLowen

Copy link
Copy Markdown
Contributor Author

Closing due to #25047

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 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-Waiting-on-Author The author needs to make changes or address concerns before this can be merged X-Needs-SME This type of work requires an SME to approve it.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants