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

Extrusion bounded #13346

Merged
merged 15 commits into from
Jun 4, 2024
Merged

Conversation

lynn-lumen
Copy link
Contributor

@lynn-lumen lynn-lumen commented May 13, 2024

Objective

  • Implement Bounded3d for some Extrusion<T>
  • Provide methods to calculate Aabb3ds and BoundingSpheres for any extrusion with a Bounded2d base shape

Solution

  • Implemented Bounded3d for all 2D bevy_math primitives with the exception of Plane2d. As far as I can see, Plane2d is pretty much a line? and I think it is very unintuitive to extrude a plane and get a plane as a result.
  • Add extrusion_bounding_box and extrusion_bounding_sphere. These are not always used internally since there are faster methods for specific extrusions. Both of them produce the optimal result within precision limits though.

Testing

  • Bounds for extrusions are tested within the same module. All unique implementations are tested.
  • The correctness was validated visually aswell.

@NthTensor NthTensor added C-Feature A new feature, making something new possible A-Math Fundamental domain-agnostic mathematical operations labels May 13, 2024
Copy link
Contributor

@IQuick143 IQuick143 left a comment

Choose a reason for hiding this comment

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

Overall the code is good, although I haven't looked through the ellipse code and the tests yet.

crates/bevy_math/src/bounding/bounded3d/extrusion.rs Outdated Show resolved Hide resolved
Co-Authored-By: IQuick 143 <IQuick143cz@gmail.com>
@pablo-lua pablo-lua added the S-Needs-Review Needs reviewer attention (from anyone!) to move forward label May 29, 2024
@lynn-lumen lynn-lumen requested a review from IQuick143 June 2, 2024 23:58
@lynn-lumen lynn-lumen mentioned this pull request Jun 3, 2024
3 tasks
@alice-i-cecile alice-i-cecile added this to the 0.14 milestone Jun 3, 2024
@alice-i-cecile alice-i-cecile requested review from mweatherley and removed request for IQuick143 June 3, 2024 22:36
Comment on lines +57 to +59
let y = signum.y * b * b / (b * b + m * m * a * a).sqrt();
let x = signum.x * a * (1. - y * y / b / b).sqrt();
rotation * Vec3::new(x, y, 0.)
Copy link
Contributor

Choose a reason for hiding this comment

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

Possible division by zero if ellipse is degenerate?

Copy link
Contributor

@NthTensor NthTensor left a comment

Choose a reason for hiding this comment

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

Very cool! Everything looks as I would expect. Finding the Ellipse code a little hard to follow without comments, but think I get the gist.

Haven't visually inspected yet, will try to later. Approving.

@alice-i-cecile alice-i-cecile 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 Jun 4, 2024
@alice-i-cecile alice-i-cecile added this pull request to the merge queue Jun 4, 2024
}
}

fn bounding_sphere<T: Primitive2d + Bounded2d>(
Copy link
Contributor

Choose a reason for hiding this comment

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

I think this should probably be renamed to something more descriptive which doesn't share a name with the Bounded3d method. Maybe bounding_sphere_from_base or similar?

fn aabb_3d(&self, translation: Vec3, rotation: Quat) -> Aabb3d {
let Vec2 { x: a, y: b } = self.base_shape.half_size;
let normal = rotation * Vec3::Z;
let conjugate_rot = rotation.conjugate();
Copy link
Contributor

Choose a reason for hiding this comment

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

I think this is a little more readable:

Suggested change
let conjugate_rot = rotation.conjugate();
let inverse_rot = rotation.conjugate();

Merged via the queue into bevyengine:main with commit 5e1c841 Jun 4, 2024
28 checks passed
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-Feature A new feature, making something new possible S-Ready-For-Final-Review This PR has been approved by the community. It's ready for a maintainer to consider merging it
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants