C:InsertPt


The InsertPt function inserts a point at an index that already exists in the CPolygon. If the index is outside the range [1, CPolygon:Count()], the method fails.

Syntax

bSuccess = CPolygon:InsertPt( nIndex, x, y )

bSuccess = CPolygon:InsertPt( nIndex, array )

bSuccess = CPolygon:InsertPt( nIndex, CPoint )

where

    nIndex is the index where to insert the point.

    x, y are two numbers for a new point inserted at index nIndex.

    array is a Lua array with indices [1] and [2] which are inserted as a new vertex at index nIndex.

    CPoint is a CPoint whose (x,y) values are inserted at index nIndex.

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

Example

The following script creates a CPolygon object and then changes the (x,y) values at index 5.

x {-1,0,1,2,3,4} ; y = {4,5,6,7,8,9}

 

A = NewPolygon( x, y )

-- create a CPolygon with 6 points

Printf("[5] = %lg,%lg", A:GetPt(5) )

-- result: [5] = 3,8

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

-- result: Count = 6

 

 

bSuccess = A:InsertPt( 5, 100, 200 )

-- insert at index [5]

if bSuccess then

 

  Printf("[5] = %lg,%lg", A:GetPt(5) )

-- result: [5] = 100,200

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

-- result: Count = 7

else Printf("Point not inserted") end

 

 

 

t = { 10,11,12,13,14,15 }

-- create a table with at least index 1 and 2

bSuccess = A:InsertPt( 5, t )

-- insert at index [5]

if bSuccess then

 

  Printf("[5] = %lg,%lg", A:GetPt(5) )

-- result: [5] = 10,11

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

-- result: Count = 8

else Printf("Point not inserted") end

 

The next example follows the above script by attempting to insert a point at index [21], which is out of bounds:

bSuccess = A:InsertPt( 21, 50, 60 )

-- insert at index [21]

if bSuccess then

 

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

-- result: Count = 8

  Printf("[21] = %lg,%lg", A:GetPt(21) )

 

else Printf("Point not inserted") end

-- result: Point not inserted

Related Topics

Add

SetPt

CPolygon class