polygon

 

Overview

Declared in "polygon.h"

Base class. Declared in namespace tal.

    This is a basic two-dimensional polygon class. This class uses some C functions from the GPC (Generic Polygon Clipper) library by Alan Murta, Advanced Interfaces Group, University of Manchester. The GPC library is declared in the namespace gpc.

    Note that you do not need to understand the GPC library to use this polygon class.

 

Construction, Assignment and Destruction

polygon()
Constructs a polygon object.

polygon(const polygon &rhs)
Copy constructor.

polygon &operator=(const polygon &rhs)
Assignment operator.

virtual ~polygon()
Destroys the polygon object.

 

Polygon Vertices

int Count() const
Number of vertices (n) the polygon has.

POINT &operator[](int nIdx)
Returns a reference to a specified polygon vertex. Argument nIdx is a zero-based index of the polygon vertices. If nIdx exceeds the total number of vertices minus 1 (n - 1), new vertices are added to the polygon until nIdx equals (n - 1). Added vertices will have default values of (0, 0).

const POINT At(int nIdx) const
Returns a copy of a specified polygon vertex. Argument nIdx is a zero-based index of the polygon vertices. Unlike the overloaded subscript operator[], no new vertices will be added if nIdx exceeds (n - 1).

void Set(int nIdx, POINT pt)
Sets a specified polygon vertex to a new value.

void Add(POINT pt)
Adds a new vertex to the polygon.

void Del(int nIdx)
Deletes a specified polygon vertex. Argument nIdx is a zero-based index of the polygon vertices.

void Clear()
Deletes all polygon vertices.

 

Validity Check

virtual bool IsValid() const
Checks the validity of the polygon vertices. Valid if there are more than three vertices, and its member function Orientation() returns a non-zero value.

 

Services

int Orientation() const
Orientation or order of the stored polygon vertices. Returns 1 for counter-clockwise direction, -1 for clockwise, and 0 for error (e.g., vertices along a straight line).

double Area() const
Area of polygon.

const POSITION Find(POINT pt) const
The position of a given point in the polygon.

const POINT Centroid() const
The center of the polygon.

const polygon Clip(const polygon &pg) const
Intersects a given polygon, and returns their overlap, if any.

const polygon Difference(const polygon &pg) const
Intersects a given polygon, and returns their difference, if any.

const polygon XOR(const polygon &pg) const
Intersects a given polygon, and returns their exclusive-OR overlap, if any.

const polygon Union(const polygon &pg) const
Intersects a given polygon, and returns their union, if any.

 

 
 
TAL Home | Code Main Page | email
 
  updated: 22-Aug-2002