Gamedev Framework (gf)  0.19.0
A C++17 framework for 2D games
Polygon.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_POLYGON_H
22 #define GF_POLYGON_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 
40  struct Transform;
41 
47  class GF_CORE_API Polygon : public PointSequence {
48  public:
52  Polygon() = default;
53 
60  : PointSequence(points)
61  {
62  }
63 
70  template<typename Iterator>
71  Polygon(Iterator first, Iterator last)
72  : PointSequence(first, last)
73  {
74  }
75 
83  Vector2f getSupport(Vector2f direction, const Transform& transform) const;
84 
91  Vector2f getSupport(Vector2f direction) const;
92 
103  bool isConvex() const;
104 
114  Winding getWinding() const;
115 
122  bool contains(Vector2f point) const;
123 
131  float getArea() const;
132  };
133 
138  inline
139  Serializer& operator|(Serializer& ar, const Polygon& polygon) {
140  return ar | static_cast<const PointSequence&>(polygon);
141  }
142 
147  inline
149  return ar | static_cast<PointSequence&>(polygon);
150  }
151 
152 #ifndef DOXYGEN_SHOULD_SKIP_THIS
153 }
154 #endif
155 }
156 
157 #endif // GF_POLYGON_H
A deserializer from a binary file.
Definition: Serialization.h:151
Polygon(Iterator first, Iterator last)
Constructor from points.
Definition: Polygon.h:71
Serializer & operator|(Serializer &ar, const Polygon &polygon)
Serialize a polygon.
Definition: Polygon.h:139
A span.
Definition: Span.h:36
A simple transformation (rotation then translation)
Definition: Transform.h:203
constexpr Vector2f transform(const Matrix3f &mat, Vector2f point)
Apply an affine transformation to a 2D point.
Definition: Transform.h:326
A serializer to a binary file.
Definition: Serialization.h:43
The namespace for gf classes.
Definition: Action.h:35
A convex polygon.
Definition: Polygon.h:47
Winding
The direction of a polygon&#39;s rotation.
Definition: Winding.h:33
Polygon(Span< const Vector2f > points)
Constructor from an array.
Definition: Polygon.h:59
General purpose math vector.
Definition: Vector.h:61
Deserializer & operator|(Deserializer &ar, Polygon &polygon)
Deserialize a polygon.
Definition: Polygon.h:148
A sequence of points.
Definition: PointSequence.h:44