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

A polyline. More...

#include <gf/Polyline.h>

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

Public Types

enum  Type {
  Chain ,
  Loop
}
 The type of polyline. More...
 

Public Member Functions

 Polyline (Type type=Chain)
 Default constructor. More...
 
 Polyline (Span< const Vector2f > points, Type type=Chain)
 Constructor from an array. More...
 
template<typename Iterator >
 Polyline (Iterator first, Iterator last, Type type=Chain)
 Constructor from points. More...
 
bool hasPrevPoint (std::size_t i) const
 Check if there is a point before the i-th point. More...
 
Vector2f getPrevPoint (std::size_t i) const
 Get the point before the i-th point. More...
 
Vector2f getPrevExtensionPoint () const
 Get the previous extension point of the first point. More...
 
bool hasNextPoint (std::size_t i) const
 Check if there is a point after the i-th point. More...
 
Vector2f getNextPoint (std::size_t i) const
 Get the point after the i-th point. More...
 
Vector2f getNextExtensionPoint () const
 Get the next extension point of the last point. More...
 
Winding getWinding () const
 Compute the winding of a simple loop polyline. More...
 
bool contains (Vector2f point) const
 Test if a point is inside the polyline. More...
 
void setType (Type type)
 Set the type of the polyline. More...
 
Type getType () const
 Get the type of the polyline. More...
 
bool isLoop () const
 Check is the polyline is a loop. More...
 
bool isChain () const
 Check is the polyline is a chain. 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...
 
void reverse ()
 Reverse the points in 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 polyline.

A polyline is a set of consecutive segments. It is defined by the points ending the segments. A polyline can be open (chain) or closed (loop).

Member Enumeration Documentation

◆ Type

The type of polyline.

Enumerator
Chain 

The polyline is open.

Loop 

The polyline is closed.

Constructor & Destructor Documentation

◆ Polyline() [1/3]

gf::Polyline::Polyline ( Type  type = Chain)
inline

Default constructor.

Parameters
typeThe type of polyline (default: chain)

◆ Polyline() [2/3]

gf::Polyline::Polyline ( Span< const Vector2f points,
Type  type = Chain 
)
inline

Constructor from an array.

Parameters
pointsThe array of points
typeThe type of polyline (default: chain)

◆ Polyline() [3/3]

template<typename Iterator >
gf::Polyline::Polyline ( Iterator  first,
Iterator  last,
Type  type = Chain 
)
inline

Constructor from points.

Parameters
firstIterator to the first point
lastIterator after the last point
typeThe type of polyline (default: chain)

Member Function Documentation

◆ contains()

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

Test if a point is inside the polyline.

If the polyline is a chain, it returns false.

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

◆ getNextExtensionPoint()

Vector2f gf::Polyline::getNextExtensionPoint ( ) const

Get the next extension point of the last point.

When the line is a chain, the line can be extended with an extension point that is the symmetric of point at index \( (n-2) \) relative to the point at index \( (n-1) \). It may be useful for the computation of splines.

Returns
The next extension point

◆ getNextPoint()

Vector2f gf::Polyline::getNextPoint ( std::size_t  i) const

Get the point after the i-th point.

Parameters
iThe index of the current point
Returns
The point after the current point
See also
hasNextPoint()

◆ getPrevExtensionPoint()

Vector2f gf::Polyline::getPrevExtensionPoint ( ) const

Get the previous extension point of the first point.

When the line is a chain, the line can be extended with an extension point that is the symmetric of point at index 1 relative to the point at index 0. It may be useful for the computation of splines.

Returns
The previous extension point

◆ getPrevPoint()

Vector2f gf::Polyline::getPrevPoint ( std::size_t  i) const

Get the point before the i-th point.

Parameters
iThe index of the current point
Returns
The point before the current point
See also
hasPrevPoint()

◆ getType()

Type gf::Polyline::getType ( ) const
inline

Get the type of the polyline.

Returns
The type of the polyline

◆ getWinding()

Winding gf::Polyline::getWinding ( ) const

Compute the winding of a simple loop polyline.

Complexity: \( O(n) \)

Returns
The winding of the simple loop polyline
See also
gf::Winding, isConvex()
Curve orientation - Wikipedia

◆ hasNextPoint()

bool gf::Polyline::hasNextPoint ( std::size_t  i) const

Check if there is a point after the i-th point.

Parameters
iThe index of the current point
Returns
True if there is a point after the current point
See also
getNextPoint()

◆ hasPrevPoint()

bool gf::Polyline::hasPrevPoint ( std::size_t  i) const

Check if there is a point before the i-th point.

Parameters
iThe index of the current point
Returns
True if there is a point before the current point
See also
getPrevPoint()

◆ isChain()

bool gf::Polyline::isChain ( ) const
inline

Check is the polyline is a chain.

Returns
True if the polyline is a chain
See also
isLoop(), setType()

◆ isLoop()

bool gf::Polyline::isLoop ( ) const
inline

Check is the polyline is a loop.

Returns
True if the polyline is a loop
See also
isChain(), setType()

◆ setType()

void gf::Polyline::setType ( Type  type)
inline

Set the type of the polyline.

Parameters
typeThe new type of the polyline