A number of algorithms on sequences of 2D points is supplied as global functions.
In all algorithms the points in the range [first,last) are interpreted
as the vertices of a polygon. The vertices in this range should have value type
Traits::Point_2. Most functions take a traits class as their last argument.
This is just a technical matter: the template argument Traits must
appear in the arguments of the function. Modern compilers should be able to
optimize this traits argument away. In all cases a default version of the function
exists without the Traits argument. These default versions use the predefined
polygon traits class from section .
| ||||
|
| |||
Returns the leftmost point from the range [first,last) with the smallest y-coordinate. TRAITS: uses Traits::Less_xy. | ||||
| ||||
|
| |||
Returns the rightmost point in the range [first,last) with
the largest y-coordinate. TRAITS: uses Traits::Less_xy. | ||||
| ||||
|
| |||
Returns the topmost point from the range [first,last) with
the largest x-coordinate. TRAITS: uses Traits::Less_yx. | ||||
| ||||
|
| |||
Returns the bottommost point from the range [first,last)
with the smallest x-coordinate. TRAITS: uses Traits::Less_yx. | ||||
| ||||
|
| |||
Returns the smallest bounding box of the points in the range
[first,last). Precondition: The range [first,last) is not empty. | ||||
| ||||
|
| |||
Computes the signed area of the polygon formed by the points in the
range [first,last). TRAITS: uses Traits::determinant_2. | ||||
| ||||
|
| |||
Returns true if the polygon formed by the points in the
range [first,last) is convex. The implementation checks if
the polygon is locally convex and if there is only one local
minimum and one local maximum with respect to the lexicographical
ordering determined by Traits::lexicographically_xy_smaller.
The complexity of the algorithm is , where
is the number of points in the range
[first,last). TRAITS: Traits::lexicographically_xy_smaller, Traits::orientation. | ||||
| ||||
|
| |||
Returns true if the polygon formed by the points in the
range [first,last) is simple. The simplicity test of a
polygon is a line-segment intersection test. For the implementation
a plane sweep algorithm is used, see also
[PS85], p.276. The
complexity of the algorithm is (worst
case), where is the number of points in the range
[first,last). TRAITS: Traits::lexicographically_yx_smaller_or_equal, \quad Traits::do_intersect, Traits::have_equal_direction. Traits::compare_x, Traits::compare_y, Traits::cross_product_2, Traits::is_negative, | ||||
| ||||
|
| |||
This determines the location of the point q with respect to
the polygon formed by the points in the range [first,last).
It returns CGAL_NEGATIVE_SIDE, or CGAL_POSITIVE_SIDE,
or CGAL_ON_ORIENTED_BOUNDARY, depending on where point
q is. For the implementation a crossing test
algorithm is used with complexity , see
[Hai94].
Precondition: The points in the range [first,last) form the vertices of a simple polygon. TRAITS: uses Traits::Less_xy, Traits::compare_x, Traits::compare_y, Traits::determinant_2, Traits::orientation and Traits::sign. | ||||
| ||||
|
| |||
Determines the location of the point q with respect to the
polygon formed by the points in the range [first,last). It
returns either CGAL_ON_BOUNDED_SIDE, CGAL_ON_BOUNDARY
or CGAL_ON_UNBOUNDED_SIDE, depending on where point q
is. Precondition: The points in the range [first,last) form the vertices of a simple polygon. TRAITS: uses Traits::compare_x, Traits::compare_y, Traits::determinant_2 and Traits::determinant_2. | ||||
| ||||
|
| |||
Returns the orientation of the polygon formed by the points in the
range [first,last). If the number of points is smaller than
three, CGAL_COLLINEAR is returned.
Precondition: The points in the range [first,last) form the vertices of a simple polygon. TRAITS: uses Traits::Less_xy and Traits::orientation. |
The polygon algorithms in section are parameterized with
a traits class Traits that defines the basic types and predicates
that the algorithms use. This section describes the minimal requirements for
the traits class. N.B. Currently the list of requirements contains several
redundant predicates that can be easily expressed in others. For example,
the lexicographical comparison functions can be expressed in the functions
compare_x and compare_y). These predicates will probably
be removed from the traits class.