Struct nannou::geom::Rect

source ·
pub struct Rect<S = f32> {
    pub x: Range<S>,
    pub y: Range<S>,
}
Expand description

Defines a Rectangle’s bounds across the x and y axes.

Fields§

§x: Range<S>

The start and end positions of the Rectangle on the x axis.

§y: Range<S>

The start and end positions of the Rectangle on the y axis.

Implementations§

source§

impl<S> Rect<S>
where S: Scalar + Float,

source

pub fn from_x_y_w_h(x: S, y: S, w: S, h: S) -> Rect<S>

Construct a Rect from the given x y coordinates and w h dimensions.

source

pub fn from_w_h(w: S, h: S) -> Rect<S>

Construct a Rect at origin with the given width and height.

source

pub fn x(&self) -> S

The position in the middle of the x bounds.

source

pub fn y(&self) -> S

The position in the middle of the y bounds.

source

pub fn x_y(&self) -> (S, S)

The centered x and y coordinates as a tuple.

source

pub fn x_y_w_h(&self) -> (S, S, S, S)

The Rect’s centered coordinates and dimensions in a tuple.

source

pub fn align_x_of(self, align: Align, other: Rect<S>) -> Rect<S>

Align self to other along the x axis in accordance with the given Align variant.

source

pub fn align_y_of(self, align: Align, other: Rect<S>) -> Rect<S>

Align self to other along the y axis in accordance with the given Align variant.

source

pub fn align_middle_x_of(self, other: Rect<S>) -> Rect<S>

Align the middle of self with the middle of the other Rect along the x axis.

source

pub fn align_middle_y_of(self, other: Rect<S>) -> Rect<S>

Align the middle of self with the middle of the other Rect along the y axis.

source

pub fn mid_top_of(self, other: Rect<S>) -> Rect<S>

Place self in the middle of the top edge of the other Rect.

source

pub fn mid_bottom_of(self, other: Rect<S>) -> Rect<S>

Place self in the middle of the bottom edge of the other Rect.

source

pub fn mid_left_of(self, other: Rect<S>) -> Rect<S>

Place self in the middle of the left edge of the other Rect.

source

pub fn mid_right_of(self, other: Rect<S>) -> Rect<S>

Place self in the middle of the right edge of the other Rect.

source

pub fn middle_of(self, other: Rect<S>) -> Rect<S>

Place self directly in the middle of the other Rect.

source

pub fn subdivision_ranges(&self) -> SubdivisionRanges<S>

The four ranges used for the Rect’s four subdivisions.

source

pub fn subdivisions(&self) -> [Rect<S>; 4]

Divide the Rect in half along the x and y axes and return the four subdivisions.

Subdivisions are yielded in the following order:

  1. Bottom left
  2. Bottom right
  3. Top left
  4. Top right
source

pub fn subdivisions_iter(&self) -> Subdivisions<S>

The same as subdivisions but each subdivision is yielded via the returned Iterator.

source§

impl<S> Rect<S>
where S: Scalar,

source

pub fn from_corner_points(_: [S; 2], _: [S; 2]) -> Rect<S>

Construct a Rect from the coordinates of two points.

source

pub fn absolute(self) -> Rect<S>

Converts self to an absolute Rect so that the magnitude of each range is always positive.

source

pub fn overlap(self, other: Rect<S>) -> Option<Rect<S>>

The Rect representing the area in which two Rects overlap.

source

pub fn max(self, other: Rect<S>) -> Rect<S>
where S: Float,

The Rect that encompass the two given sets of Rect.

source

pub fn bottom(&self) -> S

The Rect’s lowest y value.

source

pub fn top(&self) -> S

The Rect’s highest y value.

source

pub fn left(&self) -> S

The Rect’s lowest x value.

source

pub fn right(&self) -> S

The Rect’s highest x value.

source

pub fn l_r_b_t(&self) -> (S, S, S, S)

The edges of the Rect in a tuple (left, right, bottom, top).

source

pub fn shift_x(self, x: S) -> Rect<S>

Shift the Rect along the x axis.

source

pub fn shift_y(self, y: S) -> Rect<S>

Shift the Rect along the y axis.

source

pub fn left_of(self, other: Rect<S>) -> Rect<S>

Align self’s right edge with the left edge of the other Rect.

source

pub fn right_of(self, other: Rect<S>) -> Rect<S>

Align self’s left edge with the right dge of the other Rect.

source

pub fn below(self, other: Rect<S>) -> Rect<S>

Align self’s top edge with the bottom edge of the other Rect.

source

pub fn above(self, other: Rect<S>) -> Rect<S>

Align self’s bottom edge with the top edge of the other Rect.

source

pub fn align_left_of(self, other: Rect<S>) -> Rect<S>

Align self’s left edge with the left edge of the other Rect.

source

pub fn align_right_of(self, other: Rect<S>) -> Rect<S>

Align self’s right edge with the right edge of the other Rect.

source

