Gamedev Framework (gf)  0.5.0
A C++11 framework for 2D games
Polyline.h
1 /*
2  * Gamedev Framework (gf)
3  * Copyright (C) 2016-2017 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 "ArrayRef.h"
27 #include "Matrix.h"
28 #include "Portability.h"
29 #include "Vector.h"
30 
31 namespace gf {
32 #ifndef DOXYGEN_SHOULD_SKIP_THIS
33 inline namespace v1 {
34 #endif
35 
43  class GF_API Polyline {
44  public:
48  enum Type {
50  Loop,
51  };
52 
58  Polyline(Type type = Chain)
59  : m_type(type)
60  {
61 
62  }
63 
70  Polyline(ArrayRef<Vector2f> points, Type type = Chain)
71  : m_points(points.begin(), points.end())
72  , m_type(type)
73  {
74 
75  }
76 
84  template<typename Iterator>
85  Polyline(Iterator first, Iterator last, Type type = Chain)
86  : m_points(first, last)
87  , m_type(type)
88  {
89 
90  }
91 
97  void addPoint(Vector2f point);
98 
104  std::size_t getPointCount() const;
105 
111  Vector2f getPoint(std::size_t index) const;
112 
120  const Vector2f *begin() const;
121 
129  const Vector2f *end() const;
130 
139  bool hasPrevPoint(std::size_t i) const;
140 
149  Vector2f getPrevPoint(std::size_t i) const;
150 
159  bool hasNextPoint(std::size_t i) const;
160 
169  Vector2f getNextPoint(std::size_t i) const;
170 
176  void setType(Type type) {
177  m_type = type;
178  }
179 
187  bool isLoop() const {
188  return m_type == Loop;
189  }
190 
198  bool isChain() const {
199  return m_type == Chain;
200  }
201 
202  private:
203  std::vector<Vector2f> m_points;
204  Type m_type;
205  };
206 
207 #ifndef DOXYGEN_SHOULD_SKIP_THIS
208 }
209 #endif
210 }
211 
212 #endif // GF_POLYLINE_H
void setType(Type type)
Set the type of the polyline.
Definition: Polyline.h:176
Polyline(ArrayRef< Vector2f > points, Type type=Chain)
Constructor from an array.
Definition: Polyline.h:70
The polyline is open.
Definition: Polyline.h:49
Polyline(Iterator first, Iterator last, Type type=Chain)
Constructor from points.
Definition: Polyline.h:85
A polyline.
Definition: Polyline.h:43
bool isLoop() const
Check is the polyline is a loop.
Definition: Polyline.h:187
bool isChain() const
Check is the polyline is a chain.
Definition: Polyline.h:198
Polyline(Type type=Chain)
Default constructor.
Definition: Polyline.h:58
The namespace for gf classes.
Definition: Action.h:34
A constant reference to an array and its size.
Definition: ArrayRef.h:42
Type
The type of polyline.
Definition: Polyline.h:48
The polyline is closed.
Definition: Polyline.h:50