Attention: Here be dragons

This is the `latest` (unstable) version of this documentation, which may document features not available in or compatible with released stable versions of Godot.

# Rect2i¶

## 描述¶

Rect2i 是内置的 Variant 类型，代表 2D 空间中与轴对齐的矩形，使用整数坐标。由 positionsize 定义，它们都是 Vector2i。因为这个矩形不会旋转，所以可以进行快速的重合检查（见 intersects）。

## 属性¶

 Vector2i end `Vector2i(0, 0)` Vector2i position `Vector2i(0, 0)` Vector2i size `Vector2i(0, 0)`

## 构造函数¶

 Rect2i Rect2i ( ) Rect2i Rect2i ( Rect2i from ) Rect2i Rect2i ( Rect2 from ) Rect2i Rect2i ( Vector2i position, Vector2i size ) Rect2i Rect2i ( int x, int y, int width, int height )

## 方法¶

 Rect2i abs ( ) const bool encloses ( Rect2i b ) const Rect2i expand ( Vector2i to ) const int get_area ( ) const Vector2i get_center ( ) const Rect2i grow ( int amount ) const Rect2i grow_individual ( int left, int top, int right, int bottom ) const Rect2i grow_side ( int side, int amount ) const bool has_area ( ) const bool has_point ( Vector2i point ) const Rect2i intersection ( Rect2i b ) const bool intersects ( Rect2i b ) const Rect2i merge ( Rect2i b ) const

## 操作符¶

 bool operator != ( Rect2i right ) bool operator == ( Rect2i right )

## 属性说明¶

Vector2i end = `Vector2i(0, 0)`

Vector2i position = `Vector2i(0, 0)`

Vector2i size = `Vector2i(0, 0)`

## 构造函数说明¶

Rect2i Rect2i ( )

Rect2i Rect2i ( Rect2i from )

Rect2i Rect2i ( Rect2 from )

Rect2i Rect2i ( Vector2i position, Vector2i size )

Rect2i Rect2i ( int x, int y, int width, int height )

## 方法说明¶

Rect2i abs ( ) const

```var rect = Rect2i(25, 25, -100, -50)
var absolute = rect.abs() # 绝对值为 Rect2i(-75, -25, 100, 50)
```

bool encloses ( Rect2i b ) const

Rect2i expand ( Vector2i to ) const

```var rect = Rect2i(0, 0, 5, 2)

rect = rect.expand(Vector2i(10, 0)) # rect 为 Rect2i(0, 0, 10, 2)
rect = rect.expand(Vector2i(-5, 5)) # rect 为 Rect2i(-5, 0, 10, 5)
```

int get_area ( ) const

Vector2i get_center ( ) const

Rect2i grow ( int amount ) const

```var a = Rect2i(4, 4, 8, 8).grow(4) # a 为 Rect2i(0, 0, 16, 16)
var b = Rect2i(0, 0, 8, 4).grow(2) # b 为 Rect2i(-2, -2, 12, 8)
```

Rect2i grow_individual ( int left, int top, int right, int bottom ) const

Rect2i grow_side ( int side, int amount ) const

bool has_area ( ) const

bool has_point ( Vector2i point ) const

Rect2i intersection ( Rect2i b ) const

```var a = Rect2i(0, 0, 5, 10)
var b = Rect2i(2, 0, 8, 4)

var c = a.intersection(b) # c 为 Rect2i(2, 0, 3, 4)
```

bool intersects ( Rect2i b ) const

Rect2i merge ( Rect2i b ) const

## 操作符说明¶

bool operator != ( Rect2i right )

bool operator == ( Rect2i right )