pub struct Triangle<S> { /* private fields */ }Available on crate feature
math-utils only.Expand description
A 2-simplex or triangle in 2D space
Creation methods should fail with a debug assertion if the points are colinear.
Implementations§
Source§impl<S> Triangle<S>where
S: OrderedField,
impl<S> Triangle<S>where
S: OrderedField,
Sourcepub fn new(a: Point2<S>, b: Point2<S>, c: Point2<S>) -> Option<Triangle<S>>where
S: AbsDiffEq<Epsilon = S>,
pub fn new(a: Point2<S>, b: Point2<S>, c: Point2<S>) -> Option<Triangle<S>>where
S: AbsDiffEq<Epsilon = S>,
Returns None if the points are colinear:
assert!(Triangle::new (
[-1.0, -1.0].into(),
[ 0.0, 0.0].into(),
[ 1.0, 1.0].into()
).is_none());Sourcepub fn noisy(a: Point2<S>, b: Point2<S>, c: Point2<S>) -> Triangle<S>where
S: AbsDiffEq<Epsilon = S>,
pub fn noisy(a: Point2<S>, b: Point2<S>, c: Point2<S>) -> Triangle<S>where
S: AbsDiffEq<Epsilon = S>,
Panics if the points are colinear:
ⓘ
let s = Triangle::noisy (
[-1.0, -1.0].into(),
[ 0.0, 0.0].into(),
[ 1.0, 1.0].into());Sourcepub fn unchecked(a: Point2<S>, b: Point2<S>, c: Point2<S>) -> Triangle<S>where
S: AbsDiffEq<Epsilon = S>,
pub fn unchecked(a: Point2<S>, b: Point2<S>, c: Point2<S>) -> Triangle<S>where
S: AbsDiffEq<Epsilon = S>,
Debug panic if the points are colinear:
ⓘ
let s = Triangle::unchecked (
[-1.0, -1.0].into(),
[ 0.0, 0.0].into(),
[ 1.0, 1.0].into());pub fn from_array(_: [Point2<S>; 3]) -> Option<Triangle<S>>where
S: AbsDiffEq<Epsilon = S>,
pub const fn point_a(self) -> Point2<S>
pub const fn point_b(self) -> Point2<S>
pub const fn point_c(self) -> Point2<S>
pub const fn points(self) -> [Point2<S>; 3]
Sourcepub fn point(self, s: Normalized<S>, t: Normalized<S>) -> Option<Point2<S>>
pub fn point(self, s: Normalized<S>, t: Normalized<S>) -> Option<Point2<S>>
Return a parameterized point on the triangle.
Returns None if s + t > 1.0.
pub const fn edge_ab(self) -> Segment<S>
pub const fn edge_bc(self) -> Segment<S>
pub const fn edge_ca(self) -> Segment<S>
Sourcepub const fn rewind(self) -> Triangle<S>
pub const fn rewind(self) -> Triangle<S>
Change triangle winding by swapping points B and C.
Equivalent to triangle.acb().
pub fn translate(&mut self, displacement: Vec2<S>)
Sourcepub fn perpendicular_ab(self) -> NonZero2<S>
pub fn perpendicular_ab(self) -> NonZero2<S>
Returns perpendicular vector to edge AB.
let s = Triangle::unchecked (
[0.0, 0.0].into(),
[0.0, 2.0].into(),
[2.0, 1.0].into());
assert_eq!(*s.perpendicular_ab(), [-2.0, 0.0].into());
let s = Triangle::unchecked (
[ 0.0, 0.0].into(),
[ 0.0, 2.0].into(),
[-2.0, 1.0].into());
assert_eq!(*s.perpendicular_ab(), [2.0, 0.0].into());Sourcepub fn perpendicular_bc(self) -> NonZero2<S>
pub fn perpendicular_bc(self) -> NonZero2<S>
Returns perpendicular vector to edge BC.
let s = Triangle::unchecked (
[2.0, 1.0].into(),
[0.0, 0.0].into(),
[0.0, 2.0].into());
assert_eq!(*s.perpendicular_bc(), [-2.0, 0.0].into());
let s = Triangle::unchecked (
[-2.0, 1.0].into(),
[ 0.0, 0.0].into(),
[ 0.0, 2.0].into());
assert_eq!(*s.perpendicular_bc(), [2.0, 0.0].into());Sourcepub fn perpendicular_ca(self) -> NonZero2<S>
pub fn perpendicular_ca(self) -> NonZero2<S>
Returns perpendicular vector to edge CA.
let s = Triangle::unchecked (
[0.0, 2.0].into(),
[2.0, 1.0].into(),
[0.0, 0.0].into());
assert_eq!(*s.perpendicular_ca(), [-2.0, 0.0].into());
let s = Triangle::unchecked (
[ 0.0, 2.0].into(),
[-2.0, 1.0].into(),
[ 0.0, 0.0].into());
assert_eq!(*s.perpendicular_ca(), [2.0, 0.0].into());pub fn area(self) -> Positive<S>where
S: Real,
pub fn barycentric(self, coords: Vec3<S>) -> Point2<S>
pub fn trilinear(self, coords: Vec3<S>) -> Point2<S>
pub fn affine_plane(self) -> Plane2<S>
pub fn nearest_point(self, point: Point2<S>) -> ([Normalized<S>; 2], Point2<S>)
Trait Implementations§
Source§impl<S> Default for Triangle<S>
impl<S> Default for Triangle<S>
Source§fn default() -> Triangle<S>
fn default() -> Triangle<S>
A default triangle is arbitrarily chosen to be the equilateral triangle with point at 1.0 on the Y axis:
use std::f64::consts::FRAC_1_SQRT_2;
let s = Triangle::default();
let t = Triangle::noisy (
[ 0.0, 1.0].into(),
[-FRAC_1_SQRT_2, -FRAC_1_SQRT_2].into(),
[ FRAC_1_SQRT_2, -FRAC_1_SQRT_2].into()
);
approx::assert_relative_eq!(s.point_a(), t.point_a());
approx::assert_relative_eq!(s.point_b(), t.point_b());
approx::assert_relative_eq!(s.point_c(), t.point_c());Source§impl<S> PartialEq for Triangle<S>where
S: PartialEq,
impl<S> PartialEq for Triangle<S>where
S: PartialEq,
Source§impl<S> TryFrom<[Point2<S>; 3]> for Triangle<S>where
S: OrderedField + AbsDiffEq<Epsilon = S>,
impl<S> TryFrom<[Point2<S>; 3]> for Triangle<S>where
S: OrderedField + AbsDiffEq<Epsilon = S>,
impl<S> Copy for Triangle<S>where
S: Copy,
impl<S> Eq for Triangle<S>where
S: Eq,
impl<S> StructuralPartialEq for Triangle<S>
Auto Trait Implementations§
impl<S> Freeze for Triangle<S>where
S: Freeze,
impl<S> RefUnwindSafe for Triangle<S>where
S: RefUnwindSafe,
impl<S> Send for Triangle<S>where
S: Send,
impl<S> Sync for Triangle<S>where
S: Sync,
impl<S> Unpin for Triangle<S>where
S: Unpin,
impl<S> UnsafeUnpin for Triangle<S>where
S: UnsafeUnpin,
impl<S> UnwindSafe for Triangle<S>where
S: UnwindSafe,
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more
Source§impl<T> CheckedAs for T
impl<T> CheckedAs for T
Source§fn checked_as<Dst>(self) -> Option<Dst>where
T: CheckedCast<Dst>,
fn checked_as<Dst>(self) -> Option<Dst>where
T: CheckedCast<Dst>,
Casts the value.
Source§impl<Src, Dst> CheckedCastFrom<Src> for Dstwhere
Src: CheckedCast<Dst>,
impl<Src, Dst> CheckedCastFrom<Src> for Dstwhere
Src: CheckedCast<Dst>,
Source§fn checked_cast_from(src: Src) -> Option<Dst>
fn checked_cast_from(src: Src) -> Option<Dst>
Casts the value.
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<T> Content for Twhere
T: Copy,
impl<T> Content for Twhere
T: Copy,
Source§unsafe fn read<F, E>(size: usize, f: F) -> Result<T, E>
unsafe fn read<F, E>(size: usize, f: F) -> Result<T, E>
Prepares an output buffer, then turns this buffer into an
Owned.
User-provided closure F must only write to and not read from &mut Self.Source§fn get_elements_size() -> usize
fn get_elements_size() -> usize
Returns the size of each element.
Source§fn to_void_ptr(&self) -> *const ()
fn to_void_ptr(&self) -> *const ()
Produces a pointer to the data.
Source§fn ref_from_ptr<'a>(ptr: *mut (), size: usize) -> Option<*mut T>
fn ref_from_ptr<'a>(ptr: *mut (), size: usize) -> Option<*mut T>
Builds a pointer to this type from a raw pointer.
Source§fn is_size_suitable(size: usize) -> bool
fn is_size_suitable(size: usize) -> bool
Returns true if the size is suitable to store a type like this.
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
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 moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
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 moreSource§impl<Src, Dst> LosslessTryInto<Dst> for Srcwhere
Dst: LosslessTryFrom<Src>,
impl<Src, Dst> LosslessTryInto<Dst> for Srcwhere
Dst: LosslessTryFrom<Src>,
Source§fn lossless_try_into(self) -> Option<Dst>
fn lossless_try_into(self) -> Option<Dst>
Performs the conversion.
Source§impl<Src, Dst> LossyInto<Dst> for Srcwhere
Dst: LossyFrom<Src>,
impl<Src, Dst> LossyInto<Dst> for Srcwhere
Dst: LossyFrom<Src>,
Source§fn lossy_into(self) -> Dst
fn lossy_into(self) -> Dst
Performs the conversion.
Source§impl<T> OverflowingAs for T
impl<T> OverflowingAs for T
Source§fn overflowing_as<Dst>(self) -> (Dst, bool)where
T: OverflowingCast<Dst>,
fn overflowing_as<Dst>(self) -> (Dst, bool)where
T: OverflowingCast<Dst>,
Casts the value.
Source§impl<Src, Dst> OverflowingCastFrom<Src> for Dstwhere
Src: OverflowingCast<Dst>,
impl<Src, Dst> OverflowingCastFrom<Src> for Dstwhere
Src: OverflowingCast<Dst>,
Source§fn overflowing_cast_from(src: Src) -> (Dst, bool)
fn overflowing_cast_from(src: Src) -> (Dst, bool)
Casts the value.
Source§impl<T> Pointable for T
impl<T> Pointable for T
Source§impl<R, P> ReadPrimitive<R> for P
impl<R, P> ReadPrimitive<R> for P
Source§fn read_from_little_endian(read: &mut R) -> Result<Self, Error>
fn read_from_little_endian(read: &mut R) -> Result<Self, Error>
Read this value from the supplied reader. Same as
ReadEndian::read_from_little_endian().Source§impl<T> SaturatingAs for T
impl<T> SaturatingAs for T
Source§fn saturating_as<Dst>(self) -> Dstwhere
T: SaturatingCast<Dst>,
fn saturating_as<Dst>(self) -> Dstwhere
T: SaturatingCast<Dst>,
Casts the value.
Source§impl<Src, Dst> SaturatingCastFrom<Src> for Dstwhere
Src: SaturatingCast<Dst>,
impl<Src, Dst> SaturatingCastFrom<Src> for Dstwhere
Src: SaturatingCast<Dst>,
Source§fn saturating_cast_from(src: Src) -> Dst
fn saturating_cast_from(src: Src) -> Dst
Casts the value.
Source§impl<T> UnwrappedAs for T
impl<T> UnwrappedAs for T
Source§fn unwrapped_as<Dst>(self) -> Dstwhere
T: UnwrappedCast<Dst>,
fn unwrapped_as<Dst>(self) -> Dstwhere
T: UnwrappedCast<Dst>,
Casts the value.
Source§impl<Src, Dst> UnwrappedCastFrom<Src> for Dstwhere
Src: UnwrappedCast<Dst>,
impl<Src, Dst> UnwrappedCastFrom<Src> for Dstwhere
Src: UnwrappedCast<Dst>,
Source§fn unwrapped_cast_from(src: Src) -> Dst
fn unwrapped_cast_from(src: Src) -> Dst
Casts the value.
Source§impl<T> WithSubscriber for T
impl<T> WithSubscriber for T
Source§fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
Source§fn with_current_subscriber(self) -> WithDispatch<Self>
fn with_current_subscriber(self) -> WithDispatch<Self>
Source§impl<T> WrappingAs for T
impl<T> WrappingAs for T
Source§fn wrapping_as<Dst>(self) -> Dstwhere
T: WrappingCast<Dst>,
fn wrapping_as<Dst>(self) -> Dstwhere
T: WrappingCast<Dst>,
Casts the value.
Source§impl<Src, Dst> WrappingCastFrom<Src> for Dstwhere
Src: WrappingCast<Dst>,
impl<Src, Dst> WrappingCastFrom<Src> for Dstwhere
Src: WrappingCast<Dst>,
Source§fn wrapping_cast_from(src: Src) -> Dst
fn wrapping_cast_from(src: Src) -> Dst
Casts the value.