pub struct Triangle<T = f64>(pub Coord<T>, pub Coord<T>, pub Coord<T>)
where
T: CoordNum;Available on crate feature
geo-types only.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> Triangle<T>where
T: CoordNum,
impl<T> Triangle<T>where
T: CoordNum,
Sourcepub fn new(v1: Coord<T>, v2: Coord<T>, v3: Coord<T>) -> Triangle<T>
pub fn new(v1: Coord<T>, v2: Coord<T>, v3: Coord<T>) -> Triangle<T>
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<'a, T> GeometryTrait for &'a Triangle<T>where
T: CoordNum + 'a,
impl<'a, T> GeometryTrait for &'a Triangle<T>where
T: CoordNum + 'a,
Source§type PointType<'b> = Point<<&'a Triangle<T> as GeometryTrait>::T>
where
&'a Triangle<T>: 'b
type PointType<'b> = Point<<&'a Triangle<T> as GeometryTrait>::T> where &'a Triangle<T>: 'b
The type of each underlying Point, which implements PointTrait
Source§type LineStringType<'b> = LineString<<&'a Triangle<T> as GeometryTrait>::T>
where
&'a Triangle<T>: 'b
type LineStringType<'b> = LineString<<&'a Triangle<T> as GeometryTrait>::T> where &'a Triangle<T>: 'b
The type of each underlying LineString, which implements LineStringTrait
Source§type PolygonType<'b> = Polygon<<&'a Triangle<T> as GeometryTrait>::T>
where
&'a Triangle<T>: 'b
type PolygonType<'b> = Polygon<<&'a Triangle<T> as GeometryTrait>::T> where &'a Triangle<T>: 'b
The type of each underlying Polygon, which implements PolygonTrait
Source§type MultiPointType<'b> = MultiPoint<<&'a Triangle<T> as GeometryTrait>::T>
where
&'a Triangle<T>: 'b
type MultiPointType<'b> = MultiPoint<<&'a Triangle<T> as GeometryTrait>::T> where &'a Triangle<T>: 'b
The type of each underlying MultiPoint, which implements MultiPointTrait
Source§type MultiLineStringType<'b> = MultiLineString<<&'a Triangle<T> as GeometryTrait>::T>
where
&'a Triangle<T>: 'b
type MultiLineStringType<'b> = MultiLineString<<&'a Triangle<T> as GeometryTrait>::T> where &'a Triangle<T>: 'b
The type of each underlying MultiLineString, which implements MultiLineStringTrait
Source§type MultiPolygonType<'b> = MultiPolygon<<&'a Triangle<T> as GeometryTrait>::T>
where
&'a Triangle<T>: 'b
type MultiPolygonType<'b> = MultiPolygon<<&'a Triangle<T> as GeometryTrait>::T> where &'a Triangle<T>: 'b
The type of each underlying MultiPolygon, which implements MultiPolygonTrait
Source§type GeometryCollectionType<'b> = GeometryCollection<<&'a Triangle<T> as GeometryTrait>::T>
where
&'a Triangle<T>: 'b
type GeometryCollectionType<'b> = GeometryCollection<<&'a Triangle<T> as GeometryTrait>::T> where &'a Triangle<T>: 'b
The type of each underlying GeometryCollection, which implements GeometryCollectionTrait
Source§type RectType<'b> = Rect<<&'a Triangle<T> as GeometryTrait>::T>
where
&'a Triangle<T>: 'b
type RectType<'b> = Rect<<&'a Triangle<T> as GeometryTrait>::T> where &'a Triangle<T>: 'b
The type of each underlying Rect, which implements RectTrait
Source§type TriangleType<'b> = Triangle<<&'a Triangle<T> as GeometryTrait>::T>
where
&'a Triangle<T>: 'b
type TriangleType<'b> = Triangle<<&'a Triangle<T> as GeometryTrait>::T> where &'a Triangle<T>: 'b
The type of each underlying Triangle, which implements TriangleTrait
Source§type LineType<'b> = Line<<&'a Triangle<T> as GeometryTrait>::T>
where
&'a Triangle<T>: 'b
type LineType<'b> = Line<<&'a Triangle<T> as GeometryTrait>::T> where &'a Triangle<T>: 'b
The type of each underlying Line, which implements LineTrait
Source§fn dim(&self) -> Dimensions
fn dim(&self) -> Dimensions
The dimension of this geometry
Source§fn as_type(
&self,
) -> GeometryType<'_, Point<T>, LineString<T>, Polygon<T>, MultiPoint<T>, MultiLineString<T>, MultiPolygon<T>, GeometryCollection<T>, Rect<T>, Triangle<T>, Line<T>>
fn as_type( &self, ) -> GeometryType<'_, Point<T>, LineString<T>, Polygon<T>, MultiPoint<T>, MultiLineString<T>, MultiPolygon<T>, GeometryCollection<T>, Rect<T>, Triangle<T>, Line<T>>
Cast this geometry to a
GeometryType enum, which allows for downcasting to a specific
typeSource§impl<T> GeometryTrait for Triangle<T>where
T: CoordNum,
impl<T> GeometryTrait for Triangle<T>where
T: CoordNum,
Source§type PointType<'b> = Point<<Triangle<T> as GeometryTrait>::T>
where
Triangle<T>: 'b
type PointType<'b> = Point<<Triangle<T> as GeometryTrait>::T> where Triangle<T>: 'b
The type of each underlying Point, which implements PointTrait
Source§type LineStringType<'b> = LineString<<Triangle<T> as GeometryTrait>::T>
where
Triangle<T>: 'b
type LineStringType<'b> = LineString<<Triangle<T> as GeometryTrait>::T> where Triangle<T>: 'b
The type of each underlying LineString, which implements LineStringTrait
Source§type PolygonType<'b> = Polygon<<Triangle<T> as GeometryTrait>::T>
where
Triangle<T>: 'b
type PolygonType<'b> = Polygon<<Triangle<T> as GeometryTrait>::T> where Triangle<T>: 'b
The type of each underlying Polygon, which implements PolygonTrait
Source§type MultiPointType<'b> = MultiPoint<<Triangle<T> as GeometryTrait>::T>
where
Triangle<T>: 'b
type MultiPointType<'b> = MultiPoint<<Triangle<T> as GeometryTrait>::T> where Triangle<T>: 'b
The type of each underlying MultiPoint, which implements MultiPointTrait
Source§type MultiLineStringType<'b> = MultiLineString<<Triangle<T> as GeometryTrait>::T>
where
Triangle<T>: 'b
type MultiLineStringType<'b> = MultiLineString<<Triangle<T> as GeometryTrait>::T> where Triangle<T>: 'b
The type of each underlying MultiLineString, which implements MultiLineStringTrait
Source§type MultiPolygonType<'b> = MultiPolygon<<Triangle<T> as GeometryTrait>::T>
where
Triangle<T>: 'b
type MultiPolygonType<'b> = MultiPolygon<<Triangle<T> as GeometryTrait>::T> where Triangle<T>: 'b
The type of each underlying MultiPolygon, which implements MultiPolygonTrait
Source§type GeometryCollectionType<'b> = GeometryCollection<<Triangle<T> as GeometryTrait>::T>
where
Triangle<T>: 'b
type GeometryCollectionType<'b> = GeometryCollection<<Triangle<T> as GeometryTrait>::T> where Triangle<T>: 'b
The type of each underlying GeometryCollection, which implements GeometryCollectionTrait
Source§type RectType<'b> = Rect<<Triangle<T> as GeometryTrait>::T>
where
Triangle<T>: 'b
type RectType<'b> = Rect<<Triangle<T> as GeometryTrait>::T> where Triangle<T>: 'b
The type of each underlying Rect, which implements RectTrait
Source§type TriangleType<'b> = Triangle<<Triangle<T> as GeometryTrait>::T>
where
Triangle<T>: 'b
type TriangleType<'b> = Triangle<<Triangle<T> as GeometryTrait>::T> where Triangle<T>: 'b
The type of each underlying Triangle, which implements TriangleTrait
Source§type LineType<'b> = Line<<Triangle<T> as GeometryTrait>::T>
where
Triangle<T>: 'b
type LineType<'b> = Line<<Triangle<T> as GeometryTrait>::T> where Triangle<T>: 'b
The type of each underlying Line, which implements LineTrait
Source§fn dim(&self) -> Dimensions
fn dim(&self) -> Dimensions
The dimension of this geometry
Source§fn as_type(
&self,
) -> GeometryType<'_, Point<T>, LineString<T>, Polygon<T>, MultiPoint<T>, MultiLineString<T>, MultiPolygon<T>, GeometryCollection<T>, Rect<T>, Triangle<T>, Line<T>>
fn as_type( &self, ) -> GeometryType<'_, Point<T>, LineString<T>, Polygon<T>, MultiPoint<T>, MultiLineString<T>, MultiPolygon<T>, GeometryCollection<T>, Rect<T>, Triangle<T>, Line<T>>
Cast this geometry to a
GeometryType enum, which allows for downcasting to a specific
typeSource§impl<T> ToWkt<T> for Triangle<T>
§Examples
use geo_types::{coord, Triangle};
use wkt::ToWkt;
let triangle: Triangle<f64> = Triangle::new(coord!(x: 0., y: 0.), coord!(x: 4., y: 0.), coord!(x: 2., y: 4.));
assert_eq!(triangle.wkt_string(), "POLYGON((0 0,4 0,2 4,0 0))");
impl<T> ToWkt<T> for Triangle<T>
§Examples
use geo_types::{coord, Triangle};
use wkt::ToWkt;
let triangle: Triangle<f64> = Triangle::new(coord!(x: 0., y: 0.), coord!(x: 4., y: 0.), coord!(x: 2., y: 4.));
assert_eq!(triangle.wkt_string(), "POLYGON((0 0,4 0,2 4,0 0))");Source§impl<'a, T> TriangleTrait for &'a Triangle<T>where
T: CoordNum,
impl<'a, T> TriangleTrait for &'a Triangle<T>where
T: CoordNum,
Source§type CoordType<'b> = &'a Coord<<&'a Triangle<T> as GeometryTrait>::T>
where
&'a Triangle<T>: 'b
type CoordType<'b> = &'a Coord<<&'a Triangle<T> as GeometryTrait>::T> where &'a Triangle<T>: 'b
The type of each underlying coordinate, which implements CoordTrait
Source§fn first(&self) -> <&'a Triangle<T> as TriangleTrait>::CoordType<'_>
fn first(&self) -> <&'a Triangle<T> as TriangleTrait>::CoordType<'_>
Access the first coordinate in this Triangle
Source§fn second(&self) -> <&'a Triangle<T> as TriangleTrait>::CoordType<'_>
fn second(&self) -> <&'a Triangle<T> as TriangleTrait>::CoordType<'_>
Access the second coordinate in this Triangle
Source§impl<T> TriangleTrait for Triangle<T>where
T: CoordNum,
impl<T> TriangleTrait for Triangle<T>where
T: CoordNum,
Source§type CoordType<'a> = &'a Coord<<Triangle<T> as GeometryTrait>::T>
where
Triangle<T>: 'a
type CoordType<'a> = &'a Coord<<Triangle<T> as GeometryTrait>::T> where Triangle<T>: 'a
The type of each underlying coordinate, which implements CoordTrait
Source§fn first(&self) -> <Triangle<T> as TriangleTrait>::CoordType<'_>
fn first(&self) -> <Triangle<T> as TriangleTrait>::CoordType<'_>
Access the first coordinate in this Triangle
Source§fn second(&self) -> <Triangle<T> as TriangleTrait>::CoordType<'_>
fn second(&self) -> <Triangle<T> as TriangleTrait>::CoordType<'_>
Access the second coordinate in this Triangle
Source§impl<T> TryFrom<Geometry<T>> for Triangle<T>where
T: CoordNum,
Convert a Geometry enum into its inner type.
impl<T> TryFrom<Geometry<T>> for Triangle<T>where
T: CoordNum,
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.
Source§impl<T> TryFrom<Wkt<T>> for Triangle<T>where
T: CoordNum,
Fallibly convert this WKT primitive into this geo_types primitive
impl<T> TryFrom<Wkt<T>> for Triangle<T>where
T: CoordNum,
Fallibly convert this WKT primitive into this geo_types primitive
Source§impl<T> TryFromWkt<T> for Triangle<T>
impl<T> TryFromWkt<T> for Triangle<T>
impl<T> Copy for Triangle<T>
impl<T> Eq for Triangle<T>
impl<T> StructuralPartialEq for Triangle<T>where
T: CoordNum,
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
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
Source§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
Source§fn equivalent(&self, key: &K) -> bool
fn equivalent(&self, key: &K) -> bool
Compare self to
key and return true if they are equal.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<T, G> ToGeoGeometry<T> for Gwhere
T: CoordNum,
G: GeometryTrait<T = T>,
impl<T, G> ToGeoGeometry<T> for Gwhere
T: CoordNum,
G: GeometryTrait<T = T>,
Source§impl<T, G> ToGeoTriangle<T> for Gwhere
T: CoordNum,
G: TriangleTrait<T = T>,
impl<T, G> ToGeoTriangle<T> for Gwhere
T: CoordNum,
G: TriangleTrait<T = T>,
Source§fn to_triangle(&self) -> Triangle<T>
fn to_triangle(&self) -> Triangle<T>
Convert to a geo_types
Triangle.