gs.Rect Class
A class to describe rectangles. It also offers a lot of helper methods.
Constructor
gs.Rect
-
x -
y -
width -
height
Parameters:
-
xNumber- The x-coordinate of the rectangle.
-
yNumber- The x-coordinate of the rectangle.
-
widthNumber- The width of the rectangle.
-
heightNumber- The height of the rectangle.
Item Index
Methods
Methods
ceil
()
Rounds the rectangle coordinates using ceil-method.
contains
-
x -
y
Checks if the specified point is inside the rectangle.
Parameters:
-
xNumber- The x-coordinate of the point.
-
yNumber- The y-coordinate of the point.
Returns:
If true the point is inside the rectangle. Otherwise false.
contains
-
x -
y -
width -
height -
px -
py
Checks if the specified point is inside the specified rectangle.
Parameters:
-
xNumber- The x-coordinate of the rectangle.
-
yNumber- The y-coordinate of the rectangle.
-
widthNumber- The width of the rectangle.
-
heightNumber- The height of the rectangle.
-
pxNumber- The x-coordinate of the point.
-
pyNumber- The y-coordinate of the point.
Returns:
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:
-
xNumber- The x-coordinate of the rectangle.
-
yNumber- The x-coordinate of the rectangle.
-
widthNumber- The width of the rectangle.
-
heightNumber- The height of the rectangle.
floor
()
Rounds the rectangle coordinates using floor-method.
fromArray
-
a
Creates a rectangle from an array. The array should contain 4 elements for x, y, width and height in that order.
Parameters:
-
aNumber- The array with the x, y, width and height of the rectangle.
Returns:
The new created rectangle.
fromObject
-
o
Creates a rectangle from an raw object. The object should contain 4 properties named x, y, width and height.
Parameters:
-
oObject- The object with the x, y, width and height properties of the rectangle.
Returns:
The new created rectangle.
intersect
-
x -
y -
width -
height
Checks if the rectangle intersects with the specified rectangle.
Parameters:
-
xNumber- The x-coordinate of the rectangle.
-
yNumber- The y-coordinate of the rectangle.
-
widthNumber- The width of the rectangle.
-
heightNumber- The height of the rectangle.
Returns:
If true the two rectangle intersect. Otherwise false.
intersect
-
angle
Rotates the rectangle by the specified angle.
Parameters:
-
angleNumber
Returns:
The rotated rectangle.
intersect
-
x1 -
y1 -
width1 -
height1 -
x2 -
y2 -
width2 -
height2
Checks if the specified rectangle 1 intersects with the specified rectangle 2.
Parameters:
-
x1Number- The x-coordinate of the first rectangle.
-
y1Number- The y-coordinate of the first rectangle.
-
width1Number- The width of the first rectangle.
-
height1Number- The height of the first rectangle.
-
x2Number- The x-coordinate of the second rectangle.
-
y2Number- The y-coordinate of the second rectangle.
-
width2Number- The width of the second rectangle.
-
height2Number- The height of the second rectangle.
Returns:
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:
-
xNumber- The x-coordinate of the rectangle.
-
yNumber- The x-coordinate of the rectangle.
-
widthNumber- The width of the rectangle.
-
heightNumber- The height of the rectangle.
setFromObject
-
rect
Sets the coordinates of the rectangle from raw object.
Parameters:
-
rectObject- 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.
