Project
Loading...
Searching...
No Matches
Vertex.h
Go to the documentation of this file.
1// Copyright 2019-2020 CERN and copyright holders of ALICE O2.
2// See https://alice-o2.web.cern.ch/copyright for details of the copyright holders.
3// All rights not expressly granted are reserved.
4//
5// This software is distributed under the terms of the GNU General Public
6// License v3 (GPL Version 3), copied verbatim in the file "COPYING".
7//
8// In applying this license CERN does not waive the privileges and immunities
9// granted to it by virtue of its status as an Intergovernmental Organization
10// or submit itself to any jurisdiction.
11
14
15#ifndef O2_MCH_CONTOUR_VERTEX_H
16#define O2_MCH_CONTOUR_VERTEX_H
17
18#include <iostream>
19#include <iomanip>
20#include "Helper.h"
21
22namespace o2
23{
24namespace mch
25{
26namespace contour
27{
28
29template <typename T>
30struct Vertex {
31 T x;
32 T y;
33};
34
35template <typename T>
36std::ostream& operator<<(std::ostream& os, const Vertex<T>& vertex)
37{
38 os << '(' << vertex.x << ' ' << vertex.y << ')';
39 return os;
40}
41
42template <typename T>
43std::ostream& operator<<(std::ostream& os, const std::vector<Vertex<T>>& vertices)
44{
45 for (auto i = 0; i < vertices.size(); ++i) {
46 os << std::setw(5) << vertices[i].x << " " << std::setw(5) << vertices[i].y;
47 if (i < vertices.size() - 1) {
48 os << ',';
49 }
50 }
51 os << ')';
52 return os;
53}
54
55template <typename T>
56bool operator<(const Vertex<T>& lhs, const Vertex<T>& rhs)
57{
58 if (lhs.y < rhs.y) {
59 return true;
60 }
61 if (rhs.y < lhs.y) {
62 return false;
63 }
64 return lhs.x < rhs.x;
65}
66
67template <typename T>
68bool operator>(const Vertex<T>& lhs, const Vertex<T>& rhs)
69{
70 return rhs < lhs;
71}
72
73template <typename T>
74bool operator<=(const Vertex<T>& lhs, const Vertex<T>& rhs)
75{
76 return !(rhs < lhs);
77}
78
79template <typename T>
80bool operator>=(const Vertex<T>& lhs, const Vertex<T>& rhs)
81{
82 return !(lhs < rhs);
83}
84
85template <typename T>
86bool isVertical(const Vertex<T>& a, const Vertex<T>& b)
87{
88 return impl::areEqual(a.x, b.x);
89}
90
91template <typename T>
92bool isHorizontal(const Vertex<T>& a, const Vertex<T>& b)
93{
94 return impl::areEqual(a.y, b.y);
95}
96
97template <typename T>
99{
100 return {a.x - b.x, a.y - b.y};
101}
102
103template <typename T>
104auto dot(const Vertex<T>& a, const Vertex<T>& b) -> decltype(a.x * b.x)
105{
106 // dot product
107 return a.x * b.x + a.y * b.y;
108}
109
110template <typename T>
111auto squaredDistance(const Vertex<T>& a, const Vertex<T>& b) -> decltype(a.x * b.x)
112{
113 return dot(a - b, a - b);
114}
115
116template <typename T>
118 -> decltype(p0.x * p1.x)
119{
121 auto v = p1 - p0;
122 auto w = p - p0;
123
124 auto c1 = dot(w, v);
125
126 if (c1 <= 0) {
127 return squaredDistance(p, p0);
128 }
129
130 auto c2 = dot(v, v);
131 if (c2 <= c1) {
132 return squaredDistance(p, p1);
133 }
134
135 auto b = c1 / c2;
136 Vertex<T> pbase{p0.x + b * v.x, p0.y + b * v.y};
137 return squaredDistance(p, pbase);
138}
139
140template <typename T>
141bool operator==(const Vertex<T>& lhs, const Vertex<T>& rhs)
142{
143 return impl::areEqual(lhs.x, rhs.x) && impl::areEqual(lhs.y, rhs.y);
144}
145
146template <typename T>
147bool operator!=(const Vertex<T>& lhs, const Vertex<T>& rhs)
148{
149 return !(lhs == rhs);
150}
151
152} // namespace contour
153} // namespace mch
154} // namespace o2
155
156#endif
uint64_t vertex
Definition RawEventData.h:9
int32_t i
bool const GPUTPCGMMerger::trackCluster * c1
bool const GPUTPCGMMerger::trackCluster const clcomparestruct * c2
constexpr int p1()
constexpr to accelerate the coordinates changing
const GLdouble * v
Definition glcorearb.h:832
GLboolean GLboolean GLboolean b
Definition glcorearb.h:1233
GLboolean GLboolean GLboolean GLboolean a
Definition glcorearb.h:1233
GLubyte GLubyte GLubyte GLubyte w
Definition glcorearb.h:852
bool areEqual(double a, double b)
Definition Helper.h:41
Vertex< T > operator-(const Vertex< T > &a, const Vertex< T > &b)
Definition Vertex.h:98
bool operator<(const Vertex< T > &lhs, const Vertex< T > &rhs)
Definition Vertex.h:56
auto squaredDistance(const Vertex< T > &a, const Vertex< T > &b) -> decltype(a.x *b.x)
Definition Vertex.h:111
auto squaredDistanceOfPointToSegment(const Vertex< T > &p, const Vertex< T > &p0, const Vertex< T > &p1) -> decltype(p0.x *p1.x)
Definition Vertex.h:117
bool operator>(const Vertex< T > &lhs, const Vertex< T > &rhs)
Definition Vertex.h:68
bool isHorizontal(const Vertex< T > &a, const Vertex< T > &b)
Definition Vertex.h:92
bool operator>=(const Vertex< T > &lhs, const Vertex< T > &rhs)
Definition Vertex.h:80
bool operator!=(const Contour< T > &lhs, const Contour< T > &rhs)
Definition Contour.h:126
bool operator==(const Contour< T > &lhs, const Contour< T > &rhs)
Definition Contour.h:136
auto dot(const Vertex< T > &a, const Vertex< T > &b) -> decltype(a.x *b.x)
Definition Vertex.h:104
std::ostream & operator<<(std::ostream &os, const std::vector< o2::mch::contour::Polygon< T > > &polygons)
Definition Contour.h:153
bool operator<=(const Vertex< T > &lhs, const Vertex< T > &rhs)
Definition Vertex.h:74
bool isVertical(const Vertex< T > &a, const Vertex< T > &b)
Definition Vertex.h:86
a couple of static helper functions to create timestamp values for CCDB queries or override obsolete ...