⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 ugkpolygon.cpp

📁 linux下一款GIS程序源码
💻 CPP
📖 第 1 页 / 共 2 页
字号:
// ugkpolygon.cpp: implementation of the UGKPolygon class.////////////////////////////////////////////////////////////////////////#include "ugkpolygon.h"#include "ugk_memopr.h"#define NUM_SCANLINES 5typedef enum {CLIP_LEFT, CLIP_MIDDLE, CLIP_RIGHT} CLIP_STATE;#define CLIP_CHECK(min, a, max) ((a) < (min) ? CLIP_LEFT : ((a) > (max) ? CLIP_RIGHT : CLIP_MIDDLE));#define EDGE_CHECK( x0, x, x1) ((x) < MIN( (x0), (x1)) ? CLIP_LEFT : ((x) > MAX( (x0), (x1)) ? CLIP_RIGHT : CLIP_MIDDLE ))#define SWAP( a, b, t) ( (t) = (a), (a) = (b), (b) = (t) )#define UGK_NUM_RINGS(poly)   (poly->getNumInteriorRings()+1)#define UGK_GET_RING(poly, i) (i==0?poly->getExteriorRing():poly->getInteriorRing(i-1))/************************************************************************//*                             UGKPolygon()                             *//************************************************************************/UGKPolygon::UGKPolygon(){	nRingCount = 0;	papoRings  = NULL;}/************************************************************************//*                            ~UGKPolygon()                             *//************************************************************************/UGKPolygon::~UGKPolygon(){	empty();}/************************************************************************//*                               clone()                                *//************************************************************************/UGKGeometry *UGKPolygon::clone() const{    UGKPolygon  *poNewPolygon;    poNewPolygon = new UGKPolygon;    for( int i = 0; i < nRingCount; i++ )    {        poNewPolygon->addRing( papoRings[i] );    }    return poNewPolygon;}/************************************************************************//*                               empty()                                *//************************************************************************/void UGKPolygon::empty(){    if( papoRings != NULL )    {        for( int i = 0; i < nRingCount; i++ )        {            delete papoRings[i];        }        UGK_Free( papoRings );    }    papoRings = NULL;    nRingCount = 0;}/************************************************************************//*                          getGeometryType()                           *//************************************************************************/UGKwkbGeometryType UGKPolygon::getGeometryType() const{    if( getCoordinateDimension() == 3 )        return wkbPolygon25D;    else        return wkbPolygon;}/************************************************************************//*                            getDimension()                            *//************************************************************************/int UGKPolygon::getDimension() const{    return 2;}/************************************************************************//*                       getCoordinateDimension()                       *//************************************************************************/int UGKPolygon::getCoordinateDimension() const{    for( int iRing = 0; iRing < nRingCount; iRing++ )    {        if( papoRings[iRing]->getCoordinateDimension() == 3 )            return 3;    }    return 2;}/************************************************************************//*                            flattenTo2D()                             *//************************************************************************/void UGKPolygon::flattenTo2D(){    for( int iRing = 0; iRing < nRingCount; iRing++ )        papoRings[iRing]->flattenTo2D();}/************************************************************************//*                          getGeometryName()                           *//************************************************************************/const char * UGKPolygon::getGeometryName() const{    return "POLYGON";}/************************************************************************//*                          getExteriorRing()                           *//************************************************************************//** * Fetch reference to external polygon ring. * * Note that the returned ring pointer is to an internal data object of * the UGKPolygon.  It should not be modified or deleted by the application, * and the pointer is only valid till the polygon is next modified.  Use * the UGKGeometry::clone() method to make a separate copy within the * application. * * @return pointer to external ring.  May be NULL if the UGKPolygon is empty. */UGKLinearRing *UGKPolygon::getExteriorRing(){    if( nRingCount > 0 )        return papoRings[0];    else        return NULL;}const UGKLinearRing *UGKPolygon::getExteriorRing() const{    if( nRingCount > 0 )        return papoRings[0];    else        return NULL;}/************************************************************************//*                        getNumInteriorRings()                         *//************************************************************************//** * Fetch the number of internal rings. * * @return count of internal rings, zero or more. */int UGKPolygon::getNumInteriorRings() const{    if( nRingCount > 0 )        return nRingCount-1;    else        return 0;}/************************************************************************//*                          getInteriorRing()                           *//************************************************************************//** * Fetch reference to indicated internal ring. * * Note that the returned ring pointer is to an internal data object of * the UGKPolygon.  It should not be modified or deleted by the application, * and the pointer is only valid till the polygon is next modified.  Use * the UGKGeometry::clone() method to make a separate copy within the * application. * * @param iRing internal ring index from 0 to getNumInternalRings() - 1. * * @return pointer to external ring.  May be NULL if the UGKPolygon is empty. */UGKLinearRing *UGKPolygon::getInteriorRing( int iRing ){    if( iRing < 0 || iRing >= nRingCount-1 )        return NULL;    else        return papoRings[iRing+1];}const UGKLinearRing *UGKPolygon::getInteriorRing( int iRing ) const{    if( iRing < 0 || iRing >= nRingCount-1 )        return NULL;    else        return papoRings[iRing+1];}/************************************************************************//*                              addRing()                               *//************************************************************************//** * Add a ring to a polygon. * * If the polygon has no external ring (it is empty) this will be used as * the external ring, otherwise it is used as an internal ring.  The passed * UGKLinearRing remains the responsibility of the caller (an internal copy * is made). * * @param poNewRing ring to be added to the polygon. */void UGKPolygon::addRing( UGKLinearRing * poNewRing ){    papoRings = (UGKLinearRing **) UGK_Realloc( papoRings,                                               sizeof(void*) * (nRingCount+1));    papoRings[nRingCount] = new UGKLinearRing( poNewRing );    nRingCount++;}/************************************************************************//*                          addRingDirectly()                           *//************************************************************************//** * Add a ring to a polygon. * * If the polygon has no external ring (it is empty) this will be used as * the external ring, otherwise it is used as an internal ring.  Ownership * of the passed ring is assumed by the UGKPolygon, but otherwise this * method operates the same as UGKPolygon::AddRing(). * * @param poNewRing ring to be added to the polygon. */void UGKPolygon::addRingDirectly( UGKLinearRing * poNewRing ){    papoRings = (UGKLinearRing **) UGK_Realloc( papoRings,                                               sizeof(void*) * (nRingCount+1));    papoRings[nRingCount] = poNewRing;    nRingCount++;}/************************************************************************//*                              WkbSize()                               *//*                                                                      *//*      Return the size of this object in well known binary             *//*      representation including the byte order, and type information.  *//************************************************************************/int UGKPolygon::WkbSize() const{    int         nSize = 9;    int         b3D = getCoordinateDimension() == 3;    for( int i = 0; i < nRingCount; i++ )    {        nSize += papoRings[i]->_WkbSize( b3D );    }    return nSize;}/************************************************************************//*                              Centroid()                              *//************************************************************************//** * Compute the polygon centroid. * * The centroid location is applied to the passed in UGKPoint object. * * @return UGKERR_NONE on success or UGKERR_FAILURE on error. */

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -