#[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
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 i32
s 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
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
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
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)
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
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: RectSide, amount: i32) -> Rect2i
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
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 intersection(self, b: Rect2i) -> Option<Rect2i>
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
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 Rect2i
s 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 Export for Rect2i
impl Export for Rect2i
§fn default_export_info() -> PropertyHintInfo
fn default_export_info() -> 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>
§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
.