pub struct Rect {
pub x: i32,
pub y: i32,
pub w: u32,
pub h: u32,
}
Expand description
Fields§
§x: i32
X-Coordinate, can be negative
y: i32
Y-Coordinate, can be negative
w: u32
Width, can not be negative
h: u32
Height, can not be negative
Implementations§
Source§impl Rect
impl Rect
Sourcepub fn new(x: i32, y: i32, w: u32, h: u32) -> Self
pub fn new(x: i32, y: i32, w: u32, h: u32) -> Self
Shorthand method to create a new Rect
with
the provided x
, y
, w
, and h
.
Sourcepub fn surface_area(&self) -> u32
pub fn surface_area(&self) -> u32
Calculate the surface area of the Rect
Sourcepub fn center(&self) -> (i32, i32)
pub fn center(&self) -> (i32, i32)
Get the coordinate at the center of the Rect
.
The center coordinate is rounded to the nearest integer and might not be at the exact center position.
Sourcepub fn top_left_corner(&self) -> (i32, i32)
pub fn top_left_corner(&self) -> (i32, i32)
Get the top left corner point of the Rect
.
O---------+
| |
| |
| |
+---------+
Sourcepub fn top_right_corner(&self) -> (i32, i32)
pub fn top_right_corner(&self) -> (i32, i32)
Get the top right corner point of the Rect
.
+---------O
| |
| |
| |
+---------+
Sourcepub fn bottom_right_corner(&self) -> (i32, i32)
pub fn bottom_right_corner(&self) -> (i32, i32)
Get the bottom right corner point of the Rect
.
+---------+
| |
| |
| |
+---------O
Sourcepub fn bottom_left_corner(&self) -> (i32, i32)
pub fn bottom_left_corner(&self) -> (i32, i32)
Get the bottom left corner point of the Rect
.
+---------+
| |
| |
| |
O---------+
Sourcepub fn top_edge(&self) -> i32
pub fn top_edge(&self) -> i32
Get the top edge of the Rect
.
^
|
V
+---------+
| |
| |
| |
+---------+
Sourcepub fn right_edge(&self) -> i32
pub fn right_edge(&self) -> i32
Get the right edge of the Rect
.
<--------->
+---------+
| |
| |
| |
+---------+
Sourcepub fn bottom_edge(&self) -> i32
pub fn bottom_edge(&self) -> i32
Get the bottom edge of the Rect
.
+---------+ ^
| | |
| | |
| | |
+---------+ V
Trait Implementations§
impl Copy for Rect
impl Eq for Rect
impl 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 UnwindSafe for Rect
Blanket Implementations§
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
Mutably borrows from an owned value. Read more