Rect2

2D axis-aligned bounding box.

Descripción

Rect2 consists of a position, a size, and several utility functions. It is typically used for fast overlap tests.

It uses floating-point coordinates.

The 3D counterpart to Rect2 is AABB.

Negative values for size are not supported and will not work for most methods. Use abs to get a Rect2 with a positive size.

Tutoriales

Propiedades

Vector2

end

Vector2( 0, 0 )

Vector2

position

Vector2( 0, 0 )

Vector2

size

Vector2( 0, 0 )

Métodos

Rect2

Rect2 ( Vector2 position, Vector2 size )

Rect2

Rect2 ( float x, float y, float width, float height )

Rect2

abs ( )

Rect2

clip ( Rect2 b )

bool

encloses ( Rect2 b )

Rect2

expand ( Vector2 to )

float

get_area ( )

Vector2

get_center ( )

Rect2

grow ( float by )

Rect2

grow_individual ( float left, float top, float right, float bottom )

Rect2

grow_margin ( int margin, float by )

bool

has_no_area ( )

bool

has_point ( Vector2 point )

bool

intersects ( Rect2 b, bool include_borders=false )

bool

is_equal_approx ( Rect2 rect )

Rect2

merge ( Rect2 b )

Descripciones de Propiedades

Default

Vector2( 0, 0 )

Esquina final. Esto se calcula como position + size. Cambiar esta propiedad cambia el tamaño.


Default

Vector2( 0, 0 )

Esquina de inicio. Normalmente tiene valores inferiores a end.


Default

Vector2( 0, 0 )

Size from position to end. Typically, all components are positive.

If the size is negative, you can use abs to fix it.

Descripciones de Métodos

Construye un Rect2 por posición y tamaño.


Construye un Rect2 por x, y, ancho y alto.


Devuelve una Rect2 con posición y área equivalentes, modificada de manera que la esquina superior izquierda es el origen y width y height son positivos.


Devuelve la intersección de esta Rect2 y b.


Devuelve true si este Rect2 encierra completamente otro.


Returns a copy of this Rect2 expanded to include a given point.

Example:

# position (-3, 2), size (1, 1)
var rect = Rect2(Vector2(-3, 2), Vector2(1, 1))
# position (-3, -1), size (3, 4), so we fit both rect and Vector2(0, -1)
var rect2 = rect.expand(Vector2(0, -1))

Devuelve el área de la Rect2.


Returns the center of the Rect2, which is equal to position + (size / 2).


Devuelve una copia del Rect2 crecido una cantidad dada de unidades hacia todos los lados.


Devuelve una copia del Rect2 crecido una cantidad dada de unidades hacia todos los lados.


Devuelve una copia del Rect2 crecido una cantidad dada de unidades hacia la dirección del Margin.


  • bool has_no_area ( )

Devuelve true si la Rect2 está plana o vacía.


Returns true if the Rect2 contains a point. By convention, the right and bottom edges of the Rect2 are considered exclusive, so points on these edges are not included.

Note: This method is not reliable for Rect2 with a negative size. Use abs to get a positive sized equivalent rectangle to check for contained points.


Devuelve true si la Rect2 se superpone con b (es decir, tienen al menos un punto en común).

Si include_borders es true, también se considerará que se superponen si sus bordes se tocan, incluso sin intersección.


Devuelve true si este Rect2 y rect son aproximadamente iguales, llamando a is_equal_approx en cada componente.


Devuelve un Rect2 más grande que contiene este Rect2 y b.