CVB++ 14.1
polygon_3d.hpp
1#pragma once
2
3#include <vector>
4
5#include "global.hpp"
6
7#include "point_3d.hpp"
8#include "point_3d_h.hpp"
9
10namespace Cvb
11{
12
13CVB_BEGIN_INLINE_NS
14
15template <class T>
16using IsPolygonPoint =
20
21template <class T>
22using EnablePolygonPoint = std::enable_if<IsPolygonPoint<T>::value>;
23
25
27template<class T, class ENABLE = void>
28class Polygon3D final
29{
30
31#ifndef CVB_DOXYGEN
32 static_assert (IsPolygonPoint<T>::value, "CVB: Polygon type must be Point3D or Point3DH with floating point type");
33};
34
35
36template <class T>
37class Polygon3D<T,
38 typename EnablePolygonPoint<T>::type> final
39{
40
41#endif
42
43 public:
44
45
46 Polygon3D() = default;
47
48 Polygon3D(const Polygon3D&) = default;
49
50 Polygon3D& operator=(const Polygon3D&) = default;
51
52 ~Polygon3D() = default;
53
55
59 explicit Polygon3D(std::vector<T>&& points)
60 : points_(std::move(points))
61 {
62 }
63
64 Polygon3D(Polygon3D&&) = default;
65 Polygon3D& operator=(Polygon3D&&) = default;
66
68
72 explicit Polygon3D(const std::vector<T>& points) noexcept
73 : points_(points)
74 {
75 }
76
78
82 template<std::size_t N>
83 Polygon3D(const T(&list)[N]) noexcept // NOLINT
84 {
85 static_assert(N >= 3, "CVB: Poligon3D must have at least three points");
86 points_ = std::vector<T>(list, list + N); // NOLINT(cppcoreguidelines-prefer-member-initializer)
87 }
88
90
95 const T& operator[](std::size_t index) const noexcept
96 {
97 return points_[index];
98 }
99
101
106 const T& At(std::size_t index) const
107 {
108 return points_.at(index);
109 }
110
112
116 std::size_t NumPoints() const noexcept
117 {
118 return points_.size();
119 }
120
122
126 auto CBegin() const noexcept
127 {
128 return points_.cbegin();
129 }
130
132
136 auto Begin() const noexcept
137 {
138 return CBegin();
139 }
140
142
146 auto cbegin() const noexcept
147 {
148 return CBegin();
149 }
150
152
156 auto begin() const noexcept
157 {
158 return CBegin();
159 }
160
162
166 auto CEnd() const noexcept
167 {
168 return points_.cend();
169 }
170
172
176 auto End() const noexcept
177 {
178 return CEnd();
179 }
180
182
186 auto cend() const noexcept
187 {
188 return CEnd();
189 }
190
192
196 auto end() const noexcept
197 {
198 return cend();
199 }
200
202
206 auto CRBegin() const noexcept
207 {
208 return points_.crbegin();
209 }
210
212
216 auto RBegin() const noexcept
217 {
218 return CRBegin();
219 }
220
222
226 auto crbegin() const noexcept
227 {
228 return CRBegin();
229 }
230
232
236 auto rbegin() const noexcept
237 {
238 return crbegin();
239 }
240
242
246 auto CREnd() const noexcept
247 {
248 return points_.crend();
249 }
250
252
256 auto REnd() const noexcept
257 {
258 return CREnd();
259 }
260
262
266 auto crend() const noexcept
267 {
268 return CREnd();
269 }
270
272
276 auto rend() const noexcept
277 {
278 return crend();
279 }
280
282
287 bool operator==(const Polygon3D<T>& polygon) const noexcept
288 {
289 return points_ == polygon.points_;
290 }
291
292
294
299 bool operator!=(const Polygon3D<T>& polygon) const noexcept
300 {
301 return !(*this == polygon);
302 }
303
305 template <class C>
306 explicit operator Polygon3D<C>() const noexcept
307 {
308 std::vector<C> points;
309 points.reserve(points_.size());
310 for (const auto& point : points_)
311 points.emplace_back(static_cast<C>(point));
312 return Polygon3D<C>(std::move(points));
313 }
314
315 private:
316
317 std::vector<T> points_;
318
319
320
321};
322
323CVB_END_INLINE_NS
324
325
326}
A polygon in 3D space.
Definition: polygon_3d.hpp:29
auto Begin() const noexcept
Iterator access.
Definition: polygon_3d.hpp:136
auto CREnd() const noexcept
Iterator access.
Definition: polygon_3d.hpp:246
auto end() const noexcept
Iterator access.
Definition: polygon_3d.hpp:196
Polygon3D(const std::vector< T > &points) noexcept
Construct a polygon from a vector.
Definition: polygon_3d.hpp:72
auto rbegin() const noexcept
Iterator access.
Definition: polygon_3d.hpp:236
auto REnd() const noexcept
Iterator access.
Definition: polygon_3d.hpp:256
auto cend() const noexcept
Iterator access.
Definition: polygon_3d.hpp:186
const T & At(std::size_t index) const
Gets the point ata given index.
Definition: polygon_3d.hpp:106
auto CRBegin() const noexcept
Iterator access.
Definition: polygon_3d.hpp:206
const T & operator[](std::size_t index) const noexcept
Gets the point at a given index.
Definition: polygon_3d.hpp:95
auto crend() const noexcept
Iterator access.
Definition: polygon_3d.hpp:266
auto crbegin() const noexcept
Iterator access.
Definition: polygon_3d.hpp:226
auto begin() const noexcept
Iterator access.
Definition: polygon_3d.hpp:156
auto RBegin() const noexcept
Iterator access.
Definition: polygon_3d.hpp:216
bool operator!=(const Polygon3D< T > &polygon) const noexcept
Compares to an other polygon.
Definition: polygon_3d.hpp:299
Polygon3D(const T(&list)[N]) noexcept
Construct a polygon with an initializer list.
Definition: polygon_3d.hpp:83
bool operator==(const Polygon3D< T > &polygon) const noexcept
Compares to an other polygon.
Definition: polygon_3d.hpp:287
auto CBegin() const noexcept
Iterator access.
Definition: polygon_3d.hpp:126
auto End() const noexcept
Iterator access.
Definition: polygon_3d.hpp:176
Polygon3D(std::vector< T > &&points)
Construct a polygon from a vector.
Definition: polygon_3d.hpp:59
std::size_t NumPoints() const noexcept
Gets the number of points in this polygon.
Definition: polygon_3d.hpp:116
auto rend() const noexcept
Iterator access.
Definition: polygon_3d.hpp:276
auto CEnd() const noexcept
Iterator access.
Definition: polygon_3d.hpp:166
auto cbegin() const noexcept
Iterator access.
Definition: polygon_3d.hpp:146
Root namespace for the Image Manager interface.
Definition: c_barcode.h:24