#[repr(C)]pub struct Rectf {
pub left: f32,
pub top: f32,
pub right: f32,
pub bottom: f32,
}Expand description
Represents a rectangle defined by the coordinates of the upper-left corner (left, top) and the coordinates of the lower-right corner (right, bottom).
Fields§
§left: f32The x-coordinate of the left edge of the rectangle.
top: f32The y-coordinate of the top edge of the rectangle.
right: f32The x-coordinate of the right edge of the rectangle.
bottom: f32The y-coordinate of the bottom edge of the rectangle.
Implementations§
Source§impl Rectf
impl Rectf
Sourcepub fn new(left: f32, top: f32, right: f32, bottom: f32) -> Rectf
pub fn new(left: f32, top: f32, right: f32, bottom: f32) -> Rectf
Constructs the rectangle from components.
Sourcepub fn from_points(p1: impl Into<Point2f>, p2: impl Into<Point2f>) -> Rectf
pub fn from_points(p1: impl Into<Point2f>, p2: impl Into<Point2f>) -> Rectf
Constructs a rectangle that will encompass all of the axis-aligned space between the two provided points.
Sourcepub fn from_center_size(
center: impl Into<Point2f>,
size: impl Into<Sizef>,
) -> Rectf
pub fn from_center_size( center: impl Into<Point2f>, size: impl Into<Sizef>, ) -> Rectf
Constructs a rectangle given its desired center point and desired width and height.
Sourcepub fn from_center_half_extent(
center: impl Into<Point2f>,
half_extents: impl Into<Vector2f>,
) -> Rectf
pub fn from_center_half_extent( center: impl Into<Point2f>, half_extents: impl Into<Vector2f>, ) -> Rectf
Constructs a rectangle given its desired center and the desired distance from the center to the corners.
Sourcepub fn to_i32(&self) -> Recti
pub fn to_i32(&self) -> Recti
Converts this rectangle’s components to signed integers. Truncates values, perform manual rounding if you would like a different behavior.
Sourcepub fn to_u32(&self) -> Rectu
pub fn to_u32(&self) -> Rectu
Converts the components of the rectangle to unsigned integers. Beware this conversion if the components could be negative, you will experience unsigned casting underflow.
Sourcepub fn rounded(&self) -> Rectf
pub fn rounded(&self) -> Rectf
Rounds the components to the nearest integers, rounding half-way values away from zero.
Sourcepub fn half_extent(&self) -> Vector2f
pub fn half_extent(&self) -> Vector2f
Gets the half-extent of the rectangle i.e. the vector from the center to the most-positive corner.
Sourcepub fn corner(&self, corner: RectCorner) -> Point2f
pub fn corner(&self, corner: RectCorner) -> Point2f
Get the point of the specified corner.
Sourcepub fn contains_point(&self, point: impl Into<Point2f>) -> bool
pub fn contains_point(&self, point: impl Into<Point2f>) -> bool
Determines if the specified point is located inside the rectangle.
Sourcepub fn normalized(self) -> Self
pub fn normalized(self) -> Self
Normalizes the rectangle to enforce the invariants
left < right and top < bottom.
Sourcepub fn translated_by(self, translation: impl Into<Vector2f>) -> Self
pub fn translated_by(self, translation: impl Into<Vector2f>) -> Self
Translates the rectangle by the given vector.
Sourcepub fn expanded_by(self, thickness: impl Into<Thicknessf>) -> Self
pub fn expanded_by(self, thickness: impl Into<Thicknessf>) -> Self
Expands the rectangle by the given margin.
Sourcepub fn shrunken_by(self, thickness: impl Into<Thicknessf>) -> Self
pub fn shrunken_by(self, thickness: impl Into<Thicknessf>) -> Self
Shrinks the rectangle by the given margin.
Sourcepub fn combined_with(&self, other: impl Into<Rectf>) -> Self
pub fn combined_with(&self, other: impl Into<Rectf>) -> Self
Constructs a rectangle that contains both rectangles. Normalizes both arguments before performing the operation.