Gamedev Framework (gf)  0.10.0
A C++14 framework for 2D games
Triangulation.h
1 /*
2  * Gamedev Framework (gf)
3  * Copyright (C) 2016-2018 Julien Bernard
4  *
5  * This software is provided 'as-is', without any express or implied
6  * warranty. In no event will the authors be held liable for any damages
7  * arising from the use of this software.
8  *
9  * Permission is granted to anyone to use this software for any purpose,
10  * including commercial applications, and to alter it and redistribute it
11  * freely, subject to the following restrictions:
12  *
13  * 1. The origin of this software must not be misrepresented; you must not
14  * claim that you wrote the original software. If you use this software
15  * in a product, an acknowledgment in the product documentation would be
16  * appreciated but is not required.
17  * 2. Altered source versions must be plainly marked as such, and must not be
18  * misrepresented as being the original software.
19  * 3. This notice may not be removed or altered from any source distribution.
20  */
21 #ifndef GF_TRIANGULATION_H
22 #define GF_TRIANGULATION_H
23 
24 #include <vector>
25 
26 #include "ArrayRef.h"
27 #include "Portability.h"
28 #include "Vector.h"
29 
30 namespace gf {
31 #ifndef DOXYGEN_SHOULD_SKIP_THIS
32 inline namespace v1 {
33 #endif
34 
39  template<typename T>
40  class EdgeRef {
41  public:
50  EdgeRef(const T& p0, const T& p1)
51  : m_points{ &p0, &p1 }
52  {
53 
54  }
55 
61  const T& operator[](std::size_t index) const {
62  return *m_points[index];
63  }
64 
65  protected:
66  const T *m_points[2];
67  };
68 
73  template<typename T>
74  class TriangleRef {
75  public:
85  TriangleRef(T& p0, T& p1, T& p2)
86  : m_points{ &p0, &p1, &p2 }
87  {
88 
89  }
90 
96  const T& operator[](std::size_t index) const {
97  return *m_points[index];
98  }
99 
105  T& operator[](std::size_t index) {
106  return *m_points[index];
107  }
108 
109  protected:
110  T *m_points[3];
111  };
112 
120  GF_API std::vector<TriangleRef<const Vector2f>> triangulation(ArrayRef<Vector2f> points);
121 
122 // GF_API std::vector<TriangleRef<const Vector2f>> triangulationConstrained(ArrayRef<Vector2f> points, ArrayRef<EdgeRef<Vector2f>> contrainedEdges);
123 
124 #ifndef DOXYGEN_SHOULD_SKIP_THIS
125 }
126 #endif
127 }
128 
129 #endif // GF_TRIANGULATION_H
A reference to an edge (two points)
Definition: Triangulation.h:40
The namespace for gf classes.
Definition: Action.h:34
A constant reference to an array and its size.
Definition: ArrayRef.h:42
TriangleRef(T &p0, T &p1, T &p2)
Constructor with two points.
Definition: Triangulation.h:85
std::vector< TriangleRef< const Vector2f > > triangulation(ArrayRef< Vector2f > points)
Compute a Delaunay triangulation of a set of points.
const T & operator[](std::size_t index) const
Access the points of the triangle.
Definition: Triangulation.h:96
EdgeRef(const T &p0, const T &p1)
Constructor with two points.
Definition: Triangulation.h:50
A reference to a triangle (three points)
Definition: Triangulation.h:74
const T & operator[](std::size_t index) const
Access the points of the edge.
Definition: Triangulation.h:61
T & operator[](std::size_t index)
Access the points of the triangle.
Definition: Triangulation.h:105