Gamedev Framework (gf) 1.2.0
A C++17 framework for 2D games
Classes | Typedefs | Enumerations | Functions
Geometry

Geometry classes and functions. More...

Classes

struct  gf::Circ< T >
 Utility class for manipulating circles. More...
 
struct  gf::Penetration
 Data about the collision between two objects. More...
 
class  gf::Bresenham
 State for the Bresenham's line algorithm. More...
 
struct  gf::Segment< T >
 A segment with two points. More...
 
class  gf::PointSequence
 A sequence of points. More...
 
class  gf::Polygon
 A convex polygon. More...
 
class  gf::Polyline
 A polyline. More...
 
struct  gf::Rect< T >
 Utility class for manipulating 2D axis aligned rectangles. More...
 
struct  gf::Rotation
 A rotation. More...
 
struct  gf::Translation
 A translation. More...
 
struct  gf::Transform
 A simple transformation (rotation then translation) More...
 
class  gf::EdgeRef< T >
 A reference to an edge (two points) More...
 
class  gf::TriangleRef< T >
 A reference to a triangle (three points) More...
 

Typedefs

using gf::CircF = Circ< float >
 A float circle. More...
 
using gf::CircD = Circ< double >
 A double circle. More...
 
using gf::CircI = Circ< int >
 A int circle. More...
 
using gf::CircU = Circ< unsigned >
 A unsigned circle. More...
 
using gf::CircZ = Circ< std::size_t >
 A std::size_t circle. More...
 
using gf::SegmentF = Segment< float >
 A segment with float vectors. More...
 
using gf::SegmentD = Segment< double >
 A segment with double vectors. More...
 
using gf::SegmentI = Segment< int >
 A segment with int vectors. More...
 
using gf::RectF = Rect< float >
 A float rectangle. More...
 
using gf::RectD = Rect< double >
 A double rectangle. More...
 
using gf::RectI = Rect< int >
 A int rectangle. More...
 
using gf::RectU = Rect< unsigned >
 A unsigned rectangle. More...
 
using gf::RectZ = Rect< std::size_t >
 A std::size_t rectangle. More...
 

Enumerations

enum class  gf::Direction : int8_t {
  gf::Direction::Center = -1 ,
  gf::Direction::Up = 0 ,
  gf::Direction::Right = 1 ,
  gf::Direction::Down = 2 ,
  gf::Direction::Left = 3
}
 Main four directions. More...
 
enum class  gf::Orientation : int8_t {
  gf::Orientation::Center = -1 ,
  gf::Orientation::North = 0 ,
  gf::Orientation::NorthEast = 1 ,
  gf::Orientation::East = 2 ,
  gf::Orientation::SouthEast = 3 ,
  gf::Orientation::South = 4 ,
  gf::Orientation::SouthWest = 5 ,
  gf::Orientation::West = 6 ,
  gf::Orientation::NorthWest = 7
}
 Cardinal and ordinal orientation. More...
 
enum class  gf::Winding {
  gf::Winding::None ,
  gf::Winding::Clockwise ,
  gf::Winding::Counterclockwise
}
 The direction of a polygon's rotation. More...
 

Functions

GF_CORE_API Vector2f gf::unit (Direction direction)
 Get a unit vector from a direction. More...
 
GF_CORE_API Vector2i gf::displacement (Direction direction)
 Get a vector from a direction. More...
 
GF_CORE_API float gf::angle (Direction direction)
 Get an angle from a direction. More...
 
GF_CORE_API Direction gf::opposite (Direction direction)
 Get the opposite direction. More...
 
GF_CORE_API Direction gf::orthogonalCW (Direction direction)
 Get the orthogonal direction clockwise. More...
 
GF_CORE_API Direction gf::orthogonalCCW (Direction direction)
 Get the orthogonal direction counter-clockwise. More...
 
GF_CORE_API Direction gf::nextCW (Direction direction)
 Get the next direction clockwise. More...
 
