Struct geo::Rect [−][src]
pub struct Rect<T> where
T: CoordNum, { /* fields omitted */ }
Expand description
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
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>>,
Use Rect::new
instead, since Rect::try_new
will never Error
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. });
Set the Rect
’s minimum coordinate.
Panics
Panics if min
’s x/y is greater than the maximum coordinate’s x/y.
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. });
Set the Rect
’s maximum coordinate.
Panics
Panics if max
’s x/y is less than the minimum coordinate’s x/y.
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.);
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.);
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.),
],
);
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
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);
type Epsilon = T
type Epsilon = T
Used for specifying relative comparisons.
The default tolerance to use when testing values that are close together. Read more
The inverse of AbsDiffEq::abs_diff_eq
.
Because a Rect
has no winding order, the area will always be positive.
type Scalar = T
fn calculate_coordinate_position(
&self,
coord: &Coordinate<T>,
is_inside: &mut bool,
boundary_count: &mut usize
)
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
.
type Iter = Chain<Chain<Chain<Once<Coordinate<T>>, Once<Coordinate<T>>>, Once<Coordinate<T>>>, Once<Coordinate<T>>>
type ExteriorIter = Self::Iter
type Scalar = T
Iterate over all exterior and (if any) interior coordinates of a geometry. Read more
Iterate over all exterior coordinates of a geometry. Read more
Some geometries, like a MultiPoint
, can have zero coordinates - we call these empty
. Read more
The dimensions of some geometries are fixed, e.g. a Point always has 0 dimensions. However
for others, the dimensionality depends on the specific geometry instance - for example
typical Rect
s are 2-dimensional, but it’s possible to create degenerate Rect
s which
have either 1 or 0 dimensions. Read more
The dimensions of the Geometry
’s boundary, as used by OGC-SFA. Read more
impl<T> Intersects<Geometry<T>> for Rect<T> where
Geometry<T>: Intersects<Rect<T>>,
T: CoordNum,
impl<T> Intersects<Geometry<T>> for Rect<T> where
Geometry<T>: Intersects<Rect<T>>,
T: CoordNum,
impl<T> Intersects<GeometryCollection<T>> for Rect<T> where
GeometryCollection<T>: Intersects<Rect<T>>,
T: CoordNum,
impl<T> Intersects<GeometryCollection<T>> for Rect<T> where
GeometryCollection<T>: Intersects<Rect<T>>,
T: CoordNum,
impl<T> Intersects<MultiPoint<T>> for Rect<T> where
MultiPoint<T>: Intersects<Rect<T>>,
T: CoordNum,
impl<T> Intersects<MultiPoint<T>> for Rect<T> where
MultiPoint<T>: Intersects<Rect<T>>,
T: CoordNum,
impl<T> Intersects<MultiPolygon<T>> for Rect<T> where
MultiPolygon<T>: Intersects<Rect<T>>,
T: CoordNum,
impl<T> Intersects<MultiPolygon<T>> for Rect<T> where
MultiPolygon<T>: Intersects<Rect<T>>,
T: CoordNum,
impl<T> Intersects<Rect<T>> for Coordinate<T> where
Rect<T>: Intersects<Coordinate<T>>,
T: CoordNum,
impl<T> Intersects<Rect<T>> for Coordinate<T> where
Rect<T>: Intersects<Coordinate<T>>,
T: CoordNum,
impl<T> Intersects<Triangle<T>> for Rect<T> where
Triangle<T>: Intersects<Rect<T>>,
T: CoordNum,
impl<T> Intersects<Triangle<T>> for Rect<T> where
Triangle<T>: Intersects<Rect<T>>,
T: CoordNum,
impl<T> RelativeEq<Rect<T>> for Rect<T> where
T: AbsDiffEq<T, Epsilon = T> + CoordNum + RelativeEq<T>,
impl<T> RelativeEq<Rect<T>> for Rect<T> where
T: AbsDiffEq<T, Epsilon = T> + CoordNum + RelativeEq<T>,
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);
The default relative tolerance for testing values that are far-apart. Read more
The inverse of RelativeEq::relative_eq
.
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.
Auto Trait Implementations
impl<T> RefUnwindSafe for Rect<T> where
T: RefUnwindSafe,
impl<T> UnwindSafe for Rect<T> where
T: UnwindSafe,
Blanket Implementations
Mutably borrows from an owned value. Read more
Rotate a Geometry around an arbitrary point by an angle, given in degrees Read more