The class Polygon_2<PolygonTraits_2, Container> implements polygons. The Polygon_2<PolygonTraits_2, Container> is parameterised by a traits class and a container class. The latter can be any class that fulfills the requirements for an STL container. It defaults to the vector class.
#define CGAL_POLYGON_2_CACHED
In the future, this caching behavior will be the default. The only reason that it is not at the moment is that some compilers have problems when the CGAL_POLYGON_2_CACHED flag is set. This can be fixed by setting a second preprocessor flag as well:
CGAL_POLYGON_2_MOD_ITERThe drawback of setting this flag is that some illegal operations will be allowed which can lead to wrong results. The iterators of the polygon are mutable in this case, but modifying the polygon through them will not invalidate the cache.
#include <CGAL/Polygon_2.h>
| |
The traits type.
| |
| |
The container type.
|
|
| The number type, which is the field type of the points of the polygon. |
| ||
| The point type of the polygon. | |
| ||
| The type of a segment between two points of the polygon. |
The following types denote iterators that allow to traverse the vertices and edges of a polygon. Since it is questionable whether a polygon should be viewed as a circular or as a linear data structure both circulators and iterators are defined. The circulators and iterators are non-mutable.1 The iterator category is in all cases bidirectional, except for Vertex_iterator, which has the same iterator category as Container::iterator. N.B. In fact all of them should have the same iterator category as Container::iterator. However, due to compiler problems this is currently not possible.
For vertices we define
| |
|
Their value type is Point_2.
For edges we define
| |
|
Their value type is Segment_2.
| |||
Creates an empty polygon pgn.
| |||
| |||
| |||
Introduces a polygon pgn with vertices from the sequence defined by
the range [first,last).
The value type of InputIterator must be Point_2.
|
|
| |||
Acts as *pos = x, except that that would be illegal because the iterator is not mutable. | ||||
|
| |||
Inserts the vertex q before i. The return value points to the inserted vertex. | ||||
| ||||
|
| |||
Inserts the vertices in the range [first, last) before i. The value type of points in the range [first,last) must be Point_2. | ||||
|
| |||
Has the same semantics as p.insert(p.vertices_end(), q). | ||||
|
| |||
Erases the vertex pointed to by i. | ||||
|
| |||
Erases the vertices in the range [first, last). | ||||
|
| |||
Reverses the orientation of the polygon. The vertex pointed to by p.vertices_begin() remains the same. |
|
| Returns whether p is a simple polygon. |
|
| Returns whether p is convex. |
|
|
Returns the orientation of pgn. If the number of vertices
then COLLINEAR is returned. Precondition: p.is_simple(). |
|
| |
Returns POSITIVE_SIDE, or NEGATIVE_SIDE,
or ON_ORIENTED_BOUNDARY,
depending on where point q is. Precondition: p.is_simple(). | ||
|
| |
Returns the symbolic constant ON_BOUNDED_SIDE,
ON_BOUNDARY
or ON_UNBOUNDED_SIDE, depending on where point
q is. Precondition: p.is_simple(). | ||
|
| Returns the smallest bounding box containing pgn. |
|
| Returns the signed area of the polygon pgn. This means that the area is positive for counter clockwise polygons and negative for clockwise polygons. |
|
| Returns the leftmost vertex of the polygon p with the smallest y-coordinate. |
|
| |
Returns the rightmost vertex of the polygon p with the largest y-coordinate. | ||
|
| Returns topmost vertex of the polygon p with the largest x-coordinate. |
|
| |
Returns the bottommost vertex of the polygon p with the smallest x-coordinate. |
For convenience we provide the following boolean functions:
|
| |
|
| |
|
| |
|
| |
|
| |
|
| |
|
| |
|
|
|
| |
Returns a (const) reference to the -th vertex. | ||
|
| Returns a (const) reference to the -th vertex. |
|
| Returns a const reference to the -th edge. |
|
| Returns the number of vertices of the polygon pgn. |
|
| Returns . |
|
| Returns a const reference to the sequence of vertices of the polygon pgn. |
template <class Traits, class Container1, class Container2>
|
| |
Test for equality: two polygons are equal iff there exists a cyclic permutation of the vertices of p2 such that they are equal to the vertices of p1. Note that the template argument Container of p1 and p2 may be different. |
template <class Traits, class Container1, class Container2>
|
| |
Test for inequality. |
template <class Transformation, class Traits, class Container>
| ||||
| ||||
Returns the image of the polygon p under the transformation t. |
The methods is_simple, is_convex, orientation, oriented_side, bounded_side, bbox, area, left_vertex, right_vertex, top_vertex and bottom_vertex are all implemented using the algorithms on sequences of 2D points. See the corresponding global functions for information about which algorithms were used and what complexity they have.
If caching is turned on, all functions are cached except those that compute on which side of the polygon a point is situated. The cache is invalidated after any operation that modifies the polygon.
The following code fragment creates a polygon and checks if it is convex.
// file: examples/Polygon/Polygon.C #include <CGAL/Cartesian.h> #include <CGAL/Polygon_2.h> #include <iostream> typedef CGAL::Cartesian<double> K; typedef K::Point_2 Point; typedef CGAL::Polygon_2<K> Polygon; using std::cout; using std::endl; int main() { Point points[] = { Point(0,0), Point(5.1,0), Point(1,1), Point(0.5,6)}; Polygon pgn(points, points+4); // check if the polygon is simple. cout << "The polygon is " << (pgn.is_simple() ? "" : "not ") << "simple." << endl; // check if the polygon is convex cout << "The polygon is " << (pgn.is_convex() ? "" : "not ") << "convex." << endl; return 0; }
1 | At least conceptually. The enforcement depends on preprocessor flags. |