SourceXtractorPlusPlus 0.21
SourceXtractor++, the next generation SExtractor
Loading...
Searching...
No Matches
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
29namespace 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
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
102namespace std {
103
104template <>
105struct hash<SourceXtractor::PixelCoordinate>
106{
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
std::shared_ptr< DependentParameter< std::shared_ptr< EngineParameter > > > x
std::shared_ptr< DependentParameter< std::shared_ptr< EngineParameter > > > y
T max(T... args)
T min(T... args)
STL namespace.
A pixel coordinate made of two integers m_x and m_y.
PixelCoordinate operator+(const PixelCoordinate &other) const
bool operator>=(const PixelCoordinate &other) const
bool operator!=(const PixelCoordinate &other) const
bool operator<=(const PixelCoordinate &other) const
bool operator==(const PixelCoordinate &other) const
PixelCoordinate & operator+=(const PixelCoordinate &other)
PixelCoordinate operator*(double scalar) const
PixelCoordinate & operator-=(const PixelCoordinate &other)
PixelCoordinate operator-(const PixelCoordinate &other) const
std::size_t operator()(const SourceXtractor::PixelCoordinate &coord) const