Instant constructors: rect()
The instant constructor rect() creates a rect operand dynamically. Rect operands describe 2D rectangles, each with two coordinate pairs specifying the positions for the top-left and for the bottom-right rectangle corners. The top-left corner is also assumed to be the origin of the rectangle.
Declaration
rect rect( int32 aX1, int32 aY1, int32 aX2, int32 aY2 )
rect rect( point aPoint1, point aPoint2 )
rect rect()
Parameters
aX1
The X coordinate of the top-left (the origin) rectangle corner.
aY1
The Y coordinate of the top-left (the origin) rectangle corner.
aX2
The X coordinate of the bottom-right rectangle corner.
aY2
The Y coordinate of the bottom-right rectangle corner.
aPoint1
The X,Y coordinates of the top-left (the origin) rectangle corner expressed as a single point value.
aPoint2
The X,Y coordinates of the bottom-right rectangle corner expressed as a single point value.
Discussion
The first version of the rect() constructor returns a rect value with the top-left corner (the origin) arranged at the position aX1, aY1 and the bottom-right corner at the position aX2, aY2. This results in a rectangle having the width aX2-aX1 and the height aY2-aY1. For example:
var int32 x = 100; var int32 y = 200; var int32 width = 20; var int32 height = 10; var rect bounds = rect( x, y, x + w, y + h ); // bounds = <100,200,120,210>
The second version of the rect() constructor returns a rect value with the top-left corner (the origin) arranged at the position aPoint1 and the bottom-right corner at the position aPoint2. This results in a rectangle having the size aPoint2-aPoint1. For example:
var point origin = <100,200>; var point size = <20,10>; var rect bounds = rect( origin, origin + size ); // bounds = <100,200,120,210>
The third version of the rect() constructor doesn't accept any arguments. It simply returns a rect value with all coordinates set to 0 (zero). The function of this constructor corresponds thus to the rect literal <0,0,0,0>.
var rect bounds = rect(); // bounds = <0,0,0,0>