pub struct Rect {
pub x0: f32,
pub y0: f32,
pub x1: f32,
pub y1: f32,
}Expand description
An axis-aligned rectangle in logical pixels, stored as its minimum and maximum corners.
x0 and y0 are the top left corner and x1 and y1 are the bottom right
corner. A rectangle is empty when its width or its height is not positive,
which includes the case where the corners are inverted.
Fields§
§x0: f32Horizontal coordinate of the top left corner.
y0: f32Vertical coordinate of the top left corner.
x1: f32Horizontal coordinate of the bottom right corner.
y1: f32Vertical coordinate of the bottom right corner.
Implementations§
Source§impl Rect
impl Rect
Sourcepub const fn new(x0: f32, y0: f32, x1: f32, y1: f32) -> Rect
pub const fn new(x0: f32, y0: f32, x1: f32, y1: f32) -> Rect
Creates a rectangle from its minimum and maximum corners.
Sourcepub fn from_origin_size(origin: Point, size: Size) -> Rect
pub fn from_origin_size(origin: Point, size: Size) -> Rect
Creates a rectangle from its top left corner and its size.
Sourcepub fn width(self) -> f32
pub fn width(self) -> f32
Returns the horizontal extent, which is not positive when the rectangle is empty.
Sourcepub fn height(self) -> f32
pub fn height(self) -> f32
Returns the vertical extent, which is not positive when the rectangle is empty.
Sourcepub fn is_empty(self) -> bool
pub fn is_empty(self) -> bool
Returns true when the rectangle covers no area.
A rectangle is empty when its width or its height is not positive, and when either extent is NaN.
Sourcepub fn area(self) -> f32
pub fn area(self) -> f32
Returns the area in square logical pixels, or zero when the rectangle is empty.
Sourcepub fn contains(self, point: Point) -> bool
pub fn contains(self, point: Point) -> bool
Returns true when the point lies inside the rectangle or on its edge.
An empty rectangle contains no point.
Sourcepub fn translated(self, by: Point) -> Rect
pub fn translated(self, by: Point) -> Rect
Returns the rectangle moved by by.