CPolygon:Add


The Add function adds point data to the CPolygon. The new data are appended to the existing points in the polygon.

Syntax

bSuccess = CPolygon:Add( x, y )

bSuccess = CPolygon:Add( array )

bSuccess = CPolygon:Add( arrayX, arrayY )

bSuccess = CPolygon:Add( CPoint )

bSuccess = CPolygon:Add( CPolygonOld )

where

    x, y are two numbers that are added as a new point.

    array is a Lua array with elements [1] and [2] which are appended as a new point of the current CPolygon.

    CPoint is a CPoint object that is added as a new point.

    CPolygonOld is an existing CPolygon object whose points are appended to those in the current CPolygon.

    bSuccess is the returned success code. On success it is true, otherwise false.

 

This method provides a way to append 1 or more points to the points already in the CPolygon object. There are several methods for adding points to a CPolygon:

Methods for Adding Points to a CPolygon

Add

Appends 1 or more points to those already in the CPolygon.

CopyPts

Replaces all existing points with those in another CPolygon.

InsertPt

Inserts a new point at an index already in the CPolygon and increases by 1 the indices of all points above the insertion point.

SetPt

Assigns new x,y values to an existing point index.

Example

Suppose a CPolygon A already exists and may or may not contain points. The following script illustrates adding points to the polygon.

 

A:Add( 2, 3 )

-- add a point with (x=2, y=3)

 

 

x = {1,2,3,4} ; y = {10,11,12,13}

-- create tables x and y points

A:Add( x, y )

-- add 4 more points to A

 

 

P = NewPoint( 2, 4 )

-- create a CPoint

A:Add( P )

-- add 1 point with (x=2,y=4)

 

 

x = {2,34,5,6,7,3} ; y = {1,2,-3,5,-12,4}

-- create x and y tables with 6 points

B = NewPolygon( x, y )

-- create a new CPolygon

A:Add( B )

-- add 6 points to A

Printf("Count = %d", A:Count() )

-- result: Count = 10

B:delete()

-- delete B object if no longer needed

Related Topics

CopyPts

InsertPt

SetPt

CPolygon class