27#ifndef EASY3D_CORE_POLYGON_H
28#define EASY3D_CORE_POLYGON_H
34#include <easy3d/core/vec.h>
35#include <easy3d/core/box.h>
44 typedef std::vector< Vec<2, FT> > BaseClass;
54 template<
class InputIterator>
90 template<
class InputIterator>
92 std::copy(first, last, BaseClass::end());
101 for (std::size_t i = 0; i + 1 < BaseClass::size(); ++i) {
102 const auto &p1 = BaseClass::at(i);
103 const auto &p2 = BaseClass::at((i + 1) % BaseClass::size());
104 sum += (p2.x - p1.x) * (p2.y + p1.y);
110 template<
typename FT>
112 if (BaseClass::size() <= 1)
114 auto it = BaseClass::begin();
115 std::reverse(++it, BaseClass::end());
119 template<
typename FT>
122 std::size_t n = BaseClass::size();
123 for (std::size_t i = 0, j = n - 1; i < n; j = i, ++i) {
127 if (((u0.y <= p.y) && (p.y < u1.y)) ||
128 ((u1.y <= p.y) && (p.y < u0.y)))
132 double x = u0.x + (p.y - u0.y) * (u1.x - u0.x) / (u1.y - u0.y);
141 template<
typename FT>
143 for (
const auto &p : plg) {
150 template<
typename FT>
157 template<
typename FT>
160 for (
unsigned int i = 0; i < BaseClass::size(); i++) {
161 unsigned int j = (i + 1) % BaseClass::size();
164 result += t1.x * t2.y - t2.x * t1.y;
171 template<
typename FT>
GenericBox represents the bounding box of shapes.
Definition box.h:45
void grow(const Point &p)
Add a point to this box. This will compute its new extent.
Definition box.h:276
GenericPolygon()=default
Default constructor.
bool contains(const GenericPolygon< FT > &plg) const
Tests if a polygon plg lies inside this polygon (i.e., all its vertices are inside).
Definition polygon.h:142
bool is_clockwise() const
Checks if the polygon has a clockwise orientation (right-hand rule).
Definition polygon.h:96
GenericPolygon(std::size_t size)
Initializes with a know size.
Definition polygon.h:51
void reverse_orientation()
Reverses the orientation of the polygon. The first vertex (pointed to by p.begin(),...
Definition polygon.h:111
GenericBox< 2, FT > bbox() const
Returns the smallest axis-aligned bounding box containing this polygon.
Definition polygon.h:172
FT area() const
Returns the area of this polygon. This is the absolute value of the signed area, so it is always posi...
Definition polygon.h:151
GenericPolygon(InputIterator first, InputIterator last)
Initializes from a known range.
Definition polygon.h:91
bool contains(const Vec< 2, FT > &point) const
Tests if a point lies inside the polygon.
Definition polygon.h:120
FT signed_area() const
Returns the signed area of the polygon. The signed area is positive for counter clockwise polygons an...
Definition polygon.h:158
Base class for vector types. It provides generic functionality for N dimensional vectors.
Definition vec.h:30
Definition collider.cpp:182
std::vector< FT > sum(const Matrix< FT > &)
Definition matrix.h:1485