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>
impl<S> Rect<S>
Sourcepub fn from_x_y_w_h(x: S, y: S, w: S, h: S) -> Rect<S>
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.
Sourcepub fn from_w_h(w: S, h: S) -> Rect<S>
pub fn from_w_h(w: S, h: S) -> Rect<S>
Construct a Rect at origin with the given width and height.
Sourcepub fn x_y_w_h(&self) -> (S, S, S, S)
pub fn x_y_w_h(&self) -> (S, S, S, S)
The Rect’s centered coordinates and dimensions in a tuple.
Sourcepub fn align_x_of(self, align: Align, other: Rect<S>) -> Rect<S>
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.
Sourcepub fn align_y_of(self, align: Align, other: Rect<S>) -> Rect<S>
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.
Sourcepub fn align_middle_x_of(self, other: Rect<S>) -> Rect<S>
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.
Sourcepub fn align_middle_y_of(self, other: Rect<S>) -> Rect<S>
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.
Sourcepub fn mid_top_of(self, other: Rect<S>) -> Rect<S>
pub fn mid_top_of(self, other: Rect<S>) -> Rect<S>
Place self
in the middle of the top edge of the other
Rect.
Sourcepub fn mid_bottom_of(self, other: Rect<S>) -> Rect<S>
pub fn mid_bottom_of(self, other: Rect<S>) -> Rect<S>
Place self
in the middle of the bottom edge of the other
Rect.
Sourcepub fn mid_left_of(self, other: Rect<S>) -> Rect<S>
pub fn mid_left_of(self, other: Rect<S>) -> Rect<S>
Place self
in the middle of the left edge of the other
Rect.
Sourcepub fn mid_right_of(self, other: Rect<S>) -> Rect<S>
pub fn mid_right_of(self, other: Rect<S>) -> Rect<S>
Place self
in the middle of the right edge of the other
Rect.
Sourcepub fn middle_of(self, other: Rect<S>) -> Rect<S>
pub fn middle_of(self, other: Rect<S>) -> Rect<S>
Place self
directly in the middle of the other
Rect.
Sourcepub fn subdivision_ranges(&self) -> SubdivisionRanges<S>
pub fn subdivision_ranges(&self) -> SubdivisionRanges<S>
The four ranges used for the Rect
’s four subdivisions.
Sourcepub fn subdivisions(&self) -> [Rect<S>; 4]
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:
- Bottom left
- Bottom right
- Top left
- Top right
Sourcepub fn subdivisions_iter(&self) -> Subdivisions<S> ⓘ
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,
impl<S> Rect<S>where
S: Scalar,
Sourcepub fn from_corner_points(_: [S; 2], _: [S; 2]) -> Rect<S>
pub fn from_corner_points(_: [S; 2], _: [S; 2]) -> Rect<S>
Construct a Rect from the coordinates of two points.
Sourcepub fn absolute(self) -> Rect<S>
pub fn absolute(self) -> Rect<S>
Converts self
to an absolute Rect
so that the magnitude of each range is always
positive.
Sourcepub fn overlap(self, other: Rect<S>) -> Option<Rect<S>>
pub fn overlap(self, other: Rect<S>) -> Option<Rect<S>>
The Rect representing the area in which two Rects overlap.
Sourcepub fn max(self, other: Rect<S>) -> Rect<S>where
S: Float,
pub fn max(self, other: Rect<S>) -> Rect<S>where
S: Float,
The Rect that encompass the two given sets of Rect.
Sourcepub fn l_r_b_t(&self) -> (S, S, S, S)
pub fn l_r_b_t(&self) -> (S, S, S, S)
The edges of the Rect in a tuple (left, right, bottom, top).
Sourcepub fn left_of(self, other: Rect<S>) -> Rect<S>
pub fn left_of(self, other: Rect<S>) -> Rect<S>
Align self
’s right edge with the left edge of the other
Rect.
Sourcepub fn right_of(self, other: Rect<S>) -> Rect<S>
pub fn right_of(self, other: Rect<S>) -> Rect<S>
Align self
’s left edge with the right dge of the other
Rect.
Sourcepub fn below(self, other: Rect<S>) -> Rect<S>
pub fn below(self, other: Rect<S>) -> Rect<S>
Align self
’s top edge with the bottom edge of the other
Rect.
Sourcepub fn above(self, other: Rect<S>) -> Rect<S>
pub fn above(self, other: Rect<S>) -> Rect<S>
Align self
’s bottom edge with the top edge of the other
Rect.
Sourcepub fn align_left_of(self, other: Rect<S>) -> Rect<S>
pub fn align_left_of(self, other: Rect<S>) -> Rect<S>
Align self
’s left edge with the left edge of the other
Rect.
Sourcepub fn align_right_of(self, other: Rect<S>) -> Rect<S>
pub fn align_right_of(self, other: Rect<S>) -> Rect<S>
Align self
’s right edge with the right edge of the other
Rect.
Sourcepub fn align_bottom_of(self, other: Rect<S>) -> Rect<S>
pub fn align_bottom_of(self, other: Rect<S>) -> Rect<S>
Align self
’s bottom edge with the bottom edge of the other
Rect.
Sourcepub fn align_top_of(self, other: Rect<S>) -> Rect<S>
pub fn align_top_of(self, other: Rect<S>) -> Rect<S>
Align self
’s top edge with the top edge of the other
Rect.
Sourcepub fn top_left_of(self, other: Rect<S>) -> Rect<S>
pub fn top_left_of(self, other: Rect<S>) -> Rect<S>
Place self
along the top left edges of the other
Rect.
Sourcepub fn top_right_of(self, other: Rect<S>) -> Rect<S>
pub fn top_right_of(self, other: Rect<S>) -> Rect<S>
Place self
along the top right edges of the other
Rect.
Sourcepub fn bottom_left_of(self, other: Rect<S>) -> Rect<S>
pub fn bottom_left_of(self, other: Rect<S>) -> Rect<S>
Place self
along the bottom left edges of the other
Rect.
Sourcepub fn bottom_right_of(self, other: Rect<S>) -> Rect<S>
pub fn bottom_right_of(self, other: Rect<S>) -> Rect<S>
Place self
along the bottom right edges of the other
Rect.
Sourcepub fn contains_point(self, _: [S; 2]) -> bool
pub fn contains_point(self, _: [S; 2]) -> bool
Does the given point touch the Rectangle.
Sourcepub fn stretch_to_point(self, _: [S; 2]) -> Rect<S>
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.
Sourcepub fn closest_corner(&self, _: [S; 2]) -> Corner
pub fn closest_corner(&self, _: [S; 2]) -> Corner
Return the Corner of self
that is closest to the given Point.
Sourcepub fn corners_iter(&self) -> Corners<S> ⓘ
pub fn corners_iter(&self) -> Corners<S> ⓘ
An iterator yielding the four corners of the Rect
.
Sourcepub fn triangles_iter(self) -> Triangles<[S; 2]> ⓘ
pub fn triangles_iter(self) -> Triangles<[S; 2]> ⓘ
An iterator yielding the Rect
’s two Tri
’s.
Sourcepub fn corner_at_index(&self, index: u8) -> Option<[S; 2]>
pub fn corner_at_index(&self, index: u8) -> Option<[S; 2]>
Produce the corner at the given index.
Source§impl Rect
impl Rect
Sourcepub fn from_xy_wh(p: Vec2, s: Vec2) -> Rect
pub fn from_xy_wh(p: Vec2, s: Vec2) -> Rect
Construct a Rect from a given Point
and Dimensions
.
Sourcepub fn from_corners(a: Vec2, b: Vec2) -> Rect
pub fn from_corners(a: Vec2, b: Vec2) -> Rect
Construct a Rect from the coordinates of two points.
Sourcepub fn bottom_left(&self) -> Vec2
pub fn bottom_left(&self) -> Vec2
The bottom left corner Point.
Sourcepub fn bottom_right(&self) -> Vec2
pub fn bottom_right(&self) -> Vec2
The bottom right corner Point.
Sourcepub fn mid_bottom(&self) -> Vec2
pub fn mid_bottom(&self) -> Vec2
The middle of the bottom edge.
Sourcepub fn stretch_to(self, p: Vec2) -> Rect
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>
impl Rect<f64>
Sourcepub fn from_xy_wh_f64(p: DVec2, s: DVec2) -> Rect<f64>
pub fn from_xy_wh_f64(p: DVec2, s: DVec2) -> Rect<f64>
Construct a Rect from a given Point
and Dimensions
.
Sourcepub fn from_wh_f64(s: DVec2) -> Rect<f64>
pub fn from_wh_f64(s: DVec2) -> Rect<f64>
Construct a Rect at origin with the given dimensions.
Sourcepub fn from_corners_f64(a: DVec2, b: DVec2) -> Rect<f64>
pub fn from_corners_f64(a: DVec2, b: DVec2) -> Rect<f64>
Construct a Rect from the coordinates of two points.
Sourcepub fn bottom_left(&self) -> DVec2
pub fn bottom_left(&self) -> DVec2
The bottom left corner Point.
Sourcepub fn bottom_right(&self) -> DVec2
pub fn bottom_right(&self) -> DVec2
The bottom right corner Point.
Sourcepub fn mid_bottom(&self) -> DVec2
pub fn mid_bottom(&self) -> DVec2
The middle of the bottom edge.
Sourcepub fn stretch_to(self, p: DVec2) -> Rect<f64>
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>
impl<S> Rect<S>
Sourcepub fn l_t_w_h(&self) -> (S, S, S, S)
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.
Sourcepub fn l_b_w_h(&self) -> (S, S, S, S)
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.
Sourcepub fn pad_right(self, pad: S) -> Rect<S>
pub fn pad_right(self, pad: S) -> Rect<S>
The Rect with some padding applied to the right edge.
Sourcepub fn pad_bottom(self, pad: S) -> Rect<S>
pub fn pad_bottom(self, pad: S) -> Rect<S>
The rect with some padding applied to the bottom edge.
Sourcepub fn relative_to_x(self, x: S) -> Rect<S>
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.
Sourcepub fn relative_to_y(self, y: S) -> Rect<S>
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.
Sourcepub fn relative_to(self, _: [S; 2]) -> Rect<S>
pub fn relative_to(self, _: [S; 2]) -> Rect<S>
Returns a Rect
with a position relative to the given position.
Trait Implementations§
Source§impl<S> PartialOrd for Rect<S>where
S: PartialOrd,
impl<S> PartialOrd for Rect<S>where
S: PartialOrd,
impl<S> Copy for Rect<S>where
S: Copy,
impl<S> StructuralPartialEq for Rect<S>
Auto Trait Implementations§
impl<S> Freeze for Rect<S>where
S: Freeze,
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
impl<S, D, Swp, Dwp, T> AdaptInto<D, Swp, Dwp, T> for S
Source§fn adapt_into_using<M>(self, method: M) -> Dwhere
M: TransformMatrix<Swp, Dwp, T>,
fn adapt_into_using<M>(self, method: M) -> Dwhere
M: TransformMatrix<Swp, Dwp, T>,
Source§fn adapt_into(self) -> D
fn adapt_into(self) -> D
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<T, U> ConvertInto<U> for Twhere
U: ConvertFrom<T>,
impl<T, U> ConvertInto<U> for Twhere
U: ConvertFrom<T>,
Source§fn convert_into(self) -> U
fn convert_into(self) -> U
Source§fn convert_unclamped_into(self) -> U
fn convert_unclamped_into(self) -> U
Source§fn try_convert_into(self) -> Result<U, OutOfBounds<U>>
fn try_convert_into(self) -> Result<U, OutOfBounds<U>>
OutOfBounds
error is returned which contains the unclamped color. Read moreSource§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
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 moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
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