pub struct Rect {
pub x: i32,
pub y: i32,
pub width: u32,
pub height: u32,
}Expand description
A rectangle for dirty rect tracking.
§Example
use martensite_devtools::hud::Rect;
let r = Rect::new(10, 20, 100, 200);
assert_eq!(r.area(), 20_000);Fields§
§x: i32X coordinate (pixels from left).
y: i32Y coordinate (pixels from top).
width: u32Width in pixels.
height: u32Height in pixels.
Implementations§
Source§impl Rect
impl Rect
Sourcepub fn new(x: i32, y: i32, width: u32, height: u32) -> Self
pub fn new(x: i32, y: i32, width: u32, height: u32) -> Self
Creates a new rectangle.
§Example
use martensite_devtools::hud::Rect;
let r = Rect::new(0, 0, 100, 100);
assert_eq!(r.area(), 10_000);Sourcepub fn area(&self) -> u64
pub fn area(&self) -> u64
Returns the area of the rectangle in pixels.
§Example
use martensite_devtools::hud::Rect;
assert_eq!(Rect::new(0, 0, 100, 50).area(), 5_000);Sourcepub fn intersects(&self, other: &Rect) -> bool
pub fn intersects(&self, other: &Rect) -> bool
Returns true if this rectangle intersects another.
§Example
use martensite_devtools::hud::Rect;
let a = Rect::new(0, 0, 100, 100);
let b = Rect::new(50, 50, 100, 100);
let c = Rect::new(200, 200, 50, 50);
assert!(a.intersects(&b));
assert!(!a.intersects(&c));Sourcepub fn union(&self, other: &Rect) -> Rect
pub fn union(&self, other: &Rect) -> Rect
Returns the bounding union of two rectangles.
§Example
use martensite_devtools::hud::Rect;
let a = Rect::new(0, 0, 100, 100);
let b = Rect::new(50, 50, 100, 100);
let u = a.union(&b);
assert_eq!(u.x, 0);
assert_eq!(u.y, 0);
assert_eq!(u.width, 150);
assert_eq!(u.height, 150);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 UnsafeUnpin 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