Chapter 12:
Polygon Functions
 

AddPolyPoint(); Add Polygon Points

 

AllocPolyHandle(); Allocate a Poly Handle

 

ClonePolyHandle(); Clone a Poly Handle

 

ClosePolyHandle(); Close a Poly Handle

 

dump_PolyHandle(); Output information about a polygon

 

FreePolyHandle(); Free Poly Handle

 

GetPolyBounds(); Get Polygon Bounds

 

GetPolyPoint(); Get Polygon Point

 

GetPolyPointCount(); Get Polygon Point Count

 

GetPolyPtrBounds(); Get Polygon Point Bounds

 

GetPolyPtrPointCount(); Get Polygon Point Count

 

LockPolyHandle(); Lock a polygon handle

 

Points2Poly(); Put points into a polygon

 

UnlockPolyHandle(); Unlock polygon handle

AddPolyPoint

 

This function creates a point in the polygon (pPolyHdl). For non-Windows implementations, the flag isFirstPoint indicates whether the point being created is the first point in the polygon. (1 = it is the first point).

Syntax:

INT16 PUBLIC
AddPolyPoint (
     _PolyHandle FAR * hPoly,
     INT16 x,
     INT16 y,
     int isFirstPoint
);

Input:

hPoly: A polygon handle created by the AllocPolyHandle() function

 

x/y: Two INT16 values indicating the X,Y coordinates of a point

 

isFirstPoint: 0/1

 

0=

this is not the first point in the polygon

 

1=

this is the first point in the polygon

Return:

INT16: 0/1

 

0=

Error

 

1=

No Error (new point created)

Also See:

GetPolyPoint(), GetPolyPointCount(), GetPolyPtrBounds(), GetPolyPtrPointCount()

   

AllocPolyHandle

 

This function allocates memory to define a polygon the size of nPoints and returns a handle/pointer to the polygon data structure

Syntax:

_PolyHandle PUBLIC
AllocPolyHandle (
     INT16 nPoints
);

Input:

nPoints: INT16 Value indicating the number of points in the polygon.

Return:

_PolyHandle: Pointer to a polygon data structure

Also See:

ClonePolyHandle(), ClosePolyHandle(), dump_PolyHandle(), FreePolyHandle(), LockPolyHandle(), UnlockPolyHandle()

   

ClonePolyHandle

 

This function copies the polygon information structure at phPoly to a new memory location.

Syntax:

BOOLEAN16 PUBLIC
ClonePolyHandle (
     _PolyHandle FAR * phPoly
);

Input:

phPoly: A polygon handle created by the AllocPolyHandle() function

Return:

BOOLEAN16: TRUE/FALSE

 

TRUE=

polygon handle successfully cloned/copied

 

FALSE=

memory error occurred

Notes:

Your application must have previously called AllocPolyHandle() to allocate the polygon information structure and obtain the handle that is required as input to this function.

Also See:

AllocPolyHandle(), ClosePolyHandle(), dump_PolyHandle(), Duplicate(), FreePolyHandle()

   

ClosePolyHandle

 

This function closes the polygon handle (hPoly).

Syntax:

void PUBLIC
ClosePolyHandle (
     _PolyHandle FAR * hPoly
);

Input:

hPoly: A polygon handle created by the AllocPolyHandle() function

Return:

None

Example:

hPoly = AllocPolyHandle ( 0 );
if ( !hPoly ) return E00_MEM_ERROR
for ( i=0; i < nPoints; i++ )
     AddPolyPoint ( &hPoly,
          xyPoint[i*2],
          xyPoint[i*2+1], (i == 0) );
ClosePolyHandle ( &hPoly );

Also See:

AllocPolyHandle(), ClonePolyHandle(), dump_PolyHandle(), Duplicate(), FreePolyHandle()

   

dump_PolyHandle

 

This is a debugging function that outputs information about the polygon identified by hPoly.

Syntax:

void PUBLIC
dump_PolyHandle (
     _PolyHandle hPoly
);

Input:

hPoly: Polygon handle

Return:

None

   

FreePolyHandle

 

This function frees the memory allocated for the polygon handle identified by hpoly.

Syntax:

void PUBLIC
FreePolyHandle (
     _PolyHandle hPoly
);

Input:

hPoly: A polygon handle created by the AllocPolyHandle() function

Return:

None

Example:

