Murl Engine Lua Addon API  Version 1.0 beta
Murl.Math.Rectangle

A rectangle class with 2D coordinates.


Table members

Functions


Murl.Math.Rectangle.new()

The default constructor. Create an empty rectangle with the following properties:

  • The lower coordinates GetX1() and GetY1() contains the DataType's maximum value.
  • The higher coordinates GetX2() and GetY2() contains the DataType's minimum value.
  • In this case the dimension GetSizeX() and GetSizeY() returns zero.

This allowes to Include() a point in an empty rectangle which sets the lower and higher coordinates to the included point.

Murl.Math.Rectangle new()

Returns
Murl.Math.Rectangle

Murl.Math.Rectangle.new(x1, y1, x2, y2)

Constructor to initialize a rectangle with given coordinates. Takes care of setting the lower and higher coordinates correctly.

Murl.Math.Rectangle new(Number x1, Number y1, Number x2, Number y2)

Parameters
x1The X coordinate of the first point.
y1The Y coordinate of the first point.
x2The X coordinate of the second point.
y2The Y coordinate of the second point.
Returns
Murl.Math.Rectangle


Methods


Set(x1, y1, x2, y2)

Set all coordinates of the rectangle instance to a set of given coordinates. Takes care of setting the lower and higher coordinates correctly.

Set(Number x1, Number y1, Number x2, Number y2)

Parameters
x1The X coordinate of the first point.
y1The Y coordinate of the first point.
x2The X coordinate of the second point.
y2The Y coordinate of the second point.

Set(other)

Copy the content of a source rectangle to the rectangle instance.

Set(Murl.Math.Rectangle other)

Parameters
otherThe rectangle to copy from.

SetX1(x1)

Set the horizontal start coordinate. This sets the coordinate without taking care about lower and higher coordinates.

SetX1(Number x1)

Parameters
x1The X coordinate of the first point.

SetY1(y1)

Set the vertical start coordinate. This sets the coordinate without taking care about lower and higher coordinates.

SetY1(Number y1)

Parameters
y1The Y coordinate of the first point.

SetX2(x2)

Set the horizontal end coordinate. This sets the coordinate without taking care about lower and higher coordinates.

SetX2(Number x2)

Parameters
x2The X coordinate of the second point.

SetY2(y2)

Set the vertical end coordinate. This sets the coordinate without taking care about lower and higher coordinates.

SetY2(Number y2)

Parameters
y2The Y coordinate of the second point.

SetPositionAndSize(x, y, sizeX, sizeY)

Set the x / y coordinate and the horizontal / vertical size of the rectangle.

SetPositionAndSize(Number x, Number y, Number sizeX, Number sizeY)

Parameters
xThe X coordinate of the first point.
yThe Y coordinate of the first point.
sizeXThe horizontal size of the rectangle.
sizeYThe vertical size of the rectangle.

SetSize(sizeX, sizeY)

Set the horizontal and vertical size of the rectangle.

SetSize(Number sizeX, Number sizeY)

Parameters
sizeXThe horizontal size of the rectangle.
sizeYThe vertical size of the rectangle.

SetSizeX(size)

Set the horizontal size of the rectangle.

SetSizeX(Number size)

Parameters
sizeThe horizontal size of the rectangle.

SetSizeY(size)

Set the vertical size of the rectangle.

SetSizeY(Number size)

Parameters
sizeThe vertical size of the rectangle.

GetX1()

Get the lower X coordinate.

Number GetX1()

Returns
Number The lower X coordinate.

GetY1()

Get the lower Y coordinate.

Number GetY1()

Returns
Number The lower Y coordinate.

GetX2()

Get the higher X coordinate.

Number GetX2()

Returns
Number The higher X coordinate.

GetY2()

Get the higher Y coordinate.

Number GetY2()

Returns
Number The higher Y coordinate.

GetSizeX()

Get the horizontal size of the rectangle.

Number GetSizeX()

Returns
Number The horizontal size of the rectangle or zero if the lower coordinate is greater than the higher coordinated.

GetSizeY()

Get the vertical size of the rectangle.

Number GetSizeY()

Returns
Number The vertical size of the rectangle or zero if the lower coordinate is greater than the higher coordinated.

GetArea()

Get the area occupied by the rectangle.

Number GetArea()

Returns
Number The area, i.e. GetSizeX() * GetSizeY();

Unite(other)

Unite this rectangle with another rectangle.

Unite(Murl.Math.Rectangle other)

Parameters
otherThe other rectangle to unite.

Intersect(other)

Intersect this rectangle with another rectangle.

Intersect(Murl.Math.Rectangle other)

Parameters
otherThe other rectangle to intersect.

Include(x, y)

Include a point in this rectangle. Sets the lower and higher coordinates to the included point if the rectangle is empty, see default constructor Rectangle().

Include(Number x, Number y)

Parameters
xThe x-position of the point to include.
yThe y-position of the point to include.

IsIntersecting(other)

Check if a given rectangle is intersecting this rectangle.

Boolean IsIntersecting(Murl.Math.Rectangle other)

Parameters
otherThe other rectangle to check.
Returns
Boolean true if the other rectangle is intersecting this rectangle.

IsEmpty()

Check if a given rectangle is empty, i.e. its area is zero.

Boolean IsEmpty()

Returns
Boolean true if the rectangle is empty.

IsEqual(r)

Check if the rectangle instance is equal to a given second rectangle. Compares all values within the default epsilon range Limits::Epsilon().

Boolean IsEqual(Murl.Math.Rectangle r)

Parameters
rThe rectangle to compare.
Returns
Boolean true if equal to the compared rectangle.

IsEqual(r, epsilon)

Check if the rectangle instance is equal to a given second rectangle. Compares all values within a given epsilon range.

Boolean IsEqual(Murl.Math.Rectangle r, Number epsilon)

Parameters
rThe rectangle to compare.
epsilonThe epsilon to compare.
Returns
Boolean true if equal to the compared rectangle.

ToString()

Get the string representation of the object.

String ToString()

Returns
String The string representation of the object.


Metamethods


The tostring operator

Converts the object content to a string in a reasonable format.

Returns
ToString()

The equal to operator.

Equal to comparison operator. Performs a test without an epsilon range, which can be used for detecting changes i.e. DoubleBuffer<Rectangle> class. To compare within an epsilon range use Rectangle::IsEqual().

Returns
Boolean = Murl.Math.Rectangle == Murl.Math.Rectangle