Struct rerun::external::eframe::egui::epaint::emath::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§

§

impl Rect

pub const EVERYTHING: Rect = _

Infinite rectangle that contains every point.

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

pub const NAN: Rect = _

An invalid Rect filled with f32::NAN.

pub const ZERO: Rect = _

A Rect filled with zeroes.

pub const fn from_min_max(min: Pos2, max: Pos2) -> Rect

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

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

pub fn from_center_size(center: Pos2, size: Vec2) -> Rect

pub fn from_x_y_ranges( x_range: impl Into<Rangef>, y_range: impl Into<Rangef> ) -> Rect

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

Returns the bounding rectangle of the two points.

pub fn from_pos(point: Pos2) -> Rect

A zero-sized rect at a specific point.

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

Bounding-box around the points.

pub fn everything_right_of(left_x: f32) -> Rect

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

pub fn everything_left_of(right_x: f32) -> Rect

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

pub fn everything_below(top_y: f32) -> Rect

A Rect that contains every point below a certain y coordinate

pub fn everything_above(bottom_y: f32) -> Rect

A Rect that contains every point above a certain y coordinate

pub fn with_min_x(self, min_x: f32) -> Rect

pub fn with_min_y(self, min_y: f32) -> Rect

pub fn with_max_x(self, max_x: f32) -> Rect

pub fn with_max_y(self, max_y: f32) -> Rect

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

Expand by this much in each direction, keeping the center

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

Expand by this much in each direction, keeping the center

pub fn scale_from_center(self, scale_factor: f32) -> Rect

Scale up by this factor in each direction, keeping the center

pub fn scale_from_center2(self, scale_factor: Vec2) -> Rect

Scale up by this factor in each direction, keeping the center

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

Shrink by this much in each direction, keeping the center

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

Shrink by this much in each direction, keeping the center

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

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

Rotate the bounds (will expand the Rect)

pub fn intersects(self, other: Rect) -> bool

pub fn set_width(&mut self, w: f32)

keep min

pub fn set_height(&mut self, h: f32)

keep min

pub fn set_center(&mut self, center: Pos2)

Keep size

pub fn contains(&self, p: Pos2) -> bool

pub fn contains_rect(&self, other: Rect) -> bool

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

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

pub fn extend_with(&mut self, p: Pos2)

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

Expand to include the given x coordinate

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

Expand to include the given y coordinate

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

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

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

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

pub fn center(&self) -> Pos2

pub fn size(&self) -> Vec2

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

pub fn width(&self) -> f32

pub fn height(&self) -> f32

pub fn aspect_ratio(&self) -> f32

Width / height

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

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.

pub fn area(&self) -> f32

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.

Negative rectangles always return f32::INFINITY.

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.

Negative rectangles always return f32::INFINITY.

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

Signed distance to the edge of the box.

Negative inside the box.

Negative rectangles always return f32::INFINITY.

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

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

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

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

Linearly self towards other rect.

pub fn x_range(&self) -> Rangef

pub fn y_range(&self) -> Rangef

pub fn bottom_up_range(&self) -> Rangef

pub fn is_negative(&self) -> bool

width < 0 || height < 0

pub fn is_positive(&self) -> bool

width > 0 && height > 0

pub fn is_finite(&self) -> bool

True if all members are also finite.

pub fn any_nan(self) -> bool

True if any member is NaN.

§

impl Rect

§Convenience functions (assumes origin is towards left top):

pub fn left(&self) -> f32

min.x

pub fn left_mut(&mut self) -> &mut f32

min.x

pub fn set_left(&mut self, x: f32)

min.x

pub fn right(&self) -> f32

max.x

pub fn right_mut(&mut self) -> &mut f32

max.x

pub fn set_right(&mut self, x: f32)

max.x

pub fn top(&self) -> f32

min.y

pub fn top_mut(&mut self) -> &mut f32

min.y

pub fn set_top(&mut self, y: f32)

min.y

pub fn bottom(&self) -> f32

max.y

pub fn bottom_mut(&mut self) -> &mut f32

max.y

pub fn set_bottom(&mut self, y: f32)

max.y

pub fn left_top(&self) -> Pos2

pub fn center_top(&self) -> Pos2

pub fn right_top(&self) -> Pos2

pub fn left_center(&self) -> Pos2

pub fn right_center(&self) -> Pos2

pub fn left_bottom(&self) -> Pos2

pub fn center_bottom(&self) -> Pos2

pub fn right_bottom(&self) -> Pos2

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.

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.

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.

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.

§

impl Rect

pub fn intersects_ray(&self, o: Pos2, d: Vec2) -> bool

Does this Rect intersect the given ray (where d is normalized)?

A ray that starts inside the rect will return true.

Trait Implementations§

§

impl Add<Margin> for Rect

Rect + Margin

§

type Output = Rect

The resulting type after applying the + operator.
§

fn add(self, margin: Margin) -> Rect

Performs the + operation. Read more
§

impl AddAssign<Margin> for Rect

Rect += Margin

§

fn add_assign(&mut self, margin: Margin)

Performs the += operation. Read more
§

impl Clone for Rect

