pub struct Rectangle {
pub pos: Vector,
pub size: Vector,
}
Expand description
A rectangle with a top-left position and a size
Fields§
§pos: Vector
The top-left coordinate of the rectangle
size: Vector
The width and height of the rectangle
Implementations§
Source§impl Rectangle
impl Rectangle
Sourcepub fn new(pos: Vector, size: Vector) -> Rectangle
pub fn new(pos: Vector, size: Vector) -> Rectangle
Create a rectangle from a top-left vector and a size vector
Sourcepub fn new_sized(size: Vector) -> Rectangle
pub fn new_sized(size: Vector) -> Rectangle
Create a rectangle at the origin with the given size
Sourcepub fn x(&self) -> f32
pub fn x(&self) -> f32
Get the x-coordinate of the Rectangle (The origin of a Rectangle is at the top left)
Trait Implementations§
Source§impl Shape for Rectangle
impl Shape for Rectangle
Source§fn overlaps_circle(&self, c: &Circle) -> bool
fn overlaps_circle(&self, c: &Circle) -> bool
If any area is bounded by both the shape and the circle
Source§fn overlaps_rectangle(&self, b: &Rectangle) -> bool
fn overlaps_rectangle(&self, b: &Rectangle) -> bool
If any area is bounded by both the shape and the rectangle
Source§fn intersects(&self, l: &Line) -> bool
fn intersects(&self, l: &Line) -> bool
If any area bounded by the shape falls on the line
Source§fn overlaps(&self, shape: &impl Shape) -> bool
fn overlaps(&self, shape: &impl Shape) -> bool
👎Deprecated since 0.4.0-alpha0.5: Use another collision library like
vek
instead; please comment on issue #552 for use-cases other libraries don’t solveIf any area is bounded by both either shape
Source§fn bounding_box(&self) -> Rectangle
fn bounding_box(&self) -> Rectangle
A Rectangle that contains the entire shape
Source§fn transformed_bounding_box(&self, transform: Transform) -> Rectangle
fn transformed_bounding_box(&self, transform: Transform) -> Rectangle
👎Deprecated since 0.4.0-alpha0.5: Use another collision library like
vek
instead; please comment on issue #552 for use-cases other libraries don’t solveApply a transform to a shape then get the bounding box for the transformed shape Read more
Source§fn constrain(&self, outer: &Rectangle) -> Selfwhere
Self: Sized,
fn constrain(&self, outer: &Rectangle) -> Selfwhere
Self: Sized,
Create a copy of the shape that is contained within the bound
Source§fn with_center(&self, center: Vector) -> Selfwhere
Self: Sized,
fn with_center(&self, center: Vector) -> Selfwhere
Self: Sized,
Create a copy of the shape with an offset center
impl Copy for Rectangle
impl Eq 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 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