Gamedev Framework (gf)  0.7.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 "Matrix.h"
28 #include "Portability.h"
29 #include "Vector.h"
30 #include "Winding.h"
31 
32 namespace gf {
33 #ifndef DOXYGEN_SHOULD_SKIP_THIS
34 inline namespace v1 {
35 #endif
36 
37  struct Transform;
38 
44  class GF_API Polygon {
45  public:
49  Polygon() = default;
50 
57 
64  template<typename Iterator>
65  Polygon(Iterator first, Iterator last)
66  : m_points(first, last)
67  {
68 
69  }
70 
78  bool isEmpty() const;
79 
85  void addPoint(Vector2f point);
86 
92  std::size_t getPointCount() const;
93 
99  Vector2f getPoint(std::size_t index) const;
100 
108  Vector2f getCenter() const;
109 
117  Vector2f getSupport(Vector2f direction, const Transform& transform) const;
118 
125  Vector2f getSupport(Vector2f direction) const;
126 
134  const Vector2f *begin() const;
135 
143  const Vector2f *end() const;
144 
153  bool isConvex() const;
154 
164  Winding getWinding() const;
165 
166 
174  float getArea() const;
175 
181  void applyTransform(const Matrix3f& mat);
182 
183  private:
184  std::vector<Vector2f> m_points;
185  };
186 
187 #ifndef DOXYGEN_SHOULD_SKIP_THIS
188 }
189 #endif
190 }
191 
192 #endif // GF_POLYGON_H
Polygon(Iterator first, Iterator last)
Constructor from points.
Definition: Polygon.h:65
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:44
Winding
The direction of a polygon&#39;s rotation.
Definition: Winding.h:33