Skip to main content

Triangle

Struct Triangle 

Source
pub struct Triangle {
    pub v0: Point3<f64>,
    pub v1: Point3<f64>,
    pub v2: Point3<f64>,
}
Expand description

Triangle definition

Fields§

§v0: Point3<f64>§v1: Point3<f64>§v2: Point3<f64>

Implementations§

Source§

impl Triangle

Source

pub fn new(v0: Point3<f64>, v1: Point3<f64>, v2: Point3<f64>) -> Self

Create a new triangle

Source

pub fn normal(&self) -> Vector3<f64>

Calculate triangle normal.

Degenerate triangles get +Z, never NaN. A zero-area (collapsed or exactly collinear) triangle has a zero-length cross product, and the plain normalize() this used to call is v / |v| — i.e. 0.0 / 0.0, which is NaN in every component. Those NaNs were written verbatim into Mesh::normals by add_triangle_to_mesh (the only production caller of this method, via ClippingProcessor::clip_mesh), and they SURVIVED the mesh-hygiene pass: clean_degenerate / drop_thin_triangles rewrites only indices, so the degenerate triangle’s vertices stay in positions / normals as ORPHANS carrying NaN. Six of duplex.ifc’s material-layer wall slices shipped 81 NaN normal components that way, which the @ifc-lite/provenance node-hash domain check rightly rejects (every NaN bit pattern collapses to one quiet NaN when serialized, so accepting them would give distinct payloads the same hash).

+Z is this crate’s established convention for an undefined normal — the same fallback csg::normals::calculate_normals and mesh::weld_impl’s average-normals path already use — so a consumer that meets one meets them all. It is stated in the KERNEL’s own Z-up frame, like every other normal this crate writes, so a viewer that converts to Y-up reads it back as +Y; that is the conversion doing its job, not a second convention. The value is arbitrary but must be a FIXED unit vector: a zero normal would just re-create the division by zero in any shader or exporter that re-normalizes.

Non-degenerate triangles are unaffected, bit-for-bit: try_normalize(0.0) returns Some(v.unscale(|v|)) for every |v| > 0, which is exactly what normalize() computed. The extra is_finite check covers the astronomically-unlikely underflow case where |v| rounds to zero from non-zero components (division would yield ±Inf, also out of domain).

Source

pub fn cross_product(&self) -> Vector3<f64>

Calculate the cross product of edges, which is twice the area vector.

Returns a Vector3<f64> perpendicular to the triangle plane. For degenerate/collinear triangles, returns the zero vector. Use is_degenerate() or try_normalize() on the result if you need to detect and handle degenerate cases.

Source

pub fn area(&self) -> f64

Calculate triangle area (half the magnitude of the cross product).

Source

pub fn is_degenerate(&self, epsilon: f64) -> bool

Check if triangle is degenerate (zero area, collinear vertices).

Uses try_normalize on the cross product with the specified epsilon. Returns true if the cross product cannot be normalized (i.e., degenerate).

Trait Implementations§

Source§

impl Clone for Triangle

Source§

fn clone(&self) -> Triangle

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for Triangle

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<U> As for U

Source§

fn as_<T>(self) -> T
where T: CastFrom<U>, U: Sized,

Casts self to type T. The semantics of numeric casting with the as operator are followed, so <T as As>::as_::<U> can be used in the same way as T as U for numeric conversions. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self>

Converts self into a Left variant of Either<Self, Self> if into_left is true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

Converts self into a Left variant of Either<Self, Self> if into_left(&self) returns true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

impl<T> Pointable for T

Source§

const ALIGN: usize

The alignment of pointer.
Source§

type Init = T

The type for initializers.
Source§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
Source§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
Source§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
Source§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. Read more
Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<SS, SP> SupersetOf<SS> for SP
where SS: SubsetOf<SP>,

Source§

fn to_subset(&self) -> Option<SS>

The inverse inclusion map: attempts to construct self from the equivalent element of its superset. Read more
Source§

fn is_in_subset(&self) -> bool

Checks if self is actually part of its subset T (and can be converted to it).
Source§

fn to_subset_unchecked(&self) -> SS

Use with care! Same as self.to_subset but without any property checks. Always succeeds.
Source§

fn from_subset(element: &SS) -> SP

The inclusion map: converts self to the equivalent element of its superset.
Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.