Sirius  0.0.0
types.h
Go to the documentation of this file.
1 
22 #ifndef SIRIUS_TYPES_H_
23 #define SIRIUS_TYPES_H_
24 
25 #include <cmath>
26 
27 #include <array>
28 #include <string>
29 #include <vector>
30 
31 namespace sirius {
32 
33 using Buffer = std::vector<double>;
34 
38 struct Size {
39  Size() = default;
40 
41  Size(int row, int col);
42  Size(const std::array<int, 2>& size);
43 
44  ~Size() = default;
45  Size(const Size&) = default;
46  Size& operator=(const Size&) = default;
47  Size(Size&&) = default;
48  Size& operator=(Size&&) = default;
49 
50  bool operator<(const Size& rhs) const {
51  return (row < rhs.row) || ((row == rhs.row) && (col < rhs.col));
52  }
53 
54  bool operator==(const Size& rhs) const {
55  return row == rhs.row && col == rhs.col;
56  }
57 
58  Size operator*(int scale) const {
59  Size result(*this);
60  result.row *= scale;
61  result.col *= scale;
62  return result;
63  }
64 
65  Size operator*(double scale) const {
66  Size result(*this);
67  result.row = std::ceil(result.row * scale);
68  result.col = std::ceil(result.col * scale);
69  return result;
70  }
71 
72  Size& operator*=(int scale) {
73  *this = *this * scale;
74  return *this;
75  }
76 
77  int CellCount() const { return row * col; }
78 
79  int row{0};
80  int col{0};
81 };
82 
86 struct Point {
87  Point() = default;
88 
89  constexpr Point(int x, int y) noexcept : x(x), y(y) {}
90 
91  ~Point() = default;
92  Point(const Point&) = default;
93  Point& operator=(const Point&) = default;
94  Point(Point&&) = default;
95  Point& operator=(Point&&) = default;
96 
97  int x{0};
98  int y{0};
99 };
100 
105 class ZoomRatio {
106  public:
116  static ZoomRatio Create(const std::string& ratio_string);
117 
128  static ZoomRatio Create(int input_resolution, int output_resolution = 1);
129 
133  ZoomRatio() = default;
134 
135  ~ZoomRatio() = default;
136  ZoomRatio(const ZoomRatio&) = default;
137  ZoomRatio(ZoomRatio&&) = default;
138  ZoomRatio& operator=(const ZoomRatio&) = default;
139  ZoomRatio& operator=(ZoomRatio&&) = default;
140 
141  int input_resolution() const { return input_resolution_; }
142 
143  int output_resolution() const { return output_resolution_; }
144 
145  double ratio() const {
146  return input_resolution_ / static_cast<double>(output_resolution_);
147  }
148 
149  bool IsRealZoom() const;
150 
151  private:
153 
154  void ReduceRatio();
155 
156  private:
157  int input_resolution_{1};
158  int output_resolution_{1};
159 };
160 
161 } // namespace sirius
162 
163 #endif // SIRIUS_TYPES_H_
~ZoomRatio()=default
~Point()=default
~Size()=default
Definition: exception.h:27
ZoomRatio()=default
Instantiate a zoom ratio 1:1.
Size()=default
std::vector< double > Buffer
Definition: types.h:33
bool operator==(const Size &rhs) const
Definition: types.h:54
Data class that represents the 2D coordinates of a point.
Definition: types.h:86
Point()=default
int input_resolution() const
Definition: types.h:141
ZoomRatio & operator=(const ZoomRatio &)=default
bool IsRealZoom() const
bool operator<(const Size &rhs) const
Definition: types.h:50
Data class that represents zoom ratio as input_resolution/output_resolution.
Definition: types.h:105
int CellCount() const
Definition: types.h:77
int x
Definition: types.h:97
int y
Definition: types.h:98
Size & operator*=(int scale)
Definition: types.h:72
Data class that represents the size of an image.
Definition: types.h:38
Size operator*(double scale) const
Definition: types.h:65
Size operator*(int scale) const
Definition: types.h:58
Point & operator=(const Point &)=default
int row
Definition: types.h:79
static ZoomRatio Create(const std::string &ratio_string)
Create an instance from a formatted string (input_resolution:output_resolution)
Size & operator=(const Size &)=default
int col
Definition: types.h:80
constexpr Point(int x, int y) noexcept
Definition: types.h:89
int output_resolution() const
Definition: types.h:143
double ratio() const
Definition: types.h:145