CRect:new
The new method constructs a new instance of a CRect object. The CRect class includes 4 properties that describe the minimum and maximum x values and the minimum and maximum y values. You can treat this object as a classic rectangle or you can use it simply to hold 4 numbers. Using this class method is equivalent to using the global function NewRect.
R = CRect:new() R = CRect:new( CRectOld ) R = CRect:new( xmin, xmax, ymin, ymax ) R = CRect:new( CImage ) R = CRect:new( CPoint ) R = CRect:new( array ) where The first form, with no arguments, creates a default CRect object R with properties initialized to 0,0,0,0. CRectOld is an existing CRect object. This form creates a new CRect object initialized to the properties of CRectOld. xmin, xmax, ymin, ymax. are numbers. This form creates a new CRect object initialized to these 4 values. CImage is a CImage object. this form creates a new CRect object initialized to the column and row dimensions of the CImage. The CRect properties will extend from 1 to CImage:Cols(), and 1 to CImage:Rows(). CPoint is a CPoint object. A new CRect object is created with its properties set to xmin=1, xmax=CPoint.x, ymin=1, and ymax=CPoint.y. array is a lua table containing at least indicides 1 through 4. Thie form creates a new CRect object with its properties set to the first 4 values in the array. The properties are set to xmin=array[1], xmax=array[2], ymin=array[3], ymax=array[4]. R is the new CRect object. On failure, 0,0,0,0 is returned. |
Since the constructor returns a new CRect object, it can be used in an expression, likeI:SetRegion(t,CRect:new(Pt)).
The following script illustrates using the 3 constructors. All produce the same result:
|
-- create CRect A and set values |
|
-- result: 100:300, 400:800 |
|
|
|
-- copy A to a new CRect B |
|
-- result: 100:300, 400:800 |
|
|
|
-- create a default CRect C |
|
|
|
-- result: 100:300, 400:800 |