#include <ConvexPolygon.hpp>
Public Member Functions | |
ConvexPolygon () | |
void | add (double x, double y) |
double | bottom () const |
size_t | count () const |
double | leftFor (double y) const |
double | rightFor (double y) const |
double | top () const |
double | x (size_t i) const |
double | y (size_t i) const |
Static Public Attributes | |
static constexpr size_t | maxPoints |
Private Attributes | |
size_t | _botIndex |
size_t | _n |
size_t | _topIndex |
std::array< double, maxPoints > | _xv |
std::array< double, maxPoints > | _yv |
The ConvexPolygon class represents a planar convex polygon, and provides support for extracting specific properties such as the bottom-most and top-most points. There is a (fairly small) compile-time limit on the number of points to avoid memory allocation on the heap. The user should ensure that at least 3 and at most maxPoints points are added to the polygon, that they are added in consecutive clockwise order, that there is a nontrivial distance between all points, and that the resulting polygon is convex. If these restrictions are violated, the behavior of some of the functions in this class is undefined.
ConvexPolygon::ConvexPolygon | ( | ) |
Constructs an empty polygon. Use the add() function to add points to the polygon.
void ConvexPolygon::add | ( | double | x, |
double | y | ||
) |
Adds a point to the polygon. The user should ensure that at least 3 and at most 8 points are added to the polygon, that they are added in consecutive clockwise order, that there is a nontrivial distance between all points, and that the resulting polygon is convex.
|
inline |
Returns the bottom-most y-coordinate of the polygon.
|
inline |
Returns the number of points in the polygon.
double ConvexPolygon::leftFor | ( | double | y | ) | const |
Returns the x-coordinate for the left-hand intersection point of the polygon with the horizontal line at the specified y-coordinate. If the specified y-coordinate is out of range, the x-coordinate of the top or bottom point is returned.
double ConvexPolygon::rightFor | ( | double | y | ) | const |
Returns the x-coordinate for the right-hand intersection point of the polygon with the horizontal line at the specified y-coordinate. If the specified y-coordinate is out of range, the x-coordinate of the top or bottom point is returned.
|
inline |
Returns the top-most y-coordinate of the polygon.
|
inline |
Returns the x-coordinate of the point at the specified zero-based index.
|
inline |
Returns the y-coordinate of the point at the specified zero-based index.
|
staticconstexpr |
The maximum number of points that can be held by a polygon object.