EBGeometry
Compact, header-only C++ library for fast evaluation of signed distance functions
Loading...
Searching...
No Matches
EBGeometry_Polygon2D.hpp
Go to the documentation of this file.
1// SPDX-FileCopyrightText: 2022 Robert Marskar <robert.marskar@sintef.no>
2//
3// SPDX-License-Identifier: GPL-3.0-or-later
4
12#ifndef EBGEOMETRY_POLYGON2D_HPP
13#define EBGEOMETRY_POLYGON2D_HPP
14
15// Std includes
16#include <cstddef>
17#include <type_traits>
18#include <vector>
19
20// Our includes
21#include "EBGeometry_Vec.hpp"
22
23namespace EBGeometry {
24
44template <class T>
46{
47 static_assert(std::is_floating_point_v<T>, "Polygon2D requires a floating-point T");
48
49public:
66
70 using Vec2 = Vec2T<T>;
71
75 using Vec3 = Vec3T<T>;
76
80 Polygon2D() = delete;
81
88 Polygon2D(const Vec3& a_normal, const std::vector<Vec3>& a_points);
89
94 Polygon2D(const Polygon2D& a_other) = default;
95
100 Polygon2D(Polygon2D&& a_other) noexcept = default;
101
105 ~Polygon2D() = default;
106
112 Polygon2D&
113 operator=(const Polygon2D& a_other) = default;
114
120 Polygon2D&
121 operator=(Polygon2D&& a_other) noexcept = default;
122
130 [[nodiscard]] inline bool
132
140 [[nodiscard]] inline bool
142
149 [[nodiscard]] inline bool
151
159 [[nodiscard]] inline bool
161
162private:
166 size_t m_xDir = 0;
167
171 size_t m_yDir = 0;
172
176 std::vector<Vec2> m_points;
177
184 [[nodiscard]] inline Vec2
185 projectPoint(const Vec3& a_point) const noexcept;
186
193 inline void
194 define(const Vec3& a_normal, const std::vector<Vec3>& a_points);
195
201 [[nodiscard]] inline int
202 computeWindingNumber(const Vec2& P) const noexcept;
203
209 [[nodiscard]] inline size_t
210 computeCrossingNumber(const Vec2& P) const noexcept;
211
217 [[nodiscard]] inline T
218 computeSubtendedAngle(const Vec2& P) const noexcept;
219};
220
221} // namespace EBGeometry
222
223#include "EBGeometry_Polygon2DImplem.hpp"
224
225#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:46
bool isPointInside(const Vec3 &a_point, const InsideOutsideAlgorithm a_algorithm) const noexcept
Check if a point is inside or outside the 2D polygon.
~Polygon2D()=default
Destructor.
Polygon2D(const Vec3 &a_normal, const std::vector< Vec3 > &a_points)
Full constructor.
Polygon2D & operator=(const Polygon2D &a_other)=default
Copy assignment operator.
bool isPointInsidePolygonWindingNumber(const Vec3 &a_point) const noexcept
Check if a point is inside a 2D polygon, using the winding number algorithm.
bool isPointInsidePolygonSubtend(const Vec3 &a_point) const noexcept
Check if a point is inside a 2D polygon, using the subtended angles.
Polygon2D & operator=(Polygon2D &&a_other) noexcept=default
Move assignment operator.
InsideOutsideAlgorithm
Supported algorithms for performing inside/outside tests when checking if a point projects to the ins...
Definition EBGeometry_Polygon2D.hpp:55
Polygon2D(Polygon2D &&a_other) noexcept=default
Move constructor.
Polygon2D()=delete
Disallowed constructor, use the one with the normal vector and points.
Polygon2D(const Polygon2D &a_other)=default
Copy 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...
Three-dimensional vector class with arithmetic operators.
Definition EBGeometry_Vec.hpp:225
Namespace containing all of EBGeometry's functionality.
Definition EBGeometry_AnalyticDistanceFunctions.hpp:31