API Docs for: v0.1.0
Show:

Rectangle Class

The 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

Rectangle

(
  • x
  • y
  • width
  • height
)

Parameters:

  • x Number

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

  • y Number

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

  • width Number

    The overall wisth of this rectangle

  • height Number

    The overall height of this rectangle

Methods

clone

() Rectangle

Creates a clone of this Rectangle

Returns:

Rectangle:

a copy of the rectangle

contains

(
  • x
  • y
)
Boolean

Checks if the x, and y coords passed to this function are contained within this Rectangle

Parameters:

  • x Number

    The X coord of the point to test

  • y Number

    The Y coord of the point to test

Returns:

Boolean:

if the x/y coords are within this Rectangle

copy

(
  • rectangle
)
Rectangle chainable

Copies the values from another rectangle to this one

Parameters:

  • rectangle Rectangle

    The rectangle to copy vlaues from

Returns:

Rectangle:

Returns itself.

equals

(
  • rectangle
)
Boolean

Checks if this rectangle's values are equal to anothers

Parameters:

  • rectangle Rectangle

    The rectangle to check against

Returns:

Boolean:

True if they are equal

overlaps

(
  • rect
)
Boolean

Checks if this rectangle overlaps another

Parameters:

  • rect Rectangle

    The rectangle to check if this overlaps

Returns:

Boolean:

if the rectangle overlaps

toPolygon

() Polygon

Returns a polygon from this rectangle's points

Returns:

Polygon:

The new polygon

union

(
  • rectangle
  • [output]
)
Rectangle

Combines two rectangles together to create a new rectangle

Parameters:

  • rectangle Rectangle

    The rectangle to union with

  • [output] Rectangle optional

    The rectangle object to output to, a new one is created by default

Returns:

Rectangle:

a new rectangle object that is the combonation of both

Properties

_height

Number private

Default: 0

_width

Number private

Default: 0

area

Number

The area of the rectangle

bottom

Number

Returns the bottom most Y coord

halfHeight

Number

Default: 0

halfWidth

Number

Default: 0

height

Number

The height of the object

left

Number

Returns the left most X coord

perimeter

Number

The perimeter of the rectangle

position

Vector

Default: 0

right

Number

Returns the right most X coord

top

Number

Returns the top most Y coord

width

Number

The width of the object

Default: 0

x

Number

The top-left X coord of the rectangle

Default: 0

y

Number

The top-left Y coord of the rectangle

Default: 0