Expand description
A bounded 2D area whose three vertices are defined by
Coord
s. The semantics and validity are that of
the equivalent Polygon
; in addition, the three
vertices must not be collinear and they must be distinct.
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
Instantiate Self from the raw content value
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};
let triangle = Triangle::new(
coord! { x: 0., y: 0. },
coord! { x: 10., y: 20. },
coord! { x: 20., y: -10. },
);
assert_eq!(
triangle.to_polygon(),
polygon![
(x: 0., y: 0.),
(x: 10., y: 20.),
(x: 20., y: -10.),
(x: 0., y: 0.),
],
);
Trait Implementations§
source§impl<T> AbsDiffEq<Triangle<T>> for Triangle<T>where
T: AbsDiffEq<Epsilon = T> + CoordNum,
T::Epsilon: Copy,
impl<T> AbsDiffEq<Triangle<T>> for Triangle<T>where
T: AbsDiffEq<Epsilon = T> + CoordNum,
T::Epsilon: Copy,
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
The default tolerance to use when testing values that are close together. Read more
source§fn abs_diff_ne(&self, other: &Rhs, epsilon: Self::Epsilon) -> bool
fn abs_diff_ne(&self, other: &Rhs, epsilon: Self::Epsilon) -> bool
The inverse of
AbsDiffEq::abs_diff_eq
.source§impl<'de, T> Deserialize<'de> for Triangle<T>where
T: Deserialize<'de> + CoordNum,
impl<'de, T> Deserialize<'de> for Triangle<T>where
T: Deserialize<'de> + CoordNum,
source§fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
Deserialize this value from the given Serde deserializer. Read more
source§impl<T: PartialEq + CoordNum> PartialEq<Triangle<T>> for Triangle<T>
impl<T: PartialEq + CoordNum> PartialEq<Triangle<T>> for Triangle<T>
source§impl<T> RelativeEq<Triangle<T>> for Triangle<T>where
T: AbsDiffEq<Epsilon = T> + CoordNum + RelativeEq,
impl<T> RelativeEq<Triangle<T>> for Triangle<T>where
T: AbsDiffEq<Epsilon = T> + CoordNum + RelativeEq,
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
The default relative tolerance for testing values that are far-apart. Read more
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
The inverse of
RelativeEq::relative_eq
.source§impl<T: CoordNum> TryFrom<Geometry<T>> for Triangle<T>
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.