APIAny_​TriangulatePolyID

Decomposes a polygon into triangles.

    GSErrCode ACAPI_Goodies (
        APIAny_TriangulatePolyID,
        API_ElementMemo*     memo,
        API_Coord***         coords
    );

 

Parameters

memo
[in] Parameters of an polygon. The coordinates of the polygon and the subpolygon endpoints must be coords handle and pends handle in the memo.
coords
[out] Coordinates of the triangles

 

Return Values

NoError
The function has completed with success.
APIERR_BADPARS
any of the parameters are nullptr
APIERR_REFUSEDPAR
Arc in the polygon
APIERR_MEMFULL
Not enough memory to complete the operation
APIERR_IRREGULARPOLY
Input polygon is irregular.

For other common API errors see the API Errors document.

 

Remarks

This function is used to decompose a polygon into triangles. The coords handle will be allocated by the server application and filled with coordinates. The number of generated triangles should be determined based on the returned handle size.

The function accept only polygons which has no arc segments.

Do not forget to dispose the coords handle if it is not needed any more.

 

Example


#include  "GSBase.h"      /* BMhKill */

GSErrCode TriangulateSlab (const API_Guid& slabGuid)
{
    API_Element       element;
    API_ElementMemo   memo;
    API_Coord         **coords;
    Int32             nTriangles;
    GSErrCode         err;

    BNZeroMemory (&memo, sizeof (API_ElementMemo));
    BNZeroMemory (&element, sizeof (API_Element));
    element.header.guid = slabGuid;

    err = ACAPI_Element_Get (&element);
    if (!err) {
        if (element.slab.poly.nArcs > 0)
            return APIERR_REFUSEDPAR;
            err = ACAPI_Element_GetMemo (element.header.guid, &memo);
            if (!err) {
            err = ACAPI_Goodies (APIAny_TriangulatePolyID, &memo, &coords);
            if (!err) {
                nTriangles = BMGetHandleSize ((GSHandle) coords) / (3 * sizeof (API_Coord));
                /* ... */
                BMKillHandle ((GSHandle *) &coords);
            }
            ACAPI_DisposeElemMemoHdls (&memo);
        }
    }

    return err;
}

 

Requirements

Version: API 4.1 or later
Header: APIdefs_Goodies.h

 

See Also

API_ElementMemo, API_Coord,
ACAPI_Goodies, API Functions