scifir-units 2.0.0
scifir-units is a library of units of measurement, angles, coordinates, fields, and related data, all lightweight, that help in the development of scientific software and scientific machines
Loading...
Searching...
No Matches
pixel.hpp
Go to the documentation of this file.
1#ifndef SCIFIR_UNITS_SPECIAL_UNITS_PIXEL_HPP_INCLUDED
2#define SCIFIR_UNITS_SPECIAL_UNITS_PIXEL_HPP_INCLUDED
3
4#include "../units/constants.hpp"
5#include "../util/is_number.hpp"
6#include "../units/scalar_unit.hpp"
7
8#include "boost/math/constants/constants.hpp"
9
10#include <cmath>
11#include <string>
12
13using namespace std;
14
15namespace scifir
16{
17 class pixel
18 {
19 public:
20 pixel();
21 pixel(const pixel& x);
22 pixel(pixel&& x);
23 explicit pixel(float new_value);
24 explicit pixel(double new_value);
25 explicit pixel(long double new_value);
26 explicit pixel(int new_value);
27 explicit pixel(const string& init_pixel);
28 explicit pixel(const scalar_unit& x);
29
30 pixel& operator =(const pixel& x);
33 pixel& operator =(const string& init_pixel);
34 pixel& operator =(const scalar_unit& x);
35
36 explicit operator float() const
37 {
38 return float(value);
39 }
40
41 inline const float& get_value() const
42 {
43 return value;
44 }
45
46 pixel operator +(const pixel& x) const;
47 pixel operator -(const pixel& x) const;
48 pixel operator *(const pixel& x) const;
49 pixel operator /(const pixel& x) const;
50 pixel operator ^(const pixel& x) const;
51 void operator +=(const pixel& x);
52 void operator -=(const pixel& x);
53 void operator *=(const pixel& x);
54 void operator /=(const pixel& x);
55 void operator ^=(const pixel& x);
56
58 void operator =(T x)
59 {
60 value = x;
61 }
62
65 {
66 return pixel(value + x);
67 }
68
71 {
72 return pixel(value - x);
73 }
74
77 {
78 return pixel(value * x);
79 }
80
83 {
84 return pixel(value / x);
85 }
86
89 {
90 return pixel(std::pow(value, x));
91 }
92
94 void operator +=(T x)
95 {
96 value += x;
97 }
98
101 {
102 value -= x;
103 }
104
107 {
108 value *= x;
109 }
110
113 {
114 value /= x;
115 }
116
119 {
120 value = std::pow(value, x);
121 }
122
124 pixel operator ++(int);
126 pixel operator --(int);
127
129
130 string display(int number_of_decimals = 2) const;
131
132 private:
133 float value;
134
135 void initialize_from_string(const string& init_pixel);
136
137 };
138
139 string to_string(const pixel& x);
140 bool is_pixel(const string& init_pixel);
141
142 pixel sqrt(const pixel& x);
143 pixel sqrt_nth(const pixel& x,int index);
144}
145
146template<typename T, typename = typename enable_if<scifir::is_number<T>::value>::type>
148{
149 return scifir::pixel(x + y.get_value());
150}
151
152template<typename T, typename = typename enable_if<scifir::is_number<T>::value>::type>
154{
155 return scifir::pixel(x - y.get_value());
156}
157
158template<typename T, typename = typename enable_if<scifir::is_number<T>::value>::type>
160{
161 return scifir::pixel(x * y.get_value());
162}
163
164template<typename T, typename = typename enable_if<scifir::is_number<T>::value>::type>
166{
167 return scifir::pixel(x / y.get_value());
168}
169
170template<typename T, typename = typename enable_if<scifir::is_number<T>::value>::type>
172{
173 return scifir::pixel(std::pow(x, y.get_value()));
174}
175
176template<typename T, typename = typename enable_if<scifir::is_number<T>::value>::type>
177bool operator ==(T x, const scifir::pixel& y)
178{
179 return (x == y.get_value());
180}
181
182template<typename T, typename = typename enable_if<scifir::is_number<T>::value>::type>
183bool operator !=(T x, const scifir::pixel& y)
184{
185 return (x != y.get_value());
186}
187
188template<typename T, typename = typename enable_if<scifir::is_number<T>::value>::type>
189bool operator <(T x, const scifir::pixel& y)
190{
191 return (x < y.get_value());
192}
193
194template<typename T, typename = typename enable_if<scifir::is_number<T>::value>::type>
195bool operator >(T x, const scifir::pixel& y)
196{
197 return (x > y.get_value());
198}
199
200template<typename T, typename = typename enable_if<scifir::is_number<T>::value>::type>
201bool operator <=(T x, const scifir::pixel& y)
202{
203 return (x <= y.get_value());
204}
205
206template<typename T, typename = typename enable_if<scifir::is_number<T>::value>::type>
207bool operator >=(T x, const scifir::pixel& y)
208{
209 return (x >= y.get_value());
210}
211
212template<typename T, typename = typename enable_if<scifir::is_number<T>::value>::type>
213bool operator ==(const scifir::pixel& y, T x)
214{
215 return (x == y.get_value());
216}
217
218template<typename T, typename = typename enable_if<scifir::is_number<T>::value>::type>
219bool operator !=(const scifir::pixel& y, T x)
220{
221 return (x != y.get_value());
222}
223
224template<typename T, typename = typename enable_if<scifir::is_number<T>::value>::type>
225bool operator <(const scifir::pixel& y, T x)
226{
227 return (y.get_value() < x);
228}
229
230template<typename T, typename = typename enable_if<scifir::is_number<T>::value>::type>
231bool operator >(const scifir::pixel& y, T x)
232{
233 return (y.get_value() > x);
234}
235
236template<typename T, typename = typename enable_if<scifir::is_number<T>::value>::type>
237bool operator <=(const scifir::pixel& y, T x)
238{
239 return (y.get_value() <= x);
240}
241
242template<typename T, typename = typename enable_if<scifir::is_number<T>::value>::type>
243bool operator >=(const scifir::pixel& y, T x)
244{
245 return (y.get_value() >= x);
246}
247
248bool operator ==(const scifir::pixel& x, const scifir::pixel& y);
249bool operator !=(const scifir::pixel& x, const scifir::pixel& y);
250bool operator <(const scifir::pixel& x, const scifir::pixel& y);
251bool operator >(const scifir::pixel& x, const scifir::pixel& y);
252bool operator <=(const scifir::pixel& x, const scifir::pixel& y);
253bool operator >=(const scifir::pixel& x, const scifir::pixel& y);
254
255bool operator ==(const scifir::pixel& x, const string& init_pixel);
256bool operator !=(const scifir::pixel& x, const string& init_pixel);
257
258bool operator ==(const string& init_pixel, const scifir::pixel& x);
259bool operator !=(const string& init_pixel, const scifir::pixel& x);
260
261void operator +=(string& x, const scifir::pixel& y);
262string operator +(const string& x, const scifir::pixel& y);
263string operator +(const scifir::pixel& y, const string& x);
264
265ostream& operator <<(ostream& os, const scifir::pixel& x);
266istream& operator >>(istream& is, scifir::pixel& x);
267
268#endif // SCIFIR_UNITS_SPECIAL_UNITS_PIXEL_HPP_INCLUDED
void operator^=(const pixel &x)
Definition pixel.cpp:137
float value
Definition pixel.hpp:133
void operator+=(const pixel &x)
Definition pixel.cpp:117
pixel & operator++()
Definition pixel.cpp:142
pixel operator^(const pixel &x) const
Definition pixel.cpp:112
pixel operator-(const pixel &x) const
Definition pixel.cpp:97
pixel & operator=(const pixel &x)
Definition pixel.cpp:55
const float & get_value() const
Definition pixel.hpp:41
scalar_unit to_scalar_unit() const
Definition pixel.cpp:168
pixel operator*(const pixel &x) const
Definition pixel.cpp:102
void operator-=(const pixel &x)
Definition pixel.cpp:122
pixel operator+(const pixel &x) const
Definition pixel.cpp:92
string display(int number_of_decimals=2) const
Definition pixel.cpp:173
pixel & operator--()
Definition pixel.cpp:155
void operator*=(const pixel &x)
Definition pixel.cpp:127
void operator/=(const pixel &x)
Definition pixel.cpp:132
pixel operator/(const pixel &x) const
Definition pixel.cpp:107
void initialize_from_string(const string &init_pixel)
Definition pixel.cpp:180
Class that allows to create scalar units, which are composed of a value (as a float) and dimensions....
The namespace scifir contains all scifir-units, excepting the string literals, which are outside.
Definition address.cpp:6
angle sqrt_nth(const angle &x, int index)
Calculates the nth root of the angle x and returns that new angle.
Definition angle.cpp:421
string to_string(const aid &x)
Creates a string representation of aid, it's for aid equivalent to the display() function of aid.
Definition aid.cpp:582
bool is_pixel(const string &init_pixel)
Definition pixel.cpp:201
angle sqrt(const angle &x)
Calculates the square root of the angle x and returns that new angle.
Definition angle.cpp:416
scifir::pixel operator+(T x, const scifir::pixel &y)
Definition pixel.hpp:147
scifir::pixel operator*(T x, const scifir::pixel &y)
Definition pixel.hpp:159
bool operator==(T x, const scifir::pixel &y)
Definition pixel.hpp:177
scifir::pixel operator-(T x, const scifir::pixel &y)
Definition pixel.hpp:153
scifir::pixel operator/(T x, const scifir::pixel &y)
Definition pixel.hpp:165
void operator+=(string &x, const scifir::pixel &y)
Definition pixel.cpp:322
scifir::pixel operator^(T x, const scifir::pixel &y)
Definition pixel.hpp:171
bool operator!=(T x, const scifir::pixel &y)
Definition pixel.hpp:183
bool operator>(T x, const scifir::pixel &y)
Definition pixel.hpp:195
bool operator<=(T x, const scifir::pixel &y)
Definition pixel.hpp:201
istream & operator>>(istream &is, scifir::pixel &x)
Definition pixel.cpp:350
ostream & operator<<(ostream &os, const scifir::pixel &x)
Definition pixel.cpp:345
bool operator>=(T x, const scifir::pixel &y)
Definition pixel.hpp:207
bool operator<(T x, const scifir::pixel &y)
Definition pixel.hpp:189