GF_CORE_API Direction gf::nextCCW (Direction direction)
 Get the next direction counter-clockwise. More...
 
GF_CORE_API std::vector< Vector2igf::generateLine (Vector2i p0, Vector2i p1)
 Generate a line between two positions. More...
 
GF_CORE_API Polygon gf::convexHull (Span< const Vector2f > points)
 Compute the convex hull of a set of points. More...
 
GF_CORE_API std::vector< Vector2fgf::simplifyPoints (Span< const Vector2f > points, float distance=Epsilon)
 Simplify a sequence of points. More...
 
GF_CORE_API std::vector< Polylinegf::buildLines (Span< const SegmentI > segments)
 Build a set of lines from a set of segments. More...
 
GF_CORE_API Vector2f gf::unit (Orientation orientation)
 Get a unit vector from an orientation. More...
 
GF_CORE_API Vector2i gf::displacement (Orientation orientation)
 Get a vector from an orientation. More...
 
GF_CORE_API float gf::angle (Orientation orientation)
 Get an angle from a orientation. More...
 
GF_CORE_API Orientation gf::orientation (float angle)
 Get an orientation from an angle. More...
 
GF_CORE_API Orientation gf::opposite (Orientation orientation)
 Get the opposite orientation. More...
 
GF_CORE_API Orientation gf::orthogonalCW (Orientation orientation)
 Get the orthogonal orientation clockwise. More...
 
GF_CORE_API Orientation gf::orthogonalCCW (Orientation orientation)
 Get the orthogonal orientation counter-clockwise. More...
 
GF_CORE_API Orientation gf::nextCW (Orientation orientation)
 Get the next orientation clockwise. More...
 
GF_CORE_API Orientation gf::nextCCW (Orientation orientation)
 Get the next orientation counter-clockwise. More...
 
template<typename T >
constexpr Rect< T > gf::computeBoxQuarter (const Rect< T > &other, Quarter quarter)
 Divide a rectangle in quarters. More...
 
constexpr Vector2f gf::transform (const Matrix3f &mat, Vector2f point)
 Apply an affine transformation to a 2D point. More...
 
GF_CORE_API RectF gf::transform (const Matrix3f &mat, const RectF &rect)
 Apply an affine transformaton to a rectangle. More...
 
constexpr Matrix3f gf::identityTransform ()
 Identity transform. More...
 
Matrix3f gf::translation (Vector2f offset)
 Get a translation matrix. More...
 
GF_CORE_API void gf::translate (Matrix3f &mat, Vector2f offset)
 Combine the current transform with a translation. More...
 
Matrix3f gf::rotation (float angle)
 Get a rotation matrix. More...
 
Matrix3f gf::rotation (float angle, Vector2f center)
 Get a rotation matrix. More...
 
GF_CORE_API void gf::rotate (Matrix3f &mat, float angle)
 Combine the current transform with a rotation. More...
 
GF_CORE_API void gf::rotate (Matrix3f &mat, float angle, Vector2f center)
 Combine the current transform with a rotation. More...
 
Matrix3f gf::scaling (Vector2f factor)
 Get a scaling matrix. More...
 
Matrix3f gf::scaling (Vector2f factor, Vector2f center)
 Get a scaling matrix. More...
 
GF_CORE_API void gf::scale (Matrix3f &mat, Vector2f factor)
 Combine the current transform with a scaling. More...
 
GF_CORE_API void gf::scale (Matrix3f &mat, Vector2f factor, Vector2f center)
 Combine the current transform with a scaling. More...
 
GF_CORE_API std::vector< TriangleRef< const Vector2f > > gf::triangulation (Span< const Vector2f > points)
 Compute a Delaunay triangulation of a set of points. More...
 

Detailed Description

Geometry classes and functions.

Typedef Documentation

◆ CircD

using gf::CircD = typedef Circ<double>

A double circle.

See also
gf::Circ

