Tri

Struct Tri 

Source
#[repr(transparent)]
pub struct Tri<V>(pub [V; 3]);
Expand description

Triangle, defined by three vertices.

Tuple Fields§

§0: [V; 3]

Implementations§

Source§

impl<V> Tri<V>

Source

pub fn edges(&self) -> [Edge<&V>; 3]

Given a triangle ABC, returns the edges [AB, BC, CA].

§Examples
use retrofire_core::geom::{Tri, Edge};
use retrofire_core::math::{Point2, pt2};

let pts: [Point2; _] = [pt2(-1.0, 0.0), pt2(2.0, 0.0), pt2(1.0, 2.0)];
let tri = Tri(pts);

let [e0, e1, e2] = tri.edges();
assert_eq!(e0, Edge(&pts[0], &pts[1]));
assert_eq!(e1, Edge(&pts[1], &pts[2]));
assert_eq!(e2, Edge(&pts[2], &pts[0]));
Source§

impl<P: Affine, A> Tri<Vertex<P, A>>

Source

pub fn tangents(&self) -> [P::Diff; 2]

Given a triangle ABC, returns the vectors [AB, AC].

Source§

impl<A, B> Tri<Vertex2<A, B>>

Source

pub fn winding(&self) -> Winding

Returns the winding order of self.

§Examples
use retrofire_core::geom::{Tri, vertex, Winding};
use retrofire_core::math::pt2;

let mut tri = Tri([
    vertex(pt2::<_, ()>(0.0, 0.0), ()),
    vertex(pt2(0.0, 3.0), ()),
    vertex(pt2(4.0, 0.0), ()),
]);
assert_eq!(tri.winding(), Winding::Cw);

tri.0.swap(1, 2);
assert_eq!(tri.winding(), Winding::Ccw);
Source

pub fn signed_area(&self) -> f32

Returns the signed area of self.

The area is positive iff self is wound counter-clockwise.

§Examples
use retrofire_core::geom::{Tri, vertex};
use retrofire_core::math::pt2;

let tri = Tri([
    vertex(pt2::<_, ()>(0.0, 0.0), ()),
    vertex(pt2(0.0, 3.0), ()),
    vertex(pt2(4.0, 0.0), ()),
]);
assert_eq!(tri.signed_area(), -6.0);
Source

pub fn area(&self) -> f32

Returns the (positive) area of self.

§Examples
use retrofire_core::geom::{vertex, Tri};
use retrofire_core::math::pt2;

let tri = Tri([
    vertex(pt2::<_, ()>(0.0, 0.0), ()),
    vertex(pt2(0.0, 3.0), ()),
    vertex(pt2(4.0, 0.0), ()),
]);
assert_eq!(tri.area(), 6.0);
Source§

impl<A, B> Tri<Vertex3<A, B>>

Source

pub fn normal(&self) -> Normal3

Returns the normal vector of self.

The result is normalized to unit length.

§Examples
use core::f32::consts::SQRT_2;
use retrofire_core::geom::{Tri, vertex};
use retrofire_core::math::{pt3, vec3};

// Triangle lying in a 45° angle
let tri = Tri([
    vertex(pt3::<_, ()>(0.0, 0.0, 0.0), ()),
    vertex(pt3(0.0, 3.0, 3.0), ()),
    vertex(pt3(4.0, 0.0,0.0), ()),
]);
assert_eq!(tri.normal(), vec3(0.0, SQRT_2 / 2.0, -SQRT_2 / 2.0));
Source

pub fn plane(&self) -> Plane3<B>

Returns the plane that self lies on.

§Examples
use retrofire_core::geom::{Tri, Plane3, vertex};
use retrofire_core::math::{pt3, Vec3};

let tri = Tri([
    vertex(pt3::<f32, ()>(0.0, 0.0, 2.0), ()),
    vertex(pt3(1.0, 0.0, 2.0), ()),
    vertex(pt3(0.0, 1.0, 2.0), ())
]);
assert_eq!(tri.plane().normal(), Vec3::Z);
assert_eq!(tri.plane().offset(), 2.0);
Source

pub fn winding(&self) -> Winding

Returns the winding order of self, as projected to the XY plane.

Source

pub fn area(&self) -> f32

Returns the area of self.

§Examples
use retrofire_core::geom::{tri, vertex};
use retrofire_core::math::pt3;

let tri = tri(
    vertex(pt3::<_, ()>(0.0, 0.0, 0.0), ()),
    vertex(pt3(4.0, 0.0, 0.0), ()),
    vertex(pt3(0.0, 3.0, 0.0), ()),
);
assert_eq!(tri.area(), 6.0);

Trait Implementations§

Source§

impl<V: Clone> Clone for Tri<V>

Source§

fn clone(&self) -> Tri<V>

Returns a duplicate of the value. Read more
1.0.0 · Source§

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

Performs copy-assignment from source. Read more
Source§

impl<V: Debug> Debug for Tri<V>

Source§

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

Formats the value using the given formatter. Read more
Source§

impl<V: PartialEq> PartialEq for Tri<V>

Source§

fn eq(&self, other: &Tri<V>) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 · Source§

fn ne(&self, other: &Rhs) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl<V: Vary> Render<V> for Tri<usize>

Source§

type Clip = Tri<ClipVert<V>>

The type of this primitive in clip space
Source§

type Clips = [Tri<ClipVert<V>>]

The type for which Clip is implemented.
Source§

type Screen = Tri<Vertex<Point<[f32; 3], Real<3, Screen>>, V>>

The type of this primitive in screen space.
Source§

fn inline(ixd: Tri<usize>, vs: &[ClipVert<V>]) -> Tri<ClipVert<V>>

Maps the indexes of the argument to vertices.
Source§

fn depth(Tri: &Self::Clip) -> f32

Returns the (average) depth of the argument.
Source§

fn is_backface(tri: &Self::Screen) -> bool

Returns whether the argument is facing away from the camera.
Source§

fn to_screen(clip: Tri<ClipVert<V>>, tf: &Mat4x4<NdcToScreen>) -> Self::Screen

Transforms the argument from NDC to screen space.
Source§

fn rasterize<F: FnMut(Scanline<V>)>(scr: Self::Screen, scanline_fn: F)

Rasterizes the argument by calling the function for each scanline.
Source§

impl<V: Copy> Copy for Tri<V>

Source§

impl<V: Eq> Eq for Tri<V>

Source§

impl<V> StructuralPartialEq for Tri<V>

Auto Trait Implementations§

§

impl<V> Freeze for Tri<V>
where V: Freeze,

§

impl<V> RefUnwindSafe for Tri<V>
where V: RefUnwindSafe,

§

impl<V> Send for Tri<V>
where V: Send,

§

impl<V> Sync for Tri<V>
where V: Sync,

§

impl<V> Unpin for Tri<V>
where V: Unpin,

§

impl<V> UnwindSafe for Tri<V>
where V: UnwindSafe,

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<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> 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.