Libraries.Game.Shapes.Rectangle Documentation
The Rectangle class stores the location of an unrotated rectangle. This is managed as a location on the screen in (x,y) coordinates coupled with a given height and width.
Inherits from: Libraries.Language.Object
Summary
Actions Summary Table
Actions | Description |
---|---|
Area() | This action returns the area of the Rectangle. |
Compare(Libraries.Language.Object object) | This action compares two object hash codes and returns an integer. |
Contains(number testX, number testY) | This action tests if the given point is contained within the Rectangle. |
Contains(Libraries.Game.Shapes.Rectangle rectangle) | This action tests if the entire given Rectangle is contained within this Rectangle. |
CopyRectangle(Libraries.Game.Shapes.Rectangle rectangle) | This action sets the coordinates, width, and height of this rectangle to be the same as the given rectangle. |
Equals(Libraries.Language.Object object) | This action determines if two objects are equal based on their hash code values. |
FitInside(Libraries.Game.Shapes.Rectangle rectangle) | This action scales this Rectangle so it maintains the same aspect ratio and fits inside the given Rectangle. |
FitOutside(Libraries.Game.Shapes.Rectangle rectangle) | This action scales this Rectangle so it maintains the same aspect ratio and fits around the given Rectangle. |
GetAspectRatio() | This action will return the aspect ratio of the Rectangle, which is the ratio of the width over the height of the Rectangle. |
GetHashCode() | This action gets the hash code for an object. |
GetHeight() | This action returns the current height of the Rectangle. |
GetWidth() | This action returns the current width of the Rectangle. |
GetX() | This action returns the current x coordinate of the Rectangle. |
GetY() | This action returns the current y coordinate of the Rectangle. |
Merge(Libraries.Game.Shapes.Rectangle rectangle) | This action will make this Rectangle expand to contain the given Rectangle. |
Merge(number pointX, number pointY) | This action will make this Rectangle expand to contain the given point. |
Overlaps(Libraries.Game.Shapes.Rectangle rectangle) | This action tests if the given Rectangle overlaps with this Rectangle. |
Perimeter() | This action returns the perimeter of the Rectangle. |
SetCenter(number centerX, number centerY) | This action will set the x, y coordinates of the Rectangle so that the center of the Rectangle is at the given x, y coordinates. |
SetHeight(number newHeight) | This action sets the current height of the Rectangle. |
SetPosition(number newX, number newY) | This action sets the x and y coordinates of the Rectangle. |
SetRectangle(number newX, number newY, number newWidth, number newHeight) | This action sets the x and y coordinates of the Rectangle, along with the width and height. |
SetSize(number newWidth, number newHeight) | This action sets the width and height of the Rectangle. |
SetSquare(number scale) | This action sets the width and height of the rectangle to be the given value, making it into a square. |
SetWidth(number newWidth) | This action sets the current width of the Rectangle. |
SetX(number newX) | This action sets the current x coordinate of the Rectangle. |
SetY(number newY) | This action sets the current y coordinate of the Rectangle. |
Actions Documentation
Area()
This action returns the area of the Rectangle.
Example Code
use Libraries.Game.Shapes.Rectangle
use Libraries.Game.Game
class Main is Game
Rectangle rectangle
action Main
StartGame()
end
action CreateGame
rectangle:SetRectangle(0, 0, 200, 100)
number area = rectangle:Area()
end
end
Return
number:
Compare(Libraries.Language.Object object)
This action compares two object hash codes and returns an integer. The result is larger if this hash code is larger than the object passed as a parameter, smaller, or equal. In this case, -1 means smaller, 0 means equal, and 1 means larger. This action was changed in Quorum 7 to return an integer, instead of a CompareResult object, because the previous implementation was causing efficiency issues.
Example Code
Object o
Object t
integer result = o:Compare(t) //1 (larger), 0 (equal), or -1 (smaller)
Parameters
- Libraries.Language.Object: The object to compare to.
Return
integer: The Compare result, Smaller, Equal, or Larger.
Contains(number testX, number testY)
This action tests if the given point is contained within the Rectangle. If it is, this action will return true. Otherwise, it will return false.
Example Code
use Libraries.Game.Shapes.Rectangle
use Libraries.Game.Game
class Main is Game
Rectangle rectangle
action Main
StartGame()
end
action CreateGame
rectangle:SetRectangle(50, 50, 100, 100)
boolean hasPoint = rectangle:Contains(125, 75)
end
end
Parameters
Return
boolean:
Contains(Libraries.Game.Shapes.Rectangle rectangle)
This action tests if the entire given Rectangle is contained within this Rectangle. If it is, this action will return true. Otherwise, it will return false.
Example Code
use Libraries.Game.Shapes.Rectangle
use Libraries.Game.Game
class Main is Game
Rectangle rectangle1
Rectangle rectangle2
action Main
StartGame()
end
action CreateGame
rectangle1:SetRectangle(50, 50, 100, 100)
rectangle2:SetRectangle(75, 75, 50, 50)
boolean contains = rectangle1:Contains(rectangle2)
end
end
Parameters
Return
boolean:
CopyRectangle(Libraries.Game.Shapes.Rectangle rectangle)
This action sets the coordinates, width, and height of this rectangle to be the same as the given rectangle.
Example Code
use Libraries.Game.Shapes.Rectangle
use Libraries.Game.Game
class Main is Game
Rectangle rectangle1
Rectangle rectangle2
action Main
StartGame()
end
action CreateGame
rectangle1:SetRectangle(20, 20, 200, 80)
rectangle2:CopyRectangle(rectangle1)
end
end
Parameters
Equals(Libraries.Language.Object object)
This action determines if two objects are equal based on their hash code values.
Example Code
use Libraries.Language.Object
use Libraries.Language.Types.Text
Object o
Text t
boolean result = o:Equals(t)
Parameters
- Libraries.Language.Object: The to be compared.
Return
boolean: True if the hash codes are equal and false if they are not equal.
FitInside(Libraries.Game.Shapes.Rectangle rectangle)
This action scales this Rectangle so it maintains the same aspect ratio and fits inside the given Rectangle.
Example Code
use Libraries.Game.Shapes.Rectangle
use Libraries.Game.Game
class Main is Game
Rectangle rectangle1
Rectangle rectangle2
action Main
StartGame()
end
action CreateGame
rectangle1:SetRectangle(0, 0, 200, 100)
rectangle2:SetRectangle(100, 100, 150, 200)
rectangle1:FitInside(rectangle2)
end
end
Parameters
FitOutside(Libraries.Game.Shapes.Rectangle rectangle)
This action scales this Rectangle so it maintains the same aspect ratio and fits around the given Rectangle.
Example Code
use Libraries.Game.Shapes.Rectangle
use Libraries.Game.Game
class Main is Game
Rectangle rectangle1
Rectangle rectangle2
action Main
StartGame()
end
action CreateGame
rectangle1:SetRectangle(0, 0, 200, 100)
rectangle2:SetRectangle(100, 100, 150, 200)
rectangle1:FitOutside(rectangle2)
end
end
Parameters
GetAspectRatio()
This action will return the aspect ratio of the Rectangle, which is the ratio of the width over the height of the Rectangle.
Example Code
use Libraries.Game.Shapes.Rectangle
use Libraries.Game.Game
class Main is Game
Rectangle rectangle
action Main
StartGame()
end
action CreateGame
rectangle:SetSize(200, 100)
number ratio = rectangle:GetAspectRatio()
end
end
Return
number:
GetHashCode()
This action gets the hash code for an object.
Example Code
Object o
integer hash = o:GetHashCode()
Return
integer: The integer hash code of the object.
GetHeight()
This action returns the current height of the Rectangle.
Example Code
use Libraries.Game.Shapes.Rectangle
use Libraries.Game.Game
class Main is Game
Rectangle rectangle
action Main
StartGame()
end
action CreateGame
rectangle:SetHeight(100)
number height = rectangle:GetHeight()
end
end
Return
number:
GetWidth()
This action returns the current width of the Rectangle.
Example Code
use Libraries.Game.Shapes.Rectangle
use Libraries.Game.Game
class Main is Game
Rectangle rectangle
action Main
StartGame()
end
action CreateGame
rectangle:SetWidth(100)
number width = rectangle:GetWidth()
end
end
Return
number:
GetX()
This action returns the current x coordinate of the Rectangle.
Example Code
use Libraries.Game.Shapes.Rectangle
use Libraries.Game.Game
class Main is Game
Rectangle rectangle
action Main
StartGame()
end
action CreateGame
rectangle:SetRectangle(20, 20, 200, 80)
number x = rectangle:GetX()
end
end
Return
number:
GetY()
This action returns the current y coordinate of the Rectangle.
Example Code
use Libraries.Game.Shapes.Rectangle
use Libraries.Game.Game
class Main is Game
Rectangle rectangle
action Main
StartGame()
end
action CreateGame
rectangle:SetRectangle(20, 20, 200, 80)
number y = rectangle:GetY()
end
end
Return
number:
Merge(Libraries.Game.Shapes.Rectangle rectangle)
This action will make this Rectangle expand to contain the given Rectangle.
Example Code
use Libraries.Game.Shapes.Rectangle
use Libraries.Game.Game
class Main is Game
Rectangle rectangle1
Rectangle rectangle2
action Main
StartGame()
end
action CreateGame
rectangle1:SetRectangle(50, 50, 100, 100)
rectangle2:SetRectangle(100, 100, 100, 100)
rectangle1:Merge(rectangle2)
end
end
Parameters
Merge(number pointX, number pointY)
This action will make this Rectangle expand to contain the given point.
Example Code
use Libraries.Game.Shapes.Rectangle
use Libraries.Game.Game
class Main is Game
Rectangle rectangle
action Main
StartGame()
end
action CreateGame
rectangle:SetRectangle(50, 50, 100, 100)
rectangle:Merge(75, 250)
end
end
Parameters
Overlaps(Libraries.Game.Shapes.Rectangle rectangle)
This action tests if the given Rectangle overlaps with this Rectangle. If it is, this action will return true. Otherwise, it will return false.
Example Code
use Libraries.Game.Shapes.Rectangle
use Libraries.Game.Game
class Main is Game
Rectangle rectangle1
Rectangle rectangle2
action Main
StartGame()
end
action CreateGame
rectangle1:SetRectangle(50, 50, 100, 100)
rectangle2:SetRectangle(100, 100, 100, 100)
boolean overlap = rectangle1:Overlaps(rectangle2)
end
end
Parameters
Return
boolean:
Perimeter()
This action returns the perimeter of the Rectangle.
Example Code
use Libraries.Game.Shapes.Rectangle
use Libraries.Game.Game
class Main is Game
Rectangle rectangle
action Main
StartGame()
end
action CreateGame
rectangle:SetRectangle(0, 0, 200, 100)
number perimeter = rectangle:Perimeter()
end
end
Return
number:
SetCenter(number centerX, number centerY)
This action will set the x, y coordinates of the Rectangle so that the center of the Rectangle is at the given x, y coordinates.
Example Code
use Libraries.Game.Shapes.Rectangle
use Libraries.Game.Game
class Main is Game
Rectangle rectangle
action Main
StartGame()
end
action CreateGame
rectangle:SetSize(200, 100)
rectangle:SetCenter(200, 150)
end
end
Parameters
SetHeight(number newHeight)
This action sets the current height of the Rectangle.
Example Code
use Libraries.Game.Shapes.Rectangle
use Libraries.Game.Game
class Main is Game
Rectangle rectangle
action Main
StartGame()
end
action CreateGame
rectangle:SetHeight(100)
end
end
Parameters
SetPosition(number newX, number newY)
This action sets the x and y coordinates of the Rectangle.
Example Code
use Libraries.Game.Shapes.Rectangle
use Libraries.Game.Game
class Main is Game
Rectangle rectangle
action Main
StartGame()
end
action CreateGame
rectangle:SetPosition(80, 100)
end
end
Parameters
SetRectangle(number newX, number newY, number newWidth, number newHeight)
This action sets the x and y coordinates of the Rectangle, along with the width and height.
Example Code
use Libraries.Game.Shapes.Rectangle
use Libraries.Game.Game
class Main is Game
Rectangle rectangle
action Main
StartGame()
end
action CreateGame
rectangle:SetRectangle(20, 20, 200, 80)
end
end
Parameters
SetSize(number newWidth, number newHeight)
This action sets the width and height of the Rectangle.
Example Code
use Libraries.Game.Shapes.Rectangle
use Libraries.Game.Game
class Main is Game
Rectangle rectangle
action Main
StartGame()
end
action CreateGame
rectangle:SetSize(40, 70)
end
end
Parameters
SetSquare(number scale)
This action sets the width and height of the rectangle to be the given value, making it into a square.
Example Code
use Libraries.Game.Shapes.Rectangle
use Libraries.Game.Game
class Main is Game
Rectangle rectangle
action Main
StartGame()
end
action CreateGame
rectangle:SetSquare(60)
end
end
Parameters
SetWidth(number newWidth)
This action sets the current width of the Rectangle.
Example Code
use Libraries.Game.Shapes.Rectangle
use Libraries.Game.Game
class Main is Game
Rectangle rectangle
action Main
StartGame()
end
action CreateGame
rectangle:SetWidth(100)
end
end
Parameters
SetX(number newX)
This action sets the current x coordinate of the Rectangle.
Example Code
use Libraries.Game.Shapes.Rectangle
use Libraries.Game.Game
class Main is Game
Rectangle rectangle
action Main
StartGame()
end
action CreateGame
rectangle:SetX(40)
end
end
Parameters
SetY(number newY)
This action sets the current y coordinate of the Rectangle.
Example Code
use Libraries.Game.Shapes.Rectangle
use Libraries.Game.Game
class Main is Game
Rectangle rectangle
action Main
StartGame()
end
action CreateGame
rectangle:SetY(75)
end
end