The Rectangle class provides a simple object for storing and manipulating a logical rectangle for calculations

Constructor

new (x:Float = 0, y:Float = 0, width:Float = 0, height:Float = 0)

Create a new Rectangle instance

Parameters:

x

(Optional) Initial x value (default is 0)

y

(Optional) Initial y value (default is 0)

width

(Optional) Initial width value (default is 0)

height

(Optional) Initial height value (default is 0)

Variables

bottom:Float

Get or set the bottom (y + height) value of the Rectangle

bottomRight:Vector2

Get or set the bottom-right (x + width, y + height) as a Vector2

height:Float

Get or set the height of the rectangle

left:Float

Get or set the left (x) of the rectangle

right:Float

Get or set the right (x + width) of the rectangle

size:Vector2

Get or set the size (width, height) as a Vector2

top:Float

Get or set the top (y) of the rectangle

topLeft:Vector2

Get or set the top-left (x, y) as a Vector2

width:Float

Get or set the width of the rectangle

x:Float

Get or set the x of the rectangle

y:Float

Get or set the y of the rectangle

Methods

clone ():Rectangle

Creates a clone of this Rectangle

Returns:

A new Rectangle instance

contains (x:Float, y:Float):Bool

Returns whether this rectangle contains the specified (x, y) point

Parameters:

x

The x coordinate to test

y

The y coordinate to test

Returns:

Whether the point is contained in the rectangle

containsRect (rect:Rectangle):Bool

Returns whether this rectangle contains another rectangle This will return false if the second rectangle only overlaps but is not fully contained within the current rectangle

Parameters:

rect

A second Rectangle instance to test

Returns:

Whether the rect is contained within the current Rectangle

containsVector (vector:Vector2):Bool

Returns whether this rectangle contains the specified vector

Parameters:

vector

The vector to test

Returns:

Whether the vector is contained in the rectangle

copyFrom (sourceRect:Rectangle):Void

Copies the x, y, width and height of another Rectangle

Parameters:

sourceRect

Another Rectangle instance

equals (toCompare:Rectangle):Bool

Checks whether the current Rectangle and another instance have equal values

Parameters:

toCompare

Another Rectangle to compare with

Returns:

Whether both rectangles are not null and have equal values

inflate (dx:Float, dy:Float):Void

Increases the size of the current rectangle by the given delta x and y values

Parameters:

dx

A delta x value to increase the size by

dy

A delta y value to increase the size by

inflateVector (vector:Vector2):Void

Increases the size of the current rectangle by the given delta vector values

Parameters:

vector

A delta vector to increase the size by

intersection (toIntersect:Rectangle, ?result:Rectangle):Rectangle

Returns a new rectangle with the area where the current Rectangle and another Rectangle instance overlap. If they do not overlap, the returned Rectangle will be empty

Parameters:

toIntersect

Another Rectangle instance to intersect with

result

(Optional) A Rectangle instance to use for the result

Returns:

A Rectangle of the intersection area

intersects (toIntersect:Rectangle):Bool

Returns if the current Rectangle overlaps with another instance

Parameters:

toIntersect

Another Rectangle to compare with

Returns:

Whether the rectangles intersect

isEmpty ():Bool

Whether this rectangle is empty

Returns:

true if the width or height is <= 0

offset (dx:Float, dy:Float):Void

Moves the rectangle by offset x and values

Parameters:

dx

A delta x value

dy

A delta y value

offsetVector (vector:Vector2):Void

Moves the rectangle by the values of a Vector2

Parameters:

dx

A delta vector

setEmpty ():Void

Makes this rectangle empty

setTo (xa:Float, ya:Float, widtha:Float, heighta:Float):Void

Sets the values of this rectangle at once

Parameters:

xa

A new x value

ya

A new y value

widtha

A new width value

heighta

A new height value

union (toUnion:Rectangle, ?result:Rectangle):Rectangle

Combines two rectangles together, returning the minimum Rectangle that contains both rectangles

Parameters:

toUnion

A second Rectangle to unify

result

(Optional) A Rectangle instance for the result

Returns:

A Rectangle that contains the dimensions of both rectangles