API Docs for:
Show:

gs.Rect Class

A class to describe rectangles. It also offers a lot of helper methods.

Constructor

gs.Rect

(
  • x
  • y
  • width
  • height
)

Parameters:

  • x Number
    • The x-coordinate of the rectangle.
  • y Number
    • The x-coordinate of the rectangle.
  • width Number
    • The width of the rectangle.
  • height Number
    • The height of the rectangle.

Item Index

Properties

Methods

ceil

()

Rounds the rectangle coordinates using ceil-method.

contains

(
  • x
  • y
)
Boolean

Checks if the specified point is inside the rectangle.

Parameters:

  • x Number
    • The x-coordinate of the point.
  • y Number
    • The y-coordinate of the point.

Returns:

Boolean:

If true the point is inside the rectangle. Otherwise false.

contains

(
  • x
  • y
  • width
  • height
  • px
  • py
)
Boolean static

Checks if the specified point is inside the specified rectangle.

Parameters:

  • x Number
    • The x-coordinate of the rectangle.
  • y Number
    • The y-coordinate of the rectangle.
  • width Number
    • The width of the rectangle.
  • height Number
    • The height of the rectangle.
  • px Number
    • The x-coordinate of the point.
  • py Number
    • The y-coordinate of the point.

Returns:

Boolean:

If true the point is inside the rectangle. Otherwise false.

expand

(
  • x
  • y
  • width
  • height
)

Expands the rectangle so that the specified rectangle-area is covered.

Parameters:

  • x Number
    • The x-coordinate of the rectangle.
  • y Number
    • The x-coordinate of the rectangle.
  • width Number
    • The width of the rectangle.
  • height Number
    • The height of the rectangle.

floor

()

Rounds the rectangle coordinates using floor-method.

fromArray

(
  • a
)
gs.Rect static

Creates a rectangle from an array. The array should contain 4 elements for x, y, width and height in that order.

Parameters:

  • a Number
    • The array with the x, y, width and height of the rectangle.

Returns:

gs.Rect:

The new created rectangle.

fromObject

(
  • o
)
gs.Rect static

Creates a rectangle from an raw object. The object should contain 4 properties named x, y, width and height.

Parameters:

  • o Object
    • The object with the x, y, width and height properties of the rectangle.

Returns:

gs.Rect:

The new created rectangle.

intersect

(
  • x
  • y
  • width
  • height
)
Boolean

Checks if the rectangle intersects with the specified rectangle.

Parameters:

  • x Number
    • The x-coordinate of the rectangle.
  • y Number
    • The y-coordinate of the rectangle.
  • width Number
    • The width of the rectangle.
  • height Number
    • The height of the rectangle.

Returns:

Boolean:

If true the two rectangle intersect. Otherwise false.

intersect

(
  • angle
)
gs.Rect

Rotates the rectangle by the specified angle.

Parameters:

  • angle Number

Returns:

gs.Rect:

The rotated rectangle.

intersect

(
  • x1
  • y1
  • width1
  • height1
  • x2
  • y2
  • width2
  • height2
)
Boolean static

Checks if the specified rectangle 1 intersects with the specified rectangle 2.

Parameters:

  • x1 Number
    • The x-coordinate of the first rectangle.
  • y1 Number
    • The y-coordinate of the first rectangle.
  • width1 Number
    • The width of the first rectangle.
  • height1 Number
    • The height of the first rectangle.
  • x2 Number
    • The x-coordinate of the second rectangle.
  • y2 Number
    • The y-coordinate of the second rectangle.
  • width2 Number
    • The width of the second rectangle.
  • height2 Number
    • The height of the second rectangle.

Returns:

Boolean:

If true the two rectangle intersect. Otherwise false.

round

()

Rounds the rectangle coordinates using round-method.

set

(
  • x
  • y
  • width
  • height
)

Sets the coordinates of the rectangle.

Parameters:

  • x Number
    • The x-coordinate of the rectangle.
  • y Number
    • The x-coordinate of the rectangle.
  • width Number
    • The width of the rectangle.
  • height Number
    • The height of the rectangle.

setFromObject

(
  • rect
)

Sets the coordinates of the rectangle from raw object.

Parameters:

  • rect Object
    • A raw rectangle object.

Properties

height

Number

The height of the rectangle.

width

Number

The width of the rectangle.

x

Number

The x-coordinate of the rectangle.

y

Number

The y-coordinate of the rectangle.