Gamedev Framework (gf) 1.2.0
A C++17 framework for 2D games
PointSequence.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_POINT_SEQUENCE_H
22#define GF_POINT_SEQUENCE_H
23
24#include <vector>
25
26#include "CoreApi.h"
27#include "Math.h"
28#include "Matrix.h"
29#include "SerializationFwd.h"
30#include "Span.h"
31#include "Vector.h"
32
33namespace gf {
34#ifndef DOXYGEN_SHOULD_SKIP_THIS
35inline namespace v1 {
36#endif
37
44 class GF_CORE_API PointSequence {
45 public:
49 PointSequence() = default;
50
57
64 template<typename Iterator>
65 PointSequence(Iterator first, Iterator last)
66 : m_points(first, last)
67 {
68 }
69
77 bool isEmpty() const {
78 return m_points.empty();
79 }
80
86 void addPoint(Vector2f point) {
87 m_points.push_back(point);
88 }
89
95 std::size_t getPointCount() const {
96 return m_points.size();
97 }
98
104 Vector2f getPoint(std::size_t index) const;
105
114
122 const Vector2f *begin() const {
123 return m_points.data();
124 }
125
134 return m_points.data();
135 }
136
144 const Vector2f *end() const {
145 return m_points.data() + m_points.size();
146 }
147
156 return m_points.data() + m_points.size();
157 }
158
165 return m_points.front();
166 }
167
174 return m_points.back();
175 }
176
182 void applyTransform(const Matrix3f& mat);
183
189 void simplify(float distance = Epsilon);
190
194 void reverse();
195
196 protected:
200 std::vector<Vector2f>& getRawPoints() {
201 return m_points;
202 }
203
207 const std::vector<Vector2f>& getRawPoints() const {
208 return m_points;
209 }
210
211 private:
212 std::vector<Vector2f> m_points;
213 };
214
219 GF_CORE_API Serializer& operator|(Serializer& ar, const PointSequence& sequence);
220
225 GF_CORE_API Deserializer& operator|(Deserializer& ar, PointSequence& sequence);
226
227#ifndef DOXYGEN_SHOULD_SKIP_THIS
228}
229#endif
230}
231
232#endif // GF_POINT_SEQUENCE_H
A deserializer from a binary file.
Definition: Serialization.h:151
GF_CORE_API Deserializer & operator|(Deserializer &ar, PointSequence &sequence)
Deserialize a sequence.
A sequence of points.
Definition: PointSequence.h:44
const std::vector< Vector2f > & getRawPoints() const
Get the raw container of points.
Definition: PointSequence.h:207
PointSequence(Iterator first, Iterator last)
Constructor from points.
Definition: PointSequence.h:65
const Vector2f * end() const
Get an iterator past the last point.
Definition: PointSequence.h:144
Vector2f getPoint(std::size_t index) const
Get the i-th point of the sequence.
bool isEmpty() const
Check if the sequence is empty.
Definition: PointSequence.h:77
Vector2f * end()
Get an iterator past the last point.
Definition: PointSequence.h:155
std::vector< Vector2f > & getRawPoints()
Get the raw container of points.
Definition: PointSequence.h:200
std::size_t getPointCount() const
Get the number of points of the sequence.
Definition: PointSequence.h:95
Vector2f getLastPoint() const
Get the last point of the sequence.
Definition: PointSequence.h:173
PointSequence(Span< const Vector2f > points)
Constructor from an array.
PointSequence()=default
Default constructor.
Vector2f * begin()
Get an iterator to the first point.
Definition: PointSequence.h:133
Vector2f getFirstPoint() const
Get the first point of the sequence.
Definition: PointSequence.h:164
void reverse()
Reverse the points in the sequence.
void simplify(float distance=Epsilon)
Simplify the sequence.
Vector2f getCenter() const
Get the center of the sequence.
void addPoint(Vector2f point)
Add a point to the sequence.
Definition: PointSequence.h:86
void applyTransform(const Matrix3f &mat)
Apply a transformation to the sequence.
const Vector2f * begin() const
Get an iterator to the first point.
Definition: PointSequence.h:122
A serializer to a binary file.
Definition: Serialization.h:43
GF_CORE_API Serializer & operator|(Serializer &ar, const PointSequence &sequence)
Serialize a sequence.
A span.
Definition: Span.h:414
constexpr float Epsilon
Machine epsilon.
Definition: Math.h:94
The namespace for gf classes.
T data[N]
The internal representation of the vector.
Definition: Vector.h:270