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().
§Soft invariants
Rect2 requires non-negative size for certain operations, which is validated only on a best-effort basis. Violations may
cause panics in Debug mode. See also Builtin API design.
§Godot docs
Fields§
§position: Vector2§size: Vector2Implementations§
§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 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 contains_point(self, point: Vector2) -> bool
pub fn contains_point(self, point: Vector2) -> bool
Returns true if the Rect2 contains a point (excluding right/bottom edges).
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 intersect(self, b: Rect2) -> Option<Rect2>
pub fn intersect(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 DynamicSend for Rect2
impl DynamicSend for Rect2
type Inner = Rect2
fn extract_if_safe(self) -> Option<<Rect2 as DynamicSend>::Inner>
§impl Export for Rect2
impl Export for Rect2
§fn export_hint() -> PropertyHintInfo
fn export_hint() -> PropertyHintInfo
§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 GodotImmutable for Rect2
impl GodotImmutable for Rect2
fn into_runtime_immutable(self) -> Self
§impl IntoDynamicSend for Rect2
impl IntoDynamicSend for Rect2
type Target = Rect2
fn into_dynamic_send(self) -> <Rect2 as IntoDynamicSend>::Target
§impl Mul<Rect2> for Transform2D
impl Mul<Rect2> for Transform2D
§impl ToGodot for Rect2
impl ToGodot for Rect2
§fn to_godot(&self) -> <Rect2 as GodotConvert>::Via
fn to_godot(&self) -> <Rect2 as GodotConvert>::Via
§fn to_godot_owned(&self) -> Self::Via
fn to_godot_owned(&self) -> Self::Via
§fn to_variant(&self) -> Variant
fn to_variant(&self) -> Variant
§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 XformInv<Rect2> for Transform2D
impl XformInv<Rect2> for Transform2D
§fn xform_inv(&self, rhs: Rect2) -> Rect2
fn xform_inv(&self, rhs: Rect2) -> Rect2
Inversely transforms (multiplies) the given Rect2 by this Transform2D transformation matrix, under the assumption that the transformation basis is orthonormal (i.e. rotation/reflection is fine, scaling/skew is not).
For transforming by inverse of an affine transformation (e.g. with scaling) transform.affine_inverse() * vector can be used instead. See: Transform2D::affine_inverse().
Godot equivalent: rect2 * transform or transform.inverse() * rect2
impl ArrayElement for Rect2
impl BuiltinExport 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§
§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
§unsafe fn clone_to_uninit(&self, dest: *mut u8)
unsafe fn clone_to_uninit(&self, dest: *mut u8)
clone_to_uninit)