mirror of
https://github.com/hannobraun/Fornjot
synced 2025-05-04 18:08:26 +00:00
Add Triangle::is_valid
The method doesn't make sense yet, as `Triangle::new` explicitly forbids degenerate triangles. This is about to change though, and adding this method is preparation for that.
This commit is contained in:
parent
1dbd431f94
commit
d9533ee033
@ -1,3 +1,4 @@
|
||||
use approx::AbsDiffEq;
|
||||
use parry3d_f64::query::{Ray, RayCast as _};
|
||||
|
||||
use crate::Vector;
|
||||
@ -41,6 +42,26 @@ impl<const D: usize> Triangle<D> {
|
||||
self.points
|
||||
}
|
||||
|
||||
/// # Determine whether the triangle is valid
|
||||
///
|
||||
/// A triangle is valid, if it is not degenerate. In a degenerate triangle,
|
||||
/// the three points do not form an actual triangle, but a line or even a
|
||||
/// single point.
|
||||
///
|
||||
/// ## Implementation Note
|
||||
///
|
||||
/// Right now, this function computes the area of the triangle, and compares
|
||||
/// it against [`Scalar`]'s default epsilon value. This might not be
|
||||
/// flexible enough for all use cases.
|
||||
///
|
||||
/// Long-term, it might become necessary to add some way to override the
|
||||
/// epsilon value used within this function.
|
||||
pub fn is_valid(&self) -> bool {
|
||||
let [a, b, c] = self.points;
|
||||
let area = (b - a).outer(&(c - a)).magnitude();
|
||||
area > Scalar::default_epsilon()
|
||||
}
|
||||
|
||||
/// Normalize the triangle
|
||||
///
|
||||
/// Returns a new `Triangle` instance with the same points, but the points
|
||||
|
Loading…
Reference in New Issue
Block a user