◆ CircF

using gf::CircF = typedef Circ<float>

A float circle.

See also
gf::Circ

◆ CircI

using gf::CircI = typedef Circ<int>

A int circle.

See also
gf::Circ

◆ CircU

using gf::CircU = typedef Circ<unsigned>

A unsigned circle.

See also
gf::Circ

◆ CircZ

using gf::CircZ = typedef Circ<std::size_t>

A std::size_t circle.

See also
gf::Circ

◆ RectD

using gf::RectD = typedef Rect<double>

A double rectangle.

See also
gf::Rect

◆ RectF

using gf::RectF = typedef Rect<float>

A float rectangle.

See also
gf::Rect

◆ RectI

using gf::RectI = typedef Rect<int>

A int rectangle.

See also
gf::Rect

◆ RectU

using gf::RectU = typedef Rect<unsigned>

A unsigned rectangle.

See also
gf::Rect

◆ RectZ

using gf::RectZ = typedef Rect<std::size_t>

A std::size_t rectangle.

See also
gf::Rect

◆ SegmentD

using gf::SegmentD = typedef Segment<double>

A segment with double vectors.

See also
gf::Segment

◆ SegmentF

using gf::SegmentF = typedef Segment<float>

A segment with float vectors.

See also
gf::Segment

◆ SegmentI

using gf::SegmentI = typedef Segment<int>

A segment with int vectors.

See also
gf::Segment

Enumeration Type Documentation

◆ Direction

enum class gf::Direction : int8_t
strong

Main four directions.

gf::Direction represents one of the four main directions. A special value is added to represent the center, it indicates no direction.

See also
gf::Orientation
Enumerator
Center 

The center, indicates no direction.

Up 

The up direction.

Right 

The right direction.

Down 

The down direction.

Left 

The left direction.

◆ Orientation

enum class gf::Orientation : int8_t
strong

Cardinal and ordinal orientation.

gf::Orientation represents one the four cardinal orientations and the four ordinal (or intercardinal) orientations. A special value is added to represent the center, it indicates no orientation.

See also
gf::Direction
Enumerator
Center 

The center, indicates no orientation.

North 

The north orientation.

NorthEast 

The north-east orientation.

East 

The east orientation.

SouthEast 

The south-east orientation.

South 

The south orientation.

SouthWest 

The south-west orientation.

West 

The west orientation.

NorthWest 

The north-west orientation.

◆ Winding

enum class gf::Winding
strong

The direction of a polygon's rotation.

Enumerator
None 

No winding.

Clockwise 

Same direction as a clock's hands.

Counterclockwise 

Opposite direction of a clock's hands.

Function Documentation

◆ angle() [1/2]

GF_CORE_API float gf::angle ( Direction  direction)

Get an angle from a direction.

Up is at angle 0 and angle grows clockwise.

Parameters
directionThe direction
Returns
an angle (in radians) representing the direction

◆ angle() [2/2]

GF_CORE_API float gf::angle ( Orientation  orientation)

Get an angle from a orientation.

East is at angle 0 and angle grows clockwise.

Parameters
orientationThe orientation
Returns
An angle (in radians) representing the orientation
See also
gf::orientation()

◆ buildLines()

GF_CORE_API std::vector< Polyline > gf::buildLines ( Span< const SegmentI segments)

Build a set of lines from a set of segments.

Parameters
segmentsA set of segments
Returns
An array of polylines representing the lines

◆ computeBoxQuarter()

template<typename T >
constexpr Rect< T > gf::computeBoxQuarter ( const Rect< T > &  other,
Quarter  quarter 
)
constexpr

Divide a rectangle in quarters.

Parameters
otherThe rectangle to divide
quarterThe quarter to compute

◆ convexHull()

GF_CORE_API Polygon gf::convexHull ( Span< const Vector2f points)

Compute the convex hull of a set of points.

This function uses the Quickhull algorithm.

