godot::builtin

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

DimensionFloating-pointInteger
2DRect2Rect2i
3DAabb


You can convert to Rect2 using cast_float().

§Godot docs

Rect2i (stable)

Fields§

§position: Vector2i

The position of the rectangle.

§size: Vector2i

The size of the rectangle.

Implementations§

§

impl 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

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

Create a new Rect2i with the first corner at position and the opposite corner at end.

pub const fn from_rect2(rect: Rect2) -> Rect2i

👎Deprecated: Moved to Rect2::cast_int()

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 const fn end(self) -> Vector2i

The end of the Rect2i calculated as position + size.

Godot equivalent: Rect2i.size property

pub fn set_end(&mut self, end: Vector2i)

Set size based on desired end-point.

Godot equivalent: Rect2i.size property

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

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

Returns a copy of this Rect2i expanded so that the borders align with the given point.

pub const fn area(self) -> i32

Returns the area of the Rect2i.

Godot equivalent: Rect2i.get_area function

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

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

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

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

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

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 intersection(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

Returns true if the Rect2i overlaps with b (i.e. they have at least one point in common)

pub fn merge(self, b: Rect2i) -> Rect2i

Returns a larger Rect2i that contains this Rect2i and b.

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)

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 Clone for Rect2i

§

fn clone(&self) -> Rect2i

Returns a copy of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
§

impl Debug for Rect2i

§

fn fmt(&self, f: &mut Formatter<'_>) -> Result<(), Error>

Formats the value using the given formatter. Read more
§

impl Default for Rect2i

§

fn default() -> Rect2i

Returns the “default value” for a type. Read more
§

impl Display for Rect2i

§

fn fmt(&self, f: &mut Formatter<'_>) -> Result<(), Error>

Formats Rect2i to match Godot’s string representation.

§Example
use godot::prelude::*;
let rect = Rect2i::new(Vector2i::new(0, 0), Vector2i::new(1, 1));
assert_eq!(format!("{}", rect), "[P: (0, 0), S: (1, 1)]");
§

impl Export for Rect2i

§

fn export_hint() -> PropertyHintInfo

The export info to use for an exported field of this type, if no other export info is specified.
§

impl FromGodot for Rect2i

§

fn try_from_godot( via: <Rect2i as GodotConvert>::Via, ) -> Result<Rect2i, ConvertError>

Converts the Godot representation to this type, returning Err on failure.
§

fn from_godot(via: Self::Via) -> Self

⚠️ Converts the Godot representation to this type. Read more
§

fn try_from_variant(variant: &Variant) -> Result<Self, ConvertError>

Performs the conversion from a Variant, returning Err on failure.
§

fn from_variant(variant: &Variant) -> Self

⚠️ Performs the conversion from a Variant. Read more
§

impl GodotConvert for Rect2i

§

type Via = Rect2i

The type through which Self is represented in Godot.
§

impl ParamType for Rect2i

§

fn owned_to_arg<'v>(self) -> <Rect2i as ParamType>::Arg<'v>

Converts an owned value to the canonical argument type, which can be passed to impl AsArg<T>. Read more
§

impl PartialEq for Rect2i

§

fn eq(&self, other: &Rect2i) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 · Source§

fn ne(&self, other: &Rhs) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
§

impl ToGodot for Rect2i

§

type ToVia<'v> = <Rect2i as GodotConvert>::Via

Target type of to_godot(), which can differ from Via for pass-by-reference types. Read more
§

fn to_godot(&self) -> <Rect2i as ToGodot>::ToVia<'_>

Converts this type to the Godot type by reference, usually by cloning.
§

fn to_variant(&self) -> Variant

Converts this type to a Variant.
§

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

Specific property hints, only override if they deviate from GodotType::property_info, e.g. for enums/newtypes.
§

impl ArrayElement for Rect2i

§

impl AsArg<Rect2i> 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§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dst: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dst. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T> ToString for T
where T: Display + ?Sized,

Source§

default fn to_string(&self) -> String

Converts the given value to a String. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.