# Struct epaint::Rect

#[repr(C)]
pub struct Rect { pub min: Pos2, pub max: Pos2, }
Expand description

A rectangular region of space.

Usually a Rect has a positive (or zero) size, and then Self::min <= Self::max. In these cases Self::min is the left-top corner and Self::max is the right-bottom corner.

A rectangle is allowed to have a negative size, which happens when the order of min and max are swapped. These are usually a sign of an error.

Normally the unit is points (logical pixels) in screen space coordinates.

Rect does NOT implement Default, because there is no obvious default value. Rect::ZERO may seem reasonable, but when used as a bounding box, Rect::NOTHING is a better default - so be explicit instead!

## Fields§

§min: Pos2

One of the corners of the rectangle, usually the left top one.

§max: Pos2

The other corner, opposing Self::min. Usually the right bottom one.

## Implementations§

source§

### impl Rect

source

#### pub const EVERYTHING: Rect = _

Infinite rectangle that contains every point.

source

#### pub const NOTHING: Rect = _

The inverse of Self::EVERYTHING: stretches from positive infinity to negative infinity. Contains no points.

This is useful as the seed for bounding boxes.

##### §Example:
let mut rect = Rect::NOTHING;
assert!(rect.size() == Vec2::splat(-f32::INFINITY));
assert!(rect.contains(pos2(0.0, 0.0)) == false);
rect.extend_with(pos2(2.0, 1.0));
rect.extend_with(pos2(0.0, 3.0));
assert_eq!(rect, Rect::from_min_max(pos2(0.0, 1.0), pos2(2.0, 3.0)))
source

#### pub const NAN: Rect = _

An invalid Rect filled with f32::NAN.

source

#### pub const ZERO: Rect = _

A Rect filled with zeroes.

source

source

#### pub fn from_min_size(min: Pos2, size: Vec2) -> Rect

left-top corner plus a size (stretching right-down).

source

source

source

#### pub fn from_two_pos(a: Pos2, b: Pos2) -> Rect

Returns the bounding rectangle of the two points.

source

#### pub fn from_points(points: &[Pos2]) -> Rect

Bounding-box around the points.

source

#### pub fn everything_right_of(left_x: f32) -> Rect

A Rect that contains every point to the right of the given X coordinate.

source

#### pub fn everything_left_of(right_x: f32) -> Rect

A Rect that contains every point to the left of the given X coordinate.

source

#### pub fn everything_below(top_y: f32) -> Rect

A Rect that contains every point below a certain y coordinate

source

#### pub fn everything_above(bottom_y: f32) -> Rect

A Rect that contains every point above a certain y coordinate

source

source

source

source

source

#### pub fn expand(self, amnt: f32) -> Rect

Expand by this much in each direction, keeping the center

source

#### pub fn expand2(self, amnt: Vec2) -> Rect

Expand by this much in each direction, keeping the center

source

#### pub fn shrink(self, amnt: f32) -> Rect

Shrink by this much in each direction, keeping the center

source

#### pub fn shrink2(self, amnt: Vec2) -> Rect

Shrink by this much in each direction, keeping the center

source

source

#### pub fn rotate_bb(self, rot: Rot2) -> Rect

Rotate the bounds (will expand the Rect)

source

source

keep min

source

keep min

source

Keep size

source

source

source

#### pub fn clamp(&self, p: Pos2) -> Pos2

Return the given points clamped to be inside the rectangle Panics if Self::is_negative.

source

source

#### pub fn extend_with_x(&mut self, x: f32)

Expand to include the given x coordinate

source

#### pub fn extend_with_y(&mut self, y: f32)

Expand to include the given y coordinate

source

#### pub fn union(self, other: Rect) -> Rect

The union of two bounding rectangle, i.e. the minimum Rect that contains both input rectangles.

source

#### pub fn intersect(self, other: Rect) -> Rect

The intersection of two Rect, i.e. the area covered by both.

source

source

#### pub fn size(&self) -> Vec2

rect.size() == Vec2 { x: rect.width(), y: rect.height() }

source

source

source

#### pub fn aspect_ratio(&self) -> f32

Width / height

• aspect_ratio < 1: portrait / high
• aspect_ratio = 1: square
• aspect_ratio > 1: landscape / wide
source

#### pub fn square_proportions(&self) -> Vec2

[2, 1] for wide screen, and [1, 2] for portrait, etc. At least one dimension = 1, the other >= 1 Returns the proportions required to letter-box a square view area.

source

source

#### pub fn distance_to_pos(&self, pos: Pos2) -> f32

The distance from the rect to the position.

The distance is zero when the position is in the interior of the rectangle.

source

#### pub fn distance_sq_to_pos(&self, pos: Pos2) -> f32

The distance from the rect to the position, squared.

The distance is zero when the position is in the interior of the rectangle.

