VisiLibity v1 Source Code 1.0
Public Member Functions | Protected Attributes | Friends | List of all members
VisiLibity::Polygon Class Reference

simple polygon in the plane represented by list of vertices More...

#include <visilibity.hpp>

Inheritance diagram for VisiLibity::Polygon:
VisiLibity::Visibility_Polygon

Public Member Functions

 Polygon ()
 default to empty
 
 Polygon (const std::string &filename)
 construct from *.polygon file More...
 
 Polygon (const std::vector< Point > &vertices_temp)
 construct from vector of vertices More...
 
 Polygon (const Point &point0, const Point &point1, const Point &point2)
 construct triangle from 3 Points More...
 
const Pointoperator[] (unsigned i) const
 access with automatic wrap-around in forward direction More...
 
unsigned n () const
 vertex count More...
 
unsigned r () const
 reflex vertex count (nonconvex vertices) More...
 
bool is_simple (double epsilon=0.0) const
 true iff Polygon is (epsilon) simple More...
 
bool is_in_standard_form () const
 true iff lexicographically smallest vertex is first in the list of vertices representing the Polygon More...
 
double boundary_length () const
 perimeter length
 
double area () const
 
Point centroid () const
 Polygon's centroid (center of mass) More...
 
double diameter () const
 Euclidean diameter. More...
 
Bounding_Box bbox () const
 box which fits snugly around the Polygon More...
 
std::vector< Pointrandom_points (const unsigned &count, double epsilon=0.0) const
 
void write_to_file (const std::string &filename, int fios_precision_temp=FIOS_PRECISION)
 write list of vertices to *.polygon file More...
 
Pointoperator[] (unsigned i)
 access with automatic wrap-around in forward direction More...
 
void set_vertices (const std::vector< Point > &vertices_temp)
 set vertices using STL vector of Points
 
void push_back (const Point &vertex_temp)
 push a Point onto the back of the vertex list
 
void clear ()
 erase all vertices
 
void enforce_standard_form ()
 enforces that the lexicographically smallest vertex is first in the list of vertices representing the Polygon More...
 
void eliminate_redundant_vertices (double epsilon=0.0)
 eliminates vertices which are (epsilon) - colinear with their respective neighbors More...
 
void reverse ()
 reverse (cyclic) order of vertices More...
 

Protected Attributes

std::vector< Pointvertices_
 

Friends

class Point
 

Detailed Description

simple polygon in the plane represented by list of vertices

Simple here means non-self-intersecting. More precisely, edges should not (i) intersect with an edge not adjacent to it, nor (ii) intersect at more than one Point with an adjacent edge.

Remarks
vertices may be listed cw or ccw

Constructor & Destructor Documentation

◆ Polygon() [1/3]

VisiLibity::Polygon::Polygon ( const std::string &  filename)

construct from *.polygon file

Author
Karl J. Obermeyer
Remarks
for efficiency, simplicity check not called here

◆ Polygon() [2/3]

VisiLibity::Polygon::Polygon ( const std::vector< Point > &  vertices_temp)

construct from vector of vertices

Remarks
for efficiency, simplicity check not called here

◆ Polygon() [3/3]

VisiLibity::Polygon::Polygon ( const Point point0,
const Point point1,
const Point point2 
)

construct triangle from 3 Points

Remarks
for efficiency, simplicity check not called here

Member Function Documentation

◆ area()

double VisiLibity::Polygon::area ( ) const

oriented area of the Polygon

Author
Karl J. Obermeyer
Precondition
Polygon is simple, but for efficiency simplicity is not asserted. area > 0 => vertices listed ccw, area < 0 => cw
Remarks
O(n) time complexity, where n is the number of vertices representing the Polygon

◆ bbox()

Bounding_Box VisiLibity::Polygon::bbox ( ) const

box which fits snugly around the Polygon

Author
Karl J. Obermeyer
Precondition
Polygon has greater than 0 vertices

◆ centroid()

Point VisiLibity::Polygon::centroid ( ) const

Polygon's centroid (center of mass)

Author
Karl J. Obermeyer
Precondition
Polygon has greater than 0 vertices and is simple, but for efficiency simplicity is not asserted

◆ diameter()

double VisiLibity::Polygon::diameter ( ) const

Euclidean diameter.

Precondition
Polygon has greater than 0 vertices
Returns
maximum Euclidean distance between all pairs of vertices
Remarks
time complexity O(n^2), where n is the number of vertices representing the Polygon

◆ eliminate_redundant_vertices()

void VisiLibity::Polygon::eliminate_redundant_vertices ( double  epsilon = 0.0)

eliminates vertices which are (epsilon) - colinear with their respective neighbors

Author
Karl J. Obermeyer
Postcondition
the Euclidean distance between each vertex and the line segment connecting its neighbors is at least epsilon, and the Polygon is in standard form
Remarks
time complexity O(n), where n is the number of vertices representing the the Polygon

◆ enforce_standard_form()

void VisiLibity::Polygon::enforce_standard_form ( )

enforces that the lexicographically smallest vertex is first in the list of vertices representing the Polygon

Author
Karl J. Obermeyer
Remarks
O(n) time complexity, where n is the number of vertices representing the Polygon. Lex. comparison is very sensitive to perturbations if two Points nearly define a line parallel to one of the axes

◆ is_in_standard_form()

bool VisiLibity::Polygon::is_in_standard_form ( ) const

true iff lexicographically smallest vertex is first in the list of vertices representing the Polygon

Author
Karl J. Obermeyer
Remarks
lex. comparison is very sensitive to perturbations if two Points nearly define a line parallel to one of the axes

◆ is_simple()

bool VisiLibity::Polygon::is_simple ( double  epsilon = 0.0) const

true iff Polygon is (epsilon) simple

Author
Karl J. Obermeyer
Remarks
A Polygon is considered epsilon -simple iff (i) the Euclidean distance between nonadjacent edges is no greater than epsilon, (ii) adjacent edges intersect only at their single shared Point, (iii) and it has at least 3 vertices. One consequence of these conditions is that there can be no redundant vertices.

◆ n()

unsigned VisiLibity::Polygon::n ( ) const
inline

vertex count

Remarks
O(1) time complexity

◆ operator[]() [1/2]

Point & VisiLibity::Polygon::operator[] ( unsigned  i)
inline

access with automatic wrap-around in forward direction

Remarks
for efficiency, no bounds check; usually trying to access out of bounds causes a bus error

◆ operator[]() [2/2]

const Point & VisiLibity::Polygon::operator[] ( unsigned  i) const
inline

access with automatic wrap-around in forward direction

Remarks
For efficiency, no bounds check; usually trying to access out of bounds causes a bus error

◆ r()

unsigned VisiLibity::Polygon::r ( ) const

reflex vertex count (nonconvex vertices)

Author
Karl J. Obermeyer
Remarks
Works regardless of polygon orientation (ccw vs cw), but assumes no redundant vertices. Time complexity O(n), where n is the number of vertices representing the Polygon

◆ reverse()

void VisiLibity::Polygon::reverse ( )

reverse (cyclic) order of vertices

Remarks
vertex first in list is held first

◆ write_to_file()

void VisiLibity::Polygon::write_to_file ( const std::string &  filename,
int  fios_precision_temp = FIOS_PRECISION 
)

write list of vertices to *.polygon file

Author
Karl J. Obermeyer Uses intuitive human and computer readable decimal format with display precision fios_precision_temp.
Precondition
fios_precision_temp >=1

The documentation for this class was generated from the following files: