Project
Loading...
Searching...
No Matches
Edge.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_EDGE_H
16#define O2_MCH_CONTOUR_EDGE_H
17
18#include <utility>
19#include <vector>
20#include <iostream>
21#include <iomanip>
22
23#include "Interval.h"
24#include "Vertex.h"
25
26namespace o2
27{
28namespace mch
29{
30namespace contour
31{
32namespace impl
33{
34
40template <typename T>
42{
43 public:
44 ManhattanEdge(Vertex<T> b = {}, Vertex<T> e = {});
45
46 Vertex<T> begin() const { return mBegin; }
47
48 Vertex<T> end() const { return mEnd; }
49
50 private:
51 Vertex<T> mBegin;
52 Vertex<T> mEnd;
53};
54
55template <typename T>
57{
58 return isVertical(edge.begin(), edge.end());
59}
60
61template <typename T>
63{
64 return isHorizontal(edge.begin(), edge.end());
65}
66
67template <typename T>
69{
70 if (!isVertical(*this) && !isHorizontal(*this)) {
71 throw std::invalid_argument("edge should be either horizontal or vertical");
72 }
73}
74
75template <typename T>
76class VerticalEdge : public ManhattanEdge<T>
77{
78 public:
79 VerticalEdge(T x = {}, T y1 = {}, T y2 = {}) : ManhattanEdge<T>({x, y1}, {x, y2}) {}
80};
81
82template <typename T>
84{
85 public:
86 HorizontalEdge(T y = {}, T x1 = {}, T x2 = {}) : ManhattanEdge<T>({x1, y}, {x2, y}) {}
87};
88
89template <typename T>
90T top(const VerticalEdge<T>& edge)
91{
92 return std::max(edge.begin().y, edge.end().y);
93}
94
95template <typename T>
96T bottom(const VerticalEdge<T>& edge)
97{
98 return std::min(edge.begin().y, edge.end().y);
99}
100
101template <typename T>
103{
104 return edge.begin().y > edge.end().y;
105}
106
107template <typename T>
109{
110 return !isLeftEdge(edge);
111}
112
113template <typename T>
115{
116 return isLeftEdge(edge);
117}
118
119template <typename T>
121{
122 return !isTopToBottom(edge);
123}
124
125template <typename T>
127{
128 return std::min(edge.begin().x, edge.end().x);
129}
130
131template <typename T>
133{
134 return std::max(edge.begin().x, edge.end().x);
135}
136
137template <typename T>
139{
140 return edge.begin().x < edge.end().x;
141}
142
143template <typename T>
145{
146 return !isLeftToRight(edge);
147}
148
149template <typename T>
150std::ostream& operator<<(std::ostream& os, const ManhattanEdge<T>& edge)
151{
152 os << "[" << edge.begin() << "," << edge.end() << "]";
153 return os;
154}
155
156template <typename T>
157std::ostream& operator<<(std::ostream& os, const VerticalEdge<T>& edge)
158{
159 os << static_cast<const ManhattanEdge<T>>(edge);
160 os << (isTopToBottom(edge) ? 'v' : '^');
161 return os;
162}
163
164template <typename T>
165std::ostream& operator<<(std::ostream& os, const HorizontalEdge<T>& edge)
166{
167 os << static_cast<const ManhattanEdge<T>>(edge);
168 os << (isLeftToRight(edge) ? "->-" : "-<-");
169 return os;
170}
171
172template <typename T>
173bool operator==(const ManhattanEdge<T>& lhs, const ManhattanEdge<T>& rhs)
174{
175 return lhs.begin() == rhs.begin() && rhs.end() == rhs.end();
176}
177
178template <typename T>
179bool operator!=(const ManhattanEdge<T>&& lhs, const ManhattanEdge<T>& rhs)
180{
181 return !(rhs == lhs);
182}
183
184} // namespace impl
185} // namespace contour
186} // namespace mch
187} // namespace o2
188
189#endif
HorizontalEdge(T y={}, T x1={}, T x2={})
Definition Edge.h:86
ManhattanEdge(Vertex< T > b={}, Vertex< T > e={})
Definition Edge.h:68
Vertex< T > begin() const
Definition Edge.h:46
Vertex< T > end() const
Definition Edge.h:48
VerticalEdge(T x={}, T y1={}, T y2={})
Definition Edge.h:79
GLint GLenum GLint x
Definition glcorearb.h:403
GLuint GLfloat GLfloat GLfloat GLfloat y1
Definition glcorearb.h:5034
GLuint GLfloat GLfloat GLfloat x1
Definition glcorearb.h:5034
GLdouble GLdouble GLdouble GLdouble top
Definition glcorearb.h:4077
GLdouble GLdouble right
Definition glcorearb.h:4077
GLboolean GLboolean GLboolean b
Definition glcorearb.h:1233
GLint left
Definition glcorearb.h:1979
GLint GLint bottom
Definition glcorearb.h:1979
bool operator!=(const ManhattanEdge< T > &&lhs, const ManhattanEdge< T > &rhs)
Definition Edge.h:179
bool isLeftEdge(const VerticalEdge< T > &edge)
Definition Edge.h:102
bool isVertical(const ManhattanEdge< T > &edge)
Definition Edge.h:56
bool isTopToBottom(const VerticalEdge< T > &edge)
Definition Edge.h:114
bool operator==(const ManhattanEdge< T > &lhs, const ManhattanEdge< T > &rhs)
Definition Edge.h:173
bool isBottomToTop(const VerticalEdge< T > &edge)
Definition Edge.h:120
bool isLeftToRight(const HorizontalEdge< T > &edge)
Definition Edge.h:138
bool isHorizontal(const ManhattanEdge< T > &edge)
Definition Edge.h:62
bool isRightEdge(const VerticalEdge< T > &edge)
Definition Edge.h:108
std::ostream & operator<<(std::ostream &os, const ManhattanEdge< T > &edge)
Definition Edge.h:150
bool isRightToLeft(const HorizontalEdge< T > &edge)
Definition Edge.h:144
a couple of static helper functions to create timestamp values for CCDB queries or override obsolete ...