Struct geo::Rect [−][src]
pub struct Rect<T> where
T: CoordNum, { /* fields omitted */ }
An axis-aligned bounded 2D rectangle whose area is
defined by minimum and maximum Coordinate
s.
The constructors and setters ensure the maximum
Coordinate
is greater than or equal to the minimum.
Thus, a Rect
s 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::{Coordinate, Rect}; let rect = Rect::new( Coordinate { x: 0., y: 4.}, Coordinate { x: 3., y: 10.}, ); assert_eq!(3., rect.width()); assert_eq!(6., rect.height()); assert_eq!( Coordinate { x: 1.5, y: 7. }, rect.center() );
Implementations
impl<T> Rect<T> where
T: CoordNum,
[src]
T: CoordNum,
pub fn new<C>(c1: C, c2: C) -> Rect<T> where
C: Into<Coordinate<T>>,
[src]
C: Into<Coordinate<T>>,
Creates a new rectangle from two corner coordinates.
Examples
use geo_types::{Coordinate, Rect}; let rect = Rect::new( Coordinate { x: 10., y: 20. }, Coordinate { x: 30., y: 10. } ); assert_eq!(rect.min(), Coordinate { x: 10., y: 10. }); assert_eq!(rect.max(), Coordinate { x: 30., y: 20. });
pub fn try_new<C>(c1: C, c2: C) -> Result<Rect<T>, InvalidRectCoordinatesError> where
C: Into<Coordinate<T>>,
[src]
C: Into<Coordinate<T>>,
Use Rect::new
instead, since Rect::try_new
will never Error
pub fn min(self) -> Coordinate<T>
[src]
Returns the minimum Coordinate
of the Rect
.
Examples
use geo_types::{Coordinate, Rect}; let rect = Rect::new( Coordinate { x: 5., y: 5. }, Coordinate { x: 15., y: 15. }, ); assert_eq!(rect.min(), Coordinate { x: 5., y: 5. });
pub fn set_min<C>(&mut self, min: C) where
C: Into<Coordinate<T>>,
[src]
C: Into<Coordinate<T>>,
Set the Rect
’s minimum coordinate.
Panics
Panics if min
’s x/y is greater than the maximum coordinate’s x/y.
pub fn max(self) -> Coordinate<T>
[src]
Returns the maximum Coordinate
of the Rect
.
Examples
use geo_types::{Coordinate, Rect}; let rect = Rect::new( Coordinate { x: 5., y: 5. }, Coordinate { x: 15., y: 15. }, ); assert_eq!(rect.max(), Coordinate { x: 15., y: 15. });
pub fn set_max<C>(&mut self, max: C) where
C: Into<Coordinate<T>>,
[src]
C: Into<Coordinate<T>>,
Set the Rect
’s maximum coordinate.
Panics
Panics if max
’s x/y is less than the minimum coordinate’s x/y.
pub fn width(self) -> T
[src]
Returns the width of the Rect
.
Examples
use geo_types::{Coordinate, Rect}; let rect = Rect::new( Coordinate { x: 5., y: 5. }, Coordinate { x: 15., y: 15. }, ); assert_eq!(rect.width(), 10.);
pub fn height(self) -> T
[src]
Returns the height of the Rect
.
Examples
use geo_types::{Coordinate, Rect}; let rect = Rect::new( Coordinate { x: 5., y: 5. }, Coordinate { x: 15., y: 15. }, ); assert_eq!(rect.height(), 10.);
pub fn to_polygon(self) -> Polygon<T>
[src]
Create a Polygon
from the Rect
.
Examples
use geo_types::{Coordinate, Rect, polygon}; let rect = Rect::new( Coordinate { x: 0., y: 0. }, Coordinate { x: 10., y: 20. }, ); assert_eq!( rect.to_polygon(), polygon![ (x: 0., y: 0.), (x: 0., y: 20.), (x: 10., y: 20.), (x: 10., y: 0.), (x: 0., y: 0.), ], );
impl<T> Rect<T> where
T: CoordFloat,
[src]
T: CoordFloat,
pub fn center(self) -> Coordinate<T>
[src]
Returns the center Coordinate
of the Rect
.
Examples
use geo_types::{Coordinate, Rect}; let rect = Rect::new( Coordinate { x: 5., y: 5. }, Coordinate { x: 15., y: 15. }, ); assert_eq!( rect.center(), Coordinate { x: 10., y: 10. } );
Trait Implementations
impl<T> AbsDiffEq<Rect<T>> for Rect<T> where
T: AbsDiffEq<T, Epsilon = T> + CoordNum,
<T as AbsDiffEq<T>>::Epsilon: Copy,
[src]
T: AbsDiffEq<T, Epsilon = T> + CoordNum,
<T as AbsDiffEq<T>>::Epsilon: Copy,
type Epsilon = T
Used for specifying relative comparisons.
pub fn default_epsilon() -> <Rect<T> as AbsDiffEq<Rect<T>>>::Epsilon
[src]
pub fn abs_diff_eq(
&self,
other: &Rect<T>,
epsilon: <Rect<T> as AbsDiffEq<Rect<T>>>::Epsilon
) -> bool
[src]
&self,
other: &Rect<T>,
epsilon: <Rect<T> as AbsDiffEq<Rect<T>>>::Epsilon
) -> bool
Equality assertion with an absolute limit.
Examples
use geo_types::{point, Rect}; let a = Rect::new((0.0, 0.0), (10.0, 10.0)); let b = Rect::new((0.0, 0.0), (10.01, 10.0)); approx::abs_diff_eq!(a, b, epsilon=0.1); approx::abs_diff_ne!(a, b, epsilon=0.001);
pub fn abs_diff_ne(&self, other: &Rhs, epsilon: Self::Epsilon) -> bool
impl<T> Area<T> for Rect<T> where
T: CoordNum,
[src]
T: CoordNum,
Because a Rect
has no winding order, the area will always be positive.
fn signed_area(&self) -> T
[src]
fn unsigned_area(&self) -> T
[src]
impl<T> BoundingRect<T> for Rect<T> where
T: CoordNum,
[src]
T: CoordNum,
type Output = Rect<T>
fn bounding_rect(&self) -> Self::Output
[src]
impl<T> Centroid for Rect<T> where
T: GeoFloat,
[src]
T: GeoFloat,
impl<T> Clone for Rect<T> where
T: Clone + CoordNum,
[src]
T: Clone + CoordNum,
impl<T> Contains<Coordinate<T>> for Rect<T> where
T: CoordNum,
[src]
T: CoordNum,
fn contains(&self, coord: &Coordinate<T>) -> bool
[src]
impl<T> Contains<Point<T>> for Rect<T> where
T: CoordNum,
[src]
T: CoordNum,
impl<F> Contains<Rect<F>> for MultiPolygon<F> where
F: GeoFloat,
[src]
F: GeoFloat,
impl<T> Contains<Rect<T>> for Rect<T> where
T: CoordNum,
[src]
T: CoordNum,
impl<T> CoordinatePosition for Rect<T> where
T: GeoNum,
[src]
T: GeoNum,
type Scalar = T
fn calculate_coordinate_position(
&self,
coord: &Coordinate<T>,
is_inside: &mut bool,
boundary_count: &mut usize
)
[src]
&self,
coord: &Coordinate<T>,
is_inside: &mut bool,
boundary_count: &mut usize
)
fn coordinate_position(&self, coord: &Coordinate<Self::Scalar>) -> CoordPos
[src]
impl<'a, T: CoordNum + 'a> CoordsIter<'a> for Rect<T>
[src]
type Iter = Chain<Chain<Chain<Once<Coordinate<T>>, Once<Coordinate<T>>>, Once<Coordinate<T>>>, Once<Coordinate<T>>>
type ExteriorIter = Self::Iter
type Scalar = T
fn coords_iter(&'a self) -> Self::Iter
[src]
fn coords_count(&'a self) -> usize
[src]
Return the number of coordinates in the Rect
.
Note: Although a Rect
is represented by two coordinates, it is
spatially represented by four, so this method returns 4
.
fn exterior_coords_iter(&'a self) -> Self::ExteriorIter
[src]
impl<T> Copy for Rect<T> where
T: Copy + CoordNum,
[src]
T: Copy + CoordNum,
impl<T> Debug for Rect<T> where
T: Debug + CoordNum,
[src]
T: Debug + CoordNum,
impl<T> Eq for Rect<T> where
T: Eq + CoordNum,
[src]
T: Eq + CoordNum,
impl<T> From<Rect<T>> for Polygon<T> where
T: CoordNum,
[src]
T: CoordNum,
impl<T> From<Rect<T>> for Geometry<T> where
T: CoordNum,
[src]
T: CoordNum,
impl<C: CoordNum> HasDimensions for Rect<C>
[src]
fn is_empty(&self) -> bool
[src]
fn dimensions(&self) -> Dimensions
[src]
fn boundary_dimensions(&self) -> Dimensions
[src]
impl<T> Hash for Rect<T> where
T: Hash + CoordNum,
[src]
T: Hash + CoordNum,
pub fn hash<__H>(&self, state: &mut __H) where
__H: Hasher,
[src]
__H: Hasher,
pub fn hash_slice<H>(data: &[Self], state: &mut H) where
H: Hasher,
1.3.0[src]
H: Hasher,
impl<T> Intersects<Coordinate<T>> for Rect<T> where
T: CoordNum,
[src]
T: CoordNum,
fn intersects(&self, rhs: &Coordinate<T>) -> bool
[src]
impl<T> Intersects<Geometry<T>> for Rect<T> where
Geometry<T>: Intersects<Rect<T>>,
T: CoordNum,
[src]
Geometry<T>: Intersects<Rect<T>>,
T: CoordNum,
fn intersects(&self, rhs: &Geometry<T>) -> bool
[src]
impl<T> Intersects<GeometryCollection<T>> for Rect<T> where
GeometryCollection<T>: Intersects<Rect<T>>,
T: CoordNum,
[src]
GeometryCollection<T>: Intersects<Rect<T>>,
T: CoordNum,
fn intersects(&self, rhs: &GeometryCollection<T>) -> bool
[src]
impl<T> Intersects<Line<T>> for Rect<T> where
T: GeoNum,
[src]
T: GeoNum,
fn intersects(&self, rhs: &Line<T>) -> bool
[src]
impl<T> Intersects<MultiPoint<T>> for Rect<T> where
MultiPoint<T>: Intersects<Rect<T>>,
T: CoordNum,
[src]
MultiPoint<T>: Intersects<Rect<T>>,
T: CoordNum,
fn intersects(&self, rhs: &MultiPoint<T>) -> bool
[src]
impl<T> Intersects<MultiPolygon<T>> for Rect<T> where
MultiPolygon<T>: Intersects<Rect<T>>,
T: CoordNum,
[src]
MultiPolygon<T>: Intersects<Rect<T>>,
T: CoordNum,
fn intersects(&self, rhs: &MultiPolygon<T>) -> bool
[src]
impl<T> Intersects<Point<T>> for Rect<T> where
Point<T>: Intersects<Rect<T>>,
T: CoordNum,
[src]
Point<T>: Intersects<Rect<T>>,
T: CoordNum,
fn intersects(&self, rhs: &Point<T>) -> bool
[src]
impl<T> Intersects<Polygon<T>> for Rect<T> where
Polygon<T>: Intersects<Rect<T>>,
T: CoordNum,
[src]
Polygon<T>: Intersects<Rect<T>>,
T: CoordNum,
fn intersects(&self, rhs: &Polygon<T>) -> bool
[src]
impl<T> Intersects<Rect<T>> for Polygon<T> where
T: GeoNum,
[src]
T: GeoNum,
fn intersects(&self, rect: &Rect<T>) -> bool
[src]
impl<T> Intersects<Rect<T>> for Coordinate<T> where
Rect<T>: Intersects<Coordinate<T>>,
T: CoordNum,
[src]
Rect<T>: Intersects<Coordinate<T>>,
T: CoordNum,
fn intersects(&self, rhs: &Rect<T>) -> bool
[src]
impl<T> Intersects<Rect<T>> for Rect<T> where
T: CoordNum,
[src]
T: CoordNum,
fn intersects(&self, other: &Rect<T>) -> bool
[src]
impl<T> Intersects<Rect<T>> for Line<T> where
Rect<T>: Intersects<Line<T>>,
T: CoordNum,
[src]
Rect<T>: Intersects<Line<T>>,
T: CoordNum,
fn intersects(&self, rhs: &Rect<T>) -> bool
[src]
impl<T> Intersects<Triangle<T>> for Rect<T> where
Triangle<T>: Intersects<Rect<T>>,
T: CoordNum,
[src]
Triangle<T>: Intersects<Rect<T>>,
T: CoordNum,
fn intersects(&self, rhs: &Triangle<T>) -> bool
[src]
impl<T: CoordNum, NT: CoordNum> MapCoords<T, NT> for Rect<T>
[src]
type Output = Rect<NT>
fn map_coords(&self, func: impl Fn(&(T, T)) -> (NT, NT) + Copy) -> Self::Output
[src]
impl<T: CoordNum> MapCoordsInplace<T> for Rect<T>
[src]
impl<T> PartialEq<Rect<T>> for Rect<T> where
T: PartialEq<T> + CoordNum,
[src]
T: PartialEq<T> + CoordNum,
impl<F: GeoFloat> Relate<F, GeometryCollection<F>> for Rect<F>
[src]
fn relate(&self, other: &GeometryCollection<F>) -> IntersectionMatrix
[src]
impl<F: GeoFloat> Relate<F, Line<F>> for Rect<F>
[src]
fn relate(&self, other: &Line<F>) -> IntersectionMatrix
[src]
impl<F: GeoFloat> Relate<F, LineString<F>> for Rect<F>
[src]
fn relate(&self, other: &LineString<F>) -> IntersectionMatrix
[src]
impl<F: GeoFloat> Relate<F, MultiLineString<F>> for Rect<F>
[src]
fn relate(&self, other: &MultiLineString<F>) -> IntersectionMatrix
[src]
impl<F: GeoFloat> Relate<F, MultiPoint<F>> for Rect<F>
[src]
fn relate(&self, other: &MultiPoint<F>) -> IntersectionMatrix
[src]
impl<F: GeoFloat> Relate<F, MultiPolygon<F>> for Rect<F>
[src]
fn relate(&self, other: &MultiPolygon<F>) -> IntersectionMatrix
[src]
impl<F: GeoFloat> Relate<F, Point<F>> for Rect<F>
[src]
fn relate(&self, other: &Point<F>) -> IntersectionMatrix
[src]
impl<F: GeoFloat> Relate<F, Polygon<F>> for Rect<F>
[src]
fn relate(&self, other: &Polygon<F>) -> IntersectionMatrix
[src]
impl<F: GeoFloat> Relate<F, Rect<F>> for Point<F>
[src]
fn relate(&self, other: &Rect<F>) -> IntersectionMatrix
[src]
impl<F: GeoFloat> Relate<F, Rect<F>> for Line<F>
[src]
fn relate(&self, other: &Rect<F>) -> IntersectionMatrix
[src]
impl<F: GeoFloat> Relate<F, Rect<F>> for LineString<F>
[src]
fn relate(&self, other: &Rect<F>) -> IntersectionMatrix
[src]
impl<F: GeoFloat> Relate<F, Rect<F>> for Polygon<F>
[src]
fn relate(&self, other: &Rect<F>) -> IntersectionMatrix
[src]
impl<F: GeoFloat> Relate<F, Rect<F>> for MultiPoint<F>
[src]
fn relate(&self, other: &Rect<F>) -> IntersectionMatrix
[src]
impl<F: GeoFloat> Relate<F, Rect<F>> for MultiLineString<F>
[src]
fn relate(&self, other: &Rect<F>) -> IntersectionMatrix
[src]
impl<F: GeoFloat> Relate<F, Rect<F>> for MultiPolygon<F>
[src]
fn relate(&self, other: &Rect<F>) -> IntersectionMatrix
[src]
impl<F: GeoFloat> Relate<F, Rect<F>> for Rect<F>
[src]
fn relate(&self, other: &Rect<F>) -> IntersectionMatrix
[src]
impl<F: GeoFloat> Relate<F, Rect<F>> for Triangle<F>
[src]
fn relate(&self, other: &Rect<F>) -> IntersectionMatrix
[src]
impl<F: GeoFloat> Relate<F, Rect<F>> for GeometryCollection<F>
[src]
fn relate(&self, other: &Rect<F>) -> IntersectionMatrix
[src]
impl<F: GeoFloat> Relate<F, Triangle<F>> for Rect<F>
[src]
fn relate(&self, other: &Triangle<F>) -> IntersectionMatrix
[src]
impl<T> RelativeEq<Rect<T>> for Rect<T> where
T: AbsDiffEq<T, Epsilon = T> + CoordNum + RelativeEq<T>,
[src]
T: AbsDiffEq<T, Epsilon = T> + CoordNum + RelativeEq<T>,
pub fn default_max_relative() -> <Rect<T> as AbsDiffEq<Rect<T>>>::Epsilon
[src]
pub fn relative_eq(
&self,
other: &Rect<T>,
epsilon: <Rect<T> as AbsDiffEq<Rect<T>>>::Epsilon,
max_relative: <Rect<T> as AbsDiffEq<Rect<T>>>::Epsilon
) -> bool
[src]
&self,
other: &Rect<T>,
epsilon: <Rect<T> as AbsDiffEq<Rect<T>>>::Epsilon,
max_relative: <Rect<T> as AbsDiffEq<Rect<T>>>::Epsilon
) -> bool
Equality assertion within a relative limit.
Examples
use geo_types::Rect; let a = Rect::new((0.0, 0.0), (10.0, 10.0)); let b = Rect::new((0.0, 0.0), (10.01, 10.0)); approx::assert_relative_eq!(a, b, max_relative=0.1); approx::assert_relative_ne!(a, b, max_relative=0.0001);
pub fn relative_ne(
&self,
other: &Rhs,
epsilon: Self::Epsilon,
max_relative: Self::Epsilon
) -> bool
&self,
other: &Rhs,
epsilon: Self::Epsilon,
max_relative: Self::Epsilon
) -> bool
impl<T> StructuralEq for Rect<T> where
T: CoordNum,
[src]
T: CoordNum,
impl<T> StructuralPartialEq for Rect<T> where
T: CoordNum,
[src]
T: CoordNum,
impl<T> TryFrom<Geometry<T>> for Rect<T> where
T: CoordNum,
[src]
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.
type Error = Error
The type returned in the event of a conversion error.
pub fn try_from(
geom: Geometry<T>
) -> Result<Rect<T>, <Rect<T> as TryFrom<Geometry<T>>>::Error>
[src]
geom: Geometry<T>
) -> Result<Rect<T>, <Rect<T> as TryFrom<Geometry<T>>>::Error>
impl<T: CoordNum, NT: CoordNum> TryMapCoords<T, NT> for Rect<T>
[src]
Auto Trait Implementations
impl<T> RefUnwindSafe for Rect<T> where
T: RefUnwindSafe,
T: RefUnwindSafe,
impl<T> Send for Rect<T> where
T: Send,
T: Send,
impl<T> Sync for Rect<T> where
T: Sync,
T: Sync,
impl<T> Unpin for Rect<T> where
T: Unpin,
T: Unpin,
impl<T> UnwindSafe for Rect<T> where
T: UnwindSafe,
T: UnwindSafe,
Blanket Implementations
impl<T> Any for T where
T: 'static + ?Sized,
[src]
T: 'static + ?Sized,
impl<T> Borrow<T> for T where
T: ?Sized,
[src]
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
[src]
T: ?Sized,
pub fn borrow_mut(&mut self) -> &mut T
[src]
impl<'a, T, G> Extremes<'a, T> for G where
T: CoordNum,
G: CoordsIter<'a, Scalar = T>,
[src]
T: CoordNum,
G: CoordsIter<'a, Scalar = T>,
impl<T> From<T> for T
[src]
impl<T, U> Into<U> for T where
U: From<T>,
[src]
U: From<T>,
impl<T, G> RotatePoint<T> for G where
T: CoordFloat,
G: MapCoords<T, T, Output = G>,
[src]
T: CoordFloat,
G: MapCoords<T, T, Output = G>,
pub fn rotate_around_point(&Self, T, Point<T>) -> G
[src]
impl<T> Same<T> for T
type Output = T
Should always be Self
impl<T> ToOwned for T where
T: Clone,
[src]
T: Clone,
type Owned = T
The resulting type after obtaining ownership.
pub fn to_owned(&self) -> T
[src]
pub fn clone_into(&self, target: &mut T)
[src]
impl<T, G> Translate<T> for G where
T: CoordNum,
G: MapCoords<T, T, Output = G> + MapCoordsInplace<T>,
[src]
T: CoordNum,
G: MapCoords<T, T, Output = G> + MapCoordsInplace<T>,
impl<T, U> TryFrom<U> for T where
U: Into<T>,
[src]
U: Into<T>,
type Error = Infallible
The type returned in the event of a conversion error.
pub fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>
[src]
impl<T, U> TryInto<U> for T where
U: TryFrom<T>,
[src]
U: TryFrom<T>,