-
-
Notifications
You must be signed in to change notification settings - Fork 3.5k
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
Add Triangle3d
primitive to bevy_math::primitives
#12508
Conversation
Welcome, new contributor! Please make sure you've read our contributing guide and we look forward to reviewing your pull request shortly ✨ |
@alice-i-cecile I opened the I opened it as a draft so we can discuss a few things:
|
I like this, nice work. Can we get a function for the normal as well? |
For feature-parity with
Other nice to have things:
I think /// Get the normal of the triangle in the direction of `AB x AC`, where `x` denotes the cross product.
///
/// If the triangle vertices are non-finite or lie on the same line, `Err(InvalidDirectionError)` is returned.
#[inline(always)]
pub fn normal(&self) -> Result<Dir3, InvalidDirectionError> {
let ab = self.vertices[1] - self.vertices[0];
let ac = self.vertices[2] - self.vertices[0];
Dir3::new(ab.cross(ac))
} |
Side note: It'd kinda be nice if we used named properties |
@NthTensor, Awesome! I've just finished that task. Plus, I'm aiming to address those triangle-specific concerns @Jondolf raised within the week. @Jondolf, I'm excited to work on an MVP for us to integrate swiftly. While I'm impatient to dive into all the ideas you've shared, my recent joining and ongoing learning in CG, Bevy, and Rust mean I'd like to approach it with a bit of caution. Here's what I plan to tackle first:
How do you feel about deferring the remaining features to a subsequent pull request? This approach aligns with the contributors' guide to keep changes manageable and more trackable. Additionally, I need to conduct some research on mesh and gizmo support. My goal is to ensure we can quickly integrate these foundational features without unnecessary delay. Let's talk about the What if we handle these errors directly in the |
Absolutely, I'm on board! And I agree that it merits a separate PR due to its nature as a breaking change. |
Gizmos and Meshing can (imo should) be left to future work. I think we probably want to left people represent degenerate triangles. We generally allow the other primitives (including Triangle2d) to be degenerate. So returning a result from Moving to named vertices rather than arrays is a good idea, also future work. |
Awesome. Let me know when you're comfortable with an MVP, then make an issue or five for follow-up work :) I don't have strong feelings about doing it all at once versus split up, so whatever is most comfortable for you. |
This comment is more for me to keep track of the future work on this PR and any issues I might have to open after it is merged.
Let me know if there's anything else I can add, and I'll edit this. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nice work! All looks correct to me. There's some doc formatting inconsistencies, but the entire crate is rife with that so don't worry too much about it.
It'd be nice to have tests for all of the triangle math and the bounding implementations to make sure they work as expected. |
Co-authored-by: Miles Silberling-Cook <NthTensor@users.noreply.github.com>
Co-authored-by: Joona Aalto <jondolf.dev@gmail.com>
Co-authored-by: Joona Aalto <jondolf.dev@gmail.com>
I'll merge this in the merge train next Monday unless there are further concerns :) There's a couple of open discussions still so I'll give y'all a bit of time to discuss since I don't think this will block upcoming work. |
Context
GitHub Discussion Link
Objective
Solution
Triangle3d
primitive into thebevy_math
crate.Changelog
Added
Triangle3d
primitive to thebevy_math
crateChanged
Triangle2d::reverse
: the first and last vertices are swapped instead of the second and third.