Gamedev Framework (gf)  0.20.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 #include "Winding.h"
34 
35 namespace gf {
36 #ifndef DOXYGEN_SHOULD_SKIP_THIS
37 inline namespace v1 {
38 #endif
39 
47  class GF_CORE_API Polyline : public PointSequence {
48  public:
52  enum Type {
54  Loop,
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 
123  Vector2f getPrevExtensionPoint() const;
124 
133  bool hasNextPoint(std::size_t i) const;
134 
143  Vector2f getNextPoint(std::size_t i) const;
144 
155  Vector2f getNextExtensionPoint() const;
156 
166  Winding getWinding() const;
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
void setType(Type type)
Set the type of the polyline.
Definition: Polyline.h:183
A deserializer from a binary file.
Definition: Serialization.h:151
The polyline is open.
Definition: Polyline.h:53
Type getType() const
Get the type of the polyline.
Definition: Polyline.h:192
Polyline(Iterator first, Iterator last, Type type=Chain)
Constructor from points.
Definition: Polyline.h:87
A polyline.
Definition: Polyline.h:47
A span.
Definition: Span.h:36
Polyline(Span< const Vector2f > points, Type type=Chain)
Constructor from an array.
Definition: Polyline.h:73
bool isLoop() const
Check is the polyline is a loop.
Definition: Polyline.h:203
bool isChain() const
Check is the polyline is a chain.
Definition: Polyline.h:214
Polyline(Type type=Chain)
Default constructor.
Definition: Polyline.h:62
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:52
Winding
The direction of a polygon&#39;s rotation.
Definition: Winding.h:33
General purpose math vector.
Definition: Vector.h:61
The polyline is closed.
Definition: Polyline.h:54
A sequence of points.
Definition: PointSequence.h:44