§

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
§

impl Debug for Rect

§

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

Formats the value using the given formatter. Read more
§

impl<'de> Deserialize<'de> for Rect

§

fn deserialize<__D>( __deserializer: __D ) -> Result<Rect, <__D as Deserializer<'de>>::Error>
where __D: Deserializer<'de>,

Deserialize this value from the given Serde deserializer. Read more
§

impl Display for Rect

§

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

Formats the value using the given formatter. Read more
§

impl Div<f32> for Rect

§

type Output = Rect

The resulting type after applying the / operator.
§

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

Performs the / operation. Read more
§

impl From<[Pos2; 2]> for Rect

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

§

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

Converts to this type from the input type.
source§

impl From<Range2D> for Rect

source§

fn from(range2d: Range2D) -> Rect

Converts to this type from the input type.
source§

impl From<Rect> for Range2D

source§

fn from(rect: Rect) -> Range2D

Converts to this type from the input type.
source§

impl From<VisualBounds2D> for Rect

source§

fn from(v: VisualBounds2D) -> Rect

Converts to this type from the input type.
§

impl Mul<Rect> for TSTransform

Transforms the rectangle.

§

type Output = Rect

The resulting type after applying the * operator.
§

fn mul(self, rect: Rect) -> Rect

Performs the * operation. Read more
§

impl Mul<Rect> for f32

§

type Output = Rect

The resulting type after applying the * operator.
§

fn mul(self, vec: Rect) -> Rect

Performs the * operation. Read more
§

impl Mul<f32> for Rect

§

type Output = Rect

The resulting type after applying the * operator.
§

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

Performs the * operation. Read more
§

impl PartialEq for Rect

§

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

impl Serialize for Rect

§

fn serialize<__S>( &self, __serializer: __S ) -> Result<<__S as Serializer>::Ok, <__S as Serializer>::Error>
where __S: Serializer,

Serialize this value into the given Serde serializer. Read more
§

impl Sub<Margin> for Rect

Rect - Margin

§

type Output = Rect

The resulting type after applying the - operator.
§

fn sub(self, margin: Margin) -> Rect

Performs the - operation. Read more
§

impl SubAssign<Margin> for Rect

Rect -= Margin

§

fn sub_assign(&mut self, margin: Margin)

Performs the -= operation. Read more
§

impl Zeroable for Rect

§

fn zeroed() -> Self

§

impl Copy for Rect

§

impl Eq for Rect

§

impl Pod for Rect

§

impl StructuralPartialEq for Rect

Auto Trait Implementations§

§

impl Freeze for Rect

§

impl RefUnwindSafe for Rect

§

impl Send for Rect

§

impl Sync for Rect

§

impl Unpin for Rect

§

impl UnwindSafe for Rect

Blanket Implementations§

source§

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

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

impl<T> Az for T

source§

fn az<Dst>(self) -> Dst
where T: Cast<Dst>,

Casts the value.
source§

impl<T> Borrow<T> for T
where T: ?Sized,

source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

source§

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

Mutably borrows from an owned value. Read more
source§

impl<Src, Dst> CastFrom<Src> for Dst
where Src: Cast<Dst>,

source§

fn cast_from(src: Src) -> Dst

Casts the value.
source§

impl<T> CheckedAs for T

source§

fn checked_as<Dst>(self) -> Option<Dst>
where T: CheckedCast<Dst>,

Casts the value.
§

impl<T> CheckedBitPattern for T
where 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.
§

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<Src, Dst> CheckedCastFrom<Src> for Dst
where Src: CheckedCast<Dst>,

source§

fn checked_cast_from(src: Src) -> Option<Dst>

Casts the value.
§

impl<T> Downcast<T> for T

§

fn downcast(&self) -> &T

§

impl<T> Downcast for T
where T: Any,

§

fn into_any(self: Box<T>) -> Box<dyn Any>

Convert Box<dyn Trait> (where Trait: Downcast) to Box<dyn Any>. Box<dyn Any> can then be further downcast into Box<ConcreteType> where ConcreteType implements Trait.
§

fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>

Convert Rc<Trait> (where Trait: Downcast) to Rc<Any>. Rc<Any> can then be further downcast into Rc<ConcreteType> where ConcreteType implements Trait.
§

fn as_any(&self) -> &(dyn Any + 'static)

Convert &Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot generate &Any’s vtable from &Trait’s.
§

fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)

Convert &mut Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot generate &mut Any’s vtable from &mut Trait’s.
§

impl<T> DowncastSync for T
where T: Any + Send + Sync,

§

fn into_any_arc(self: Arc<T>) -> Arc<dyn Any + Sync + Send>

Convert Arc<Trait> (where Trait: Downcast) to Arc<Any>. Arc<Any> can then be further downcast into Arc<ConcreteType> where ConcreteType implements Trait.
source§

impl<T> DynClone for T
where T: Clone,

§

impl<Q, K> Equivalent<K> for Q
where Q: Eq + ?Sized, K: Borrow<Q> + ?Sized,

§

fn equivalent(&self, key: &K) -> bool

Checks if this value is equivalent to the given key. Read more
§

