GPolygon Class Reference

[libgfc Index] [libgfc Hierarchy] [Headers]


The 2D polygon (with holes) ADT More...

#include <src/gadt_polygon.h>

Inherits: GSpatial

Public Members


Detailed Description

The 2D polygon (with holes) ADT.

A polygon is a bounded area defined by one or more rings. If there are more than one rings, then there is one outer boundary ring and the rest are interier rings (holes). The internal data layout is very similar to that of an ArcView shapefile Polygon record (without all the record headers etc).

The first ring is the outer boundary of the polygon by default.


Result input(const char* in) [public virtual]

User format: "n_rings, #_points_1, #_points_2, ... #_points_N, x1 y1 x2 y2 ... xm ym"

Result output(char*& out) [public virtual]

generates a string with same format in input

int cmp(const GADT&) const [public virtual]

compares the area with the polygon 'a's area. Returns -1 if 'a' has larger area; or zero if they equal; otherwise 1

void set(int n_parts, int n_pnts, const int* parts, const Coord* coord) [public virtual]

this method accepts severl "parts" each of which are a series of ordered points. All existing data will be replaced by the new data.

int numRings(void) const [public]

return number of rings

bool hasHole(void) const [public]

return 1 if the polygon has holes

Result addRing(int n_vertices, Coord* coords) [public]

add a ring to the owning polygon

Parameters:
coords the coordinates of the new ring
n_vertices number of vertices in the new ring

int getRing(int nth, Coord*& coords) [public]

return the information about a particular ring

Parameters:
coords where the coordinates of the ring begin
nth which ring to get
Returns:
the number of vertices in this ring.

void setMbr(const GRect& b) [public]

set the MBR

Result genMbr(GRect& r) [public]

recalculate the MBR for this polygon

Parameters:
r is the newly calculated MBR

double distance(const GADT& other) const [public]

return distance between this polygon and another object.

if the argument is another polygon, we calculte the distance between the centroids of the two polygons' outer boundary ring only... this may not really what we want since we don't take into account any of the holes of either polygon.

@Return the distance.

double area() const [public]

return the area (not including any holes)

double sarea(int n_points, Coord* coord) const [public]

calculate the signed area of a ring (simple polygon without holes).

Parameters:
n_points number of vertices in the ring
coord coordinates of the vertices. Can be used to determine the ordering of vertices.

double sarea() const [public]

calculate the signed area of a polygon (assuming a simple one). the area of holes are subtracted from that of the outer boundary ring.

double perimeter() const [public]

return the perimeter (including those of the holes)

double perimeter(int nth) const [public]

calculate the perimeter of a particular ring

Parameters:
nth specifies the ring

int classify(int, Coord*) [public]

Determine the class of the polygon according to its convexity. It calls some inlines that are useful routines in their own right.

Originally by Peter Schorn & Frederick Fisher, In "Graphics Gems IV", Academic Press 1994.

Returns:
the class of the polygon; for meaning of return values see geomacro.h, they are GCONVEX_CW, GCONVEX_CCW, GNOT_CONVEX, GNOT_CONVEX_DEGENERATE, GCONEXT_DEGENERATE.

int classify() [public]

handy version of the classify method.

double centroid(GPoint& ctr) const [public]

return the centroid (of the outer boundary ring!)

double centroid(int, Coord*, GPoint&) const [public]

calculate the centrod of a ring (simple polygon w/o holes).

int covers(const GSpatial& ) const [public virtual]

ADT-in-Polygon checking. It is a driver that calls sub-routines according to the given type. for now it's only accepting point ADT.

int intersects(const GSpatial&) const [public virtual]

check if this polygon intersects with other adt objects. calls subroutines accordingly with given type of adt.

int intersects(int n_point, Coord* coo) const [public virtual]

check if this polygon intersects with a linear series of connected coordinates.

int intersects(const GOps& ops) const [public virtual]

check if the polygon intersects a set of ordered point series.

int isInside(const GRect& other) const [public]

check if this polygon is inside the given rectangle.

Returns:
1 if true, otherwise 0.

int isInside(const GCircle& other) const [public]

check if this polygon is inside the given circle.

Returns:
1 if true, otherwise 0.

Documentation generated by lqian@lqian-sun on Wed Jul 14 09:36:10 EDT 1999
Kdoc