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

A convex polygon. More...

#include <gf/Polygon.h>

Inheritance diagram for gf::Polygon:
Inheritance graph
[legend]

Public Member Functions

 Polygon ()=default
 Default constructor. More...
 
 Polygon (Span< const Vector2f > points)
 Constructor from an array. More...
 
template<typename Iterator >
 Polygon (Iterator first, Iterator last)
 Constructor from points. 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...
 
bool isConvex () const
 Check if the polygon is convex. More...
 
Winding getWinding () const
 Compute the winding of a convex polygon. More...
 
bool contains (Vector2f point) const
 Test if a point is inside the (convex) polygon. More...
 
float getArea () const
 Compute the area of the polygon. More...
 
- Public Member Functions inherited from gf::PointSequence
 PointSequence ()=default
 Default constructor. More...
 
 PointSequence (Span< const Vector2f > points)
 Constructor from an array. More...
 
template<typename Iterator >
 PointSequence (Iterator first, Iterator last)
 Constructor from points. More...
 
bool isEmpty () const
 Check if the sequence is empty. More...
 
void addPoint (Vector2f point)
 Add a point to the sequence. More...
 
std::size_t getPointCount () const
 Get the number of points of the sequence. More...
 
Vector2f getPoint (std::size_t index) const
 Get the i-th point of the sequence. More...
 
Vector2f getCenter () const
 Get the center of the sequence. More...
 
const Vector2fbegin () const
 Get an iterator to the first point. More...
 
Vector2fbegin ()
 Get an iterator to the first point. More...
 
const Vector2fend () const
 Get an iterator past the last point. More...
 
Vector2fend ()
 Get an iterator past the last point. More...
 
Vector2f getFirstPoint () const
 Get the first point of the sequence. More...
 
Vector2f getLastPoint () const
 Get the last point of the sequence. More...
 
void applyTransform (const Matrix3f &mat)
 Apply a transformation to the sequence. More...
 
void simplify (float distance=Epsilon)
 Simplify the sequence. More...
 

Additional Inherited Members

- Protected Member Functions inherited from gf::PointSequence
std::vector< Vector2f > & getRawPoints ()
 Get the raw container of points. More...
 
const std::vector< Vector2f > & getRawPoints () const
 Get the raw container of points. More...
 

Detailed Description

A convex polygon.

Constructor & Destructor Documentation

◆ Polygon() [1/3]

gf::Polygon::Polygon ( )
default

Default constructor.

◆ Polygon() [2/3]

gf::Polygon::Polygon ( Span< const Vector2f points)
inline

Constructor from an array.

Parameters
pointsThe array of points

◆ Polygon() [3/3]

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

◆ contains()

bool gf::Polygon::contains ( Vector2f  point) const

Test if a point is inside the (convex) polygon.

Parameters
pointThe point to test
Returns
True if the point is inside the polygon

◆ getArea()

float gf::Polygon::getArea ( ) const

Compute the area of the polygon.

Complexity: \( O(n) \)

Returns
The area of the polygon

◆ getSupport() [1/2]

Vector2f gf::Polygon::getSupport ( Vector2f  direction,
const Transform transform 
) const

Get the farthest point in a direction.

Parameters
directionThe direction to search (in world coordinates)
transformThe transformation of the polygon
Returns
The farthest point of the polygon in the given direction

◆ getSupport() [2/2]

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

◆ getWinding()

Winding gf::Polygon::getWinding ( ) const

Compute the winding of a convex polygon.

Complexity: \( O(n) \)

Returns
The winding of the convex polygon
See also
gf::Winding, isConvex()
Curve orientation - Wikipedia

◆ isConvex()

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.

This function does not handle self-intersecting polygons (yet).

Returns
True if the polygon is convex