source

#### pub fn signed_distance_to_pos(&self, pos: Pos2) -> f32

Signed distance to the edge of the box.

Negative inside the box.

let rect = Rect::from_min_max(pos2(0.0, 0.0), pos2(1.0, 1.0));
assert_eq!(rect.signed_distance_to_pos(pos2(0.50, 0.50)), -0.50);
assert_eq!(rect.signed_distance_to_pos(pos2(0.75, 0.50)), -0.25);
assert_eq!(rect.signed_distance_to_pos(pos2(1.50, 0.50)), 0.50);
source

#### pub fn lerp_inside(&self, t: Vec2) -> Pos2

Linearly interpolate so that [0, 0] is Self::min and [1, 1] is Self::max.

source

#### pub fn lerp_towards(&self, other: &Rect, t: f32) -> Rect

Linearly self towards other rect.

source

source

source

source

#### pub fn is_negative(&self) -> bool

width < 0 || height < 0

source

#### pub fn is_positive(&self) -> bool

width > 0 && height > 0

source

#### pub fn is_finite(&self) -> bool

True if all members are also finite.

source

#### pub fn any_nan(self) -> bool

True if any member is NaN.

source§

### impl Rect

source

min.x

source

min.x

source

min.x

source

max.x

source

max.x

source

max.x

source

min.y

source

min.y

source

min.y

source

max.y

source

max.y

source

max.y

source

source

source

source

source

source

source

source

source

#### pub fn split_left_right_at_fraction(&self, t: f32) -> (Rect, Rect)

Split rectangle in left and right halves. t is expected to be in the (0,1) range.

source

#### pub fn split_left_right_at_x(&self, split_x: f32) -> (Rect, Rect)

Split rectangle in left and right halves at the given x coordinate.

source

#### pub fn split_top_bottom_at_fraction(&self, t: f32) -> (Rect, Rect)

Split rectangle in top and bottom halves. t is expected to be in the (0,1) range.

source

#### pub fn split_top_bottom_at_y(&self, split_y: f32) -> (Rect, Rect)

Split rectangle in top and bottom halves at the given y coordinate.

## Trait Implementations§

source§

### impl Clone for Rect

source§

#### fn clone(&self) -> Rect

Returns a copy of the value. Read more
1.0.0 · source§

#### fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
source§

### impl Debug for Rect

source§

#### fn fmt(&self, f: &mut Formatter<'_>) -> Result<(), Error>

Formats the value using the given formatter. Read more
source§

### impl Div<f32> for Rect

§

#### type Output = Rect

The resulting type after applying the / operator.
source§

#### fn div(self, factor: f32) -> Rect

Performs the / operation. Read more
source§

### impl From<[Pos2; 2]> for Rect

from (min, max) or (left top, right bottom)

source§

#### fn from(_: [Pos2; 2]) -> Rect

Converts to this type from the input type.
source§

### impl Mul<f32> for Rect

§

#### type Output = Rect

The resulting type after applying the * operator.
source§

#### fn mul(self, factor: f32) -> Rect

Performs the * operation. Read more
source§

### impl PartialEq for Rect

source§

#### fn eq(&self, other: &Rect) -> bool

This method tests for self and other values to be equal, and is used by ==.
1.0.0 · source§

#### fn ne(&self, other: &Rhs) -> bool

This method tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
source§

source§

source§

source§

source§

source§

§

§

§

§

§

§

## Blanket Implementations§

source§

### impl<T> Any for Twhere T: 'static + ?Sized,

source§

#### fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

### impl<T> Borrow<T> for Twhere T: ?Sized,

source§

#### fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

### impl<T> BorrowMut<T> for Twhere T: ?Sized,

source§

#### fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
source§

### impl<T> CheckedBitPattern for Twhere T: AnyBitPattern,

§

#### type Bits = T

Self must have the same layout as the specified Bits except for the possible invalid bit patterns being checked during is_valid_bit_pattern.
source§

#### fn is_valid_bit_pattern(_bits: &T) -> bool

If this function returns true, then it must be valid to reinterpret bits as &Self.
source§

### impl<T> From<T> for T

source§

#### fn from(t: T) -> T

Returns the argument unchanged.

source§

### impl<T, U> Into<U> for Twhere U: From<T>,

source§

#### fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

source§

### impl<T> ToOwned for Twhere T: Clone,

§

#### type Owned = T

The resulting type after obtaining ownership.
source§

#### fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
source§

#### fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
source§

### impl<T, U> TryFrom<U> for Twhere U: Into<T>,

§

#### type Error = Infallible

The type returned in the event of a conversion error.
source§

#### fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
source§

### impl<T, U> TryInto<U> for Twhere U: TryFrom<T>,

§

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

The type returned in the event of a conversion error.
source§

#### fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
source§

source§