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