Gamedev Framework (gf)  0.10.0
A C++14 framework for 2D games
Geometry.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_GEOMETRY_H
22 #define GF_GEOMETRY_H
23 
24 #include <vector>
25 
26 #include "ArrayRef.h"
27 #include "Heightmap.h"
28 #include "Polygon.h"
29 #include "Portability.h"
30 #include "Random.h"
31 #include "Vector.h"
32 
33 namespace gf {
34 #ifndef DOXYGEN_SHOULD_SKIP_THIS
35 inline namespace v1 {
36 #endif
37 
45  class Bresenham {
46  public:
53  Bresenham(Vector2i p0, Vector2i p1);
54 
61  bool step(Vector2i& res);
62 
63  private:
64  Vector2i m_p0;
65  Vector2i m_p1;
66  Vector2i m_delta;
67  Vector2i m_step;
68  int m_error;
69  };
70 
83  GF_API std::vector<Vector2i> generateLine(Vector2i p0, Vector2i p1);
84 
97  GF_API std::vector<Vector2f> midpointDisplacement1D(Vector2f p0, Vector2f p1, Random& random, unsigned iterations, Vector2f direction, float initialFactor = 1.0f, float reductionFactor = 0.5f);
98 
112  GF_API std::vector<Vector2f> midpointDisplacement1D(Vector2f p0, Vector2f p1, Random& random, unsigned iterations, float initialFactor = 1.0f, float reductionFactor = 0.5f);
113 
114 
135  GF_API Heightmap midpointDisplacement2D(Vector2i size, Random& random, ArrayRef<double> initialValues = nullptr);
136 
137 
158  GF_API Heightmap diamondSquare2D(Vector2i size, Random& random, ArrayRef<double> initialValues = nullptr);
159 
160 
172  GF_API Polygon convexHull(ArrayRef<Vector2f> points);
173 
174 
185  GF_API std::vector<Vector2f> simplifyPoints(ArrayRef<Vector2f> points, float distance = Epsilon);
186 
187 #ifndef DOXYGEN_SHOULD_SKIP_THIS
188 }
189 #endif
190 }
191 
192 #endif // GF_GEOMETRY_H
A random engine.
Definition: Random.h:45
std::vector< Vector2f > midpointDisplacement1D(Vector2f p0, Vector2f p1, Random &random, unsigned iterations, Vector2f direction, float initialFactor=1.0f, float reductionFactor=0.5f)
1D midpoint displacement
Heightmap diamondSquare2D(Vector2i size, Random &random, ArrayRef< double > initialValues=nullptr)
2D diamond square
constexpr float Epsilon
Machine epsilon.
Definition: Math.h:74
std::vector< Vector2f > simplifyPoints(ArrayRef< Vector2f > points, float distance=Epsilon)
Simplify a sequence of points.
A heightmap.
Definition: Heightmap.h:44
std::vector< Vector2i > generateLine(Vector2i p0, Vector2i p1)
Generate a line between two positions.
The namespace for gf classes.
Definition: Action.h:34
A constant reference to an array and its size.
Definition: ArrayRef.h:42
State for the Bresenham&#39;s line algorithm.
Definition: Geometry.h:45
A convex polygon.
Definition: Polygon.h:45
Polygon convexHull(ArrayRef< Vector2f > points)
Compute the convex hull of a set of points.
Heightmap midpointDisplacement2D(Vector2i size, Random &random, ArrayRef< double > initialValues=nullptr)
2D midpoint displacement