Gamedev Framework (gf) 1.2.0
A C++17 framework for 2D games
Geometry.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_GEOMETRY_H
22#define GF_GEOMETRY_H
23
24#include <vector>
25
26#include "CoreApi.h"
27#include "GeometryTypes.h"
28#include "Heightmap.h"
29#include "Polygon.h"
30#include "Polyline.h"
31#include "Random.h"
32#include "Span.h"
33#include "Vector.h"
34
35namespace gf {
36#ifndef DOXYGEN_SHOULD_SKIP_THIS
37inline namespace v1 {
38#endif
39
47 class GF_CORE_API Bresenham {
48 public:
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_CORE_API std::vector<Vector2i> generateLine(Vector2i p0, Vector2i p1);
86
99 GF_CORE_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_CORE_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_CORE_API Heightmap midpointDisplacement2D(Vector2i size, Random& random, Span<const double> initialValues = nullptr);
138
139
160 GF_CORE_API Heightmap diamondSquare2D(Vector2i size, Random& random, Span<const double> initialValues = nullptr);
161
162
175
176
187 GF_CORE_API std::vector<Vector2f> simplifyPoints(Span<const Vector2f> points, float distance = Epsilon);
188
189
197 GF_CORE_API std::vector<Polyline> buildLines(Span<const SegmentI> segments);
198
199
200#ifndef DOXYGEN_SHOULD_SKIP_THIS
201}
202#endif
203}
204
205#endif // GF_GEOMETRY_H
State for the Bresenham's line algorithm.
Definition: Geometry.h:47
bool step(Vector2i &res)
Generate a new point on the line.
Bresenham(Vector2i p0, Vector2i p1)
Constructor.
A heightmap.
Definition: Heightmap.h:44
A convex polygon.
Definition: Polygon.h:47
A set of random utilities.
Definition: Random.h:83
A span.
Definition: Span.h:414
GF_CORE_API std::vector< Vector2i > generateLine(Vector2i p0, Vector2i p1)
Generate a line between two positions.
GF_CORE_API std::vector< Polyline > buildLines(Span< const SegmentI > segments)
Build a set of lines from a set of segments.
GF_CORE_API std::vector< Vector2f > simplifyPoints(Span< const Vector2f > points, float distance=Epsilon)
Simplify a sequence of points.
GF_CORE_API Polygon convexHull(Span< const Vector2f > points)
Compute the convex hull of a set of points.
constexpr float Epsilon
Machine epsilon.
Definition: Math.h:94
GF_CORE_API Heightmap midpointDisplacement2D(Vector2i size, Random &random, Span< const double > initialValues=nullptr)
2D midpoint displacement
GF_CORE_API Heightmap diamondSquare2D(Vector2i size, Random &random, Span< const double > initialValues=nullptr)
2D diamond square
GF_CORE_API 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
The namespace for gf classes.