SourceXtractorPlusPlus  0.15
Please provide a description of the project.
PixelCoordinate.h
Go to the documentation of this file.
1 
23 #ifndef _SEUTILS_PIXELCOORDINATE_H
24 #define _SEUTILS_PIXELCOORDINATE_H
25 
26 #include <functional>
27 #include <boost/functional/hash.hpp>
28 
29 namespace SourceXtractor {
30 
38  int m_x, m_y;
39 
40  PixelCoordinate() : m_x(0), m_y(0) {}
41 
42  PixelCoordinate(int x, int y) : m_x(x), m_y(y) {}
43 
44  bool operator==(const PixelCoordinate& other) const {
45  return m_x == other.m_x && m_y == other.m_y;
46  }
47 
48  bool operator!=(const PixelCoordinate& other) const {
49  return !(*this == other);
50  }
51 
52  PixelCoordinate operator*(double scalar) const {
53  return PixelCoordinate(static_cast<int>(m_x * scalar),
54  static_cast<int>(m_y * scalar));
55  }
56 
58  return PixelCoordinate(m_x + other.m_x, m_y + other.m_y);
59  }
60 
62  m_x += other.m_x;
63  m_y += other.m_y;
64  return *this;
65  }
66 
68  return PixelCoordinate(m_x - other.m_x, m_y - other.m_y);
69  }
70 
72  m_x -= other.m_x;
73  m_y -= other.m_y;
74  return *this;
75  }
76 
77  bool operator>=(const PixelCoordinate& other) const {
78  return m_x >= other.m_x && m_y >= other.m_y;
79  }
80 
81  bool operator<=(const PixelCoordinate& other) const {
82  return m_x <= other.m_x && m_y <= other.m_y;
83  }
84 
90  bool clip(int w, int h) {
91  int ox = m_x, oy = m_y;
92  m_x = std::min(std::max(0, m_x), w - 1);
93  m_y = std::min(std::max(0, m_y), h - 1);
94  return ox != m_x || oy != m_y;
95  }
96 };
97 
98 
99 } /* namespace SourceXtractor */
100 
101 
102 namespace std {
103 
104 template <>
105 struct hash<SourceXtractor::PixelCoordinate>
106 {
108  std::size_t local_hash = 0;
109  boost::hash_combine(local_hash, coord.m_x);
110  boost::hash_combine(local_hash, coord.m_y);
111  return local_hash;
112  }
113 };
114 
115 } // namespace std
116 
117 
118 #endif
SourceXtractor::PixelCoordinate::operator==
bool operator==(const PixelCoordinate &other) const
Definition: PixelCoordinate.h:44
SourceXtractor::PixelCoordinate
A pixel coordinate made of two integers m_x and m_y.
Definition: PixelCoordinate.h:37
SourceXtractor::PixelCoordinate::operator-
PixelCoordinate operator-(const PixelCoordinate &other) const
Definition: PixelCoordinate.h:67
SourceXtractor::PixelCoordinate::operator<=
bool operator<=(const PixelCoordinate &other) const
Definition: PixelCoordinate.h:81
SourceXtractor::PixelCoordinate::PixelCoordinate
PixelCoordinate(int x, int y)
Definition: PixelCoordinate.h:42
SourceXtractor::PixelCoordinate::operator*
PixelCoordinate operator*(double scalar) const
Definition: PixelCoordinate.h:52
SourceXtractor
Definition: Aperture.h:30
SourceXtractor::PixelCoordinate::m_x
int m_x
Definition: PixelCoordinate.h:38
SourceXtractor::PixelCoordinate::operator>=
bool operator>=(const PixelCoordinate &other) const
Definition: PixelCoordinate.h:77
SourceXtractor::PixelCoordinate::m_y
int m_y
Definition: PixelCoordinate.h:38
SourceXtractor::PixelCoordinate::operator!=
bool operator!=(const PixelCoordinate &other) const
Definition: PixelCoordinate.h:48
SourceXtractor::PixelCoordinate::operator+=
PixelCoordinate & operator+=(const PixelCoordinate &other)
Definition: PixelCoordinate.h:61
SourceXtractor::PixelCoordinate::operator+
PixelCoordinate operator+(const PixelCoordinate &other) const
Definition: PixelCoordinate.h:57
SourceXtractor::PixelCoordinate::PixelCoordinate
PixelCoordinate()
Definition: PixelCoordinate.h:40
std::min
T min(T... args)
SourceXtractor::PixelCoordinate::clip
bool clip(int w, int h)
Definition: PixelCoordinate.h:90
x
std::shared_ptr< DependentParameter< std::shared_ptr< EngineParameter > > > x
Definition: MoffatModelFittingTask.cpp:94
std
STL namespace.
std::size_t
std::max
T max(T... args)
y
std::shared_ptr< DependentParameter< std::shared_ptr< EngineParameter > > > y
Definition: MoffatModelFittingTask.cpp:94
SourceXtractor::PixelCoordinate::operator-=
PixelCoordinate & operator-=(const PixelCoordinate &other)
Definition: PixelCoordinate.h:71
std::hash
std::hash< SourceXtractor::PixelCoordinate >::operator()
std::size_t operator()(const SourceXtractor::PixelCoordinate &coord) const
Definition: PixelCoordinate.h:107