CPoint:new


The new method constructs a new instance of a CPoint object. The CPoint class includes 2 properties that describe the x and y values of a point. You can treat this object as a classic point or you can use it simply to hold 2 numbers. Using this class method is equivalent to using the global function NewPoint.

Syntax

P = CPoint:new()

P = CPoint:new( CPointOld )

P = CPoint:new( x, y )

P = CPoint:new( x )

P = CPoint:new( CRect )

P = CPoint:new( array )

where

    The first form with no arguments creates a default CPoint object with properties initialized to the default values 0,0.

    If a CPoint is passed, a new CPoint object is created initialized to the properties of the CPointOld argument.

    x, y are numbers, If two numbers are passed, the new CPoint is inialized accordingly. If one number is passed, both x and y properties are initialized to the same value.

    If a CRect is passed, the CPoiont is initialized to the width and height of the rectangle. This is useful for using the CPoint as a size measurement.

    If a lua array is passed, the new CPoint is initialized to the first 2 values in a Lua array, in particular, the values of array[1] and array[2].

    A new CPoint object, P, is returned.

Example

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

A = CPoint:new(100,300)

-- create CPoint A and set values

Printf("%d %d", A.x, A.y )

-- result: 100 300

 

 

B = CPoint:new(A)

-- copy CPoint A to a new CPoint B

Printf("%d %d", B.x, B.y )

-- result: 100 300

 

 

C = CPoint:new()

-- create a default CPoint C

C:Set(100,300)

 

Printf("%d %d", C.x, C.y )

-- result: 100 300

Related Topics

delete

CPoint class

NewPoint

CRect class