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 Note that the object can also be created using new_rect.

Syntax

R = CRect:new()

bullet.gif    Creates a default CRect object with properties initialized to the default values 0,0,0,0.

R = CRect:new( CRect2 )

bullet.gif    This is a copy constructor. It creates a new CRect object initialized to the properties of the CRect2 argument.

R = CRect:new( xmin, xmax, ymin, ymax )

bullet.gif    Creates a CRect object initialized to xmin, xmax, ymin, ymax.

R = CRect:Set( xmin, xmax, ymin, ymax )

bullet.gif    Creates a new CRect object with properties set to the numbers nXmin, nXmax, nYmin, and nYmax. The values may be positive or negative. If the rectangle will involve working with images or arrays, then the values of nXmin and nXmax should usually be 1.

R = CRect:new( CImage )

bullet.gif    Creates a new CRect object initialized to the column and row dimensions of a CImage. The rectangle will extend from 1 to CImage:Cols(), and 1 to CImage:Rows().

R = CRect:new( table )

bullet.gif    Creates a new CRect object from the first 4 values in a 1-dimensional array, in particular, the values of table[1] through table[4]. These numbers are assigned in order to the rectangle properties xmin, xmax, ymin, and ymax.

bullet.gif    On failure, nil is returned.

Remarks

These different constructors are provided to greatly expand the versatility of the CRect class. Also, since the contructor returns the new CRect, the constructor is useful in an expression, like I:SetRegionVal( t, CRect:new(Point) ).

Example

The following script illustrates using the 3 constructors. All produce the same result:

A = CRect:new(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 = CRect:new(A)

-- copy 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 = CRect:new()

-- 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, delete, new_rect


Mira Pro x64 Script User's Guide, Copyright Ⓒ 2024 Mirametrics, Inc. All Rights Reserved.