pub struct Rect<T = f64>where
T: CoordNum,{ /* private fields */ }geo-types only.Expand description
An axis-aligned bounded 2D rectangle whose area is
defined by minimum and maximum Coords.
The constructors and setters ensure the maximum
Coord is greater than or equal to the minimum.
Thus, a Rects width, height, and area is guaranteed to
be greater than or equal to zero.
Note. While Rect implements MapCoords and
RotatePoint algorithmic traits, the usage is expected
to maintain the axis alignment. In particular, only
rotation by integer multiples of 90 degrees, will
preserve the original shape. In other cases, the min,
and max points are rotated or transformed, and a new
rectangle is created (with coordinate swaps to ensure
min < max).
§Examples
use geo_types::{coord, Rect};
let rect = Rect::new(
coord! { x: 0., y: 4.},
coord! { x: 3., y: 10.},
);
assert_eq!(3., rect.width());
assert_eq!(6., rect.height());
assert_eq!(
coord! { x: 1.5, y: 7. },
rect.center()
);Implementations§
Source§impl<T> Rect<T>where
T: CoordNum,
impl<T> Rect<T>where
T: CoordNum,
Sourcepub fn new<C>(c1: C, c2: C) -> Rect<T>
pub fn new<C>(c1: C, c2: C) -> Rect<T>
Creates a new rectangle from two corner coordinates.
Coords are stored and returned (by iterators) in CCW order
§Examples
use geo_types::{coord, Rect};
let rect = Rect::new(
coord! { x: 10., y: 20. },
coord! { x: 30., y: 10. }
);
assert_eq!(rect.min(), coord! { x: 10., y: 10. });
assert_eq!(rect.max(), coord! { x: 30., y: 20. });pub fn try_new<C>(c1: C, c2: C) -> Result<Rect<T>, InvalidRectCoordinatesError>
Rect::new instead, since Rect::try_new will never ErrorSourcepub fn min(self) -> Coord<T>
pub fn min(self) -> Coord<T>
Returns the minimum Coord of the Rect.
§Examples
use geo_types::{coord, Rect};
let rect = Rect::new(
coord! { x: 5., y: 5. },
coord! { x: 15., y: 15. },
);
assert_eq!(rect.min(), coord! { x: 5., y: 5. });Sourcepub fn set_min<C>(&mut self, min: C)
pub fn set_min<C>(&mut self, min: C)
Set the Rect’s minimum coordinate.
§Panics
Panics if min’s x/y is greater than the maximum coordinate’s x/y.
Sourcepub fn max(self) -> Coord<T>
pub fn max(self) -> Coord<T>
Returns the maximum Coord of the Rect.
§Examples
use geo_types::{coord, Rect};
let rect = Rect::new(
coord! { x: 5., y: 5. },
coord! { x: 15., y: 15. },
);
assert_eq!(rect.max(), coord! { x: 15., y: 15. });Sourcepub fn set_max<C>(&mut self, max: C)
pub fn set_max<C>(&mut self, max: C)
Set the Rect’s maximum coordinate.
§Panics
Panics if max’s x/y is less than the minimum coordinate’s x/y.
Sourcepub fn width(self) -> T
pub fn width(self) -> T
Returns the width of the Rect.
§Examples
use geo_types::{coord, Rect};
let rect = Rect::new(
coord! { x: 5., y: 5. },
coord! { x: 15., y: 15. },
);
assert_eq!(rect.width(), 10.);Sourcepub fn height(self) -> T
pub fn height(self) -> T
Returns the height of the Rect.
§Examples
use geo_types::{coord, Rect};
let rect = Rect::new(
coord! { x: 5., y: 5. },
coord! { x: 15., y: 15. },
);
assert_eq!(rect.height(), 10.);Sourcepub fn to_polygon(self) -> Polygon<T>
pub fn to_polygon(self) -> Polygon<T>
Create a Polygon from the Rect.
§Examples
use geo_types::{coord, Rect, polygon};
let rect = Rect::new(
coord! { x: 0., y: 0. },
coord! { x: 1., y: 2. },
);
// Output is CCW
assert_eq!(
rect.to_polygon(),
polygon![
(x: 1., y: 0.),
(x: 1., y: 2.),
(x: 0., y: 2.),
(x: 0., y: 0.),
(x: 1., y: 0.),
],
);pub fn to_lines(&self) -> [Line<T>; 4]
Sourcepub fn split_x(self) -> [Rect<T>; 2]
pub fn split_x(self) -> [Rect<T>; 2]
Split a rectangle into two rectangles along the X-axis with equal widths.
§Examples
let rect = geo_types::Rect::new(
geo_types::coord! { x: 0., y: 0. },
geo_types::coord! { x: 4., y: 4. },
);
let [rect1, rect2] = rect.split_x();
assert_eq!(
geo_types::Rect::new(
geo_types::coord! { x: 0., y: 0. },
geo_types::coord! { x: 2., y: 4. },
),
rect1,
);
assert_eq!(
geo_types::Rect::new(
geo_types::coord! { x: 2., y: 0. },
geo_types::coord! { x: 4., y: 4. },
),
rect2,
);Sourcepub fn split_y(self) -> [Rect<T>; 2]
pub fn split_y(self) -> [Rect<T>; 2]
Split a rectangle into two rectangles along the Y-axis with equal heights.
§Examples
let rect = geo_types::Rect::new(
geo_types::coord! { x: 0., y: 0. },
geo_types::coord! { x: 4., y: 4. },
);
let [rect1, rect2] = rect.split_y();
assert_eq!(
geo_types::Rect::new(
geo_types::coord! { x: 0., y: 0. },
geo_types::coord! { x: 4., y: 2. },
),
rect1,
);
assert_eq!(
geo_types::Rect::new(
geo_types::coord! { x: 0., y: 2. },
geo_types::coord! { x: 4., y: 4. },
),
rect2,
);Trait Implementations§
Source§impl<'a, T> GeometryTrait for &'a Rect<T>where
T: CoordNum + 'a,
impl<'a, T> GeometryTrait for &'a Rect<T>where
T: CoordNum + 'a,
Source§type PointType<'b> = Point<<&'a Rect<T> as GeometryTrait>::T>
where
&'a Rect<T>: 'b
type PointType<'b> = Point<<&'a Rect<T> as GeometryTrait>::T> where &'a Rect<T>: 'b
Source§type LineStringType<'b> = LineString<<&'a Rect<T> as GeometryTrait>::T>
where
&'a Rect<T>: 'b
type LineStringType<'b> = LineString<<&'a Rect<T> as GeometryTrait>::T> where &'a Rect<T>: 'b
Source§type PolygonType<'b> = Polygon<<&'a Rect<T> as GeometryTrait>::T>
where
&'a Rect<T>: 'b
type PolygonType<'b> = Polygon<<&'a Rect<T> as GeometryTrait>::T> where &'a Rect<T>: 'b
Source§type MultiPointType<'b> = MultiPoint<<&'a Rect<T> as GeometryTrait>::T>
where
&'a Rect<T>: 'b
type MultiPointType<'b> = MultiPoint<<&'a Rect<T> as GeometryTrait>::T> where &'a Rect<T>: 'b
Source§type MultiLineStringType<'b> = MultiLineString<<&'a Rect<T> as GeometryTrait>::T>
where
&'a Rect<T>: 'b
type MultiLineStringType<'b> = MultiLineString<<&'a Rect<T> as GeometryTrait>::T> where &'a Rect<T>: 'b
Source§type MultiPolygonType<'b> = MultiPolygon<<&'a Rect<T> as GeometryTrait>::T>
where
&'a Rect<T>: 'b
type MultiPolygonType<'b> = MultiPolygon<<&'a Rect<T> as GeometryTrait>::T> where &'a Rect<T>: 'b
Source§type GeometryCollectionType<'b> = GeometryCollection<<&'a Rect<T> as GeometryTrait>::T>
where
&'a Rect<T>: 'b
type GeometryCollectionType<'b> = GeometryCollection<<&'a Rect<T> as GeometryTrait>::T> where &'a Rect<T>: 'b
Source§type RectType<'b> = Rect<<&'a Rect<T> as GeometryTrait>::T>
where
&'a Rect<T>: 'b
type RectType<'b> = Rect<<&'a Rect<T> as GeometryTrait>::T> where &'a Rect<T>: 'b
Source§type TriangleType<'b> = Triangle<<&'a Rect<T> as GeometryTrait>::T>
where
&'a Rect<T>: 'b
type TriangleType<'b> = Triangle<<&'a Rect<T> as GeometryTrait>::T> where &'a Rect<T>: 'b
Source§type LineType<'b> = Line<<&'a Rect<T> as GeometryTrait>::T>
where
&'a Rect<T>: 'b
type LineType<'b> = Line<<&'a Rect<T> as GeometryTrait>::T> where &'a Rect<T>: 'b
Source§fn dim(&self) -> Dimensions
fn dim(&self) -> Dimensions
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>>
GeometryType enum, which allows for downcasting to a specific
typeSource§impl<T> GeometryTrait for Rect<T>where
T: CoordNum,
impl<T> GeometryTrait for Rect<T>where
T: CoordNum,
Source§type PointType<'b> = Point<<Rect<T> as GeometryTrait>::T>
where
Rect<T>: 'b
type PointType<'b> = Point<<Rect<T> as GeometryTrait>::T> where Rect<T>: 'b
Source§type LineStringType<'b> = LineString<<Rect<T> as GeometryTrait>::T>
where
Rect<T>: 'b
type LineStringType<'b> = LineString<<Rect<T> as GeometryTrait>::T> where Rect<T>: 'b
Source§type PolygonType<'b> = Polygon<<Rect<T> as GeometryTrait>::T>
where
Rect<T>: 'b
type PolygonType<'b> = Polygon<<Rect<T> as GeometryTrait>::T> where Rect<T>: 'b
Source§type MultiPointType<'b> = MultiPoint<<Rect<T> as GeometryTrait>::T>
where
Rect<T>: 'b
type MultiPointType<'b> = MultiPoint<<Rect<T> as GeometryTrait>::T> where Rect<T>: 'b
Source§type MultiLineStringType<'b> = MultiLineString<<Rect<T> as GeometryTrait>::T>
where
Rect<T>: 'b
type MultiLineStringType<'b> = MultiLineString<<Rect<T> as GeometryTrait>::T> where Rect<T>: 'b
Source§type MultiPolygonType<'b> = MultiPolygon<<Rect<T> as GeometryTrait>::T>
where
Rect<T>: 'b
type MultiPolygonType<'b> = MultiPolygon<<Rect<T> as GeometryTrait>::T> where Rect<T>: 'b
Source§type GeometryCollectionType<'b> = GeometryCollection<<Rect<T> as GeometryTrait>::T>
where
Rect<T>: 'b
type GeometryCollectionType<'b> = GeometryCollection<<Rect<T> as GeometryTrait>::T> where Rect<T>: 'b
Source§type RectType<'b> = Rect<<Rect<T> as GeometryTrait>::T>
where
Rect<T>: 'b
type RectType<'b> = Rect<<Rect<T> as GeometryTrait>::T> where Rect<T>: 'b
Source§type TriangleType<'b> = Triangle<<Rect<T> as GeometryTrait>::T>
where
Rect<T>: 'b
type TriangleType<'b> = Triangle<<Rect<T> as GeometryTrait>::T> where Rect<T>: 'b
Source§type LineType<'b> = Line<<Rect<T> as GeometryTrait>::T>
where
Rect<T>: 'b
type LineType<'b> = Line<<Rect<T> as GeometryTrait>::T> where Rect<T>: 'b
Source§fn dim(&self) -> Dimensions
fn dim(&self) -> Dimensions
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>>
GeometryType enum, which allows for downcasting to a specific
typeSource§impl<'a, T> RectTrait for &'a Rect<T>where
T: CoordNum + 'a,
impl<'a, T> RectTrait for &'a Rect<T>where
T: CoordNum + 'a,
Source§impl<T> RectTrait for Rect<T>where
T: CoordNum,
impl<T> RectTrait for Rect<T>where
T: CoordNum,
Source§impl<T> ToWkt<T> for Rect<T>
§Examples
use geo_types::{coord, Rect};
use wkt::ToWkt;
let rect: Rect<f64> = Rect::new(coord!(x: 4., y: 4.), coord!(x: 8., y: 8.));
assert_eq!(rect.wkt_string(), "POLYGON((8 4,8 8,4 8,4 4,8 4))");
impl<T> ToWkt<T> for Rect<T>
§Examples
use geo_types::{coord, Rect};
use wkt::ToWkt;
let rect: Rect<f64> = Rect::new(coord!(x: 4., y: 4.), coord!(x: 8., y: 8.));
assert_eq!(rect.wkt_string(), "POLYGON((8 4,8 8,4 8,4 4,8 4))");Source§impl<T> TryFrom<Geometry<T>> for Rect<T>where
T: CoordNum,
Convert a Geometry enum into its inner type.
impl<T> TryFrom<Geometry<T>> for Rect<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 Rect<T>where
T: CoordNum,
Fallibly convert this WKT primitive into this geo_types primitive
impl<T> TryFrom<Wkt<T>> for Rect<T>where
T: CoordNum,
Fallibly convert this WKT primitive into this geo_types primitive
Source§impl<T> TryFromWkt<T> for Rect<T>
impl<T> TryFromWkt<T> for Rect<T>
impl<T> Copy for Rect<T>
impl<T> Eq for Rect<T>
impl<T> StructuralPartialEq for Rect<T>where
T: CoordNum,
Auto Trait Implementations§
impl<T> Freeze for Rect<T>where
T: Freeze,
impl<T> RefUnwindSafe for Rect<T>where
T: RefUnwindSafe,
impl<T> Send for Rect<T>where
T: Send,
impl<T> Sync for Rect<T>where
T: Sync,
impl<T> Unpin for Rect<T>where
T: Unpin,
impl<T> UnwindSafe for Rect<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
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
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> ⓘ
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> ⓘ
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 more