![]() |
Gamedev Framework (gf)
0.9.0
A C++14 framework for 2D games
|
A convex polygon. More...
#include <gf/Polygon.h>
Public Member Functions | |
Polygon ()=default | |
Default constructor. More... | |
Polygon (ArrayRef< Vector2f > points) | |
Constructor from an array. More... | |
template<typename Iterator > | |
Polygon (Iterator first, Iterator last) | |
Constructor from points. More... | |
bool | isEmpty () const |
Check if the polygon is empty. More... | |
void | addPoint (Vector2f point) |
Add a point to the polygon. More... | |
std::size_t | getPointCount () const |
Get the number of points of the polygon. More... | |
Vector2f | getPoint (std::size_t index) const |
Get the i-th point of the polygon. More... | |
Vector2f | getCenter () const |
Get the center of the polygon. More... | |
Vector2f | getSupport (Vector2f direction, const Transform &transform) const |
Get the farthest point in a direction. More... | |
Vector2f | getSupport (Vector2f direction) const |
Get the farthest point in a direction. More... | |
const Vector2f * | begin () const |
Get an iterator to the first point. More... | |
const Vector2f * | end () const |
Get an iterator past the last point. More... | |
bool | isConvex () const |
Check if the polygon is convex. More... | |
Winding | getWinding () const |
Compute the winding of a convex polygon. More... | |
float | getArea () const |
Compute the area of the polygon. More... | |
void | applyTransform (const Matrix3f &mat) |
Apply a transformation to the polygon. More... | |
A convex polygon.
|
default |
Default constructor.
Constructor from an array.
points | The array of points |
|
inline |
Constructor from points.
first | Iterator to the first point |
last | Iterator after the last point |
void gf::Polygon::addPoint | ( | Vector2f | point | ) |
Add a point to the polygon.
point | The point to add to the polygon |
void gf::Polygon::applyTransform | ( | const Matrix3f & | mat | ) |
Apply a transformation to the polygon.
mat | The transformation matrix |
const Vector2f* gf::Polygon::begin | ( | ) | const |
const Vector2f* gf::Polygon::end | ( | ) | const |
float gf::Polygon::getArea | ( | ) | const |
Compute the area of the polygon.
Complexity: \( O(n) \)
Vector2f gf::Polygon::getCenter | ( | ) | const |
Get the center of the polygon.
As the polygon is convex, the center is inside the polygon
Vector2f gf::Polygon::getPoint | ( | std::size_t | index | ) | const |
Get the i-th point of the polygon.
index | The index of the point |
std::size_t gf::Polygon::getPointCount | ( | ) | const |
Get the number of points of the polygon.
Get the farthest point in a direction.
direction | The direction to search (in world coordinates) |
transform | The transformation of the polygon |
Get the farthest point in a direction.
direction | The direction to search |
Winding gf::Polygon::getWinding | ( | ) | const |
Compute the winding of a convex polygon.
Complexity: \( O(n) \)
bool gf::Polygon::isConvex | ( | ) | const |
Check if the polygon is convex.
This function should return true, otherwise you may have problems in other functions which assume that the polygon is convex.
bool gf::Polygon::isEmpty | ( | ) | const |
Check if the polygon is empty.
An empty polygon has no points.