-
Notifications
You must be signed in to change notification settings - Fork 0
/
iframe.units.hpp
234 lines (171 loc) · 5.29 KB
/
iframe.units.hpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
#include <array>
#include "iframe.hpp"
#include "../expression_template/expression_template.hpp"
namespace tomolatoon::units
{
struct Percent
{
using Basis = double (*)(const double);
Percent(Basis basis, double per = 1.0) noexcept
: m_basis(basis), m_per(per) {}
double per() const noexcept {
return m_per;
}
double value() const noexcept {
return m_basis(m_per);
}
double operator[]([[maybe_unused]] size_t i) const noexcept {
return m_basis(m_per);
}
operator double() const noexcept {
return m_basis(m_per);
}
private:
Basis m_basis;
double m_per;
};
// ET = Percent, Expression
template <class ET>
struct Length
{
Length(ET et)
: m_et(std::move(et)) {}
explicit operator double() const noexcept {
return m_et[0];
}
// Add
template <class ET>
Length operator+(const Length<ET>& rhs) const noexcept {
return Length(Expression<decltype(*this), Add, decltype(rhs)>(this->m_et, rhs.m_et));
}
// Sub
template <class ET>
Length operator-(const Length<ET>& rhs) const noexcept {
return Length(Expression<decltype(*this), Sub, decltype(rhs)>(this->m_et, rhs.m_et));
}
// Mul
Length operator*(const double rhs) const noexcept {
return Length(Expression<decltype(*this), Mul, decltype(rhs)>(this->m_et, rhs));
}
// Div
template <class ET>
Length operator/(const Length<ET>& rhs) const noexcept {
return Length(Expression<decltype(*this), Div, decltype(rhs)>(this->m_et, rhs.m_et));
}
private:
ET m_et;
};
inline double per(const double source, const double per) noexcept;
inline double vw(const double p) noexcept;
inline double vh(const double p) noexcept;
struct vwf: Length<Percent>
{
vwf(double per)
: Length(Percent(vw, per)) {}
};
struct vhf: Length<Percent>
{
vhf(double per)
: Length(Percent(vh, per)) {}
};
inline double sw(const double p) noexcept;
inline double sh(const double p) noexcept;
struct swf: Length<Percent>
{
swf(double per)
: Length(Percent(sw, per)) {}
};
struct shf: Length<Percent>
{
shf(double per)
: Length(Percent(sh, per)) {}
};
inline namespace literals
{
inline double operator""_vw(const unsigned long long per) noexcept;
inline double operator""_vw(const long double per) noexcept;
inline double operator""_vh(const unsigned long long per) noexcept;
inline double operator""_vh(const long double per) noexcept;
inline vwf operator""_vwf(const unsigned long long per) noexcept;
inline vwf operator""_vwf(const long double per) noexcept;
inline vhf operator""_vhf(const unsigned long long per) noexcept;
inline vhf operator""_vhf(const long double per) noexcept;
inline double operator""_sw(const unsigned long long per) noexcept;
inline double operator""_sw(const long double per) noexcept;
inline double operator""_sh(const unsigned long long per) noexcept;
inline double operator""_sh(const long double per) noexcept;
inline swf operator""_swf(const unsigned long long per) noexcept;
inline swf operator""_swf(const long double per) noexcept;
inline shf operator""_shf(const unsigned long long per) noexcept;
inline shf operator""_shf(const long double per) noexcept;
} // namespace literals
} // namespace tomolatoon::units
namespace tomolatoon::units
{
inline double per(const double source, const double per) noexcept {
return per * 0.01 * source;
}
inline double vw(const double p) noexcept {
return per(Iframe::Width(), p);
}
inline double vh(const double p) noexcept {
return per(Iframe::Height(), p);
}
inline double sw(const double p) noexcept {
return per(Scene::Width(), p);
}
inline double sh(const double p) noexcept {
return per(Scene::Height(), p);
}
inline namespace literals
{
inline double operator""_vw(const unsigned long long per) noexcept {
return vw((double)per);
}
inline double operator""_vw(const long double per) noexcept {
return vw((double)per);
}
inline double operator""_vh(const unsigned long long per) noexcept {
return vh((double)per);
}
inline double operator""_vh(const long double per) noexcept {
return vh((double)per);
}
inline vwf operator""_vwf(const unsigned long long per) noexcept {
return vwf((double)per);
}
inline vwf operator""_vwf(const long double per) noexcept {
return vwf((double)per);
}
inline vhf operator""_vhf(const unsigned long long per) noexcept {
return vhf((double)per);
}
inline vhf operator""_vhf(const long double per) noexcept {
return vhf((double)per);
}
inline double operator""_sw(const unsigned long long per) noexcept {
return sw((double)per);
}
inline double operator""_sw(const long double per) noexcept {
return sw((double)per);
}
inline double operator""_sh(const unsigned long long per) noexcept {
return sh((double)per);
}
inline double operator""_sh(const long double per) noexcept {
return sh((double)per);
}
inline swf operator""_swf(const unsigned long long per) noexcept {
return swf((double)per);
}
inline swf operator""_swf(const long double per) noexcept {
return swf((double)per);
}
inline shf operator""_shf(const unsigned long long per) noexcept {
return shf((double)per);
}
inline shf operator""_shf(const long double per) noexcept {
return shf((double)per);
}
} // namespace literals
} // namespace tomolatoon::units