switch (pNode->nNodeType)
{
case POLYGON:
case POLYLINE:
if (pNode->info.poly.hPoly) {
     FreePolyHandle(pNode->info.poly.hPoly);
     pNode->info.poly.hPoly = NULL;
     }
break;

Also See:

AllocPolyHandle()

   

GetPolyBounds()

 

This function stores the polygon boundary information (x,y coordinates) in the rectangle data structure identified by pRect.

Syntax:

void PUBLIC
GetPolyBounds (
     _PolyHandle hPoly,
     Rect FAR * pRect
);

Input:

hPoly: A polygon handle created by the AllocPolyHandle() function

 

pRect: Pointer to a rectangle data structure. See the Rect structure in Appendix A.

Return:

None

Also See:

GetPolyPoint()

GetPolyPoint()

 

This function sets pnX and pnY to the polygon point at nIndex.

Syntax:

INT16 PUBLIC
GetPolyPoint (
     _PolyHandle FAR *pPolyHdl,
     INT16 nIndex,
     PINT16 pnX,
     PINT16 pnY
);

Input:

pPolyHdl: Pointer to a polygon handle

 

nIndex: Index number of polygon point

 

pnX: Place to store x-coordinate of point. Will be -1 if nIndex is invalid

 

pnY: Place to store y-coordinate of point. Will be -1 if nIndex is invalid.

Return:

INT16; 0/1

 

Value

Description

 

One =

OK

 

Zero =

nIndex was invalid

Example:

if (
     !GetPolyPoint ( &rPoly,
           (INT16) i,
          &nX, &nY) )
nError = ETDI_STDPOLY_FAILURE

Also See:

GetPolyBounds(), GetPolyPointCount()

   

GetPolyPointCount()

 

This function returns the number of points defined in the polygon identified by hPoly.

Syntax:

INT16 PUBLIC
GetPolyPointCount (
     _PolyHandle hPoly
);

Input:

hPoly: A polygon handle created by the AllocPolyHandle() function

Return:

INT16 value indicating the number of points in the polygon

Example:

INT16 ulPoints;
ulPoints =
     GetPolyPointCount ( hPoly );

Also See:

GetPolyPoint()

GetPolyPtrBounds()

 

This function sets the rectangle pRect to the boundaries of the polygon identified by pPoly.

Syntax:

void PUBLIC
GetPolyPtrBounds (
     _PolyPtr pPoly,
     Rect FAR * pRect
);

Input:

pPoly: Pointer to a polygon returned by LockPolyHandle()

 

pRect: Pointer to a rectangle data structure. See the Rect structure in Appendix A.

Return:

None

Also See:

GetPolyBounds()

   

GetPolyPtrPointCount()

 

This function returns the number of points in the polygon identified by pPoly.

Syntax:

INT16 PUBLIC
GetPolyPtrPointCount (
     _PolyPtr pPoly
);

Input:

pPoly: Pointer to a polygon returned by LockPolyHandle()

Return:

INT16 : Number of points defined in the polygon

Also See:

GetPolyPointCount()

   

LockPolyHandle

 

This function locks the polygon handle specified by the input parameter hPoly.

Syntax:

_PolyPtr PUBLIC
LockPolyHandle (
     _PolyHandle hPoly
);

Input:

hPoly: Polygon handle

Return:

PolyPtr: Pointer to the locked polygon handle

Example:

pNode = (AnodeInfoPtr)
     LockHandle((MEMHDL)hNode);
pPoly = LockPolyHandle(
     pNode->info.poly.hPoly);
pointCount = GetPolyPtrPointCount(pPoly);
pNode->bounds.left = PointX(&pPoly->polyPoints[0]);
pNode->bounds.right = PointX(&pPoly->polyPoints[0]);
pNode->bounds.top = PointY(&pPoly->polyPoints[0]);
pNode->bounds.bottom = PointY(&pPoly->polyPoints[0]);
UnlockPolyHandle(pNode->info.poly.hPoly);

Also See:

UnlockPolyHandle()

   

Points2Poly

 

This function puts nCount points at ptData into a polygon.

Syntax:

_PolyHandle PUBLIC
Points2Poly (
     Point *ptData,
     INT16 nCount
);

Input:

ptData: Place where points are stored

 

nCount: Number of points

Return:

PolyHandle: Polygon handle

Example:

/*** put data points into a Mac polygon ***/
slicePoly = Points2Poly(ptData, nCount);
if (!slicePoly) return E00_MEM_ERROR;

Also See:

GetPolyPoint(), GetPolyPointCount()

   

UnlockPolyHandle

 

This function unlocks a polygon handle previous locked by LockPolyHandle().

Syntax:

void PUBLIC
UnlockPolyHandle (
     _PolyHandle hPoly
);

Input:

hPoly: Polygon handle

Return:

None

Example:

/* Unlock the anode handle and poly handle */
switch (nDestID) {
case DESTID_GRAPH_ANODEMASTER:
     UnlockPolyHandle(
          pAnodeInfo->info.poly.hPoly);
break;
}

Also See:

AllocPolyHandle(), LockPolyHandle()