pub fn align_bottom_of(self, other: Rect<S>) -> Rect<S>

Align self’s bottom edge with the bottom edge of the other Rect.

source

pub fn align_top_of(self, other: Rect<S>) -> Rect<S>

Align self’s top edge with the top edge of the other Rect.

source

pub fn top_left_of(self, other: Rect<S>) -> Rect<S>

Place self along the top left edges of the other Rect.

source

pub fn top_right_of(self, other: Rect<S>) -> Rect<S>

Place self along the top right edges of the other Rect.

source

pub fn bottom_left_of(self, other: Rect<S>) -> Rect<S>

Place self along the bottom left edges of the other Rect.

source

pub fn bottom_right_of(self, other: Rect<S>) -> Rect<S>

Place self along the bottom right edges of the other Rect.

source

pub fn contains_point(self, _: [S; 2]) -> bool

Does the given point touch the Rectangle.

source

pub fn stretch_to_point(self, _: [S; 2]) -> Rect<S>

Stretches the closest edge(s) to the given point if the point lies outside of the Rect area.

source

pub fn closest_corner(&self, _: [S; 2]) -> Corner

Return the Corner of self that is closest to the given Point.

source

pub fn corners(&self) -> Quad<[S; 2]>

The four corners of the Rect.

source

pub fn corners_iter(&self) -> Corners<S>

An iterator yielding the four corners of the Rect.

source

pub fn triangles(&self) -> (Tri<[S; 2]>, Tri<[S; 2]>)

Return two Tris that represent the Rect.

source

pub fn triangles_iter(self) -> Triangles<[S; 2]>

An iterator yielding the Rect’s two Tri’s.

source

pub fn corner_at_index(&self, index: u8) -> Option<[S; 2]>

Produce the corner at the given index.

source§

impl Rect

source

pub fn from_xy_wh(p: Vec2, s: Vec2) -> Rect

Construct a Rect from a given Point and Dimensions.

source

pub fn from_wh(s: Vec2) -> Rect

Construct a Rect at origin with the given dimensions.

source

pub fn from_corners(a: Vec2, b: Vec2) -> Rect

Construct a Rect from the coordinates of two points.

source

pub fn xy(&self) -> Vec2

The xy position in the middle of the bounds.

source

pub fn wh(&self) -> Vec2

The total dimensions of the Rect.

source

pub fn xy_wh(&self) -> (Vec2, Vec2)

Convert the Rect to a Point and Dimensions.

source

pub fn top_left(&self) -> Vec2

The top left corner Point.

source

pub fn bottom_left(&self) -> Vec2

The bottom left corner Point.

source

pub fn top_right(&self) -> Vec2

The top right corner Point.

source

pub fn bottom_right(&self) -> Vec2

The bottom right corner Point.

source

pub fn mid_left(&self) -> Vec2

The middle of the left edge.

source

pub fn mid_top(&self) -> Vec2

The middle of the top edge.

source

pub fn mid_right(&self) -> Vec2

The middle of the right edge.

source

pub fn mid_bottom(&self) -> Vec2

The middle of the bottom edge.

source

pub fn shift(self, v: Vec2) -> Rect

Shift the Rect by the given vector.

source

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

Does the given point touch the Rectangle.

source

pub fn stretch_to(self, p: Vec2) -> Rect

Stretches the closest edge(s) to the given point if the point lies outside of the Rect area.

source§

impl Rect<f64>

source

pub fn from_xy_wh_f64(p: DVec2, s: DVec2) -> Rect<f64>

Construct a Rect from a given Point and Dimensions.

source

pub fn from_wh_f64(s: DVec2) -> Rect<f64>

Construct a Rect at origin with the given dimensions.

source

pub fn from_corners_f64(a: DVec2, b: DVec2) -> Rect<f64>

Construct a Rect from the coordinates of two points.

source

pub fn xy(&self) -> DVec2

The xy position in the middle of the bounds.

source

pub fn wh(&self) -> DVec2

The total dimensions of the Rect.

source

pub fn xy_wh(&self) -> (DVec2, DVec2)

Convert the Rect to a Point and Dimensions.

source

pub fn top_left(&self) -> DVec2

The top left corner Point.

source

pub fn bottom_left(&self) -> DVec2

The bottom left corner Point.

source

pub fn top_right(&self) -> DVec2

The top right corner Point.

source

pub fn bottom_right(&self) -> DVec2

The bottom right corner Point.

source

pub fn mid_left(&self) -> DVec2

The middle of the left edge.

source

pub fn mid_top(&self) -> DVec2

The middle of the top edge.

source

pub fn mid_right(&self) -> DVec2

The middle of the right edge.

source

pub fn mid_bottom(&self) -> DVec2

The middle of the bottom edge.

source

pub fn shift(self, v: DVec2) -> Rect<f64>

Shift the Rect by the given vector.

source

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

Does the given point touch the Rectangle.

source

pub fn stretch_to(self, p: DVec2) -> Rect<f64>