Complexity: \( O(n \log n)\) on average, \( O(n^2) \) on worst case

Parameters
pointsThe set of points
Returns
A (convex) polygon that contains the points

◆ displacement() [1/2]

GF_CORE_API Vector2i gf::displacement ( Direction  direction)

Get a vector from a direction.

The vector has its coordinates at -1, 0 or 1 depending on the direction. It can be used to represent the displacement on a grid in the given direction.

Parameters
directionThe direction
Returns
A vector representing the direction

◆ displacement() [2/2]

GF_CORE_API Vector2i gf::displacement ( Orientation  orientation)

Get a vector from an orientation.

The vector has its coordinates at -1, 0 or 1 depending on the orientation. It can be used to represent the displacement on a grid in the given orientation.

Parameters
orientationThe orientation
Returns
A vector representing the orientation

◆ generateLine()

GF_CORE_API std::vector< Vector2i > gf::generateLine ( Vector2i  p0,
Vector2i  p1 
)

Generate a line between two positions.

This function uses Bresenham's line algorithm.

Parameters
p0The first point of the line
p1The last point of the line
Returns
A series of point beginning at the first point and ending just before the last point
See also
gf::Bresenham

◆ identityTransform()

constexpr Matrix3f gf::identityTransform ( )
constexpr

Identity transform.

Returns
The identity matrix

◆ nextCCW() [1/2]

GF_CORE_API Direction gf::nextCCW ( Direction  direction)

Get the next direction counter-clockwise.

Parameters
directionThe direction
Returns
The next direction counter-clockwise

◆ nextCCW() [2/2]

GF_CORE_API Orientation gf::nextCCW ( Orientation  orientation)

Get the next orientation counter-clockwise.

Parameters
orientationThe orientation
Returns
The next orientation counter-clockwise

◆ nextCW() [1/2]

GF_CORE_API Direction gf::nextCW ( Direction  direction)

Get the next direction clockwise.

Parameters
directionThe direction
Returns
The next direction clockwise

◆ nextCW() [2/2]

GF_CORE_API Orientation gf::nextCW ( Orientation  orientation)

Get the next orientation clockwise.

Parameters
orientationThe orientation
Returns
The next orientation clockwise

◆ opposite() [1/2]

GF_CORE_API Direction gf::opposite ( Direction  direction)

Get the opposite direction.

Parameters
directionThe direction
Returns
The opposite direction

◆ opposite() [2/2]

GF_CORE_API Orientation gf::opposite ( Orientation  orientation)

Get the opposite orientation.

Parameters
orientationThe orientation
Returns
The opposite orientation

◆ orientation()

GF_CORE_API Orientation gf::orientation ( float  angle)

Get an orientation from an angle.

East is at angle 0 and angle grows clockwise.

Parameters
angleThe angle
Returns
An orientation for the angle
See also
gf::angle()

◆ orthogonalCCW() [1/2]

GF_CORE_API Direction gf::orthogonalCCW ( Direction  direction)

Get the orthogonal direction counter-clockwise.

Parameters
directionThe direction
Returns
The orthogonal direction counter-clockwise

◆ orthogonalCCW() [2/2]

GF_CORE_API Orientation gf::orthogonalCCW ( Orientation  orientation)

Get the orthogonal orientation counter-clockwise.

Parameters
orientationThe orientation
Returns
The orthogonal orientation counter-clockwise

◆ orthogonalCW() [1/2]

GF_CORE_API Direction gf::orthogonalCW ( Direction  direction)

Get the orthogonal direction clockwise.

Parameters
directionThe direction
Returns
The orthogonal direction clockwise

◆ orthogonalCW() [2/2]

GF_CORE_API Orientation gf::orthogonalCW ( Orientation  orientation)

Get the orthogonal orientation clockwise.

Parameters
orientationThe orientation
Returns
The orthogonal orientation clockwise

◆ rotate() [1/2]

GF_CORE_API void gf::rotate ( Matrix3f mat,
float  angle 
)

