NewPoint


The NewPoint function returns a new CPoint object. This function is a global form of the CPoint:new method. The CPoint class includes x and y properties. You can use this object as a coordinate point or simply as a pair of numbers that are processed together.

Syntax

P = NewPoint()

P = NewPoint( CPointOld )

P = NewPoint( x, y )

P = NewPoint( x )

P = NewPoint( CPoint )

P = NewPoint( CRect )

P = NewPoint( 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.

 Since this function returns a new CPoint object, it is useful in expressions like I:Setn(NewPoint(t)).

Example

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

 

A = NewPoint(100,300)

-- create CPoint A and set values

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

-- result: 100 300

 

 

B = NewPoint(A)

-- copy CPoint A to a new CPoint B

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

-- result: 100 300

 

 

C = NewPoint()

-- create a default CPoint C

C:Set(100,300)

 

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

-- result: 100 300

Related Topics

CPoint class

CRect class