vtdata library
Public Member Functions | List of all members
DPolygon2 Class Reference

Inherits DLine2Array.

Public Member Functions

uint NumTotalVertices () const
 
bool ComputeExtents (DRECT &rect) const
 
bool ContainsPoint (const DPoint2 &p) const
 
void GetAsDLine2 (DLine2 &dline) const
 
int WhichRing (int &iVtxNum) const
 
void NearestPoint (const DPoint2 &Point, int &iIndex, double &dist) const
 
bool NearestSegment (const DPoint2 &Point, int &iIndex, double &dist, DPoint2 &Intersection) const
 
void Add (const DPoint2 &p)
 
void Mult (double factor)
 
void ReverseOrder ()
 
void InsertPointAfter (int iInsertAfter, const DPoint2 &Point)
 
void RemovePoint (int N)
 
int RemoveDegeneratePoints (double dEpsilon)
 
int RemoveColinearPoints (double dEpsilon)
 

Detailed Description

We represent a polygon as a collection of closed rings, each of which is represented by a DLine2. The first DLine2 is the 'outside' ring, any subsequent DLine2 are 'inside' rings, which are holes.

In most usage, there should be a consistency in the vertex ordering: the 'outside' ring should be counter-clockwise, and the 'inside' ring(s) should be clockwise.

Member Function Documentation

void DPolygon2::Add ( const DPoint2 p)

Add the given amount to all coordinates of the polygon. Spatially, this offsets the location of the polygon.

void DPolygon2::GetAsDLine2 ( DLine2 dline) const

Normally the polygon is stored as a series of rings. Sometimes it is necessary to access the polygon as a single array of points instead.

This method fills a provided DLine2 with all the points of all rings of the polygon.

void DPolygon2::InsertPointAfter ( int  iInsertAfter,
const DPoint2 Point 
)

The insertion point can be on the outer ring, or any inner ring.

void DPolygon2::Mult ( double  factor)

Multiplies (scales) all the coordinates of the polygon.

void DPolygon2::NearestPoint ( const DPoint2 Point,
int &  iIndex,
double &  dClosest 
) const

Return the nearest point (of the points which make up the line). This is not the same as the closest place on the line, which may lie between the defining points; use NearestSegment to find that.

Parameters
PointThe input point.
iIndexIndex of the first point of the nearest line segment.
dClosestDistance from the DLine2 to the input point.
bool DPolygon2::NearestSegment ( const DPoint2 Point,
int &  iIndex,
double &  dist,
DPoint2 Intersection 
) const

Returns the location of the closest point on the polygon to a given point.

Parameters
PointThe input point.
iIndexIndex of the first point of the nearest line segment.
distDistance from the DPolygon2 to the input point.
IntersectionThe closest point on the DPolygon2.
Returns
True if a closest point was found.
int DPolygon2::RemoveColinearPoints ( double  dEpsilon)

For each ring of the polygon, remove any points which are co-linear, defined as point p(n) which is less than dEpsilon displaced from the line from P(n-1) to P(n+1)

Returns
The number of points that were removed.
int DPolygon2::RemoveDegeneratePoints ( double  dEpsilon)

For each ring of the polygon, remove any points which are degenerate (less than dEpsilon apart).

Returns
The number of points that were removed.
void DPolygon2::RemovePoint ( int  N)

The Nth point can be on the outer ring, or any inner ring.