Struct Rect2
#[repr(C)]pub struct Rect2 {
pub position: Vector2,
pub size: Vector2,
}
Expand description
2D axis-aligned bounding box.
Rect2
consists of a position, a size, and several utility functions. It is typically used for
fast overlap tests.
§All bounding-box types
You can convert to Rect2i
using cast_int()
.
§Godot docs
Fields§
§position: Vector2
§size: Vector2
Implementations§
§impl Rect2
impl Rect2
pub const fn new(position: Vector2, size: Vector2) -> Rect2
pub const fn new(position: Vector2, size: Vector2) -> Rect2
Create a new Rect2
from a position and a size.
Godot equivalent: Rect2(Vector2 position, Vector2 size)
pub fn from_corners(position: Vector2, end: Vector2) -> Rect2
pub fn from_corners(position: Vector2, end: Vector2) -> Rect2
Create a new Rect2
with the first corner at position
and the opposite corner at end
.
pub const fn from_components(x: f32, y: f32, width: f32, height: f32) -> Rect2
pub const fn from_components(x: f32, y: f32, width: f32, height: f32) -> Rect2
Create a new Rect2
from four reals representing position (x,y)
and size (width,height)
.
Godot equivalent: Rect2(float x, float y, float width, float height)
pub const fn from_rect2i(rect: Rect2i) -> Rect2
Rect2i::cast_float()
pub const fn cast_int(self) -> Rect2i
pub const fn cast_int(self) -> Rect2i
Create a new Rect2i
from a Rect2
, using as
for real
to i32
conversions.
Godot equivalent: Rect2i(Rect2 from)
pub fn abs(self) -> Rect2
pub fn abs(self) -> Rect2
Returns a rectangle with the same geometry, with top-left corner as position
and non-negative size.
pub fn encloses(self, b: Rect2) -> bool
pub fn encloses(self, b: Rect2) -> bool
Whether self
covers at least the entire area of b
(and possibly more).
pub fn expand(self, to: Vector2) -> Rect2
pub fn expand(self, to: Vector2) -> Rect2
Returns a copy of this rectangle expanded to include a given point.
Note: This method is not reliable for Rect2
with a negative size. Use abs
to get a positive sized equivalent rectangle for expanding.
pub fn merge(self, b: Rect2) -> Rect2
pub fn merge(self, b: Rect2) -> Rect2
Returns a larger rectangle that contains this Rect2
and b
.
Note: This method is not reliable for Rect2
with a negative size. Use abs
to get a positive sized equivalent rectangle for merging.
pub fn center(self) -> Vector2
pub fn center(self) -> Vector2
Returns the center of the Rect2, which is equal to position + (size / 2)
.
pub fn grow(self, amount: f32) -> Rect2
pub fn grow(self, amount: f32) -> Rect2
Returns a copy of the Rect2 grown by the specified amount
on all sides.
pub fn grow_individual(
self,
left: f32,
top: f32,
right: f32,
bottom: f32,
) -> Rect2
pub fn grow_individual( self, left: f32, top: f32, right: f32, bottom: f32, ) -> Rect2
Returns a copy of the Rect2 grown by the specified amount on each side individually.
pub fn grow_side(self, side: Side, amount: f32) -> Rect2
pub fn grow_side(self, side: Side, amount: f32) -> Rect2
Returns a copy of the Rect2
grown by the specified amount
on the specified RectSide
.
amount
may be negative, but care must be taken: If the resulting size
has
negative components the computation may be incorrect.
pub fn has_area(self) -> bool
pub fn has_area(self) -> bool
Returns true
if the Rect2 has area, and false
if the Rect2 is linear, empty, or has a negative size. See also get_area
.
pub fn has_point(self, point: Vector2) -> bool
pub fn has_point(self, point: Vector2) -> bool
Returns true
if the Rect2 contains a point. By convention, the right and bottom edges of the Rect2 are considered exclusive, so points on these edges are not included.
Note: This method is not reliable for Rect2 with a negative size. Use abs
to get a positive sized equivalent rectangle to check for contained points.
pub fn intersection(self, b: Rect2) -> Option<Rect2>
pub fn intersection(self, b: Rect2) -> Option<Rect2>
Returns the intersection of this Rect2 and b
. If the rectangles do not intersect, an empty Rect2 is returned.
pub fn intersects(self, b: Rect2) -> bool
pub fn intersects(self, b: Rect2) -> bool
Checks whether two rectangles have at least one point in common.
Also returns true
if the rects only touch each other (share a point/edge).
See intersects_exclude_borders
if you want to return false
in that case.
Godot equivalent: Rect2.intersects(Rect2 b, bool include_borders = true)
pub fn intersects_exclude_borders(self, b: Rect2) -> bool
pub fn intersects_exclude_borders(self, b: Rect2) -> bool
Checks whether two rectangles have at least one inner point in common (not on the borders).
Returns false
if the rects only touch each other (share a point/edge).
See intersects
if you want to return true
in that case.
Godot equivalent: Rect2.intersects(AABB b, bool include_borders = false)
pub fn is_finite(self) -> bool
pub fn is_finite(self) -> bool
Returns true
if this Rect2 is finite, by calling @GlobalScope.is_finite
on each component.
pub fn assert_nonnegative(self)
pub fn assert_nonnegative(self)
Assert that the size of the Rect2
is not negative.
Certain functions will fail to give a correct result if the size is negative.
Trait Implementations§
§impl ApiParam for Rect2
impl ApiParam for Rect2
§fn owned_to_arg<'v>(self) -> <Rect2 as ApiParam>::Arg<'v>
fn owned_to_arg<'v>(self) -> <Rect2 as ApiParam>::Arg<'v>
impl AsArg<T>
. Read more§impl ArrayElement for Rect2
impl ArrayElement for Rect2
fn debug_validate_elements(_array: &Array<Self>) -> Result<(), ConvertError>
§impl Export for Rect2
impl Export for Rect2
§fn export_hint() -> PropertyHintInfo
fn export_hint() -> PropertyHintInfo
§fn as_node_class() -> Option<ClassName>
fn as_node_class() -> Option<ClassName>
§impl FromGodot for Rect2
impl FromGodot for Rect2
§fn try_from_godot(
via: <Rect2 as GodotConvert>::Via,
) -> Result<Rect2, ConvertError>
fn try_from_godot( via: <Rect2 as GodotConvert>::Via, ) -> Result<Rect2, ConvertError>
Err
on failure.§fn from_godot(via: Self::Via) -> Self
fn from_godot(via: Self::Via) -> Self
§fn try_from_variant(variant: &Variant) -> Result<Self, ConvertError>
fn try_from_variant(variant: &Variant) -> Result<Self, ConvertError>
Variant
, returning Err
on failure.§fn from_variant(variant: &Variant) -> Self
fn from_variant(variant: &Variant) -> Self
§impl Mul<Rect2> for Transform2D
impl Mul<Rect2> for Transform2D
§impl ToGodot for Rect2
impl ToGodot for Rect2
§impl Var for Rect2
impl Var for Rect2
fn get_property(&self) -> <Rect2 as GodotConvert>::Via
fn set_property(&mut self, value: <Rect2 as GodotConvert>::Via)
§fn var_hint() -> PropertyHintInfo
fn var_hint() -> PropertyHintInfo
GodotType::property_info
, e.g. for enums/newtypes.impl AsArg<Rect2> for Rect2
impl Copy for Rect2
impl GodotType for Rect2
impl StructuralPartialEq for Rect2
Auto Trait Implementations§
impl Freeze for Rect2
impl RefUnwindSafe for Rect2
impl Send for Rect2
impl Sync for Rect2
impl Unpin for Rect2
impl UnwindSafe for Rect2
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
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§unsafe fn clone_to_uninit(&self, dst: *mut T)
unsafe fn clone_to_uninit(&self, dst: *mut T)
clone_to_uninit
)