17 #ifndef MIR_GEOMETRY_DIMENSIONS_GENERIC_H_
18 #define MIR_GEOMETRY_DIMENSIONS_GENERIC_H_
21 #include <type_traits>
56 template<
typename Tag>
61 template<
typename OtherTag>
64 template <
typename Q = T>
65 constexpr
typename std::enable_if<std::is_integral<Q>::value,
int>::type
as_int()
const
88 template<typename W, typename std::enable_if<std::is_same<typename W::TagType, Tag>::value,
bool>::type =
true>
94 template<typename U, typename std::enable_if<std::is_scalar<U>::value,
bool>::type =
true>
102 return value == rhs.as_value();
107 return value != rhs.as_value();
112 return value <= rhs.as_value();
117 return value >= rhs.as_value();
122 return value < rhs.as_value();
127 return value > rhs.as_value();
138 template<
class GeometricType,
typename Tag>
141 template<typename W, typename std::enable_if<std::is_base_of<detail::ValueWrapperBase, W>::value,
bool>::type =
true>
144 out << value.as_value();
157 template<
template<
typename>
typename T>
158 inline constexpr T<DeltaXTag>
operator+(T<DeltaXTag> lhs, T<DeltaXTag> rhs){
return T<DeltaXTag>(lhs.as_value() + rhs.as_value()); }
159 template<
template<
typename>
typename T>
160 inline constexpr T<DeltaYTag>
operator+(T<DeltaYTag> lhs, T<DeltaYTag> rhs) {
return T<DeltaYTag>(lhs.as_value() + rhs.as_value()); }
161 template<
template<
typename>
typename T>
162 inline constexpr T<DeltaXTag>
operator-(T<DeltaXTag> lhs, T<DeltaXTag> rhs) {
return T<DeltaXTag>(lhs.as_value() - rhs.as_value()); }
163 template<
template<
typename>
typename T>
164 inline constexpr T<DeltaYTag>
operator-(T<DeltaYTag> lhs, T<DeltaYTag> rhs) {
return T<DeltaYTag>(lhs.as_value() - rhs.as_value()); }
165 template<
template<
typename>
typename T>
166 inline constexpr T<DeltaXTag>
operator-(T<DeltaXTag> rhs) {
return T<DeltaXTag>(-rhs.as_value()); }
167 template<
template<
typename>
typename T>
168 inline constexpr T<DeltaYTag>
operator-(T<DeltaYTag> rhs) {
return T<DeltaYTag>(-rhs.as_value()); }
169 template<
template<
typename>
typename T>
170 inline T<DeltaXTag>&
operator+=(T<DeltaXTag>& lhs, T<DeltaXTag> rhs) {
return lhs = lhs + rhs; }
171 template<
template<
typename>
typename T>
172 inline T<DeltaYTag>&
operator+=(T<DeltaYTag>& lhs, T<DeltaYTag> rhs) {
return lhs = lhs + rhs; }
173 template<
template<
typename>
typename T>
174 inline T<DeltaXTag>&
operator-=(T<DeltaXTag>& lhs, T<DeltaXTag> rhs) {
return lhs = lhs - rhs; }
175 template<
template<
typename>
typename T>
176 inline T<DeltaYTag>&
operator-=(T<DeltaYTag>& lhs, T<DeltaYTag> rhs) {
return lhs = lhs - rhs; }
179 template<
template<
typename>
typename T>
180 inline constexpr T<XTag>
operator+(T<XTag> lhs, T<DeltaXTag> rhs) {
return T<XTag>(lhs.as_value() + rhs.as_value()); }
181 template<
template<
typename>
typename T>
182 inline constexpr T<YTag>
operator+(T<YTag> lhs, T<DeltaYTag> rhs) {
return T<YTag>(lhs.as_value() + rhs.as_value()); }
183 template<
template<
typename>
typename T>
184 inline constexpr T<XTag>
operator-(T<XTag> lhs, T<DeltaXTag> rhs) {
return T<XTag>(lhs.as_value() - rhs.as_value()); }
185 template<
template<
typename>
typename T>
186 inline constexpr T<YTag>
operator-(T<YTag> lhs, T<DeltaYTag> rhs) {
return T<YTag>(lhs.as_value() - rhs.as_value()); }
187 template<
template<
typename>
typename T>
188 inline T<XTag>&
operator+=(T<XTag>& lhs, T<DeltaXTag> rhs) {
return lhs = lhs + rhs; }
189 template<
template<
typename>
typename T>
190 inline T<YTag>&
operator+=(T<YTag>& lhs, T<DeltaYTag> rhs) {
return lhs = lhs + rhs; }
191 template<
template<
typename>
typename T>
192 inline T<XTag>&
operator-=(T<XTag>& lhs, T<DeltaXTag> rhs) {
return lhs = lhs - rhs; }
193 template<
template<
typename>
typename T>
194 inline T<YTag>&
operator-=(T<YTag>& lhs, T<DeltaYTag> rhs) {
return lhs = lhs - rhs; }
197 template<
template<
typename>
typename T>
198 inline constexpr T<WidthTag>
operator+(T<WidthTag> lhs, T<DeltaXTag> rhs) {
return T<WidthTag>(lhs.as_value() + rhs.as_value()); }
199 template<
template<
typename>
typename T>
200 inline constexpr T<HeightTag>
operator+(T<HeightTag> lhs, T<DeltaYTag> rhs) {
return T<HeightTag>(lhs.as_value() + rhs.as_value()); }
201 template<
template<
typename>
typename T>
202 inline constexpr T<WidthTag>
operator-(T<WidthTag> lhs, T<DeltaXTag> rhs) {
return T<WidthTag>(lhs.as_value() - rhs.as_value()); }
203 template<
template<
typename>
typename T>
204 inline constexpr T<HeightTag>
operator-(T<HeightTag> lhs, T<DeltaYTag> rhs) {
return T<HeightTag>(lhs.as_value() - rhs.as_value()); }
205 template<
template<
typename>
typename T>
206 inline T<WidthTag>&
operator+=(T<WidthTag>& lhs, T<DeltaXTag> rhs) {
return lhs = lhs + rhs; }
207 template<
template<
typename>
typename T>
208 inline T<HeightTag>&
operator+=(T<HeightTag>& lhs, T<DeltaYTag> rhs) {
return lhs = lhs + rhs; }
209 template<
template<
typename>
typename T>
210 inline T<WidthTag>&
operator-=(T<WidthTag>& lhs, T<DeltaXTag> rhs) {
return lhs = lhs - rhs; }
211 template<
template<
typename>
typename T>
212 inline T<HeightTag>&
operator-=(T<HeightTag>& lhs, T<DeltaYTag> rhs) {
return lhs = lhs - rhs; }
215 template<
template<
typename>
typename T>
216 inline constexpr T<WidthTag>
operator+(T<WidthTag> lhs, T<WidthTag> rhs) {
return T<WidthTag>(lhs.as_value() + rhs.as_value()); }
217 template<
template<
typename>
typename T>
218 inline constexpr T<HeightTag>
operator+(T<HeightTag> lhs, T<HeightTag> rhs) {
return T<HeightTag>(lhs.as_value() + rhs.as_value()); }
219 template<
template<
typename>
typename T>
220 inline T<WidthTag>&
operator+=(T<WidthTag>& lhs, T<WidthTag> rhs) {
return lhs = lhs + rhs; }
221 template<
template<
typename>
typename T>
222 inline T<HeightTag>&
operator+=(T<HeightTag>& lhs, T<HeightTag> rhs) {
return lhs = lhs + rhs; }
225 template<
template<
typename>
typename T>
226 inline constexpr T<DeltaXTag>
operator-(T<XTag> lhs, T<XTag> rhs) {
return T<DeltaXTag>(lhs.as_value() - rhs.as_value()); }
227 template<
template<
typename>
typename T>
228 inline constexpr T<DeltaYTag>
operator-(T<YTag> lhs, T<YTag> rhs) {
return T<DeltaYTag>(lhs.as_value() - rhs.as_value()); }
231 template<
template<
typename>
typename T>
232 inline constexpr T<DeltaXTag>
operator-(T<WidthTag> lhs, T<WidthTag> rhs) {
return T<DeltaXTag>(lhs.as_value() - rhs.as_value()); }
233 template<
template<
typename>
typename T>
234 inline constexpr T<DeltaYTag>
operator-(T<HeightTag> lhs, T<HeightTag> rhs) {
return T<DeltaYTag>(lhs.as_value() - rhs.as_value()); }
237 template<
template<
typename>
typename T,
typename Scalar>
238 inline constexpr T<WidthTag>
operator*(Scalar scale, T<WidthTag>
const& w) {
return T<WidthTag>{scale*w.as_value()}; }
239 template<
template<
typename>
typename T,
typename Scalar>
240 inline constexpr T<HeightTag>
operator*(Scalar scale, T<HeightTag>
const& h) {
return T<HeightTag>{scale*h.as_value()}; }
241 template<
template<
typename>
typename T,
typename Scalar>
242 inline constexpr T<DeltaXTag>
operator*(Scalar scale, T<DeltaXTag>
const& dx) {
return T<DeltaXTag>{scale*dx.as_value()}; }
243 template<
template<
typename>
typename T,
typename Scalar>
244 inline constexpr T<DeltaYTag>
operator*(Scalar scale, T<DeltaYTag>
const& dy) {
return T<DeltaYTag>{scale*dy.as_value()}; }
245 template<
template<
typename>
typename T,
typename Scalar>
246 inline constexpr T<WidthTag>
operator*(T<WidthTag>
const& w, Scalar scale) {
return scale*w; }
247 template<
template<
typename>
typename T,
typename Scalar>
248 inline constexpr T<HeightTag>
operator*(T<HeightTag>
const& h, Scalar scale) {
return scale*h; }
249 template<
template<
typename>
typename T,
typename Scalar>
250 inline constexpr T<DeltaXTag>
operator*(T<DeltaXTag>
const& dx, Scalar scale) {
return scale*dx; }
251 template<
template<
typename>
typename T,
typename Scalar>
252 inline constexpr T<DeltaYTag>
operator*(T<DeltaYTag>
const& dy, Scalar scale) {
return scale*dy; }
255 template<
template<
typename>
typename T,
typename Scalar>
256 inline constexpr T<WidthTag>
operator/(T<WidthTag>
const& w, Scalar scale) {
return T<WidthTag>{w.as_value() / scale}; }
257 template<
template<
typename>
typename T,
typename Scalar>
258 inline constexpr T<HeightTag>
operator/(T<HeightTag>
const& h, Scalar scale) {
return T<HeightTag>{h.as_value() / scale}; }
259 template<
template<
typename>
typename T,
typename Scalar>
260 inline constexpr T<DeltaXTag>
operator/(T<DeltaXTag>
const& dx, Scalar scale) {
return T<DeltaXTag>{dx.as_value() / scale}; }
261 template<
template<
typename>
typename T,
typename Scalar>
262 inline constexpr T<DeltaYTag>
operator/(T<DeltaYTag>
const& dy, Scalar scale) {
return T<DeltaYTag>{dy.as_value() / scale}; }
265 template<
template<
typename>
typename T>
266 inline constexpr T<WidthTag>
as_width(T<DeltaXTag>
const& dx) {
return T<WidthTag>{dx.as_value()}; }
267 template<
template<
typename>
typename T>
268 inline constexpr T<HeightTag>
as_height(T<DeltaYTag>
const& dy) {
return T<HeightTag>{dy.as_value()}; }
269 template<
template<
typename>
typename T>
270 inline constexpr T<XTag>
as_x(T<DeltaXTag>
const& dx) {
return T<XTag>{dx.as_value()}; }
271 template<
template<
typename>
typename T>
272 inline constexpr T<YTag>
as_y(T<DeltaYTag>
const& dy) {
return T<YTag>{dy.as_value()}; }
273 template<
template<
typename>
typename T>
274 inline constexpr T<DeltaXTag>
as_delta(T<XTag>
const& x) {
return T<DeltaXTag>{x.as_value()}; }
275 template<
template<
typename>
typename T>
276 inline constexpr T<DeltaYTag>
as_delta(T<YTag>
const& y) {
return T<DeltaYTag>{y.as_value()}; }
277 template<
template<
typename>
typename T>
278 inline constexpr T<XTag>
as_x(T<WidthTag>
const& w) {
return T<XTag>{w.as_value()}; }
279 template<
template<
typename>
typename T>
280 inline constexpr T<YTag>
as_y(T<HeightTag>
const& h) {
return T<YTag>{h.as_value()}; }
281 template<
template<
typename>
typename T>
282 inline constexpr T<WidthTag>
as_width(T<XTag>
const& x) {
return T<WidthTag>{x.as_value()}; }
283 template<
template<
typename>
typename T>
284 inline constexpr T<HeightTag>
as_height(T<YTag>
const& y) {
return T<HeightTag>{y.as_value()}; }
285 template<
template<
typename>
typename T>
286 inline constexpr T<DeltaXTag>
as_delta(T<WidthTag>
const& w) {
return T<DeltaXTag>{w.as_value()}; }
287 template<
template<
typename>
typename T>
288 inline constexpr T<DeltaYTag>
as_delta(T<HeightTag>
const& h) {
return T<DeltaYTag>{h.as_value()}; }
290 template<
typename Target,
typename Source>
291 inline constexpr Target
dim_cast(Source s) {
return Target(s.as_value()); }
typename Value< T >::template Wrapper< WidthTag > Width
Definition: dimensions_generic.h:148
std::ostream & operator<<(std::ostream &out, W const &value)
Definition: dimensions_generic.h:142
typename Value< T >::template Wrapper< DeltaYTag > DeltaY
Definition: dimensions_generic.h:153
typename GeometricType::template Corresponding< Tag > Corresponding
Definition: dimensions_generic.h:139
typename Value< T >::template Wrapper< YTag > Y
Definition: dimensions_generic.h:151
typename Value< T >::template Wrapper< DeltaXTag > DeltaX
Definition: dimensions_generic.h:152
typename Value< T >::template Wrapper< XTag > X
Definition: dimensions_generic.h:150
typename Value< T >::template Wrapper< HeightTag > Height
Definition: dimensions_generic.h:149
constexpr T< WidthTag > operator*(Scalar scale, T< WidthTag > const &w)
Definition: dimensions_generic.h:238
constexpr T< HeightTag > as_height(T< DeltaYTag > const &dy)
Definition: dimensions_generic.h:268
constexpr T< XTag > as_x(T< DeltaXTag > const &dx)
Definition: dimensions_generic.h:270
constexpr T< DeltaXTag > as_delta(T< XTag > const &x)
Definition: dimensions_generic.h:274
constexpr T< DeltaXTag > operator+(T< DeltaXTag > lhs, T< DeltaXTag > rhs)
Definition: dimensions_generic.h:158
constexpr T< WidthTag > as_width(T< DeltaXTag > const &dx)
Definition: dimensions_generic.h:266
constexpr T< YTag > as_y(T< DeltaYTag > const &dy)
Definition: dimensions_generic.h:272
constexpr T< WidthTag > operator/(T< WidthTag > const &w, Scalar scale)
Definition: dimensions_generic.h:256
T< DeltaXTag > & operator-=(T< DeltaXTag > &lhs, T< DeltaXTag > rhs)
Definition: dimensions_generic.h:174
constexpr Target dim_cast(Source s)
Definition: dimensions_generic.h:291
constexpr T< DeltaXTag > operator-(T< DeltaXTag > lhs, T< DeltaXTag > rhs)
Definition: dimensions_generic.h:162
T< DeltaXTag > & operator+=(T< DeltaXTag > &lhs, T< DeltaXTag > rhs)
Definition: dimensions_generic.h:170
Definition: splash_session.h:22
Definition: dimensions_generic.h:38
Definition: dimensions_generic.h:39
Definition: dimensions_generic.h:35
These tag types determine what type of dimension a value holds and what operations are possible with ...
Definition: dimensions_generic.h:34
Definition: dimensions_generic.h:36
Definition: dimensions_generic.h:37
Definition: dimensions_generic.h:44
Wraps a geometry value and prevents it from being accidentally used for invalid operations (such as s...
Definition: dimensions_generic.h:58
constexpr std::enable_if< std::is_integral< Q >::value, int >::type as_int() const
Definition: dimensions_generic.h:65
constexpr auto operator<(Wrapper< Tag > const &rhs) const -> bool
Definition: dimensions_generic.h:120
constexpr auto operator!=(Wrapper< Tag > const &rhs) const -> bool
Definition: dimensions_generic.h:105
constexpr Wrapper(W const &value) noexcept
Definition: dimensions_generic.h:89
constexpr Wrapper(U const &value) noexcept
Definition: dimensions_generic.h:95
constexpr Wrapper(Wrapper const &that) noexcept
Definition: dimensions_generic.h:83
Wrapper & operator=(Wrapper const &that) noexcept
Definition: dimensions_generic.h:77
constexpr T as_value() const noexcept
Definition: dimensions_generic.h:70
T value
Definition: dimensions_generic.h:131
constexpr auto operator>(Wrapper< Tag > const &rhs) const -> bool
Definition: dimensions_generic.h:125
constexpr auto operator==(Wrapper< Tag > const &rhs) const -> bool
Definition: dimensions_generic.h:100
T ValueType
Definition: dimensions_generic.h:59
Tag TagType
Definition: dimensions_generic.h:60
constexpr auto operator<=(Wrapper< Tag > const &rhs) const -> bool
Definition: dimensions_generic.h:110
constexpr auto operator>=(Wrapper< Tag > const &rhs) const -> bool
Definition: dimensions_generic.h:115
constexpr Wrapper() noexcept
Definition: dimensions_generic.h:75
Definition: dimensions_generic.h:51