23#ifndef VCL_SPACE_CORE_POLYGON_H
24#define VCL_SPACE_CORE_POLYGON_H
48template<Po
intConcept Po
intT>
51 std::vector<PointT> mPoints;
61 using Iterator =
typename std::vector<PointT>::iterator;
67 static const uint
DIM = PointT::DIM;
79 Polygon(std::initializer_list<PointT> points) : mPoints(points) {}
89 template<
typename Iterator>
91 requires (std::is_same_v<typename Iterator::value_type, PointT>)
113 uint
size()
const {
return mPoints.size(); }
153 PointT&
point(uint
i) {
return mPoints.at(
i); }
160 const PointT&
point(uint
i)
const {
return mPoints.at(
i); }
173 return mPoints.at(
i).dist(mPoints[(
i + 1) % mPoints.size()]);
214 template<
typename WIterator>
288 template<
typename Iterator>
290 std::is_same_v<typename Iterator::value_type, PointT> &&
338 template<
typename Iterator>
340 requires (std::is_same_v<typename Iterator::value_type, PointT>)
386 template<
typename Iterator,
typename WIterator>
391 requires (std::is_same_v<typename Iterator::value_type, PointT>)
416 template<Range Rp, Range Rw>
444 template<
typename Iterator>
446 requires (std::is_same_v<typename Iterator::value_type, PointT>)
448 using Scalar = PointType::ScalarType;
452 const PointT& p0 = *
i;
457 const PointT& p1 = *
i1;
492 template<
typename Iterator>
494 requires (std::is_same_v<typename Iterator::value_type, PointT>)
496 using Scalar = PointType::ScalarType;
501 const PointT& p0 = *
i;
506 const PointT& p1 = *
i1;
537template<
typename Scalar>
564template<
typename Scalar>
597 std::remove_cvref_t<T>,
598 Polygon<typename RemoveRef<T>::PointType>>;
A class representing a box in N-dimensional space.
Definition box.h:46
The Polygon class represents a polygon in a N-dimensional Euclidean space.
Definition polygon.h:50
static PointT barycenter(Iterator begin, Iterator end)
Computes the barycenter of a container of points iterated between the iterators begin and end,...
Definition polygon.h:339
uint size() const
Returns the number of points that define the polygon.
Definition polygon.h:113
PointT weightedBarycenter(WIterator wBegin) const
Computes the weighted barycenter of the polygon.
Definition polygon.h:215
static ScalarType perimeter(R &&range)
Calculates the perimeter of a polygon defined by a range of points.
Definition polygon.h:471
Polygon(Iterator begin, Iterator end)
Construct a new Polygon object from a range of points.
Definition polygon.h:90
static PointT weightedBarycenter(Iterator begin, Iterator end, WIterator wBegin)
Computes the weighted barycenter of a container of 3D points iterated between the iterators begin and...
Definition polygon.h:387
PointT normal() const
Computes the normal of the polygon.
Definition polygon.h:187
Iterator begin()
Returns an iterator pointing to the first point of the polygon.
Definition polygon.h:253
const PointType & operator[](uint i) const
Returns the i-th point of the polygon.
Definition polygon.h:248
static PointT normal(Iterator begin, Iterator end)
Computes the normal of a container of 3D points iterated between the iterators begin and end,...
Definition polygon.h:289
static PointT weightedBarycenter(Rp &&rPolygon, Rw &&rWeights)
Computes the weighted barycenter of a container of 3D points iterated between the iterators begin and...
Definition polygon.h:417
static ScalarType area(Iterator begin, Iterator end)
Calculates the area of a polygon. This function works also with simple triangles, but it is less effi...
Definition polygon.h:493
static PointT barycenter(R &&range)
Computes the barycenter of a container of points iterated between the iterators begin and end,...
Definition polygon.h:364
PointT::ScalarType ScalarType
The scalar type of the points that define the polygon.
Definition polygon.h:55
PointType & operator[](uint i)
Returns the i-th point of the polygon.
Definition polygon.h:240
void resize(uint n)
Resizes the polygon to contain n points.
Definition polygon.h:120
ScalarType sideLength(uint i) const
Returns the side length of the i-th side of the polygon.
Definition polygon.h:171
typename std::vector< PointT >::const_iterator ConstIterator
The const iterator type of the polygon.
Definition polygon.h:64
PointT barycenter() const
Computes the barycenter of the polygon.
Definition polygon.h:200
PointT PointType
The type of the points that define the polygon.
Definition polygon.h:58
ScalarType area() const
Returns the area of the polygon.
Definition polygon.h:232
PointT & point(uint i)
Returns the point at index i in the polygon.
Definition polygon.h:153
ConstIterator begin() const
Returns a const iterator pointing to the first point of the polygon.
Definition polygon.h:264
void clear()
Clears the polygon, removing all points.
Definition polygon.h:132
const PointT & point(uint i) const
Returns the point at index i in the polygon.
Definition polygon.h:160
ScalarType perimeter() const
Returns the perimeter of the polygon.
Definition polygon.h:225
void reserve(uint n)
Reserves space for n points in the polygon.
Definition polygon.h:127
Polygon(std::initializer_list< PointT > points)
Construct a new Polygon object from an initializer list of points.
Definition polygon.h:79
ConstIterator end() const
Returns a const iterator pointing past the last point of the polygon.
Definition polygon.h:270
static ScalarType perimeter(Iterator begin, Iterator end)
Calculates the perimeter of a polygon defined by a range of points.
Definition polygon.h:445
void pushBack(const PointT &point)
Adds a point to the back of the polygon.
Definition polygon.h:139
typename std::vector< PointT >::iterator Iterator
The iterator type of the polygon.
Definition polygon.h:61
Iterator end()
Returns an iterator pointing past the last point of the polygon.
Definition polygon.h:258
Polygon()
Construct a new empty Polygon object.
Definition polygon.h:72
void pushBack(PointT &&point)
Adds a point to the back of the polygon.
Definition polygon.h:146
static ScalarType area(R &&range)
Calculates the area of a polygon. This function works also with simple triangles, but it is less effi...
Definition polygon.h:521
static const uint DIM
The dimension of the points that define the polygon.
Definition polygon.h:67
static PointT normal(R &&range)
Computes the normal of a container of 3D points iterated between the iterators begin and end,...
Definition polygon.h:321
Polygon(R &&range)
Construct a new Polygon object from a range of points.
Definition polygon.h:103
ScalarType area() const
Computes the area of the triangle.
Definition triangle.h:217
A concept representing a 2D Polygon.
Definition polygon.h:611
A concept representing a 3D Polygon.
Definition polygon.h:624
A concept representing a Polygon.
Definition polygon.h:596