Stretches the closest edge(s) to the given point if the point lies outside of the Rect area.

source§

impl<S> Rect<S>
where S: Scalar<Output = S> + Neg,

source

pub fn w(&self) -> S

The width of the Rect.

source

pub fn h(&self) -> S

The height of the Rect.

source

pub fn w_h(&self) -> (S, S)

The width and height of the Rect as a tuple.

source

pub fn len(&self) -> S

The length of the longest side of the rectangle.

source

pub fn l_t_w_h(&self) -> (S, S, S, S)

The left and top edges of the Rect along with the width and height.

source

pub fn l_b_w_h(&self) -> (S, S, S, S)

The left and bottom edges of the Rect along with the width and height.

source

pub fn pad_left(self, pad: S) -> Rect<S>

The Rect with some padding applied to the left edge.

source

pub fn pad_right(self, pad: S) -> Rect<S>

The Rect with some padding applied to the right edge.

source

pub fn pad_bottom(self, pad: S) -> Rect<S>

The rect with some padding applied to the bottom edge.

source

pub fn pad_top(self, pad: S) -> Rect<S>

The Rect with some padding applied to the top edge.

source

pub fn pad(self, pad: S) -> Rect<S>

The Rect with some padding amount applied to each edge.

source

pub fn padding(self, padding: Padding<S>) -> Rect<S>

The Rect with some padding applied.

source

pub fn relative_to_x(self, x: S) -> Rect<S>

Returns a Rect with a position relative to the given position on the x axis.

source

pub fn relative_to_y(self, y: S) -> Rect<S>

Returns a Rect with a position relative to the given position on the y axis.

source

pub fn relative_to(self, _: [S; 2]) -> Rect<S>

Returns a Rect with a position relative to the given position.

source

pub fn invert_x(self) -> Rect<S>

Invert the x axis (aka flip around the y axis).

source

pub fn invert_y(self) -> Rect<S>

Invert the y axis (aka flip around the x axis).

Trait Implementations§

source§

impl<S> Clone for Rect<S>
where S: Clone,

source§

fn clone(&self) -> Rect<S>

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<S> Debug for Rect<S>
where S: Debug,

source§

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

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

impl From<Rect> for Rect

source§

fn from(r: Rect<f32>) -> Self

Converts to this type from the input type.
source§

impl<S> PartialEq for Rect<S>
where S: PartialEq,

source§

fn eq(&self, other: &Rect<S>) -> 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§

impl<S> PartialOrd for Rect<S>
where S: PartialOrd,

source§

fn partial_cmp(&self, other: &Rect<S>) -> Option<Ordering>

This method returns an ordering between self and other values if one exists. Read more
1.0.0 · source§

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

This method tests less than (for self and other) and is used by the < operator. Read more
1.0.0 · source§

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

This method tests less than or equal to (for self and other) and is used by the <= operator. Read more
1.0.0 · source§

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

This method tests greater than (for self and other) and is used by the > operator. Read more
1.0.0 · source§

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

This method tests greater than or equal to (for self and other) and is used by the >= operator. Read more
source§

impl<S> Copy for Rect<S>
where S: Copy,

source§

impl<S> StructuralPartialEq for Rect<S>

Auto Trait Implementations§

§

impl<S> RefUnwindSafe for Rect<S>
where S: RefUnwindSafe,

§

impl<S> Send for Rect<S>
where S: Send,

§

impl<S> Sync for Rect<S>
where S: Sync,

§

impl<S> Unpin for Rect<S>
where S: Unpin,

§

impl<S> UnwindSafe for Rect<S>
where S: UnwindSafe,

Blanket Implementations§

source§

impl<S, D, Swp, Dwp, T> AdaptInto<D, Swp, Dwp, T> for S
where T: Component + Float, Swp: WhitePoint, Dwp: WhitePoint, D: AdaptFrom<S, Swp, Dwp, T>,

source§

fn adapt_into_using<M>(self, method: M) -> D
where M: TransformMatrix<Swp, Dwp, T>,

Convert the source color to the destination color using the specified method
source§

fn adapt_into(self) -> D

Convert the source color to the destination color using the bradford method by default
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> 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<T, U> ConvertInto<U> for T
where U: ConvertFrom<T>,

source§

fn convert_into(self) -> U

Convert into T with values clamped to the color defined bounds Read more
source§

fn convert_unclamped_into(self) -> U

Convert into T. The resulting color might be invalid in its color space Read more
source§

fn try_convert_into(self) -> Result<U, OutOfBounds<U>>

Convert into T, returning ok if the color is inside of its defined range, otherwise an OutOfBounds error is returned which contains the unclamped color. Read more
§

impl<T> Downcast<T> for T

§

fn downcast(&self) -> &T

source§

impl<T> From<T> for T

source§

fn from(t: T) -> T

Returns the argument unchanged.

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.

§

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

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> WasmNotSend for T
where T: Send,

§

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