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 Coordinates.

The constructors and setters ensure the maximum Coordinate 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::{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]

pub fn new<C>(c1: C, c2: C) -> Rect<T> where
    C: Into<Coordinate<T>>, 
[src]

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]

👎 Deprecated since 0.6.2:

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]

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]

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]

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]

type Epsilon = T

Used for specifying relative comparisons.

pub fn abs_diff_eq(
    &self,
    other: &Rect<T>,
    epsilon: <Rect<T> as AbsDiffEq<Rect<T>>>::Epsilon
) -> bool
[src]

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);

impl<T> Area<T> for Rect<T> where
    T: CoordNum
[src]

Because a Rect has no winding order, the area will always be positive.

impl<T> BoundingRect<T> for Rect<T> where
    T: CoordNum
[src]

type Output = Rect<T>

impl<T> Centroid for Rect<T> where
    T: GeoFloat
[src]

type Output = Point<T>

impl<T> Clone for Rect<T> where
    T: Clone + CoordNum
[src]

impl<T> Contains<Coordinate<T>> for Rect<T> where
    T: CoordNum
[src]

impl<T> Contains<Point<T>> for Rect<T> where
    T: CoordNum
[src]

impl<F> Contains<Rect<F>> for MultiPolygon<F> where
    F: GeoFloat
[src]

impl<T> Contains<Rect<T>> for Rect<T> where
    T: CoordNum
[src]

impl<T> CoordinatePosition for Rect<T> where
    T: GeoNum
[src]

type Scalar = T

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_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.

impl<T> Copy for Rect<T> where
    T: Copy + CoordNum
[src]

impl<T> Debug for Rect<T> where
    T: Debug + CoordNum
[src]

impl<T> Eq for Rect<T> where
    T: Eq + CoordNum
[src]

impl<T> From<Rect<T>> for Polygon<T> where
    T: CoordNum
[src]

impl<T> From<Rect<T>> for Geometry<T> where
    T: CoordNum
[src]

impl<C: CoordNum> HasDimensions for Rect<C>[src]

impl<T> Hash for Rect<T> where
    T: Hash + CoordNum
[src]

impl<T> Intersects<Coordinate<T>> for Rect<T> where
    T: CoordNum
[src]

impl<T> Intersects<Geometry<T>> for Rect<T> where
    Geometry<T>: Intersects<Rect<T>>,
    T: CoordNum
[src]

impl<T> Intersects<GeometryCollection<T>> for Rect<T> where
    GeometryCollection<T>: Intersects<Rect<T>>,
    T: CoordNum
[src]

impl<T> Intersects<Line<T>> for Rect<T> where
    T: GeoNum
[src]

impl<T> Intersects<MultiPoint<T>> for Rect<T> where
    MultiPoint<T>: Intersects<Rect<T>>,
    T: CoordNum
[src]

impl<T> Intersects<MultiPolygon<T>> for Rect<T> where
    MultiPolygon<T>: Intersects<Rect<T>>,
    T: CoordNum
[src]

impl<T> Intersects<Point<T>> for Rect<T> where
    Point<T>: Intersects<Rect<T>>,
    T: CoordNum
[src]

impl<T> Intersects<Polygon<T>> for Rect<T> where
    Polygon<T>: Intersects<Rect<T>>,
    T: CoordNum
[src]

impl<T> Intersects<Rect<T>> for Polygon<T> where
    T: GeoNum
[src]

impl<T> Intersects<Rect<T>> for Coordinate<T> where
    Rect<T>: Intersects<Coordinate<T>>,
    T: CoordNum
[src]

impl<T> Intersects<Rect<T>> for Rect<T> where
    T: CoordNum
[src]

impl<T> Intersects<Rect<T>> for Line<T> where
    Rect<T>: Intersects<Line<T>>,
    T: CoordNum
[src]

impl<T> Intersects<Triangle<T>> for Rect<T> where
    Triangle<T>: Intersects<Rect<T>>,
    T: CoordNum
[src]

