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
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.
§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
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};
// 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: 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.
impl<T: Copy + CoordNum> Copy for Triangle<T>
impl<T: Eq + CoordNum> Eq for Triangle<T>
impl<T: CoordNum> StructuralPartialEq for Triangle<T>
Auto Trait Implementations§
impl<T> Freeze for Triangle<T>where
T: Freeze,
impl<T> RefUnwindSafe for Triangle<T>where
T: RefUnwindSafe,
impl<T> Send for Triangle<T>where
T: Send,
impl<T> Sync for Triangle<T>where
T: Sync,
impl<T> Unpin for Triangle<T>where
T: Unpin,
impl<T> UnwindSafe for Triangle<T>where
T: 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