EBGeometry  1.0
EBGeometry_Polygon2D.hpp
Go to the documentation of this file.
1 /* EBGeometry
2  * Copyright © 2022 Robert Marskar
3  * Please refer to Copyright.txt and LICENSE in the EBGeometry root directory.
4  */
12 #ifndef EBGeometry_Polygon2D
13 #define EBGeometry_Polygon2D
14 
15 // Std includes
16 #include <memory>
17 #include <vector>
18 
19 // Our includes
20 #include "EBGeometry_Vec.hpp"
22 
41 template <class T>
42 class Polygon2D
43 {
44 public:
50  {
51  SubtendedAngle,
52  CrossingNumber,
53  WindingNumber
54  };
55 
59  using Vec2 = Vec2T<T>;
60 
64  using Vec3 = Vec3T<T>;
65 
69  Polygon2D() = delete;
70 
76  Polygon2D(const Vec3& a_normal, const std::vector<Vec3>& a_points);
77 
81  ~Polygon2D() = default;
82 
89  inline bool
90  isPointInside(const Vec3& a_point, const InsideOutsideAlgorithm a_algorithm) const noexcept;
91 
99  inline bool
100  isPointInsidePolygonWindingNumber(const Vec3& a_point) const noexcept;
101 
108  inline bool
109  isPointInsidePolygonSubtend(const Vec3& a_point) const noexcept;
110 
118  inline bool
119  isPointInsidePolygonCrossingNumber(const Vec3& a_point) const noexcept;
120 
121 private:
125  size_t m_xDir;
126 
130  size_t m_yDir;
131 
135  std::vector<Vec2> m_points;
136 
143  inline Vec2
144  projectPoint(const Vec3& a_point) const noexcept;
145 
152  inline void
153  define(const Vec3& a_normal, const std::vector<Vec3>& a_points);
154 
160  inline int
161  computeWindingNumber(const Vec2& P) const noexcept;
162 
168  inline size_t
169  computeCrossingNumber(const Vec2& P) const noexcept;
170 
176  inline T
177  computeSubtendedAngle(const Vec2& P) const noexcept;
178 };
179 
181 
182 #include "EBGeometry_Polygon2DImplem.hpp"
183 
184 #endif
Declaration of 2D and 3D point/vector classes with templated precision. Used with DCEL tools.
Class for embedding a polygon face into 2D.
Definition: EBGeometry_Polygon2D.hpp:43
bool isPointInsidePolygonSubtend(const Vec3 &a_point) const noexcept
Check if a point is inside a 2D polygon, using the subtended angles.
InsideOutsideAlgorithm
Supported algorithms for performing inside/outside tests when checking if a point projects to the ins...
Definition: EBGeometry_Polygon2D.hpp:50
bool isPointInside(const Vec3 &a_point, const InsideOutsideAlgorithm a_algorithm) const noexcept
Check if a point is inside or outside the 2D polygon.
Polygon2D()=delete
Disallowed constructor, use the one with the normal vector and points.
bool isPointInsidePolygonWindingNumber(const Vec3 &a_point) const noexcept
Check if a point is inside a 2D polygon, using the winding number algorithm.
~Polygon2D()=default
Destructor (does nothing.
Polygon2D(const Vec3 &a_normal, const std::vector< Vec3 > &a_points)
Full constructor.
bool isPointInsidePolygonCrossingNumber(const Vec3 &a_point) const noexcept
Check if a point is inside a 2D polygon, by computing the number of times a ray crosses the polygon e...
Two-dimensional vector class with arithmetic operators.
Definition: EBGeometry_Vec.hpp:31
Three-dimensional vector class with arithmetic operators.
Definition: EBGeometry_Vec.hpp:218