15#ifndef O2_MCH_CONTOUR_POLYGON_H
16#define O2_MCH_CONTOUR_POLYGON_H
21#include <initializer_list>
38std::vector<o2::mch::contour::Vertex<T>>
getVertices(
const Polygon<T>& polygon);
41std::vector<o2::mch::contour::Vertex<T>>
getSortedVertices(
const Polygon<T>& polygon);
51 template <
typename InputIterator>
54 std::copy(
first, last, std::back_inserter(mVertices));
71 for (
auto i = 0;
i < mVertices.size() - 1; ++
i) {
79 bool isClosed()
const {
return mVertices.back() == mVertices.front(); }
89 for (
auto i = 0;
i < mVertices.size() - 1; ++
i) {
90 auto& current = mVertices[
i];
91 auto& next = mVertices[
i + 1];
92 area += current.x * next.y - next.x * current.y;
99 for (
auto i = 0;
i < mVertices.size(); ++
i) {
100 mVertices[
i].x *= sx;
101 mVertices[
i].y *= sy;
107 for (
auto i = 0;
i < mVertices.size(); ++
i) {
108 mVertices[
i].x += dx;
109 mVertices[
i].y += dy;
116 os << polygon.mVertices;
122 std::vector<o2::mch::contour::Vertex<T>> mVertices;
131 Polygon<T> pol(vertices.begin(), vertices.end());
133 throw std::logic_error(
"closing resulted in non Manhattan polygon");
143 return !(rhs == lhs);
153 if (lhs.size() != rhs.size()) {
160 if (l.size() !=
r.size()) {
164 for (
auto i = 0;
i < l.size(); ++
i) {
183 throw std::invalid_argument(
"contains method can only work with closed polygons");
186 auto j = mVertices.size() - 1;
187 bool oddNodes{
false};
188 for (
auto i = 0;
i < mVertices.size();
i++) {
189 if ((mVertices[
i].
y < yp && mVertices[
j].
y >= yp) || (mVertices[
j].
y < yp && mVertices[
i].
y >= yp)) {
191 (yp - mVertices[
i].
y) / (mVertices[
j].
y - mVertices[
i].
y) * (mVertices[
j].
x - mVertices[
i].
x) <
193 oddNodes = !oddNodes;
204 std::vector<o2::mch::contour::Vertex<T>> vertices;
205 vertices.reserve(polygon.
size());
206 for (
auto i = 0;
i < polygon.
size(); ++
i) {
207 vertices.push_back(polygon[
i]);
215 std::vector<o2::mch::contour::Vertex<T>> vertices;
220 vertices.reserve(
size);
221 for (
auto i = 0;
i <
size; ++
i) {
222 vertices.push_back(polygon[
i]);
224 std::sort(vertices.begin(), vertices.end());
232 T xmin{std::numeric_limits<T>::max()};
233 T xmax{std::numeric_limits<T>::lowest()};
234 T ymin{std::numeric_limits<T>::max()};
235 T ymax{std::numeric_limits<T>::lowest()};
237 for (
const auto&
v : vertices) {
238 xmin = std::min(xmin,
v.x);
239 xmax = std::max(xmax,
v.x);
240 ymin = std::min(ymin,
v.y);
241 ymax = std::max(ymax,
v.y);
243 return {xmin, ymin, xmax, ymax};
262 T xmin{std::numeric_limits<T>::max()};
263 T xmax{std::numeric_limits<T>::lowest()};
264 T ymin{std::numeric_limits<T>::max()};
265 T ymax{std::numeric_limits<T>::lowest()};
267 for (
const auto& p : polygons) {
269 xmin = std::min(xmin,
b.xmin());
270 xmax = std::max(xmax,
b.xmax());
271 ymin = std::min(ymin,
b.ymin());
272 ymax = std::max(ymax,
b.ymax());
274 return {xmin, ymin, xmax, ymax};
280 T d{std::numeric_limits<T>::max()};
281 for (
auto i = 0;
i < polygon.size() - 1; ++
i) {
282 auto s0 = polygon[
i];
283 auto s1 = polygon[
i + 1];
void translate(T dx, T dy)
bool isCounterClockwiseOriented() const
double signedArea() const
bool contains(T x, T y) const
o2::mch::contour::Vertex< T > operator[](int i) const
Polygon(InputIterator first, InputIterator last)
o2::mch::contour::Vertex< T > firstVertex() const
typename std::vector< o2::mch::contour::Vertex< T > >::size_type size_type
Polygon(std::initializer_list< o2::mch::contour::Vertex< T > > args)
friend std::ostream & operator<<(std::ostream &os, const Polygon< T > &polygon)
GLuint GLfloat GLfloat GLfloat GLfloat GLfloat GLfloat GLfloat GLfloat s1
GLboolean GLboolean GLboolean b
GLuint GLfloat GLfloat GLfloat GLfloat GLfloat GLfloat s0
std::vector< o2::mch::contour::Vertex< T > > getVertices(const std::vector< o2::mch::contour::Polygon< T > > &polygons)
auto squaredDistancePointToPolygon(const Vertex< T > &point, const Polygon< T > &polygon) -> decltype(point.x *point.x)
auto squaredDistanceOfPointToSegment(const Vertex< T > &p, const Vertex< T > &p0, const Vertex< T > &p1) -> decltype(p0.x *p1.x)
bool isHorizontal(const Vertex< T > &a, const Vertex< T > &b)
bool operator!=(const Contour< T > &lhs, const Contour< T > &rhs)
BBox< T > getBBox(const Contour< T > &contour)
Polygon< T > close(Polygon< T > polygon)
bool operator==(const Contour< T > &lhs, const Contour< T > &rhs)
std::vector< o2::mch::contour::Vertex< T > > getSortedVertices(const std::vector< o2::mch::contour::Polygon< T > > &polygons)
bool isVertical(const Vertex< T > &a, const Vertex< T > &b)
a couple of static helper functions to create timestamp values for CCDB queries or override obsolete ...