# PIXI.Rectangle

``class Rectangle``

Rectangle object is an area defined by its position, as indicated by its top-left corner point (x, y) and by its width and its height.

## Constructor

``new PIXI.Rectangle(x: string | number, y: string | number, width: string | number, height: string | number) → {}``
Parameters:
Name Type Default Description
x string | number 0

The X coordinate of the upper-left corner of the rectangle

y string | number 0

The Y coordinate of the upper-left corner of the rectangle

width string | number 0

The overall width of the rectangle

height string | number 0

The overall height of the rectangle

## Summary

### Properties from Rectangle

 PIXI.Rectangle static EMPTY A constant empty rectangle. number bottom Returns the bottom edge of the rectangle. number height = 0 number left Returns the left edge of the rectangle. number right Returns the right edge of the rectangle. number top Returns the top edge of the rectangle. SHAPES.RECT type = PIXI.SHAPES.RECT number width = 0 number x = 0 number y = 0

### Methods from Rectangle

 this ceil(resolution: number, eps: number) PIXI.Rectangle clone() boolean contains(x: number, y: number) boolean containsRect(other: Rectangle) PIXI.Rectangle copyFrom(rectangle: PIXI.Rectangle) PIXI.Rectangle copyTo(rectangle: PIXI.Rectangle) this enlarge(rectangle: PIXI.Rectangle) boolean equals(other: Rectangle) Accepts `other` Rectangle and returns true if the given Rectangle is equal to `this` Rectangle. this fit(rectangle: PIXI.Rectangle) Rectangle intersection(other: Rectangle, outRect: Rectangle) boolean intersects(other: Rectangle, transform: Matrix) this pad(paddingX: number, paddingY) Rectangle union(other: Rectangle, outRect: Rectangle)

## Public Properties EMPTY
``static EMPTY: PIXI.Rectangle``

A constant empty rectangle. bottom
``bottom: number``

Returns the bottom edge of the rectangle. height
``height: number = 0`` left
``left: number``

Returns the left edge of the rectangle. top
``top: number``

Returns the top edge of the rectangle. type
``type: SHAPES.RECT = PIXI.SHAPES.RECT``

The type of the object, mainly used to avoid `instanceof` checks

See: PIXI.SHAPES width
``width: number = 0`` x
``x: number = 0`` y
``y: number = 0``

## Public Methods ceil
``ceil(resolution: number, eps: number) → {this}``

Enlarges rectangle that way its corners lie on grid

Parameters:
Name Type Default Description
resolution number 1

resolution

eps number 0.001

precision

Returns:
Type Description
this

Returns itself. clone
``clone() → {PIXI.Rectangle}``

Creates a clone of this Rectangle

Returns:
Type Description
PIXI.Rectangle

a copy of the rectangle contains
``contains(x: number, y: number) → {boolean}``

Checks whether the x and y coordinates given are contained within this Rectangle

Parameters:
Name Type Description
x number

The X coordinate of the point to test

y number

The Y coordinate of the point to test

Returns:
Type Description
boolean

Whether the x/y coordinates are within this Rectangle containsRect
``containsRect(other: Rectangle) → {boolean}``

Determines whether the `other` Rectangle is contained within `this` Rectangle object. Rectangles that occupy the same space are considered to be containing each other. Rectangles without area (width or height equal to zero) can't contain anything, not even other arealess rectangles.

Note: Only available with @pixi/math-extras.

Parameters:
Name Type Description
other Rectangle

The Rectangle to fit inside `this`.

Returns:
Type Description
boolean

A value of `true` if `this` Rectangle contains `other`; otherwise `false`. copyFrom
``copyFrom(rectangle: PIXI.Rectangle) → {PIXI.Rectangle}``

Copies another rectangle to this one.

Parameters:
Name Type Description
rectangle PIXI.Rectangle

The rectangle to copy from.

Returns:
Type Description
PIXI.Rectangle

Returns itself. copyTo
``copyTo(rectangle: PIXI.Rectangle) → {PIXI.Rectangle}``

Copies this rectangle to another one.

Parameters:
Name Type Description
rectangle PIXI.Rectangle

The rectangle to copy to.

Returns:
Type Description
PIXI.Rectangle

Returns given parameter. enlarge
``enlarge(rectangle: PIXI.Rectangle) → {this}``

Enlarges this rectangle to include the passed rectangle.

Parameters:
Name Type Description
rectangle PIXI.Rectangle

The rectangle to include.

Returns:
Type Description
this

Returns itself. equals
``equals(other: Rectangle) → {boolean}``

Accepts `other` Rectangle and returns true if the given Rectangle is equal to `this` Rectangle.

Note: Only available with @pixi/math-extras.

Parameters:
Name Type Description
other Rectangle

The Rectangle to compare with `this`

Returns:
Type Description
boolean

Returns true if all `x`, `y`, `width`, and `height` are equal. fit
``fit(rectangle: PIXI.Rectangle) → {this}``

Fits this rectangle around the passed one.

Parameters:
Name Type Description
rectangle PIXI.Rectangle

The rectangle to fit.

Returns:
Type Description
this

Returns itself. intersection
``intersection(other: Rectangle, outRect: Rectangle) → {Rectangle}``

If the area of the intersection between the Rectangles `other` and `this` is not zero, returns the area of intersection as a Rectangle object. Otherwise, return an empty Rectangle with its properties set to zero. Rectangles without area (width or height equal to zero) can't intersect or be intersected and will always return an empty rectangle with its properties set to zero.

Note: Only available with @pixi/math-extras.

Parameters:
Name Type Attributes Description
other Rectangle

The Rectangle to intersect with `this`.

outRect Rectangle

<optional>

A Rectangle object in which to store the value, optional (otherwise will create a new Rectangle).

Returns:
Type Description
Rectangle

The intersection of `this` and `other`. intersects
``intersects(other: Rectangle, transform: Matrix) → {boolean}``

Determines whether the `other` Rectangle transformed by `transform` intersects with `this` Rectangle object. Returns true only if the area of the intersection is >0, this means that Rectangles sharing a side are not overlapping. Another side effect is that an arealess rectangle (width or height equal to zero) can't intersect any other rectangle.

Parameters:
Name Type Attributes Description
other Rectangle

The Rectangle to intersect with `this`.

transform Matrix

<optional>

The transformation matrix of `other`.

Returns:
Type Description
boolean

A value of `true` if the transformed `other` Rectangle intersects with `this`; otherwise `false`. pad
``pad(paddingX: number, paddingY) → {this}``

Parameters:
Name Type Default Description

Returns:
Type Description
this

Returns itself. union
``union(other: Rectangle, outRect: Rectangle) → {Rectangle}``

Adds `this` and `other` Rectangles together to create a new Rectangle object filling the horizontal and vertical space between the two rectangles.

Note: Only available with @pixi/math-extras.

Parameters:
Name Type Attributes Description
other Rectangle

The Rectangle to unite with `this`.

outRect Rectangle

<optional>

A Rectangle object in which to store the value, optional (otherwise will create a new Rectangle).

Returns:
Type Description
Rectangle

The union of `this` and `other`.