Gamedev Framework (gf)  0.17.0
A C++14 framework for 2D games
Geometry.h
1 /*
2  * Gamedev Framework (gf)
3  * Copyright (C) 2016-2019 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 "GeometryTypes.h"
28 #include "Heightmap.h"
29 #include "Polygon.h"
30 #include "Polyline.h"
31 #include "Portability.h"
32 #include "Random.h"
33 #include "Vector.h"
34 
35 namespace gf {
36 #ifndef DOXYGEN_SHOULD_SKIP_THIS
37 inline namespace v1 {
38 #endif
39 
47  class Bresenham {
48  public:
55  Bresenham(Vector2i p0, Vector2i p1);
56 
63  bool step(Vector2i& res);
64 
65  private:
66  Vector2i m_p0;
67  Vector2i m_p1;
68  Vector2i m_delta;
69  Vector2i m_step;
70  int m_error;
71  };
72 
85  GF_API std::vector<Vector2i> generateLine(Vector2i p0, Vector2i p1);
86 
99  GF_API std::vector<Vector2f> midpointDisplacement1D(Vector2f p0, Vector2f p1, Random& random, unsigned iterations, Vector2f direction, float initialFactor = 1.0f, float reductionFactor = 0.5f);
100 
114  GF_API std::vector<Vector2f> midpointDisplacement1D(Vector2f p0, Vector2f p1, Random& random, unsigned iterations, float initialFactor = 1.0f, float reductionFactor = 0.5f);
115 
116 
137  GF_API Heightmap midpointDisplacement2D(Vector2i size, Random& random, ArrayRef<double> initialValues = nullptr);
138 
139 
160  GF_API Heightmap diamondSquare2D(Vector2i size, Random& random, ArrayRef<double> initialValues = nullptr);
161 
162 
174  GF_API Polygon convexHull(ArrayRef<Vector2f> points);
175 
176 
187  GF_API std::vector<Vector2f> simplifyPoints(ArrayRef<Vector2f> points, float distance = Epsilon);
188 
189 
197  GF_API std::vector<Polyline> buildLines(ArrayRef<SegmentI> segments);
198 
199 
200 #ifndef DOXYGEN_SHOULD_SKIP_THIS
201 }
202 #endif
203 }
204 
205 #endif // GF_GEOMETRY_H
A random engine.
Definition: Random.h:47
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:96
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.
std::vector< Polyline > buildLines(ArrayRef< SegmentI > segments)
Build a set of lines from a set of segments.
The namespace for gf classes.
Definition: Action.h:35
A constant reference to an array and its size.
Definition: ArrayRef.h:43
State for the Bresenham&#39;s line algorithm.
Definition: Geometry.h:47
A convex polygon.
Definition: Polygon.h:46
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