Rect
struct · ferroui-base · v0.5.0
struct Rect
Defines a rectangle.
Members
xywidthheightnewfrom_sizefrom_position_sizefrom_pointspositionsizerightbottomlefttoptop_lefttop_rightbottom_leftbottom_rightcentercontainscontains_exclusivecontains_rectcenter_rectinflateinflate_thicknessdeflatedeflate_thicknessequalsintersectintersectstransform_to_aabbtranslatenormalizeunionunion_optionalwith_xwith_ywith_widthwith_heightparseis_empty
x
x: f64
The X position.
y
y: f64
The Y position.
width
width: f64
The width.
height
height: f64
The height.
new
const fn new(x: f64, y: f64, width: f64, height: f64) -> Self
Initializes a new instance of the Rect structure.
from_size
const fn from_size(size: Size) -> Self
Initializes a Rect at the origin with the given size.
from_position_size
const fn from_position_size(position: Point, size: Size) -> Self
Initializes a Rect from its position and size.
from_points
fn from_points(top_left: Point, bottom_right: Point) -> Self
Initializes a Rect from its top left and bottom right corners.
position
const fn position(self: &Self) -> Point
Gets the position of the rectangle.
size
const fn size(self: &Self) -> Size
Gets the size of the rectangle.
right
fn right(self: &Self) -> f64
Gets the right position of the rectangle.
bottom
fn bottom(self: &Self) -> f64
Gets the bottom position of the rectangle.
left
const fn left(self: &Self) -> f64
Gets the left position.
top
const fn top(self: &Self) -> f64
Gets the top position.
top_left
const fn top_left(self: &Self) -> Point
Gets the top left point of the rectangle.
top_right
fn top_right(self: &Self) -> Point
Gets the top right point of the rectangle.
bottom_left
fn bottom_left(self: &Self) -> Point
Gets the bottom left point of the rectangle.
bottom_right
fn bottom_right(self: &Self) -> Point
Gets the bottom right point of the rectangle.
center
fn center(self: &Self) -> Point
Gets the center point of the rectangle.
contains
fn contains(self: &Self, p: Point) -> bool
Determines whether a point is in the bounds of the rectangle (edges inclusive).
contains_exclusive
fn contains_exclusive(self: &Self, p: Point) -> bool
Determines whether a point is in the bounds of the rectangle, exclusive of the rectangle's bottom/right edge.
contains_rect
fn contains_rect(self: &Self, r: Rect) -> bool
Determines whether the rectangle fully contains another rectangle.
center_rect
fn center_rect(self: &Self, rect: Rect) -> Rect
Centers another rectangle in this rectangle.
inflate
fn inflate(self: &Self, thickness: f64) -> Rect
Inflates the rectangle by the same amount on every side.
inflate_thickness
fn inflate_thickness(self: &Self, thickness: Thickness) -> Rect
Inflates the rectangle.
deflate
fn deflate(self: &Self, thickness: f64) -> Rect
Deflates the rectangle by the same amount on every side.
deflate_thickness
fn deflate_thickness(self: &Self, thickness: Thickness) -> Rect
Deflates the rectangle by a Thickness. The deflated rectangle size
cannot be less than 0.
equals
fn equals(self: &Self, other: Rect) -> bool
Returns a boolean indicating whether the rect is equal to the other given rect (exact comparison).
intersect
fn intersect(self: &Self, rect: Rect) -> Rect
Gets the intersection of two rectangles, or an empty (default) rectangle if they do not overlap.
intersects
fn intersects(self: &Self, rect: Rect) -> bool
Determines whether a rectangle intersects with this rectangle.
transform_to_aabb
fn transform_to_aabb(self: &Self, matrix: Matrix) -> Rect
Returns the axis-aligned bounding box of a transformed rectangle.
translate
fn translate(self: &Self, offset: Vector) -> Rect
Translates the rectangle by an offset.
normalize
fn normalize(self: &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.
union
fn union(self: &Self, rect: Rect) -> Rect
Gets the union of two rectangles. A rectangle whose width and height are both zero is ignored.
union_optional
fn union_optional(left: Option<Rect>, right: Option<Rect>) -> Option<Rect>
Union of two optional rectangles; a missing side yields the other side.
with_x
const fn with_x(self: &Self, x: f64) -> Rect
Returns a new Rect with the specified X position.
with_y
const fn with_y(self: &Self, y: f64) -> Rect
Returns a new Rect with the specified Y position.
with_width
const fn with_width(self: &Self, width: f64) -> Rect
Returns a new Rect with the specified width.
with_height
const fn with_height(self: &Self, height: f64) -> Rect
Returns a new Rect with the specified height.
parse
fn parse(s: &str) -> Result<Self, FormatError>
Parses a Rect string ("x, y, width, height").
is_empty
fn is_empty(self: &Self) -> bool
This method should be used internally to check for the rect emptiness. Once a dedicated "empty" value exists this is the single place to update.
Trait implementations
SendSyncFreezeUnsafeUnpinUnpinUnwindSafeRefUnwindSafePropertyValueAnyValueClassDefaultsBorrow<T>BorrowMut<T>CloneToUninitInto<U>From<T>TryInto<U>TryFrom<U>AnyToOwnedToStringErasedDestructorIntoEitherFrom<Rect>BatchValueMarkupTypedValueTypeRegistrationCloneCopyDebugStructuralPartialEqPartialEqDefaultMul<Vector>Mul<f64>Div<Vector>MulAssign<Vector>MulAssign<f64>DivAssign<Vector>FromStrDisplay
Availability
Extracted for aarch64-apple-darwin. Cargo features are listed in the crate index.