Struct Rect2i
#[repr(C)]pub struct Rect2i {
pub position: Vector2i,
pub size: Vector2i,
}Expand description
2D axis-aligned integer bounding box.
Rect2i 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 Rect2 using cast_float().
§Soft invariants
Rect2i 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: Vector2iThe position of the rectangle.
size: Vector2iThe size of the rectangle.
Implementations§
§impl Rect2i
impl Rect2i
pub const fn new(position: Vector2i, size: Vector2i) -> Rect2i
pub const fn new(position: Vector2i, size: Vector2i) -> Rect2i
Create a new Rect2i from a position and a size.
Godot equivalent: Rect2i(Vector2i position, Vector2i size)
pub const fn from_components(x: i32, y: i32, width: i32, height: i32) -> Rect2i
pub const fn from_components(x: i32, y: i32, width: i32, height: i32) -> Rect2i
Create a new Rect2i from four i32s representing position (x,y) and size (width,height).
Godot equivalent: Rect2i(float x, float y, float width, float height)
pub fn from_corners(position: Vector2i, end: Vector2i) -> Rect2i
pub fn from_corners(position: Vector2i, end: Vector2i) -> Rect2i
Create a new Rect2i with the first corner at position and the opposite corner at end.
pub const fn cast_float(self) -> Rect2
pub const fn cast_float(self) -> Rect2
Create a new Rect2 from a Rect2i, using as for i32 to real conversions.
Godot equivalent: Rect2(Rect2i from)
pub fn abs(self) -> Rect2i
pub fn abs(self) -> Rect2i
Returns a Rect2i with equivalent position and area, modified so that the top-left corner
is the origin and width and height are positive.
pub const fn encloses(self, other: Rect2i) -> bool
pub const fn encloses(self, other: Rect2i) -> bool
Returns true if this Rect2i completely encloses another one.
Any Rect2i encloses itself, i.e. an enclosed Rect2i does is not required to be a proper sub-rect.
pub fn expand(self, to: Vector2i) -> Rect2i
pub fn expand(self, to: Vector2i) -> Rect2i
Returns a copy of this Rect2i expanded so that the borders align with the given point.
pub const fn area(self) -> i32
pub const fn area(self) -> i32
Returns the area of the Rect2i.
Godot equivalent: Rect2i.get_area function
pub fn center(self) -> Vector2i
pub fn center(self) -> Vector2i
Returns the center of the Rect2i, which is equal to position + (size / 2).
If size is an odd number, the returned center value will be rounded towards position.
Godot equivalent: Rect2i.get_center function
pub fn grow(self, amount: i32) -> Rect2i
pub fn grow(self, amount: i32) -> Rect2i
Returns a copy of the Rect2i grown by the specified amount on all sides.
amount may be negative, but care must be taken: If the resulting size has
negative components the computation may be incorrect.
pub fn grow_individual(
self,
left: i32,
top: i32,
right: i32,
bottom: i32,
) -> Rect2i
pub fn grow_individual( self, left: i32, top: i32, right: i32, bottom: i32, ) -> Rect2i
Returns a copy of the Rect2i grown by the specified amount on each side individually.
The individual amounts may be negative, but care must be taken: If the resulting size has
negative components the computation may be incorrect.
pub fn grow_side(self, side: Side, amount: i32) -> Rect2i
pub fn grow_side(self, side: Side, amount: i32) -> Rect2i
Returns a copy of the Rect2i 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 const fn has_area(self) -> bool
pub const fn has_area(self) -> bool
Returns true if the Rect2i has area, and false if the Rect2i is linear, empty, or
has a negative size.
pub const fn contains_point(self, point: Vector2i) -> bool
pub const fn contains_point(self, point: Vector2i) -> bool
Returns true if the Rect2i contains a point. By convention, the right and bottom edges
of the Rect2i are considered exclusive, so points on these edges are not included.
Godot equivalent: Rect2i.has_point function
pub fn intersect(self, b: Rect2i) -> Option<Rect2i>
pub fn intersect(self, b: Rect2i) -> Option<Rect2i>
Returns the intersection of this Rect2i and b.
If the rectangles do not intersect, None is returned.
Note that rectangles that only share a border do not intersect.
pub fn intersects(self, b: Rect2i) -> bool
pub fn intersects(self, b: Rect2i) -> bool
Returns true if the Rect2i overlaps with b (i.e. they have at least one
point in common)
pub const fn is_negative(self) -> bool
pub const fn is_negative(self) -> bool
Returns true if either of the coordinates of this Rect2is size vector is negative.
pub const fn assert_nonnegative(self)
pub const fn assert_nonnegative(self)
Assert that the size of the Rect2i is not negative.
Certain functions will fail to give a correct result if the size is negative.
Trait Implementations§
§impl DynamicSend for Rect2i
impl DynamicSend for Rect2i
type Inner = Rect2i
fn extract_if_safe(self) -> Option<<Rect2i as DynamicSend>::Inner>
§impl Export for Rect2i
impl Export for Rect2i
§fn export_hint() -> PropertyHintInfo
fn export_hint() -> PropertyHintInfo
§impl FromGodot for Rect2i
impl FromGodot for Rect2i
§fn try_from_godot(
via: <Rect2i as GodotConvert>::Via,
) -> Result<Rect2i, ConvertError>
fn try_from_godot( via: <Rect2i as GodotConvert>::Via, ) -> Result<Rect2i, 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 Rect2i
impl GodotImmutable for Rect2i
fn into_runtime_immutable(self) -> Self
§impl IntoDynamicSend for Rect2i
impl IntoDynamicSend for Rect2i
type Target = Rect2i
fn into_dynamic_send(self) -> <Rect2i as IntoDynamicSend>::Target
§impl ToGodot for Rect2i
impl ToGodot for Rect2i
§fn to_godot(&self) -> <Rect2i as GodotConvert>::Via
fn to_godot(&self) -> <Rect2i 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 Rect2i
impl Var for Rect2i
fn get_property(&self) -> <Rect2i as GodotConvert>::Via
fn set_property(&mut self, value: <Rect2i as GodotConvert>::Via)
§fn var_hint() -> PropertyHintInfo
fn var_hint() -> PropertyHintInfo
GodotType::property_info, e.g. for enums/newtypes.impl ArrayElement for Rect2i
impl BuiltinExport for Rect2i
impl Copy for Rect2i
impl Eq for Rect2i
impl GodotType for Rect2i
impl StructuralPartialEq for Rect2i
Auto Trait Implementations§
impl Freeze for Rect2i
impl RefUnwindSafe for Rect2i
impl Send for Rect2i
impl Sync for Rect2i
impl Unpin for Rect2i
impl UnwindSafe for Rect2i
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)