pub struct Rect {
pub x: f64,
pub y: f64,
pub width: f64,
pub height: f64,
}Expand description
Defines a rectangle.
Fields§
§x: f64The X position.
y: f64The Y position.
width: f64The width.
height: f64The height.
Implementations§
Source§impl Rect
impl Rect
Sourcepub const fn new(x: f64, y: f64, width: f64, height: f64) -> Self
pub const fn new(x: f64, y: f64, width: f64, height: f64) -> Self
Initializes a new instance of the Rect structure.
Sourcepub const fn from_size(size: Size) -> Self
pub const fn from_size(size: Size) -> Self
Initializes a Rect at the origin with the given size.
Sourcepub const fn from_position_size(position: Point, size: Size) -> Self
pub const fn from_position_size(position: Point, size: Size) -> Self
Initializes a Rect from its position and size.
Sourcepub fn from_points(top_left: Point, bottom_right: Point) -> Self
pub fn from_points(top_left: Point, bottom_right: Point) -> Self
Initializes a Rect from its top left and bottom right corners.
Sourcepub fn bottom_left(&self) -> Point
pub fn bottom_left(&self) -> Point
Gets the bottom left point of the rectangle.
Sourcepub fn bottom_right(&self) -> Point
pub fn bottom_right(&self) -> Point
Gets the bottom right point of the rectangle.
Sourcepub fn contains(&self, p: Point) -> bool
pub fn contains(&self, p: Point) -> bool
Determines whether a point is in the bounds of the rectangle (edges inclusive).
Sourcepub fn contains_exclusive(&self, p: Point) -> bool
pub fn contains_exclusive(&self, p: Point) -> bool
Determines whether a point is in the bounds of the rectangle, exclusive of the rectangle’s bottom/right edge.
Sourcepub fn contains_rect(&self, r: Rect) -> bool
pub fn contains_rect(&self, r: Rect) -> bool
Determines whether the rectangle fully contains another rectangle.
Sourcepub fn center_rect(&self, rect: Rect) -> Rect
pub fn center_rect(&self, rect: Rect) -> Rect
Centers another rectangle in this rectangle.
Sourcepub fn inflate(&self, thickness: f64) -> Rect
pub fn inflate(&self, thickness: f64) -> Rect
Inflates the rectangle by the same amount on every side.
Sourcepub fn inflate_thickness(&self, thickness: Thickness) -> Rect
pub fn inflate_thickness(&self, thickness: Thickness) -> Rect
Inflates the rectangle.
Sourcepub fn deflate(&self, thickness: f64) -> Rect
pub fn deflate(&self, thickness: f64) -> Rect
Deflates the rectangle by the same amount on every side.
Sourcepub fn deflate_thickness(&self, thickness: Thickness) -> Rect
pub fn deflate_thickness(&self, thickness: Thickness) -> Rect
Deflates the rectangle by a Thickness. The deflated rectangle size
cannot be less than 0.
Sourcepub fn equals(&self, other: Rect) -> bool
pub fn equals(&self, other: Rect) -> bool
Returns a boolean indicating whether the rect is equal to the other given rect (exact comparison).
Sourcepub fn intersect(&self, rect: Rect) -> Rect
pub fn intersect(&self, rect: Rect) -> Rect
Gets the intersection of two rectangles, or an empty (default) rectangle if they do not overlap.
Sourcepub fn intersects(&self, rect: Rect) -> bool
pub fn intersects(&self, rect: Rect) -> bool
Determines whether a rectangle intersects with this rectangle.
Sourcepub fn transform_to_aabb(&self, matrix: Matrix) -> Rect
pub fn transform_to_aabb(&self, matrix: Matrix) -> Rect
Returns the axis-aligned bounding box of a transformed rectangle.
Sourcepub fn normalize(&self) -> Rect
pub fn normalize(&self) -> Rect
Normalizes the rectangle so both the width and height are positive, without changing its location: positive-size rects are returned unchanged, negative sizes are flipped. A rect with any NaN edge becomes the default rect.
Sourcepub fn union(&self, rect: Rect) -> Rect
pub fn union(&self, rect: Rect) -> Rect
Gets the union of two rectangles. A rectangle whose width and height are both zero is ignored.
Sourcepub fn union_optional(left: Option<Rect>, right: Option<Rect>) -> Option<Rect>
pub fn union_optional(left: Option<Rect>, right: Option<Rect>) -> Option<Rect>
Union of two optional rectangles; a missing side yields the other side.
Sourcepub const fn with_width(&self, width: f64) -> Rect
pub const fn with_width(&self, width: f64) -> Rect
Returns a new Rect with the specified width.
Sourcepub const fn with_height(&self, height: f64) -> Rect
pub const fn with_height(&self, height: f64) -> Rect
Returns a new Rect with the specified height.
Trait Implementations§
Source§impl BatchValue for Rect
impl BatchValue for Rect
impl Copy for Rect
Source§impl DivAssign<Vector> for Rect
impl DivAssign<Vector> for Rect
Source§fn div_assign(&mut self, scale: Vector)
fn div_assign(&mut self, scale: Vector)
/= operation. Read moreSource§impl From<Rect> for RoundedRect
impl From<Rect> for RoundedRect
Source§fn from(r: Rect) -> RoundedRect
fn from(r: Rect) -> RoundedRect
Source§impl MarkupTyped for Rect
impl MarkupTyped for Rect
Source§const MARKUP: &'static MarkupType
const MARKUP: &'static MarkupType
Source§impl MulAssign<Vector> for Rect
impl MulAssign<Vector> for Rect
Source§fn mul_assign(&mut self, scale: Vector)
fn mul_assign(&mut self, scale: Vector)
*= operation. Read moreSource§impl MulAssign<f64> for Rect
impl MulAssign<f64> for Rect
Source§fn mul_assign(&mut self, scale: f64)
fn mul_assign(&mut self, scale: f64)
*= operation. Read moreimpl 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 UnsafeUnpin for Rect
impl UnwindSafe for Rect
Blanket Implementations§
Source§impl<T> AnyValue for Twhere
T: PartialEq + 'static,
impl<T> AnyValue for Twhere
T: PartialEq + 'static,
fn any_value_as_any(&self) -> &(dyn Any + 'static)
fn any_value_eq(&self, other: &(dyn AnyValue + 'static)) -> bool
fn any_value_type_name(&self) -> &'static str
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> ClassDefaults for Twhere
T: ?Sized,
impl<T> ClassDefaults for Twhere
T: ?Sized,
Source§fn static_constructor()
fn static_constructor()
affects_render, metadata
overrides). Read more