23#ifndef VCL_SPACE_CORE_POLYGON_H
24#define VCL_SPACE_CORE_POLYGON_H
28#include <vclib/concepts/range.h>
29#include <vclib/concepts/space/polygon.h>
30#include <vclib/space/core/point.h>
51template<Po
intConcept Po
intT>
54 std::vector<PointT> mPoints;
64 using Iterator =
typename std::vector<PointT>::iterator;
70 static const uint
DIM = PointT::DIM;
82 Polygon(std::initializer_list<PointT> points) : mPoints(points) {}
92 template<
typename Iterator>
94 requires (std::is_same_v<typename Iterator::value_type, PointT>)
116 uint
size()
const {
return mPoints.size(); }
156 PointT&
point(uint
i) {
return mPoints.at(
i); }
163 const PointT&
point(uint
i)
const {
return mPoints.at(
i); }
176 return mPoints.at(
i).dist(mPoints[(
i + 1) % mPoints.size()]);
217 template<
typename WIterator>
291 template<
typename Iterator>
293 std::is_same_v<typename Iterator::value_type, PointT> &&
341 template<
typename Iterator>
343 requires (std::is_same_v<typename Iterator::value_type, PointT>)
389 template<
typename Iterator,
typename WIterator>
394 requires (std::is_same_v<typename Iterator::value_type, PointT>)
419 template<Range Rp, Range Rw>
447 template<
typename Iterator>
449 requires (std::is_same_v<typename Iterator::value_type, PointT>)
451 using Scalar = PointType::ScalarType;
455 const PointT& p0 = *
i;
460 const PointT& p1 = *
i1;
495 template<
typename Iterator>
497 requires (std::is_same_v<typename Iterator::value_type, PointT>)
499 using Scalar = PointType::ScalarType;
504 const PointT& p0 = *
i;
509 const PointT& p1 = *
i1;
540template<
typename Scalar>
567template<
typename Scalar>
The Polygon class represents a polygon in a N-dimensional Euclidean space.
Definition polygon.h:53
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:342
uint size() const
Returns the number of points that define the polygon.
Definition polygon.h:116
PointT weightedBarycenter(WIterator wBegin) const
Computes the weighted barycenter of the polygon.
Definition polygon.h:218
static ScalarType perimeter(R &&range)
Calculates the perimeter of a polygon defined by a range of points.
Definition polygon.h:474
Polygon(Iterator begin, Iterator end)
Construct a new Polygon object from a range of points.
Definition polygon.h:93
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:390
PointT normal() const
Computes the normal of the polygon.
Definition polygon.h:190
Iterator begin()
Returns an iterator pointing to the first point of the polygon.
Definition polygon.h:256
const PointType & operator[](uint i) const
Returns the i-th point of the polygon.
Definition polygon.h:251
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:292
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:420
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:496
static PointT barycenter(R &&range)
Computes the barycenter of a container of points iterated between the iterators begin and end,...
Definition polygon.h:367
PointT::ScalarType ScalarType
The scalar type of the points that define the polygon.
Definition polygon.h:58
PointType & operator[](uint i)
Returns the i-th point of the polygon.
Definition polygon.h:243
void resize(uint n)
Resizes the polygon to contain n points.
Definition polygon.h:123
ScalarType sideLength(uint i) const
Returns the side length of the i-th side of the polygon.
Definition polygon.h:174
typename std::vector< PointT >::const_iterator ConstIterator
The const iterator type of the polygon.
Definition polygon.h:67
PointT barycenter() const
Computes the barycenter of the polygon.
Definition polygon.h:203
PointT PointType
The type of the points that define the polygon.
Definition polygon.h:61
ScalarType area() const
Returns the area of the polygon.
Definition polygon.h:235
PointT & point(uint i)
Returns the point at index i in the polygon.
Definition polygon.h:156
ConstIterator begin() const
Returns a const iterator pointing to the first point of the polygon.
Definition polygon.h:267
void clear()
Clears the polygon, removing all points.
Definition polygon.h:135
const PointT & point(uint i) const
Returns the point at index i in the polygon.
Definition polygon.h:163
ScalarType perimeter() const
Returns the perimeter of the polygon.
Definition polygon.h:228
void reserve(uint n)
Reserves space for n points in the polygon.
Definition polygon.h:130
Polygon(std::initializer_list< PointT > points)
Construct a new Polygon object from an initializer list of points.
Definition polygon.h:82
ConstIterator end() const
Returns a const iterator pointing past the last point of the polygon.
Definition polygon.h:273
static ScalarType perimeter(Iterator begin, Iterator end)
Calculates the perimeter of a polygon defined by a range of points.
Definition polygon.h:448
void pushBack(const PointT &point)
Adds a point to the back of the polygon.
Definition polygon.h:142
typename std::vector< PointT >::iterator Iterator
The iterator type of the polygon.
Definition polygon.h:64
Iterator end()
Returns an iterator pointing past the last point of the polygon.
Definition polygon.h:261
Polygon()
Construct a new empty Polygon object.
Definition polygon.h:75
void pushBack(PointT &&point)
Adds a point to the back of the polygon.
Definition polygon.h:149
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:524
static const uint DIM
The dimension of the points that define the polygon.
Definition polygon.h:70
static PointT normal(R &&range)
Computes the normal of a container of 3D points iterated between the iterators begin and end,...
Definition polygon.h:324
Polygon(R &&range)
Construct a new Polygon object from a range of points.
Definition polygon.h:106
A class representing a line segment in n-dimensional space. The class is parameterized by a PointConc...
Definition segment.h:43
ScalarType area() const
Computes the area of the triangle.
Definition triangle.h:219