Gamedev Framework (gf) 1.2.0
A C++17 framework for 2D games
Polyline.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_POLYLINE_H
22#define GF_POLYLINE_H
23
24#include <vector>
25
26#include "CoreApi.h"
27#include "Math.h"
28#include "Matrix.h"
29#include "PointSequence.h"
30#include "SerializationFwd.h"
31#include "Span.h"
32#include "Vector.h"
33#include "Winding.h"
34
35namespace gf {
36#ifndef DOXYGEN_SHOULD_SKIP_THIS
37inline namespace v1 {
38#endif
39
47 class GF_CORE_API Polyline : public PointSequence {
48 public:
52 enum Type {
55 };
56
62 Polyline(Type type = Chain)
63 : m_type(type)
64 {
65 }
66
73 Polyline(Span<const Vector2f> points, Type type = Chain)
74 : PointSequence(points)
75 , m_type(type)
76 {
77 }
78
86 template<typename Iterator>
87 Polyline(Iterator first, Iterator last, Type type = Chain)
88 : PointSequence(first, last)
89 , m_type(type)
90 {
91
92 }
93
102 bool hasPrevPoint(std::size_t i) const;
103
112 Vector2f getPrevPoint(std::size_t i) const;
113
124
133 bool hasNextPoint(std::size_t i) const;
134
143 Vector2f getNextPoint(std::size_t i) const;
144
156
167
176 bool contains(Vector2f point) const;
177
183 void setType(Type type) {
184 m_type = type;
185 }
186
192 Type getType() const {
193 return m_type;
194 }
195
203 bool isLoop() const {
204 return m_type == Loop;
205 }
206
214 bool isChain() const {
215 return m_type == Chain;
216 }
217
218 private:
219 Type m_type;
220 };
221
226 GF_CORE_API Serializer& operator|(Serializer& ar, const Polyline& polyline);
227
232 GF_CORE_API Deserializer& operator|(Deserializer& ar, Polyline& polyline);
233
234#ifndef DOXYGEN_SHOULD_SKIP_THIS
235}
236#endif
237}
238
239#endif // GF_POLYLINE_H
A deserializer from a binary file.
Definition: Serialization.h:151
GF_CORE_API Deserializer & operator|(Deserializer &ar, Polyline &polyline)
Deserialize a polyline.
A sequence of points.
Definition: PointSequence.h:44
A polyline.
Definition: Polyline.h:47
Type
The type of polyline.
Definition: Polyline.h:52
@ Chain
The polyline is open.
Definition: Polyline.h:53
@ Loop
The polyline is closed.
Definition: Polyline.h:54
bool hasPrevPoint(std::size_t i) const
Check if there is a point before the i-th point.
bool hasNextPoint(std::size_t i) const
Check if there is a point after the i-th point.
Polyline(Span< const Vector2f > points, Type type=Chain)
Constructor from an array.
Definition: Polyline.h:73
bool contains(Vector2f point) const
Test if a point is inside the polyline.
Winding getWinding() const
Compute the winding of a simple loop polyline.
Vector2f getPrevExtensionPoint() const
Get the previous extension point of the first point.
Vector2f getNextPoint(std::size_t i) const
Get the point after the i-th point.
Polyline(Type type=Chain)
Default constructor.
Definition: Polyline.h:62
Polyline(Iterator first, Iterator last, Type type=Chain)
Constructor from points.
Definition: Polyline.h:87
void setType(Type type)
Set the type of the polyline.
Definition: Polyline.h:183
Vector2f getNextExtensionPoint() const
Get the next extension point of the last point.
bool isChain() const
Check is the polyline is a chain.
Definition: Polyline.h:214
bool isLoop() const
Check is the polyline is a loop.
Definition: Polyline.h:203
Type getType() const
Get the type of the polyline.
Definition: Polyline.h:192
Vector2f getPrevPoint(std::size_t i) const
Get the point before the i-th point.
A serializer to a binary file.
Definition: Serialization.h:43
GF_CORE_API Serializer & operator|(Serializer &ar, const Polyline &polyline)
Serialize a polyline.
A span.
Definition: Span.h:414
Winding
The direction of a polygon's rotation.
Definition: Winding.h:33
The namespace for gf classes.