pub struct Rect {
pub top_left: Point,
pub top_right: Point,
pub bottom_right: Point,
pub bottom_left: Point,
pub size: Size,
}Expand description
A rectangle, described by its four corners and a size.
Fields§
§top_left: PointThe top-left corner.
top_right: PointThe top-right corner.
bottom_right: PointThe bottom-right corner.
bottom_left: PointThe bottom-left corner.
size: SizeThe Rectangle’s size.
Implementations§
Source§impl Rect
impl Rect
Sourcepub fn from_size(origin: Point, size: Size) -> Rect
pub fn from_size(origin: Point, size: Size) -> Rect
Construct a Rect from its top-left corner and its size.
§Examples
let rect = Rect::from_size(Point::new(10, 20), Size::new(30, 40));
assert_eq!(rect.top_left, Point::new(10, 20));
assert_eq!(rect.top_right, Point::new(40, 20));
assert_eq!(rect.bottom_left, Point::new(10, 60));
assert_eq!(rect.bottom_right, Point::new(40, 60));
assert_eq!(rect.size, Size::new(30, 40));Sourcepub fn from_points(top_left: Point, bottom_right: Point) -> Rect
pub fn from_points(top_left: Point, bottom_right: Point) -> Rect
Construct a Rect from its top-left and bottom-right corners.
§Examples
let rect = Rect::from_points(Point::new(10, 20), Point::new(30, 40));
assert_eq!(rect.top_left, Point::new(10, 20));
assert_eq!(rect.top_right, Point::new(30, 20));
assert_eq!(rect.bottom_left, Point::new(10, 40));
assert_eq!(rect.bottom_right, Point::new(30, 40));
assert_eq!(rect.size, Size::new(20, 20));Sourcepub fn from_values(x: i32, y: i32, width: i32, height: i32) -> Rect
pub fn from_values(x: i32, y: i32, width: i32, height: i32) -> Rect
Construct a Rect from its top-left corner and its size, values unwrapped.
§Examples
assert_eq!(Rect::from_values(10, 20, 30, 40), Rect::from_size(Point::new(10, 20), Size::new(30, 40)));Sourcepub fn from_point_values(
top_left_x: i32,
top_left_y: i32,
bottom_right_x: i32,
bottom_right_y: i32,
) -> Rect
pub fn from_point_values( top_left_x: i32, top_left_y: i32, bottom_right_x: i32, bottom_right_y: i32, ) -> Rect
Construct a Rect from its top-left and bottom-right corners, values unwrapped.
§Examples
assert_eq!(Rect::from_point_values(10, 20, 30, 40), Rect::from_points(Point::new(10, 20), Point::new(30, 40)));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