NewRect


The NewRect function creates and returns a new CRect object. This function is a global form of the CRect:new method. 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 and manipulate 4 numbers.

Syntax

R = NewRect()

R = NewRect( CRectOld )

R = NewRect( xmin, xmax, ymin, ymax )

R = NewRect( CImage )

R = NewRect( CPoint )

R = NewRect( 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 a new CRect object.

  

Since this function returns a new CRect object, it can be used in an expression like I:SetRegion(t,NewRect(Pt)).

Example

The following script illustrates using various forms of NewRect. All produce the same result:

 

A = NewRect(100,300,400,800)

-- create CRect A and set values

Printf("%d:%d,%d:%d", A.xmin,A.xmax,A.ymin,A.ymax )

-- result: 100:300, 400:800

 

 

B = NewRect(A)

-- copy CRect A to a new CRect B

Printf("%d:%d,%d:%d", B.xmin,B.xmax,B.ymin,B.ymax )

-- result: 100:300, 400:800

 

 

C = NewRect()

-- create a default CRect C

C:Set(100,300,400,800)

 

Printf("%d:%d,%d:%d", C.xmin,C.xmax,C.ymin,C.ymax )

-- result: 100:300, 400:800

Related Topics

CRect class

CPoint class