Combine the current transform with a rotation.

Parameters
matThe current transform
angleThe angle of the rotation (in radians)

◆ rotate() [2/2]

GF_CORE_API void gf::rotate ( Matrix3f mat,
float  angle,
Vector2f  center 
)

Combine the current transform with a rotation.

Parameters
matThe current transform
angleThe angle of the rotation (in radians)
centerThe center of the rotation

◆ rotation() [1/2]

Matrix3f gf::rotation ( float  angle)
inline

Get a rotation matrix.

Parameters
angleThe angle of the rotation (in radians)
Returns
A rotation of angle radians

◆ rotation() [2/2]

Matrix3f gf::rotation ( float  angle,
Vector2f  center 
)
inline

Get a rotation matrix.

Parameters
angleThe angle of the rotation (in radians)
centerThe center of the rotation
Returns
A rotation of angle radians of origin center

◆ scale() [1/2]

GF_CORE_API void gf::scale ( Matrix3f mat,
Vector2f  factor 
)

Combine the current transform with a scaling.

Parameters
matThe current transform
factorThe scaling factor

◆ scale() [2/2]

GF_CORE_API void gf::scale ( Matrix3f mat,
Vector2f  factor,
Vector2f  center 
)

Combine the current transform with a scaling.

Parameters
matThe current transform
factorThe scaling factor
centerThe center of the scaling

◆ scaling() [1/2]

Matrix3f gf::scaling ( Vector2f  factor)
inline

Get a scaling matrix.

Parameters
factorThe scaling factor
Returns
A scaling by factor

◆ scaling() [2/2]

Matrix3f gf::scaling ( Vector2f  factor,
Vector2f  center 
)
inline

Get a scaling matrix.

Parameters
factorThe scaling factor
centerThe center of the scaling
Returns
A scaling by factor of origin center

◆ simplifyPoints()

GF_CORE_API std::vector< Vector2f > gf::simplifyPoints ( Span< const Vector2f points,
float  distance = Epsilon 
)

Simplify a sequence of points.

This function uses the Douglas–Peucker algorithm.

Parameters
pointsThe sequence of points
distanceThe maximum authorized distance between the original points and the simplified points
Returns
A new simplified sequence of points

◆ transform() [1/2]

GF_CORE_API RectF gf::transform ( const Matrix3f mat,
const RectF rect 
)

Apply an affine transformaton to a rectangle.

The resulting rectangle is axis-aligned

Parameters
matThe transformation matrix
rectThe rectangle to transform
Returns
The transformed rectangle

◆ transform() [2/2]

constexpr Vector2f gf::transform ( const Matrix3f mat,
Vector2f  point 
)
constexpr

Apply an affine transformation to a 2D point.

Parameters
matThe transformation matrix
pointThe point to transform
Returns
The transformed point

◆ translate()

GF_CORE_API void gf::translate ( Matrix3f mat,
Vector2f  offset 
)

Combine the current transform with a translation.

Parameters
matThe current transform
offsetThe offset of the translation

◆ translation()

Matrix3f gf::translation ( Vector2f  offset)
inline

Get a translation matrix.

Parameters
offsetThe offset of the translation
Returns
A translation by offset

◆ triangulation()

GF_CORE_API std::vector< TriangleRef< const Vector2f > > gf::triangulation ( Span< const Vector2f points)

Compute a Delaunay triangulation of a set of points.

Parameters
pointsThe set of points
Returns
A set of triangles refering to the original points

◆ unit() [1/2]

GF_CORE_API Vector2f gf::unit ( Direction  direction)

Get a unit vector from a direction.

Parameters
directionThe direction
Returns
A unit vector representing the direction

◆ unit() [2/2]

GF_CORE_API Vector2f gf::unit ( Orientation  orientation)

Get a unit vector from an orientation.

Parameters
orientationThe orientation
Returns
A unit vector representing the orientation