CPolygon:SetPt


The SetPt function changes the (x,y) values for a point already in the CPolygon. If the index is outside the range [1, CPolygon:Count()], the method fails.

Syntax

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

bSuccess = CPolygon:SetPt( nIndex, array )

bSuccess = CPolygon:SetPt( nIndex, CPoint )

where

    nIndex is the index where to insert the point.

    x, y are two numbers that replace the (x,y) values at index nIndex.

    array is a Lua array with containing indices [1] and [2] that are used as the x and y values.

    CPoint is a CPoint object whose (x,y) values replace those 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

 

 

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

-- change x,y at index [5]

if bSuccess then

 

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

-- result: [5] = 100,200

else Printf("Point not set") end

 

 

 

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

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

bSuccess = A:SetPt( 5, t )

-- change x,y at index [5]

if bSuccess then

 

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

-- result: [5] = 10,11

else Printf("Point not set") end

 

The next example follows the above script by attempting to change the value at index [21], which does not already exist in the CPolygon:

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

-- change x,y at index [21]

if bSuccess then

 

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

 

else Printf("Point not set") end

-- result: Point not set

Related Topics

Add

InsertPt

CPolygon class