📄 ugklinearring.cpp
字号:
// ugklinearring.cpp: implementation of the UGKLinearRing class.////////////////////////////////////////////////////////////////////////#include "ugklinearring.h"#include <assert.h>#include <math.h>/************************************************************************//* UGKLinearRing() *//************************************************************************/UGKLinearRing::UGKLinearRing(){}/************************************************************************//* ~UGKLinearRing() *//************************************************************************/UGKLinearRing::~UGKLinearRing(){}/************************************************************************//* UGKLinearRing() *//************************************************************************/UGKLinearRing::UGKLinearRing( UGKLinearRing * poSrcRing ){ assert(poSrcRing != NULL); setNumPoints( poSrcRing->getNumPoints() ); memcpy( paoPoints, poSrcRing->paoPoints, sizeof(UGKRawPoint) * getNumPoints() ); if( poSrcRing->padfZ ) { Make3D(); memcpy( padfZ, poSrcRing->padfZ, sizeof(double) * getNumPoints() ); }}/************************************************************************//* getGeometryName() *//************************************************************************/const char * UGKLinearRing::getGeometryName() const { return "LINEARRING";}/************************************************************************//* WkbSize() *//* *//* Disable this method. *//************************************************************************/int UGKLinearRing::WkbSize() const{ return 0;}/************************************************************************//* _WkbSize() *//* *//* Helper method for UGKPolygon. NOT THE NORMAL WkbSize() METHOD! *//************************************************************************/int UGKLinearRing::_WkbSize( int b3D ) const{ if( b3D ) return 4 + 24 * nPointCount; else return 4 + 16 * nPointCount;}/************************************************************************//* clone() *//* *//* We override the UGKCurve clone() to ensure that we get the *//* correct virtual table. *//************************************************************************/UGKGeometry *UGKLinearRing::clone() const{ UGKLinearRing *poNewLinearRing; poNewLinearRing = new UGKLinearRing(); poNewLinearRing->setPoints( nPointCount, paoPoints, padfZ ); return poNewLinearRing;}/************************************************************************//* isClockwise() *//************************************************************************//* 判断是否是顺时针 *//** * Returns TRUE if the ring has clockwise winding. * * @return TRUE if clockwise otherwise FALSE. */int UGKLinearRing::isClockwise() const{ double dfSum = 0.0; for( int iVert = 0; iVert < nPointCount-1; iVert++ ) { dfSum += paoPoints[iVert].x * paoPoints[iVert+1].y - paoPoints[iVert].y * paoPoints[iVert+1].x; } dfSum += paoPoints[nPointCount-1].x * paoPoints[0].y - paoPoints[nPointCount-1].y * paoPoints[0].x; return dfSum < 0.0;}/************************************************************************//* closeRing() *//* 让曲线封闭成一个环 *//************************************************************************/void UGKLinearRing::closeRings(){ if( nPointCount < 2 ) return; if( getX(0) != getX(nPointCount-1) || getY(0) != getY(nPointCount-1) || getZ(0) != getZ(nPointCount-1) ) { addPoint( getX(0), getY(0), getZ(0) ); }}/************************************************************************//* get_Area() *//* 返回封闭区域的面积 *//************************************************************************//** * Compute area of ring. * * The area is computed according to Green's Theorem: * * Area is "Sum(x(i)*y(i+1) - x(i+1)*y(i))/2" for i = 0 to pointCount-1, * assuming the last point is a duplicate of the first. * * @return computed area. */double UGKLinearRing::get_Area() const{ double dfAreaSum = 0.0; int i; for( i = 0; i < nPointCount-1; i++ ) { dfAreaSum += 0.5 * ( paoPoints[i].x * paoPoints[i+1].y - paoPoints[i+1].x * paoPoints[i].y ); } dfAreaSum += 0.5 * ( paoPoints[nPointCount-1].x * paoPoints[0].y - paoPoints[0].x * paoPoints[nPointCount-1].y ); return fabs(dfAreaSum);}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -