Gamedev Framework (gf)  0.3.0
A C++11 framework for 2D games
Public Member Functions | List of all members
gf::Polygon Class Reference

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...
 
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
 Get the farthest point in a direction. More...
 
const Vector2fbegin () const
 Get an iterator to the first point. More...
 
const Vector2fend () const
 Get an iterator past the last point. More...
 
void applyTransform (const Matrix3f &mat)
 Apply a transformation to the polygon. More...
 

Detailed Description

A convex polygon.

Constructor & Destructor Documentation

gf::Polygon::Polygon ( )
default

Default constructor.

gf::Polygon::Polygon ( ArrayRef< Vector2f points)

Constructor from an array.

Parameters
pointsThe array of points
template<typename Iterator >
gf::Polygon::Polygon ( Iterator  first,
Iterator  last 
)
inline

Constructor from points.

Parameters
firstIterator to the first point
lastIterator after the last point

Member Function Documentation

void gf::Polygon::addPoint ( Vector2f  point)

Add a point to the polygon.

Parameters
pointThe point to add to the polygon
void gf::Polygon::applyTransform ( const Matrix3f mat)

Apply a transformation to the polygon.

Parameters
matThe transformation matrix
const Vector2f* gf::Polygon::begin ( ) const

Get an iterator to the first point.

Returns
A pointer to the first point
See also
end()
const Vector2f* gf::Polygon::end ( ) const

Get an iterator past the last point.

Returns
A pointer past the last point
See also
begin()
Vector2f gf::Polygon::getCenter ( ) const

Get the center of the polygon.

As the polygon is convex, the center is inside the polygon

Returns
The center of the polygon
Vector2f gf::Polygon::getPoint ( std::size_t  index) const

Get the i-th point of the polygon.

Parameters
indexThe index of the point
std::size_t gf::Polygon::getPointCount ( ) const

Get the number of points of the polygon.

Returns
The number of points of the polygon
Vector2f gf::Polygon::getSupport ( Vector2f  direction) const

Get the farthest point in a direction.

Parameters
directionThe direction to search
Returns
The farthest point of the polygon in the given direction