Gamedev Framework (gf)  0.19.0
A C++17 framework for 2D games
Polyline.h
1 /*
2  * Gamedev Framework (gf)
3  * Copyright (C) 2016-2021 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 
34 namespace gf {
35 #ifndef DOXYGEN_SHOULD_SKIP_THIS
36 inline namespace v1 {
37 #endif
38 
46  class GF_CORE_API Polyline : public PointSequence {
47  public:
51  enum Type {
53  Loop,
54  };
55 
61  Polyline(Type type = Chain)
62  : m_type(type)
63  {
64  }
65 
72  Polyline(Span<const Vector2f> points, Type type = Chain)
73  : PointSequence(points)
74  , m_type(type)
75  {
76  }
77 
85  template<typename Iterator>
86  Polyline(Iterator first, Iterator last, Type type = Chain)
87  : PointSequence(first, last)
88  , m_type(type)
89  {
90 
91  }
92 
101  bool hasPrevPoint(std::size_t i) const;
102 
111  Vector2f getPrevPoint(std::size_t i) const;
112 
122  Vector2f getPrevExtensionPoint() const;
123 
132  bool hasNextPoint(std::size_t i) const;
133 
142  Vector2f getNextPoint(std::size_t i) const;
143 
154  Vector2f getNextExtensionPoint() const;
155 
161  void setType(Type type) {
162  m_type = type;
163  }
164 
170  Type getType() const {
171  return m_type;
172  }
173 
181  bool isLoop() const {
182  return m_type == Loop;
183  }
184 
192  bool isChain() const {
193  return m_type == Chain;
194  }
195 
196  private:
197  Type m_type;
198  };
199 
204  GF_CORE_API Serializer& operator|(Serializer& ar, const Polyline& polyline);
205 
210  GF_CORE_API Deserializer& operator|(Deserializer& ar, Polyline& polyline);
211 
212 #ifndef DOXYGEN_SHOULD_SKIP_THIS
213 }
214 #endif
215 }
216 
217 #endif // GF_POLYLINE_H
void setType(Type type)
Set the type of the polyline.
Definition: Polyline.h:161
A deserializer from a binary file.
Definition: Serialization.h:151
The polyline is open.
Definition: Polyline.h:52
Type getType() const
Get the type of the polyline.
Definition: Polyline.h:170
Polyline(Iterator first, Iterator last, Type type=Chain)
Constructor from points.
Definition: Polyline.h:86
A polyline.
Definition: Polyline.h:46
A span.
Definition: Span.h:36
Polyline(Span< const Vector2f > points, Type type=Chain)
Constructor from an array.
Definition: Polyline.h:72
bool isLoop() const
Check is the polyline is a loop.
Definition: Polyline.h:181
bool isChain() const
Check is the polyline is a chain.
Definition: Polyline.h:192
Polyline(Type type=Chain)
Default constructor.
Definition: Polyline.h:61
A serializer to a binary file.
Definition: Serialization.h:43
The namespace for gf classes.
Definition: Action.h:35
Type
The type of polyline.
Definition: Polyline.h:51
General purpose math vector.
Definition: Vector.h:61
The polyline is closed.
Definition: Polyline.h:53
A sequence of points.
Definition: PointSequence.h:44