[−][src]Struct euclid::Rect
A 2d Rectangle optionally tagged with a unit.
Fields
origin: Point2D<T, U>
size: Size2D<T, U>
Implementations
impl<T, U> Rect<T, U>
[src]
impl<T, U> Rect<T, U> where
T: Zero,
[src]
T: Zero,
pub fn zero() -> Self
[src]
Constructor, setting all sides to zero.
pub fn from_size(size: Size2D<T, U>) -> Self
[src]
Creates a rect of the given size, at offset zero.
impl<T, U> Rect<T, U> where
T: Copy + Add<T, Output = T>,
[src]
T: Copy + Add<T, Output = T>,
pub fn min(&self) -> Point2D<T, U>
[src]
pub fn max(&self) -> Point2D<T, U>
[src]
pub fn max_x(&self) -> T
[src]
pub fn min_x(&self) -> T
[src]
pub fn max_y(&self) -> T
[src]
pub fn min_y(&self) -> T
[src]
pub fn width(&self) -> T
[src]
pub fn height(&self) -> T
[src]
pub fn x_range(&self) -> Range<T>
[src]
pub fn y_range(&self) -> Range<T>
[src]
#[must_use]pub fn translate(&self, by: Vector2D<T, U>) -> Self
[src]
Returns the same rectangle, translated by a vector.
pub fn to_box2d(&self) -> Box2D<T, U>
[src]
impl<T, U> Rect<T, U> where
T: Copy + PartialOrd + Add<T, Output = T>,
[src]
T: Copy + PartialOrd + Add<T, Output = T>,
pub fn contains(&self, p: Point2D<T, U>) -> bool
[src]
Returns true if this rectangle contains the point. Points are considered in the rectangle if they are on the left or top edge, but outside if they are on the right or bottom edge.
pub fn intersects(&self, other: &Self) -> bool
[src]
impl<T, U> Rect<T, U> where
T: Copy + PartialOrd + Add<T, Output = T> + Sub<T, Output = T>,
[src]
T: Copy + PartialOrd + Add<T, Output = T> + Sub<T, Output = T>,
pub fn intersection(&self, other: &Self) -> Option<Self>
[src]
impl<T, U> Rect<T, U> where
T: Copy + Add<T, Output = T> + Sub<T, Output = T>,
[src]
T: Copy + Add<T, Output = T> + Sub<T, Output = T>,
impl<T, U> Rect<T, U> where
T: Copy + Zero + PartialOrd + Add<T, Output = T>,
[src]
T: Copy + Zero + PartialOrd + Add<T, Output = T>,
pub fn contains_rect(&self, rect: &Self) -> bool
[src]
Returns true if this rectangle contains the interior of rect. Always returns true if rect is empty, and always returns false if rect is nonempty but this rectangle is empty.
impl<T, U> Rect<T, U> where
T: Copy + Zero + PartialOrd + Add<T, Output = T> + Sub<T, Output = T>,
[src]
T: Copy + Zero + PartialOrd + Add<T, Output = T> + Sub<T, Output = T>,
pub fn inner_rect(&self, offsets: SideOffsets2D<T, U>) -> Self
[src]
Calculate the size and position of an inner rectangle.
Subtracts the side offsets from all sides. The horizontal and vertical offsets must not be larger than the original side length. This method assumes y oriented downward.
impl<T, U> Rect<T, U> where
T: Copy + Add<T, Output = T> + Sub<T, Output = T>,
[src]
T: Copy + Add<T, Output = T> + Sub<T, Output = T>,
pub fn outer_rect(&self, offsets: SideOffsets2D<T, U>) -> Self
[src]
Calculate the size and position of an outer rectangle.
Add the offsets to all sides. The expanded rectangle is returned. This method assumes y oriented downward.
impl<T, U> Rect<T, U> where
T: Copy + Zero + PartialOrd + Sub<T, Output = T>,
[src]
T: Copy + Zero + PartialOrd + Sub<T, Output = T>,
pub fn from_points<I>(points: I) -> Self where
I: IntoIterator,
I::Item: Borrow<Point2D<T, U>>,
[src]
I: IntoIterator,
I::Item: Borrow<Point2D<T, U>>,
Returns the smallest rectangle defined by the top/bottom/left/right-most points provided as parameter.
Note: This function has a behavior that can be surprising because
the right-most and bottom-most points are exactly on the edge
of the rectangle while the contains
function is has exclusive
semantic on these edges. This means that the right-most and bottom-most
points provided to from_points
will count as not contained by the rect.
This behavior may change in the future.
impl<T, U> Rect<T, U> where
T: Copy + One + Add<Output = T> + Sub<Output = T> + Mul<Output = T>,
[src]
T: Copy + One + Add<Output = T> + Sub<Output = T> + Mul<Output = T>,
pub fn lerp(&self, other: Self, t: T) -> Self
[src]
Linearly interpolate between this rectangle and another rectangle.
impl<T, U> Rect<T, U> where
T: Copy + One + Add<Output = T> + Div<Output = T>,
[src]
T: Copy + One + Add<Output = T> + Div<Output = T>,
impl<T, U> Rect<T, U> where
T: Copy + PartialOrd + Add<T, Output = T> + Sub<T, Output = T> + Zero,
[src]
T: Copy + PartialOrd + Add<T, Output = T> + Sub<T, Output = T> + Zero,
impl<T, U> Rect<T, U>
[src]
impl<T: Copy + Mul<T, Output = T>, U> Rect<T, U>
[src]
impl<T: Zero + PartialEq, U> Rect<T, U>
[src]
pub fn is_empty(&self) -> bool
[src]
Returns true if the size is zero, regardless of the origin's value.
impl<T: Zero + PartialOrd, U> Rect<T, U>
[src]
pub fn is_empty_or_negative(&self) -> bool
[src]
impl<T: Copy + Zero + PartialOrd, U> Rect<T, U>
[src]
pub fn to_non_empty(&self) -> Option<NonEmpty<Self>>
[src]
impl<T: Copy, U> Rect<T, U>
[src]
pub fn to_untyped(&self) -> Rect<T, UnknownUnit>
[src]
Drop the units, preserving only the numeric value.
pub fn from_untyped(r: &Rect<T, UnknownUnit>) -> Rect<T, U>
[src]
Tag a unitless value with units.
pub fn cast_unit<V>(&self) -> Rect<T, V>
[src]
Cast the unit
impl<T: NumCast + Copy, U> Rect<T, U>
[src]
pub fn cast<NewT: NumCast>(&self) -> Rect<NewT, U>
[src]
Cast from one numeric representation to another, preserving the units.
When casting from floating point to integer coordinates, the decimals are truncated as one would expect from a simple cast, but this behavior does not always make sense geometrically. Consider using round(), round_in or round_out() before casting.
pub fn try_cast<NewT: NumCast>(&self) -> Option<Rect<NewT, U>>
[src]
Fallible cast from one numeric representation to another, preserving the units.
When casting from floating point to integer coordinates, the decimals are truncated as one would expect from a simple cast, but this behavior does not always make sense geometrically. Consider using round(), round_in or round_out() before casting.
pub fn to_f32(&self) -> Rect<f32, U>
[src]
Cast into an f32
rectangle.
pub fn to_f64(&self) -> Rect<f64, U>
[src]
Cast into an f64
rectangle.
pub fn to_usize(&self) -> Rect<usize, U>
[src]
Cast into an usize
rectangle, truncating decimals if any.
When casting from floating point rectangles, it is worth considering whether
to round()
, round_in()
or round_out()
before the cast in order to
obtain the desired conversion behavior.
pub fn to_u32(&self) -> Rect<u32, U>
[src]
Cast into an u32
rectangle, truncating decimals if any.
When casting from floating point rectangles, it is worth considering whether
to round()
, round_in()
or round_out()
before the cast in order to
obtain the desired conversion behavior.
pub fn to_u64(&self) -> Rect<u64, U>
[src]
Cast into an u64
rectangle, truncating decimals if any.
When casting from floating point rectangles, it is worth considering whether
to round()
, round_in()
or round_out()
before the cast in order to
obtain the desired conversion behavior.
pub fn to_i32(&self) -> Rect<i32, U>
[src]
Cast into an i32
rectangle, truncating decimals if any.
When casting from floating point rectangles, it is worth considering whether
to round()
, round_in()
or round_out()
before the cast in order to
obtain the desired conversion behavior.
pub fn to_i64(&self) -> Rect<i64, U>
[src]
Cast into an i64
rectangle, truncating decimals if any.
When casting from floating point rectangles, it is worth considering whether
to round()
, round_in()
or round_out()
before the cast in order to
obtain the desired conversion behavior.
impl<T: Floor + Ceil + Round + Add<T, Output = T> + Sub<T, Output = T>, U> Rect<T, U>
[src]
#[must_use]pub fn round(&self) -> Self
[src]
Return a rectangle with edges rounded to integer coordinates, such that the returned rectangle has the same set of pixel centers as the original one. Edges at offset 0.5 round up. Suitable for most places where integral device coordinates are needed, but note that any translation should be applied first to avoid pixel rounding errors. Note that this is not rounding to nearest integer if the values are negative. They are always rounding as floor(n + 0.5).
Usage notes
Note, that when using with floating-point T
types that method can significantly
loose precision for large values, so if you need to call this method very often it
is better to use Box2D
.
#[must_use]pub fn round_in(&self) -> Self
[src]
Return a rectangle with edges rounded to integer coordinates, such that the original rectangle contains the resulting rectangle.
Usage notes
Note, that when using with floating-point T
types that method can significantly
loose precision for large values, so if you need to call this method very often it
is better to use Box2D
.
#[must_use]pub fn round_out(&self) -> Self
[src]
Return a rectangle with edges rounded to integer coordinates, such that the original rectangle is contained in the resulting rectangle.
Usage notes
Note, that when using with floating-point T
types that method can significantly
loose precision for large values, so if you need to call this method very often it
is better to use Box2D
.
Trait Implementations
impl<T: Clone, U> Clone for Rect<T, U>
[src]
fn clone(&self) -> Self
[src]
fn clone_from(&mut self, source: &Self)
1.0.0[src]
impl<T: Copy, U> Copy for Rect<T, U>
[src]
impl<T: Debug, U> Debug for Rect<T, U>
[src]
impl<T: Default, U> Default for Rect<T, U>
[src]
impl<T: Display, U> Display for Rect<T, U>
[src]
impl<T: Clone + Div, U1, U2> Div<Scale<T, U1, U2>> for Rect<T, U2>
[src]
type Output = Rect<T::Output, U1>
The resulting type after applying the /
operator.
fn div(self, scale: Scale<T, U1, U2>) -> Self::Output
[src]
impl<T: Clone + Div, U> Div<T> for Rect<T, U>
[src]
type Output = Rect<T::Output, U>
The resulting type after applying the /
operator.
fn div(self, scale: T) -> Self::Output
[src]
impl<T: Clone + DivAssign, U> DivAssign<Scale<T, U, U>> for Rect<T, U>
[src]
fn div_assign(&mut self, scale: Scale<T, U, U>)
[src]
impl<T: Clone + DivAssign, U> DivAssign<T> for Rect<T, U>
[src]
fn div_assign(&mut self, scale: T)
[src]
impl<T: Eq, U> Eq for Rect<T, U>
[src]
impl<T, U> From<Size2D<T, U>> for Rect<T, U> where
T: Zero,
[src]
T: Zero,
impl<T: Hash, U> Hash for Rect<T, U>
[src]
fn hash<H: Hasher>(&self, h: &mut H)
[src]
fn hash_slice<H>(data: &[Self], state: &mut H) where
H: Hasher,
1.3.0[src]
H: Hasher,
impl<T: Clone + Mul, U1, U2> Mul<Scale<T, U1, U2>> for Rect<T, U1>
[src]
type Output = Rect<T::Output, U2>
The resulting type after applying the *
operator.
fn mul(self, scale: Scale<T, U1, U2>) -> Self::Output
[src]
impl<T: Clone + Mul, U> Mul<T> for Rect<T, U>
[src]
type Output = Rect<T::Output, U>
The resulting type after applying the *
operator.
fn mul(self, scale: T) -> Self::Output
[src]
impl<T: Clone + MulAssign, U> MulAssign<Scale<T, U, U>> for Rect<T, U>
[src]
fn mul_assign(&mut self, scale: Scale<T, U, U>)
[src]
impl<T: Clone + MulAssign, U> MulAssign<T> for Rect<T, U>
[src]
fn mul_assign(&mut self, scale: T)
[src]
impl<T: PartialEq, U> PartialEq<Rect<T, U>> for Rect<T, U>
[src]
Auto Trait Implementations
impl<T, U> RefUnwindSafe for Rect<T, U> where
T: RefUnwindSafe,
U: RefUnwindSafe,
T: RefUnwindSafe,
U: RefUnwindSafe,
impl<T, U> Send for Rect<T, U> where
T: Send,
U: Send,
T: Send,
U: Send,
impl<T, U> Sync for Rect<T, U> where
T: Sync,
U: Sync,
T: Sync,
U: Sync,
impl<T, U> Unpin for Rect<T, U> where
T: Unpin,
U: Unpin,
T: Unpin,
U: Unpin,
impl<T, U> UnwindSafe for Rect<T, U> where
T: UnwindSafe,
U: UnwindSafe,
T: UnwindSafe,
U: 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,
fn borrow_mut(&mut self) -> &mut T
[src]
impl<T> From<T> for T
[src]
impl<T, U> Into<U> for T where
U: From<T>,
[src]
U: From<T>,
impl<T> ToOwned for T where
T: Clone,
[src]
T: Clone,
type Owned = T
The resulting type after obtaining ownership.
fn to_owned(&self) -> T
[src]
fn clone_into(&self, target: &mut T)
[src]
impl<T> ToString for T where
T: Display + ?Sized,
[src]
T: Display + ?Sized,
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.
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>,