#[repr(C)]pub struct Rectangle {
pub x: f32,
pub y: f32,
pub width: f32,
pub height: f32,
}Expand description
An axis-aligned rectangle defined by its top-left corner and dimensions.
Rectangle is a #[repr(C)] struct with four f32 fields: x and y for the top-left
corner position, and width / height for the extents. It maps directly to raylib’s
Rectangle type in C.
Collision and containment helpers are available as methods:
check_collision_recs,
check_collision_point_rec,
get_collision_rec,
check_collision_circle_rec.
§Examples
use raylib_sys::Rectangle;
let r1 = Rectangle::new(0.0, 0.0, 10.0, 10.0);
let r2 = Rectangle::new(5.0, 5.0, 10.0, 10.0);
let r3 = Rectangle::new(20.0, 20.0, 10.0, 10.0);
assert!(r1.check_collision_recs(r2)); // overlapping
assert!(!r1.check_collision_recs(r3)); // non-overlappingFields§
§x: f32§y: f32§width: f32§height: f32Implementations§
Source§impl Rectangle
impl Rectangle
pub fn new(x: f32, y: f32, width: f32, height: f32) -> Self
Sourcepub fn check_collision_recs(&self, other: Rectangle) -> bool
pub fn check_collision_recs(&self, other: Rectangle) -> bool
Check collision between two rectangles
Sourcepub fn check_collision_circle_rec(
&self,
center: impl Into<Vector2>,
radius: f32,
) -> bool
pub fn check_collision_circle_rec( &self, center: impl Into<Vector2>, radius: f32, ) -> bool
Checks collision between circle and rectangle.
Sourcepub fn get_collision_rec(&self, other: Rectangle) -> Option<Rectangle>
pub fn get_collision_rec(&self, other: Rectangle) -> Option<Rectangle>
Gets the overlap between two colliding rectangles.
use raylib_sys::Rectangle;
let r1 = Rectangle::new(0.0, 0.0, 10.0, 10.0);
let r2 = Rectangle::new(20.0, 20.0, 10.0, 10.0);
assert_eq!(None, r1.get_collision_rec(r2));
assert_eq!(Some(r1), r1.get_collision_rec(r1));Sourcepub fn check_collision_point_rec(&self, point: impl Into<Vector2>) -> bool
pub fn check_collision_point_rec(&self, point: impl Into<Vector2>) -> bool
Checks if point is inside rectangle.
Trait Implementations§
impl Copy for Rectangle
impl StructuralPartialEq for Rectangle
Auto Trait Implementations§
impl Freeze for Rectangle
impl RefUnwindSafe for Rectangle
impl Send for Rectangle
impl Sync for Rectangle
impl Unpin for Rectangle
impl UnsafeUnpin for Rectangle
impl UnwindSafe for Rectangle
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