impl<Q, K> Equivalent<K> for Q
where Q: Eq + ?Sized, K: Borrow<Q> + ?Sized,

§

fn equivalent(&self, key: &K) -> bool

Compare self to key and return true if they are equal.
source§

impl<Q, K> Equivalent<K> for Q
where Q: Eq + ?Sized, K: Borrow<Q> + ?Sized,

source§

fn equivalent(&self, key: &K) -> bool

Compare self to key and return true if they are equal.
source§

impl<T> From<T> for T

source§

fn from(t: T) -> T

Returns the argument unchanged.

§

impl<T> FromRef<T> for T
where T: Clone,

§

fn from_ref(input: &T) -> T

Converts to this type from a reference to the input type.
§

impl<T> Instrument for T

§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided [Span], returning an Instrumented wrapper. Read more
§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
source§

impl<T, U> Into<U> for T
where 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> IntoEither for T

source§

fn into_either(self, into_left: bool) -> Either<Self, Self>

Converts self into a Left variant of Either<Self, Self> if into_left is true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

Converts self into a Left variant of Either<Self, Self> if into_left(&self) returns true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
source§

impl<T> IntoRequest<T> for T

source§

fn into_request(self) -> Request<T>

Wrap the input message T in a tonic::Request
source§

impl<Src, Dst> LosslessTryInto<Dst> for Src
where Dst: LosslessTryFrom<Src>,

source§

fn lossless_try_into(self) -> Option<Dst>

Performs the conversion.
source§

impl<Src, Dst> LossyInto<Dst> for Src
where Dst: LossyFrom<Src>,

source§

fn lossy_into(self) -> Dst

Performs the conversion.
source§

impl<T> OverflowingAs for T

source§

fn overflowing_as<Dst>(self) -> (Dst, bool)
where T: OverflowingCast<Dst>,

Casts the value.
source§

impl<Src, Dst> OverflowingCastFrom<Src> for Dst
where Src: OverflowingCast<Dst>,

source§

fn overflowing_cast_from(src: Src) -> (Dst, bool)

Casts the value.
§

impl<T> Pointable for T

§

const ALIGN: usize = _

The alignment of pointer.
§

type Init = T

The type for initializers.
§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. Read more
source§

impl<T> Same for T

§

type Output = T

Should always be Self
source§

impl<T> SaturatingAs for T

source§

fn saturating_as<Dst>(self) -> Dst
where T: SaturatingCast<Dst>,

Casts the value.
source§

impl<Src, Dst> SaturatingCastFrom<Src> for Dst
where Src: SaturatingCast<Dst>,

source§

fn saturating_cast_from(src: Src) -> Dst

Casts the value.
§

impl<T> To for T
where T: ?Sized,

§

fn to<T>(self) -> T
where Self: Into<T>,

Converts to T by calling Into<T>::into.
§

fn try_to<T>(self) -> Result<T, Self::Error>
where Self: TryInto<T>,

Tries to convert to T by calling TryInto<T>::try_into.
source§

impl<T> ToOwned for T
where 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
§

impl<T> ToSmolStr for T
where T: Display + ?Sized,

§

fn to_smolstr(&self) -> SmolStr

source§

impl<T> ToString for T
where T: Display + ?Sized,

source§

default fn to_string(&self) -> String

Converts the given value to a String. Read more
source§

impl<T, U> TryFrom<U> for T
where 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 T
where 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§

impl<T> UnwrappedAs for T

source§

fn unwrapped_as<Dst>(self) -> Dst
where T: UnwrappedCast<Dst>,

Casts the value.
source§

impl<Src, Dst> UnwrappedCastFrom<Src> for Dst
where Src: UnwrappedCast<Dst>,

source§

fn unwrapped_cast_from(src: Src) -> Dst

Casts the value.
§

impl<T> Upcast<T> for T

§

fn upcast(&self) -> Option<&T>

§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

§

fn vzip(self) -> V

§

impl<T> WithSubscriber for T

§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a [WithDispatch] wrapper. Read more
§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a [WithDispatch] wrapper. Read more
source§

impl<T> WrappingAs for T

source§

fn wrapping_as<Dst>(self) -> Dst
where T: WrappingCast<Dst>,

Casts the value.
source§

impl<Src, Dst> WrappingCastFrom<Src> for Dst
where Src: WrappingCast<Dst>,

source§

fn wrapping_cast_from(src: Src) -> Dst

Casts the value.
§

impl<T> Allocation for T
where T: RefUnwindSafe + Send + Sync,

§

impl<T> AnyBitPattern for T
where T: Pod,

source§

impl<T> DeserializeOwned for T
where T: for<'de> Deserialize<'de>,

§

impl<T> NoUninit for T
where T: Pod,

§

impl<T> SerializableAny for T
where T: 'static + Any + Clone + Serialize + for<'a> Deserialize<'a> + Send + Sync,

§

impl<T> Ungil for T
where T: Send,

§

impl<T> WasmNotSend for T
where T: Send,

§

impl<T> WasmNotSendSync for T

§

impl<T> WasmNotSync for T
where T: Sync,