The class Polygon_2<PolygonTraits_2, Container> implements polygons. The Polygon_2<PolygonTraits_2, Container> is parameterized 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.
#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). | ||
|
| Erases all vertices. |
|
| Reverses the orientation of the polygon. The vertex pointed to by p.vertices_begin() remains the same. |
|
| Returns whether pgn is a simple polygon. | ||
|
| Returns whether pgn is convex. | ||
|
|
Returns the orientation of pgn. If the number of vertices
p.size() < 3 then COLLINEAR is returned.
| ||
|
|
Returns POSITIVE_SIDE, or NEGATIVE_SIDE,
or ON_ORIENTED_BOUNDARY,
depending on where point q is.
| ||
|
|
Returns the symbolic constant ON_BOUNDED_SIDE,
ON_BOUNDARY
or ON_UNBOUNDED_SIDE, depending on where point
q is.
| ||
|
| 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 pgn with the smallest y-coordinate. | ||
|
| Returns the rightmost vertex of the polygon pgn with the largest y-coordinate. | ||
|
| Returns topmost vertex of the polygon pgn with the largest x-coordinate. | ||
|
| Returns the bottommost vertex of the polygon pgn with the smallest x-coordinate. |
For convenience we provide the following Boolean functions:
|
| |
|
|
|
|
|
|
|
| |
|
| |
|
|
|
|
| |
|
|
|
| Returns a (const) reference to the i-th vertex. |
|
| Returns a (const) reference to the i-th vertex. |
|
| Returns a const reference to the i-th edge. |
|
| Returns the number of vertices of the polygon pgn. |
|
| Returns p.size() == 0. |
|
| 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 I/O operators are defined for iostream. The format for the iostream is an internal format.
|
| |||
Inserts the polygon pgn into the stream os.
| ||||
|
| |||
Reads a polygon from stream is and assigns it
to pgn.
|
The information output in the iostream is the number of points followed by the output of the coordinates of the vertices.
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.
The following code fragment creates a polygon and checks if it is convex.
File: examples/Polygon/Polygon.cpp
#include <CGAL/Exact_predicates_inexact_constructions_kernel.h> #include <CGAL/Polygon_2.h> #include <iostream> typedef CGAL::Exact_predicates_inexact_constructions_kernel K; typedef K::Point_2 Point; typedef CGAL::Polygon_2<K> Polygon_2; 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_2 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. |