Gamedev Framework (gf)  0.10.0
A C++14 framework for 2D games
Polygon.h
1 /*
2  * Gamedev Framework (gf)
3  * Copyright (C) 2016-2018 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 "Math.h"
28 #include "Matrix.h"
29 #include "Portability.h"
30 #include "Vector.h"
31 #include "Winding.h"
32 
33 namespace gf {
34 #ifndef DOXYGEN_SHOULD_SKIP_THIS
35 inline namespace v1 {
36 #endif
37 
38  struct Transform;
39 
45  class GF_API Polygon {
46  public:
50  Polygon() = default;
51 
58 
65  template<typename Iterator>
66  Polygon(Iterator first, Iterator last)
67  : m_points(first, last)
68  {
69 
70  }
71 
79  bool isEmpty() const;
80 
86  void addPoint(Vector2f point);
87 
93  std::size_t getPointCount() const;
94 
100  Vector2f getPoint(std::size_t index) const;
101 
109  Vector2f getCenter() const;
110 
118  Vector2f getSupport(Vector2f direction, const Transform& transform) const;
119 
126  Vector2f getSupport(Vector2f direction) const;
127 
135  const Vector2f *begin() const;
136 
144  const Vector2f *end() const;
145 
154  bool isConvex() const;
155 
165  Winding getWinding() const;
166 
167 
175  float getArea() const;
176 
182  void applyTransform(const Matrix3f& mat);
183 
189  void simplify(float distance = Epsilon);
190 
191  private:
192  std::vector<Vector2f> m_points;
193  };
194 
195 #ifndef DOXYGEN_SHOULD_SKIP_THIS
196 }
197 #endif
198 }
199 
200 #endif // GF_POLYGON_H
Polygon(Iterator first, Iterator last)
Constructor from points.
Definition: Polygon.h:66
constexpr Vector2f transform(const Matrix3f &mat, Vector2f point)
Apply an affine transformation to a 2D point.
Definition: Transform.h:331
constexpr float Epsilon
Machine epsilon.
Definition: Math.h:74
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:45
Winding
The direction of a polygon&#39;s rotation.
Definition: Winding.h:33