impl<T: CoordNum, NT: CoordNum> MapCoords<T, NT> for Rect<T>[src]

type Output = Rect<NT>

impl<T: CoordNum> MapCoordsInplace<T> for Rect<T>[src]

impl<T> PartialEq<Rect<T>> for Rect<T> where
    T: PartialEq<T> + CoordNum
[src]

impl<F: GeoFloat> Relate<F, GeometryCollection<F>> for Rect<F>[src]

impl<F: GeoFloat> Relate<F, Line<F>> for Rect<F>[src]

impl<F: GeoFloat> Relate<F, LineString<F>> for Rect<F>[src]

impl<F: GeoFloat> Relate<F, MultiLineString<F>> for Rect<F>[src]

impl<F: GeoFloat> Relate<F, MultiPoint<F>> for Rect<F>[src]

impl<F: GeoFloat> Relate<F, MultiPolygon<F>> for Rect<F>[src]

impl<F: GeoFloat> Relate<F, Point<F>> for Rect<F>[src]

impl<F: GeoFloat> Relate<F, Polygon<F>> for Rect<F>[src]

impl<F: GeoFloat> Relate<F, Rect<F>> for Point<F>[src]

impl<F: GeoFloat> Relate<F, Rect<F>> for Line<F>[src]

impl<F: GeoFloat> Relate<F, Rect<F>> for LineString<F>[src]

impl<F: GeoFloat> Relate<F, Rect<F>> for Polygon<F>[src]

impl<F: GeoFloat> Relate<F, Rect<F>> for MultiPoint<F>[src]

impl<F: GeoFloat> Relate<F, Rect<F>> for MultiLineString<F>[src]

impl<F: GeoFloat> Relate<F, Rect<F>> for MultiPolygon<F>[src]

impl<F: GeoFloat> Relate<F, Rect<F>> for Rect<F>[src]

impl<F: GeoFloat> Relate<F, Rect<F>> for Triangle<F>[src]

impl<F: GeoFloat> Relate<F, Rect<F>> for GeometryCollection<F>[src]

impl<F: GeoFloat> Relate<F, Triangle<F>> for Rect<F>[src]

impl<T> RelativeEq<Rect<T>> for Rect<T> where
    T: AbsDiffEq<T, Epsilon = T> + CoordNum + RelativeEq<T>, 
[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]

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);

impl<T> StructuralEq for Rect<T> where
    T: CoordNum
[src]

impl<T> StructuralPartialEq for Rect<T> where
    T: CoordNum
[src]

impl<T> TryFrom<Geometry<T>> for Rect<T> where
    T: CoordNum
[src]

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.

impl<T: CoordNum, NT: CoordNum> TryMapCoords<T, NT> for Rect<T>[src]

type Output = Rect<NT>

Auto Trait Implementations

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

impl<T> Any for T where
    T: 'static + ?Sized
[src]

impl<T> Borrow<T> for T where
    T: ?Sized
[src]

impl<T> BorrowMut<T> for T where
    T: ?Sized
[src]

impl<'a, T, G> Extremes<'a, T> for G where
    T: CoordNum,
    G: CoordsIter<'a, Scalar = T>, 
[src]

impl<T> From<T> for T[src]

impl<T, U> Into<U> for T where
    U: From<T>, 
[src]

impl<T, G> RotatePoint<T> for G where
    T: CoordFloat,
    G: MapCoords<T, T, Output = G>, 
[src]

impl<T> Same<T> for T

type Output = T

Should always be Self

impl<T> ToOwned for T where
    T: Clone
[src]

type Owned = T

The resulting type after obtaining ownership.

impl<T, G> Translate<T> for G where
    T: CoordNum,
    G: MapCoords<T, T, Output = G> + MapCoordsInplace<T>, 
[src]

impl<T, U> TryFrom<U> for T where
    U: Into<T>, 
[src]

type Error = Infallible

The type returned in the event of a conversion error.

impl<T, U> TryInto<U> for T where
    U: TryFrom<T>, 
[src]

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.