Gamedev Framework (gf) 1.2.0
A C++17 framework for 2D games
Triangulation.h
1/*
2 * Gamedev Framework (gf)
3 * Copyright (C) 2016-2022 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 "CoreApi.h"
27#include "Span.h"
28#include "Vector.h"
29
30namespace gf {
31#ifndef DOXYGEN_SHOULD_SKIP_THIS
32inline 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>
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_CORE_API std::vector<TriangleRef<const Vector2f>> triangulation(Span<const Vector2f> points);
121
122// GF_CORE_API std::vector<TriangleRef<const Vector2f>> triangulationConstrained(Span<const Vector2f> points, Span<const 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
const T & operator[](std::size_t index) const
Access the points of the edge.
Definition: Triangulation.h:61
EdgeRef(const T &p0, const T &p1)
Constructor with two points.
Definition: Triangulation.h:50
A span.
Definition: Span.h:414
A reference to a triangle (three points)
Definition: Triangulation.h:74
T & operator[](std::size_t index)
Access the points of the triangle.
Definition: Triangulation.h:105
TriangleRef(T &p0, T &p1, T &p2)
Constructor with three points.
Definition: Triangulation.h:85
const T & operator[](std::size_t index) const
Access the points of the triangle.
Definition: Triangulation.h:96
GF_CORE_API std::vector< TriangleRef< const Vector2f > > triangulation(Span< const Vector2f > points)
Compute a Delaunay triangulation of a set of points.
The namespace for gf classes.