vtdata library
|
Public Member Functions | |
DLine2 (int size) | |
DLine2 (const DLine2 &ref) | |
DLine2 & | operator= (const DLine2 &v) |
DLine2 & | operator= (const FLine2 &v) |
void | Add (const DPoint2 &p) |
Add a given offset to all points. | |
void | Mult (double factor) |
Multiply all points by a given factor. | |
void | InsertPointAfter (int iInsertAfter, const DPoint2 &Point) |
void | RemovePoint (int i) |
void | ReverseOrder () |
int | RemoveDegeneratePoints (double dEpsilon, bool bClosed) |
int | RemoveColinearPoints (double dEpsilon, bool bClosed) |
bool | ContainsPoint (const DPoint2 &p) const |
double | SegmentLength (uint i) const |
void | NearestPoint (const DPoint2 &Point, int &iIndex, double &dist) const |
bool | NearestSegment (const DPoint2 &Point, int &iIndex, double &dist, DPoint2 &Intersection) const |
bool | IsConvex () const |
DPoint2 & | GetSafePoint (int index) const |
void | SetSafePoint (int index, const DPoint2 &p) |
double | Length () const |
DPoint2 | Centroid () const |
DPoint2 | Centroid2 () const |
double | Area () const |
Public Member Functions inherited from vtArray< DPoint2 > | |
vtArray (uint size=0) | |
vtArray (const vtArray< DPoint2 > &) | |
uint | GetSize () const |
uint | GetMaxSize () const |
bool | SetSize (uint) |
bool | SetMaxSize (uint) |
uint | GetElemSize () const |
DPoint2 * | GetData () const |
void | FreeData () |
bool | IsEmpty () const |
DPoint2 & | GetAt (uint i) const |
bool | SetAt (uint i, DPoint2) |
vtArray< DPoint2 > & | operator= (const vtArray< DPoint2 > &) |
DPoint2 & | operator[] (uint i) |
const DPoint2 & | operator[] (uint i) const |
void | Clear () |
bool | RemoveAt (uint i, int n=1) |
int | Append (const DPoint2 &) |
int | Append (const vtArray< DPoint2 > &) |
int | Find (const DPoint2 &) const |
Additional Inherited Members | |
Protected Member Functions inherited from vtArray< DPoint2 > | |
virtual bool | Grow (uint) |
virtual void | DestructItems (uint first, uint last) |
Protected Attributes inherited from vtArray< DPoint2 > | |
uint | m_Size |
uint | m_MaxSize |
DPoint2 * | m_Data |
A series of 2D points. This is useful for representing either a series of points, line segments or a simple closed polygon. Double-precision.
DPoint2 DLine2::Centroid | ( | ) | const |
Centroid (centre of gravity/mass) of the polygon
Note: I've observed some numerical precision issues with this method. With 7-digit coordinates (e.g. x=2388836, y=4690396) the centroid computed may be several units away from its correct location, in fact even outside the polygon for a convex shape.
DPoint2 DLine2::Centroid2 | ( | ) | const |
(Approximate) centroid of a polygon, using simple averaging of the vertices.
bool DLine2::ContainsPoint | ( | const DPoint2 & | p | ) | const |
With the assumption that this set of points defines a closed polygon, test whether the polygon contains a given point. Since a simple array of points being interpreted as a polygon, this means the data may be concave or convex, but not contains holes.
DPoint2 & DLine2::GetSafePoint | ( | int | index | ) | const |
Get a point on the line, safely wrapping around to the end or beginning for index values that are out of range.
void DLine2::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.
Point | The input point. |
iIndex | Index of the first point of the nearest line segment. |
dClosest | Distance from the DLine2 to the input point. |
bool DLine2::NearestSegment | ( | const DPoint2 & | Point, |
int & | iIndex, | ||
double & | dist, | ||
DPoint2 & | Intersection | ||
) | const |
Returns the location of the closest point on the line to a given point.
Point | The input point. |
iIndex | Index of the first point of the nearest line segment. |
dist | Distance from the DLine2 to the input point. |
Intersection | The closest point on the DLine2. |
int DLine2::RemoveColinearPoints | ( | double | dEpsilon, |
bool | bClosed | ||
) |
Given three points A B C, where the distance from B to the line A-C is less than dEpsilon units, B is co-linear and should be removed.
We could use another measure of linearity, the angle between (B-A) and (C-A), but didn't do that.
dEpsilon | Distance. |
bClosed | If true, treat this as a closed polyline (a simple polygon) by wrapping around from the last to the first point. |
int DLine2::RemoveDegeneratePoints | ( | double | dEpsilon, |
bool | bClosed | ||
) |
Given four points A B C D, where B and C are identical, then this line is a triangle not a rectangle. Remove the identical points to produce A B D. Points are identical if they are within dEpsilon of each other.
dEpsilon | Distance. |
bClosed | If true, treat this as a closed polyline (a simple polygon) by wrapping around from the last to the first point. |
double DLine2::SegmentLength | ( | uint | i | ) | const |
Return the length of the N'th segment in the line, which is the distance between points N and N+1. If the length of the last segment is requested, a closed polygon is assumed.