Skip to content
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

Reworked Segment types into their cartesian forms #17404

Open
wants to merge 47 commits into
base: main
Choose a base branch
from

Conversation

Sigma-dev
Copy link
Contributor

Objective

Segment2d and Segment3d are currently hard to work with because unlike many other primary shapes, they are bound to the origin.
The objective of this PR is to allow these segments to exist anywhere in cartesian space, making them much more useful in a variety of contexts.

Solution

Reworking the existing segment type's internal fields and methods to allow them to exist anywhere in cartesian space.
I have done both reworks for 2d and 3d segments but I was unsure if I should just have it all here or not so feel free to tell me how I should proceed, for now I have only pushed Segment2d changes.

As I am not a very seasoned contributor, this first implementation is very likely sloppy and will need some additional work from my end, I am open to all criticisms and willing to work to get this to bevy's standards.

Testing

I am not very familiar with the standards of testing. Of course my changes had to pass the thorough existing tests for primitive shapes.
I also checked the gizmo 2d shapes intersection example and everything looked fine.

I did add a few utility methods to the types that have no tests yet. I am willing to implement some if it is deemed necessary

Migration Guide

The segment type constructors changed so if someone previously created a Segment2d with a direction and length they would now need to use the from_direction constructor

@Jondolf Jondolf self-requested a review January 16, 2025 12:30
@Jondolf Jondolf added C-Usability A targeted quality-of-life change that makes Bevy easier to use A-Math Fundamental domain-agnostic mathematical operations M-Needs-Migration-Guide A breaking change to Bevy's public API that needs to be noted in a migration guide S-Needs-Review Needs reviewer attention (from anyone!) to move forward labels Jan 16, 2025
@IQuick143 IQuick143 self-requested a review January 16, 2025 12:41
Copy link
Member

@alice-i-cecile alice-i-cecile left a comment

Choose a reason for hiding this comment

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

Looks good so far. but I'd prefer to do the 3D segment changes in the same PR. This is straightforward to review and I really don't want to ship one without the other.

@alice-i-cecile alice-i-cecile added the X-Uncontroversial This work is generally agreed upon label Jan 16, 2025
crates/bevy_gizmos/src/primitives/dim3.rs Outdated Show resolved Hide resolved
crates/bevy_math/src/bounding/bounded2d/primitive_impls.rs Outdated Show resolved Hide resolved
crates/bevy_math/src/bounding/bounded2d/primitive_impls.rs Outdated Show resolved Hide resolved
crates/bevy_math/src/bounding/bounded3d/primitive_impls.rs Outdated Show resolved Hide resolved
@@ -359,22 +359,25 @@ impl Primitive3d for Line3d {}
reflect(Serialize, Deserialize)
)]
pub struct Segment3d {
Copy link
Contributor

Choose a reason for hiding this comment

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

I won't copy all of my comments from the 2D version, but most of them also apply here in 3D.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

For the things you havn't specificially mentionned for the Segment3d, I have done the translation and rotation changes, tell me if I missed anything else

crates/bevy_math/src/primitives/dim3.rs Outdated Show resolved Hide resolved
crates/bevy_math/src/primitives/dim3.rs Outdated Show resolved Hide resolved
examples/2d/bounding_2d.rs Outdated Show resolved Hide resolved
crates/bevy_math/src/primitives/dim2.rs Outdated Show resolved Hide resolved
@Sigma-dev
Copy link
Contributor Author

Sigma-dev commented Jan 17, 2025

If I didn't miss anything (unlikely) I should have addressed everything except the stuff I left questions about.
I'm open to any new required changes as well of course

@alice-i-cecile alice-i-cecile added this to the 0.16 milestone Jan 18, 2025
Copy link
Contributor

@Jondolf Jondolf left a comment

Choose a reason for hiding this comment

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

Some inconsistencies between 2D and 3D

crates/bevy_math/src/primitives/dim3.rs Outdated Show resolved Hide resolved
crates/bevy_math/src/primitives/dim3.rs Outdated Show resolved Hide resolved
crates/bevy_math/src/primitives/dim3.rs Show resolved Hide resolved
@Sigma-dev
Copy link
Contributor Author

Everything should be fixed now

@Jondolf
Copy link
Contributor

Jondolf commented Jan 18, 2025

This is still unadressed, though I'm fine fixing it in a follow-up too if you'd prefer #17404 (comment)

Copy link
Contributor

@Jondolf Jondolf left a comment

Choose a reason for hiding this comment

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

Looks great now, thanks for your patience on this! I'll add some more helpers and do a small clean-up pass in a follow-up.

@Jondolf Jondolf added 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 Jan 18, 2025
@Sigma-dev
Copy link
Contributor Author

I appreciate your patience as well, there was quite a lot to fix

Copy link
Contributor

@Jondolf Jondolf left a comment

Choose a reason for hiding this comment

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

Found a few more things

crates/bevy_gizmos/src/primitives/dim2.rs Outdated Show resolved Hide resolved
crates/bevy_gizmos/src/primitives/dim3.rs Outdated Show resolved Hide resolved
crates/bevy_math/src/primitives/dim3.rs Outdated Show resolved Hide resolved
crates/bevy_math/src/primitives/dim2.rs Outdated Show resolved Hide resolved
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-Usability A targeted quality-of-life change that makes Bevy easier to use M-Needs-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-Uncontroversial This work is generally agreed upon
Projects
None yet
Development

Successfully merging this pull request may close these issues.

7 participants