Struct godot::prelude::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.

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 const fn from_rect2(rect: Rect2) -> Rect2i

Create a new Rect2i from a Rect2, using as for real to i32 conversions.

Godot equivalent: Rect2i(Rect2 from)

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 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: RectSide, 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 default_export_info() -> 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>

Performs the conversion.
§

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

⚠️ Performs the conversion. Read more
§

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

Performs the conversion from a Variant.
§

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

§

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

This method tests for self and other values to be equal, and is used by ==.
1.0.0 · source§

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

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

impl ToGodot for Rect2i

§

fn to_godot(&self) -> <Rect2i as GodotConvert>::Via

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

fn into_godot(self) -> <Rect2i as GodotConvert>::Via

Converts this type to the Godot type. Read more
§

fn to_variant(&self) -> Variant

Converts this type to a Variant.
§

impl TypeStringHint for Rect2i

§

fn type_string() -> String

Returns the representation of this type as a type string. Read more
§

impl Var for Rect2i

§

impl ArrayElement 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> 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,

§

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>,

§

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>,

§

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.