pub struct Triangle<T: CoordNum = f64>(pub Coord<T>, pub Coord<T>, pub Coord<T>);Expand description
A bounded 2D area whose three vertices are defined by
Coords. The semantics and validity are that of
the equivalent Polygon; in addition, the three
vertices must not be collinear and they must be distinct.
§Notes
Irrespective of input order the resulting geometry has ccw order and its vertices are yielded in ccw order by iterators
Tuple Fields§
§0: Coord<T>1: Coord<T>2: Coord<T>Implementations§
Source§impl<T: CoordNum> Triangle<T>
impl<T: CoordNum> Triangle<T>
Sourcepub fn new(v1: Coord<T>, v2: Coord<T>, v3: Coord<T>) -> Self
pub fn new(v1: Coord<T>, v2: Coord<T>, v3: Coord<T>) -> Self
Create a new Triangle, enforcing default (counter clockwise) winding order.
If the vertices are given in clockwise order, they will be reversed. Degenerate triangles (collinear or identical vertices) are stored as-is.
Sourcepub fn unchecked_winding(v1: Coord<T>, v2: Coord<T>, v3: Coord<T>) -> Self
pub fn unchecked_winding(v1: Coord<T>, v2: Coord<T>, v3: Coord<T>) -> Self
Create a Triangle without normalising the winding order.
Use this when the caller has already verified CCW winding, or when the calling code does not depend on a particular winding order (e.g. inside tight loops where the orientation check would be wasteful).
Unlike Triangle::new, vertices are stored in the order given.
pub fn to_array(&self) -> [Coord<T>; 3]
pub fn to_lines(&self) -> [Line<T>; 3]
Sourcepub fn to_polygon(self) -> Polygon<T>
pub fn to_polygon(self) -> Polygon<T>
Create a Polygon from the Triangle.
§Examples
use geo_types::{coord, Triangle, polygon};
// Input is CW
let triangle = Triangle::new(
coord! { x: 0., y: 0. },
coord! { x: 10., y: 20. },
coord! { x: 20., y: -10. },
);
// Output is CCW
assert_eq!(
triangle.to_polygon(),
polygon![
(x: 20., y: -10.),
(x: 10., y: 20.),
(x: 0., y: 0.),
(x: 20., y: -10.),
],
);Trait Implementations§
Source§impl<T> AbsDiffEq for Triangle<T>
impl<T> AbsDiffEq for Triangle<T>
Source§fn abs_diff_eq(&self, other: &Self, epsilon: Self::Epsilon) -> bool
fn abs_diff_eq(&self, other: &Self, epsilon: Self::Epsilon) -> bool
Equality assertion with an absolute limit.
§Examples
use geo_types::{point, Triangle};
let a = Triangle::new((0.0, 0.0).into(), (10.0, 10.0).into(), (0.0, 5.0).into());
let b = Triangle::new((0.0, 0.0).into(), (10.01, 10.0).into(), (0.0, 5.0).into());
approx::abs_diff_eq!(a, b, epsilon=0.1);
approx::abs_diff_ne!(a, b, epsilon=0.001);Source§fn default_epsilon() -> Self::Epsilon
fn default_epsilon() -> Self::Epsilon
Source§fn abs_diff_ne(&self, other: &Rhs, epsilon: Self::Epsilon) -> bool
fn abs_diff_ne(&self, other: &Rhs, epsilon: Self::Epsilon) -> bool
AbsDiffEq::abs_diff_eq.Source§impl<T> RTreeObject for Triangle<T>
impl<T> RTreeObject for Triangle<T>
Source§impl<T> RelativeEq for Triangle<T>where
T: CoordNum + RelativeEq<Epsilon = T>,
impl<T> RelativeEq for Triangle<T>where
T: CoordNum + RelativeEq<Epsilon = T>,
Source§fn relative_eq(
&self,
other: &Self,
epsilon: Self::Epsilon,
max_relative: Self::Epsilon,
) -> bool
fn relative_eq( &self, other: &Self, epsilon: Self::Epsilon, max_relative: Self::Epsilon, ) -> bool
Equality assertion within a relative limit.
§Examples
use geo_types::{point, Triangle};
let a = Triangle::new((0.0, 0.0).into(), (10.0, 10.0).into(), (0.0, 5.0).into());
let b = Triangle::new((0.0, 0.0).into(), (10.01, 10.0).into(), (0.0, 5.0).into());
approx::assert_relative_eq!(a, b, max_relative=0.1);
approx::assert_relative_ne!(a, b, max_relative=0.0001);Source§fn default_max_relative() -> Self::Epsilon
fn default_max_relative() -> Self::Epsilon
Source§fn relative_ne(
&self,
other: &Rhs,
epsilon: Self::Epsilon,
max_relative: Self::Epsilon,
) -> bool
fn relative_ne( &self, other: &Rhs, epsilon: Self::Epsilon, max_relative: Self::Epsilon, ) -> bool
RelativeEq::relative_eq.Source§impl<T: CoordNum> TryFrom<Geometry<T>> for Triangle<T>
Convert a Geometry enum into its inner type.
impl<T: CoordNum> TryFrom<Geometry<T>> for Triangle<T>
Convert a Geometry enum into its inner type.
Fails if the enum case does not match the type you are trying to convert it to.