Gamedev Framework (gf)  0.5.0
A C++11 framework for 2D games
Polygon.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_POLYGON_H
22 #define GF_POLYGON_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 
36  struct Transform;
37 
42  enum class Winding {
43  Clockwise,
45  };
46 
52  class GF_API Polygon {
53  public:
57  Polygon() = default;
58 
65 
72  template<typename Iterator>
73  Polygon(Iterator first, Iterator last)
74  : m_points(first, last)
75  {
76 
77  }
78 
84  void addPoint(Vector2f point);
85 
91  std::size_t getPointCount() const;
92 
98  Vector2f getPoint(std::size_t index) const;
99 
107  Vector2f getCenter() const;
108 
116  Vector2f getSupport(Vector2f direction, const Transform& transform) const;
117 
124  Vector2f getSupport(Vector2f direction) const;
125 
133  const Vector2f *begin() const;
134 
142  const Vector2f *end() const;
143 
152  bool isConvex() const;
153 
163  Winding getWinding() const;
164 
165 
173  float getArea() const;
174 
180  void applyTransform(const Matrix3f& mat);
181 
182  private:
183  std::vector<Vector2f> m_points;
184  };
185 
186 #ifndef DOXYGEN_SHOULD_SKIP_THIS
187 }
188 #endif
189 }
190 
191 #endif // GF_POLYGON_H
Polygon(Iterator first, Iterator last)
Constructor from points.
Definition: Polygon.h:73
constexpr Vector2f transform(const Matrix3f &mat, Vector2f point)
Apply an affine transformation to a 2D point.
Definition: Transform.h:331
A simple transformation (rotation then translation)
Definition: Transform.h:204
The namespace for gf classes.
Definition: Action.h:34
A constant reference to an array and its size.
Definition: ArrayRef.h:42
A convex polygon.
Definition: Polygon.h:52
Opposite direction of a clock&#39;s hands.
Winding
The direction of a polygon&#39;s rotation.
Definition: Polygon.h:42
Same direction as a clock&#39;s hands.