17#ifndef MIR_GEOMETRY_DIMENSIONS_GENERIC_H_
18#define MIR_GEOMETRY_DIMENSIONS_GENERIC_H_
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();
138template<
class GeometricType,
typename Tag>
141template<typename W, typename std::enable_if<std::is_base_of<detail::ValueWrapperBase, W>::value,
bool>::type =
true>
144 out << value.as_value();
157template<
template<
typename>
typename T>
158inline constexpr T<DeltaXTag>
operator+(T<DeltaXTag> lhs, T<DeltaXTag> rhs){
return T<DeltaXTag>(lhs.as_value() + rhs.as_value()); }
159template<
template<
typename>
typename T>
160inline constexpr T<DeltaYTag>
operator+(T<DeltaYTag> lhs, T<DeltaYTag> rhs) {
return T<DeltaYTag>(lhs.as_value() + rhs.as_value()); }
161template<
template<
typename>
typename T>
162inline constexpr T<DeltaXTag>
operator-(T<DeltaXTag> lhs, T<DeltaXTag> rhs) {
return T<DeltaXTag>(lhs.as_value() - rhs.as_value()); }
163template<
template<
typename>
typename T>
164inline constexpr T<DeltaYTag>
operator-(T<DeltaYTag> lhs, T<DeltaYTag> rhs) {
return T<DeltaYTag>(lhs.as_value() - rhs.as_value()); }
165template<
template<
typename>
typename T>
166inline constexpr T<DeltaXTag>
operator-(T<DeltaXTag> rhs) {
return T<DeltaXTag>(-rhs.as_value()); }
167template<
template<
typename>
typename T>
168inline constexpr T<DeltaYTag>
operator-(T<DeltaYTag> rhs) {
return T<DeltaYTag>(-rhs.as_value()); }
169template<
template<
typename>
typename T>
170inline T<DeltaXTag>&
operator+=(T<DeltaXTag>& lhs, T<DeltaXTag> rhs) {
return lhs = lhs + rhs; }
171template<
template<
typename>
typename T>
172inline T<DeltaYTag>&
operator+=(T<DeltaYTag>& lhs, T<DeltaYTag> rhs) {
return lhs = lhs + rhs; }
173template<
template<
typename>
typename T>
174inline T<DeltaXTag>&
operator-=(T<DeltaXTag>& lhs, T<DeltaXTag> rhs) {
return lhs = lhs - rhs; }
175template<
template<
typename>
typename T>
176inline T<DeltaYTag>&
operator-=(T<DeltaYTag>& lhs, T<DeltaYTag> rhs) {
return lhs = lhs - rhs; }
179template<
template<
typename>
typename T>
180inline constexpr T<XTag>
operator+(T<XTag> lhs, T<DeltaXTag> rhs) {
return T<XTag>(lhs.as_value() + rhs.as_value()); }
181template<
template<
typename>
typename T>
182inline constexpr T<YTag>
operator+(T<YTag> lhs, T<DeltaYTag> rhs) {
return T<YTag>(lhs.as_value() + rhs.as_value()); }
183template<
template<
typename>
typename T>
184inline constexpr T<XTag>
operator-(T<XTag> lhs, T<DeltaXTag> rhs) {
return T<XTag>(lhs.as_value() - rhs.as_value()); }
185template<
template<
typename>
typename T>
186inline constexpr T<YTag>
operator-(T<YTag> lhs, T<DeltaYTag> rhs) {
return T<YTag>(lhs.as_value() - rhs.as_value()); }
187template<
template<
typename>
typename T>
188inline T<XTag>&
operator+=(T<XTag>& lhs, T<DeltaXTag> rhs) {
return lhs = lhs + rhs; }
189template<
template<
typename>
typename T>
190inline T<YTag>&
operator+=(T<YTag>& lhs, T<DeltaYTag> rhs) {
return lhs = lhs + rhs; }
191template<
template<
typename>
typename T>
192inline T<XTag>&
operator-=(T<XTag>& lhs, T<DeltaXTag> rhs) {
return lhs = lhs - rhs; }
193template<
template<
typename>
typename T>
194inline T<YTag>&
operator-=(T<YTag>& lhs, T<DeltaYTag> rhs) {
return lhs = lhs - rhs; }
197template<
template<
typename>
typename T>
198inline constexpr T<WidthTag>
operator+(T<WidthTag> lhs, T<DeltaXTag> rhs) {
return T<WidthTag>(lhs.as_value() + rhs.as_value()); }
199template<
template<
typename>
typename T>
200inline constexpr T<HeightTag>
operator+(T<HeightTag> lhs, T<DeltaYTag> rhs) {
return T<HeightTag>(lhs.as_value() + rhs.as_value()); }
201template<
template<
typename>
typename T>
202inline constexpr T<WidthTag>
operator-(T<WidthTag> lhs, T<DeltaXTag> rhs) {
return T<WidthTag>(lhs.as_value() - rhs.as_value()); }
203template<
template<
typename>
typename T>
204inline constexpr T<HeightTag>
operator-(T<HeightTag> lhs, T<DeltaYTag> rhs) {
return T<HeightTag>(lhs.as_value() - rhs.as_value()); }
205template<
template<
typename>
typename T>
206inline T<WidthTag>&
operator+=(T<WidthTag>& lhs, T<DeltaXTag> rhs) {
return lhs = lhs + rhs; }
207template<
template<
typename>
typename T>
208inline T<HeightTag>&
operator+=(T<HeightTag>& lhs, T<DeltaYTag> rhs) {
return lhs = lhs + rhs; }
209template<
template<
typename>
typename T>
210inline T<WidthTag>&
operator-=(T<WidthTag>& lhs, T<DeltaXTag> rhs) {
return lhs = lhs - rhs; }
211template<
template<
typename>
typename T>
212inline T<HeightTag>&
operator-=(T<HeightTag>& lhs, T<DeltaYTag> rhs) {
return lhs = lhs - rhs; }
215template<
template<
typename>
typename T>
216inline constexpr T<WidthTag>
operator+(T<WidthTag> lhs, T<WidthTag> rhs) {
return T<WidthTag>(lhs.as_value() + rhs.as_value()); }
217template<
template<
typename>
typename T>
218inline constexpr T<HeightTag>
operator+(T<HeightTag> lhs, T<HeightTag> rhs) {
return T<HeightTag>(lhs.as_value() + rhs.as_value()); }
219template<
template<
typename>
typename T>
220inline T<WidthTag>&
operator+=(T<WidthTag>& lhs, T<WidthTag> rhs) {
return lhs = lhs + rhs; }
221template<
template<
typename>
typename T>
222inline T<HeightTag>&
operator+=(T<HeightTag>& lhs, T<HeightTag> rhs) {
return lhs = lhs + rhs; }
225template<
template<
typename>
typename T>
226inline constexpr T<DeltaXTag>
operator-(T<XTag> lhs, T<XTag> rhs) {
return T<DeltaXTag>(lhs.as_value() - rhs.as_value()); }
227template<
template<
typename>
typename T>
228inline constexpr T<DeltaYTag>
operator-(T<YTag> lhs, T<YTag> rhs) {
return T<DeltaYTag>(lhs.as_value() - rhs.as_value()); }
231template<
template<
typename>
typename T>
232inline constexpr T<DeltaXTag>
operator-(T<WidthTag> lhs, T<WidthTag> rhs) {
return T<DeltaXTag>(lhs.as_value() - rhs.as_value()); }
233template<
template<
typename>
typename T>
234inline constexpr T<DeltaYTag>
operator-(T<HeightTag> lhs, T<HeightTag> rhs) {
return T<DeltaYTag>(lhs.as_value() - rhs.as_value()); }
237template<
template<
typename>
typename T,
typename Scalar>
238inline constexpr T<WidthTag>
operator*(Scalar scale, T<WidthTag>
const& w) {
return T<WidthTag>{scale*w.as_value()}; }
239template<
template<
typename>
typename T,
typename Scalar>
240inline constexpr T<HeightTag>
operator*(Scalar scale, T<HeightTag>
const& h) {
return T<HeightTag>{scale*h.as_value()}; }
241template<
template<
typename>
typename T,
typename Scalar>
242inline constexpr T<DeltaXTag>
operator*(Scalar scale, T<DeltaXTag>
const& dx) {
return T<DeltaXTag>{scale*dx.as_value()}; }
243template<
template<
typename>
typename T,
typename Scalar>
244inline constexpr T<DeltaYTag>
operator*(Scalar scale, T<DeltaYTag>
const& dy) {
return T<DeltaYTag>{scale*dy.as_value()}; }
245template<
template<
typename>
typename T,
typename Scalar>
246inline constexpr T<WidthTag>
operator*(T<WidthTag>
const& w, Scalar scale) {
return scale*w; }
247template<
template<
typename>
typename T,
typename Scalar>
248inline constexpr T<HeightTag>
operator*(T<HeightTag>
const& h, Scalar scale) {
return scale*h; }
249template<
template<
typename>
typename T,
typename Scalar>
250inline constexpr T<DeltaXTag>
operator*(T<DeltaXTag>
const& dx, Scalar scale) {
return scale*dx; }
251template<
template<
typename>
typename T,
typename Scalar>
252inline constexpr T<DeltaYTag>
operator*(T<DeltaYTag>
const& dy, Scalar scale) {
return scale*dy; }
255template<
template<
typename>
typename T,
typename Scalar>
256inline constexpr T<WidthTag>
operator/(T<WidthTag>
const& w, Scalar scale) {
return T<WidthTag>{w.as_value() / scale}; }
257template<
template<
typename>
typename T,
typename Scalar>
258inline constexpr T<HeightTag>
operator/(T<HeightTag>
const& h, Scalar scale) {
return T<HeightTag>{h.as_value() / scale}; }
259template<
template<
typename>
typename T,
typename Scalar>
260inline constexpr T<DeltaXTag>
operator/(T<DeltaXTag>
const& dx, Scalar scale) {
return T<DeltaXTag>{dx.as_value() / scale}; }
261template<
template<
typename>
typename T,
typename Scalar>
262inline constexpr T<DeltaYTag>
operator/(T<DeltaYTag>
const& dy, Scalar scale) {
return T<DeltaYTag>{dy.as_value() / scale}; }
265template<
template<
typename>
typename T>
266inline constexpr T<WidthTag>
as_width(T<DeltaXTag>
const& dx) {
return T<WidthTag>{dx.as_value()}; }
267template<
template<
typename>
typename T>
268inline constexpr T<HeightTag>
as_height(T<DeltaYTag>
const& dy) {
return T<HeightTag>{dy.as_value()}; }
269template<
template<
typename>
typename T>
270inline constexpr T<XTag>
as_x(T<DeltaXTag>
const& dx) {
return T<XTag>{dx.as_value()}; }
271template<
template<
typename>
typename T>
272inline constexpr T<YTag>
as_y(T<DeltaYTag>
const& dy) {
return T<YTag>{dy.as_value()}; }
273template<
template<
typename>
typename T>
274inline constexpr T<DeltaXTag>
as_delta(T<XTag>
const& x) {
return T<DeltaXTag>{x.as_value()}; }
275template<
template<
typename>
typename T>
276inline constexpr T<DeltaYTag>
as_delta(T<YTag>
const& y) {
return T<DeltaYTag>{y.as_value()}; }
277template<
template<
typename>
typename T>
278inline constexpr T<XTag>
as_x(T<WidthTag>
const& w) {
return T<XTag>{w.as_value()}; }
279template<
template<
typename>
typename T>
280inline constexpr T<YTag>
as_y(T<HeightTag>
const& h) {
return T<YTag>{h.as_value()}; }
281template<
template<
typename>
typename T>
282inline constexpr T<WidthTag>
as_width(T<XTag>
const& x) {
return T<WidthTag>{x.as_value()}; }
283template<
template<
typename>
typename T>
284inline constexpr T<HeightTag>
as_height(T<YTag>
const& y) {
return T<HeightTag>{y.as_value()}; }
285template<
template<
typename>
typename T>
286inline constexpr T<DeltaXTag>
as_delta(T<WidthTag>
const& w) {
return T<DeltaXTag>{w.as_value()}; }
287template<
template<
typename>
typename T>
288inline constexpr T<DeltaYTag>
as_delta(T<HeightTag>
const& h) {
return T<DeltaYTag>{h.as_value()}; }
290template<
typename Target,
typename Source>
291inline constexpr Target
dim_cast(Source s) {
return Target(s.as_value()); }
std::ostream & operator<<(std::ostream &out, W const &value)
Definition: dimensions_generic.h:142
typename Value< T >::template Wrapper< WidthTag > Width
Definition: dimensions_generic.h:148
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< YTag > as_y(T< DeltaYTag > const &dy)
Definition: dimensions_generic.h:272
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:162
T< DeltaXTag > & operator+=(T< DeltaXTag > &lhs, T< DeltaXTag > rhs)
Definition: dimensions_generic.h:170
constexpr T< HeightTag > as_height(T< DeltaYTag > const &dy)
Definition: dimensions_generic.h:268
T< DeltaXTag > & operator-=(T< DeltaXTag > &lhs, T< DeltaXTag > rhs)
Definition: dimensions_generic.h:174
constexpr T< XTag > as_x(T< DeltaXTag > const &dx)
Definition: dimensions_generic.h:270
constexpr Target dim_cast(Source s)
Definition: dimensions_generic.h:291
constexpr T< WidthTag > operator/(T< WidthTag > const &w, Scalar scale)
Definition: dimensions_generic.h:256
constexpr T< WidthTag > as_width(T< DeltaXTag > const &dx)
Definition: dimensions_generic.h:266
constexpr T< WidthTag > operator*(Scalar scale, T< WidthTag > const &w)
Definition: dimensions_generic.h:238
constexpr T< DeltaXTag > operator+(T< DeltaXTag > lhs, T< DeltaXTag > rhs)
Definition: dimensions_generic.h:158
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 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
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 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: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
Wrapper & operator=(Wrapper const &that) noexcept
Definition: dimensions_generic.h:77
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