2
3
4
5
6
7
8
9
10
11
12
13
14
15
17#ifndef MIR_GEOMETRY_DIMENSIONS_H_
18#define MIR_GEOMETRY_DIMENSIONS_H_
32template<
typename T,
typename Tag>
41 template <
typename Q = T>
42 constexpr typename std::enable_if<std::is_integral<Q>::value,
int>::
type as_int()
const
47 template <
typename Q = T>
48 constexpr typename std::enable_if<std::is_integral<Q>::value, uint32_t>::
type as_uint32_t()
const
66 constexpr Value(Value
const& that)
noexcept
72 explicit constexpr Value(Value<U, Tag>
const& value)
noexcept
73 :
value{
static_cast<T>(value.as_value())}
77 template<
typename U,
typename std::enable_if<std::is_scalar<U>::value,
bool>::type =
true>
78 explicit constexpr Value(U
const& value)
noexcept
79 :
value{
static_cast<T>(value)}
83 inline constexpr auto operator == (Value<T, Tag>
const& rhs)
const ->
bool
85 return value == rhs.as_value();
88 inline constexpr auto operator != (Value<T, Tag>
const& rhs)
const ->
bool
90 return value != rhs.as_value();
93 inline constexpr auto operator <= (Value<T, Tag>
const& rhs)
const ->
bool
95 return value <= rhs.as_value();
98 inline constexpr auto operator >= (Value<T, Tag>
const& rhs)
const ->
bool
100 return value >= rhs.as_value();
103 inline constexpr auto operator < (Value<T, Tag>
const& rhs)
const ->
bool
105 return value < rhs.as_value();
108 inline constexpr auto operator > (Value<T, Tag>
const& rhs)
const ->
bool
110 return value > rhs.as_value();
117template<
typename T,
typename Tag>
118std::ostream& operator<<(std::ostream& out, Value<T, Tag>
const& value)
120 out << value.as_value();
126inline constexpr DeltaX<
T>
operator+(DeltaX<T> lhs, DeltaX<T> rhs){
return DeltaX<T>(lhs.as_value() + rhs.as_value()); }
128inline constexpr DeltaY<
T>
operator+(DeltaY<T> lhs, DeltaY<T> rhs) {
return DeltaY<T>(lhs.as_value() + rhs.as_value()); }
130inline constexpr DeltaX<
T>
operator-(DeltaX<T> lhs, DeltaX<T> rhs) {
return DeltaX<T>(lhs.as_value() - rhs.as_value()); }
132inline constexpr DeltaY<
T>
operator-(DeltaY<T> lhs, DeltaY<T> rhs) {
return DeltaY<T>(lhs.as_value() - rhs.as_value()); }
134inline constexpr DeltaX<
T>
operator-(DeltaX<T> rhs) {
return DeltaX<T>(-rhs.as_value()); }
136inline constexpr DeltaY<
T>
operator-(DeltaY<T> rhs) {
return DeltaY<T>(-rhs.as_value()); }
138inline DeltaX<
T>&
operator+=(DeltaX<T>& lhs, DeltaX<T> rhs) {
return lhs = lhs + rhs; }
140inline DeltaY<
T>&
operator+=(DeltaY<T>& lhs, DeltaY<T> rhs) {
return lhs = lhs + rhs; }
142inline DeltaX<
T>&
operator-=(DeltaX<T>& lhs, DeltaX<T> rhs) {
return lhs = lhs - rhs; }
144inline DeltaY<
T>&
operator-=(DeltaY<T>& lhs, DeltaY<T> rhs) {
return lhs = lhs - rhs; }
148inline constexpr X<
T>
operator+(X<T> lhs, DeltaX<T> rhs) {
return X<T>(lhs.as_value() + rhs.as_value()); }
150inline constexpr Y<
T>
operator+(Y<T> lhs, DeltaY<T> rhs) {
return Y<T>(lhs.as_value() + rhs.as_value()); }
152inline constexpr X<
T>
operator-(X<T> lhs, DeltaX<T> rhs) {
return X<T>(lhs.as_value() - rhs.as_value()); }
154inline constexpr Y<
T>
operator-(Y<T> lhs, DeltaY<T> rhs) {
return Y<T>(lhs.as_value() - rhs.as_value()); }
156inline X<
T>&
operator+=(X<T>& lhs, DeltaX<T> rhs) {
return lhs = lhs + rhs; }
158inline Y<
T>&
operator+=(Y<T>& lhs, DeltaY<T> rhs) {
return lhs = lhs + rhs; }
160inline X<
T>&
operator-=(X<T>& lhs, DeltaX<T> rhs) {
return lhs = lhs - rhs; }
162inline Y<
T>&
operator-=(Y<T>& lhs, DeltaY<T> rhs) {
return lhs = lhs - rhs; }
166inline constexpr Width<
T>
operator+(Width<T> lhs, DeltaX<T> rhs) {
return Width<T>(lhs.as_value() + rhs.as_value()); }
168inline constexpr Height<
T>
operator+(Height<T> lhs, DeltaY<T> rhs) {
return Height<T>(lhs.as_value() + rhs.as_value()); }
170inline constexpr Width<
T>
operator-(Width<T> lhs, DeltaX<T> rhs) {
return Width<T>(lhs.as_value() - rhs.as_value()); }
172inline constexpr Height<
T>
operator-(Height<T> lhs, DeltaY<T> rhs) {
return Height<T>(lhs.as_value() - rhs.as_value()); }
174inline Width<
T>&
operator+=(Width<T>& lhs, DeltaX<T> rhs) {
return lhs = lhs + rhs; }
176inline Height<
T>&
operator+=(Height<T>& lhs, DeltaY<T> rhs) {
return lhs = lhs + rhs; }
178inline Width<
T>&
operator-=(Width<T>& lhs, DeltaX<T> rhs) {
return lhs = lhs - rhs; }
180inline Height<
T>&
operator-=(Height<T>& lhs, DeltaY<T> rhs) {
return lhs = lhs - rhs; }
184inline constexpr Width<
T>
operator+(Width<T> lhs, Width<T> rhs) {
return Width<T>(lhs.as_value() + rhs.as_value()); }
186inline constexpr Height<
T>
operator+(Height<T> lhs, Height<T> rhs) {
return Height<T>(lhs.as_value() + rhs.as_value()); }
188inline Width<
T>&
operator+=(Width<T>& lhs, Width<T> rhs) {
return lhs = lhs + rhs; }
190inline Height<
T>&
operator+=(Height<T>& lhs, Height<T> rhs) {
return lhs = lhs + rhs; }
194inline constexpr DeltaX<
T>
operator-(X<T> lhs, X<T> rhs) {
return DeltaX<T>(lhs.as_value() - rhs.as_value()); }
196inline constexpr DeltaY<
T>
operator-(Y<T> lhs, Y<T> rhs) {
return DeltaY<T>(lhs.as_value() - rhs.as_value()); }
200inline constexpr DeltaX<
T>
operator-(Width<T> lhs, Width<T> rhs) {
return DeltaX<T>(lhs.as_value() - rhs.as_value()); }
202inline constexpr DeltaY<
T>
operator-(Height<T> lhs, Height<T> rhs) {
return DeltaY<T>(lhs.as_value() - rhs.as_value()); }
205template<
typename T,
typename Scalar>
206inline constexpr Width<
T>
operator*(Scalar scale, Width<T>
const& w) {
return Width<T>{scale*w.as_value()}; }
207template<
typename T,
typename Scalar>
208inline constexpr Height<
T>
operator*(Scalar scale, Height<T>
const& h) {
return Height<T>{scale*h.as_value()}; }
209template<
typename T,
typename Scalar>
210inline constexpr DeltaX<
T>
operator*(Scalar scale, DeltaX<T>
const& dx) {
return DeltaX<T>{scale*dx.as_value()}; }
211template<
typename T,
typename Scalar>
212inline constexpr DeltaY<
T>
operator*(Scalar scale, DeltaY<T>
const& dy) {
return DeltaY<T>{scale*dy.as_value()}; }
213template<
typename T,
typename Scalar>
214inline constexpr Width<
T>
operator*(Width<T>
const& w, Scalar scale) {
return scale*w; }
215template<
typename T,
typename Scalar>
216inline constexpr Height<
T>
operator*(Height<T>
const& h, Scalar scale) {
return scale*h; }
217template<
typename T,
typename Scalar>
218inline constexpr DeltaX<
T>
operator*(DeltaX<T>
const& dx, Scalar scale) {
return scale*dx; }
219template<
typename T,
typename Scalar>
220inline constexpr DeltaY<
T>
operator*(DeltaY<T>
const& dy, Scalar scale) {
return scale*dy; }
223template<
typename T,
typename Scalar>
224inline constexpr Width<
T>
operator/(Width<T>
const& w, Scalar scale) {
return Width<T>{w.as_value() / scale}; }
225template<
typename T,
typename Scalar>
226inline constexpr Height<
T>
operator/(Height<T>
const& h, Scalar scale) {
return Height<T>{h.as_value() / scale}; }
227template<
typename T,
typename Scalar>
228inline constexpr DeltaX<
T>
operator/(DeltaX<T>
const& dx, Scalar scale) {
return DeltaX<T>{dx.as_value() / scale}; }
229template<
typename T,
typename Scalar>
230inline constexpr DeltaY<
T>
operator/(DeltaY<T>
const& dy, Scalar scale) {
return DeltaY<T>{dy.as_value() / scale}; }
235inline constexpr generic::
Width<
T>
as_width(generic::DeltaX<T>
const& dx) {
return generic::Width<T>{dx.as_value()}; }
239inline constexpr generic::
X<
T>
as_x(generic::DeltaX<T>
const& dx) {
return generic::X<T>{dx.as_value()}; }
241inline constexpr generic::
Y<
T>
as_y(generic::DeltaY<T>
const& dy) {
return generic::Y<T>{dy.as_value()}; }
247inline constexpr generic::
X<
T>
as_x(generic::Width<T>
const& w) {
return generic::X<T>{w.as_value()}; }
249inline constexpr generic::
Y<
T>
as_y(generic::Height<T>
const& h) {
return generic::Y<T>{h.as_value()}; }
DeltaX< T > & operator-=(DeltaX< T > &lhs, DeltaX< T > rhs)
Definition dimensions.h:142
constexpr Width< T > operator*(Width< T > const &w, Scalar scale)
Definition dimensions.h:214
constexpr Width< T > operator/(Width< T > const &w, Scalar scale)
Definition dimensions.h:224
constexpr DeltaX< T > operator+(DeltaX< T > lhs, DeltaX< T > rhs)
Definition dimensions.h:126
DeltaX< T > & operator+=(DeltaX< T > &lhs, DeltaX< T > rhs)
Definition dimensions.h:138
constexpr DeltaX< T > operator-(DeltaX< T > rhs)
Definition dimensions.h:134
constexpr Width< T > operator*(Scalar scale, Width< T > const &w)
Definition dimensions.h:206
constexpr DeltaX< T > operator-(DeltaX< T > lhs, DeltaX< T > rhs)
Definition dimensions.h:130
Basic geometry types. Types for dimensions, displacements, etc. and the operations that they support.
Definition size.h:27
constexpr generic::DeltaX< T > as_delta(generic::X< T > const &x)
Definition dimensions.h:243
constexpr generic::X< T > as_x(generic::DeltaX< T > const &dx)
Definition dimensions.h:239
constexpr generic::Width< T > as_width(generic::DeltaX< T > const &dx)
Definition dimensions.h:235
constexpr generic::Height< T > as_height(generic::DeltaY< T > const &dy)
Definition dimensions.h:237
constexpr generic::Y< T > as_y(generic::DeltaY< T > const &dy)
Definition dimensions.h:241
constexpr Value(Value const &that) noexcept
Definition dimensions.h:66
constexpr T as_value() const noexcept
Definition dimensions.h:53
constexpr auto operator<(Value< T, Tag > const &rhs) const -> bool
Definition dimensions.h:103
constexpr auto operator>=(Value< T, Tag > const &rhs) const -> bool
Definition dimensions.h:98
constexpr Value() noexcept
Definition dimensions.h:58
constexpr std::enable_if< std::is_integral< Q >::value, uint32_t >::type as_uint32_t() const
Definition dimensions.h:48
constexpr auto operator<=(Value< T, Tag > const &rhs) const -> bool
Definition dimensions.h:93
Value & operator=(Value const &that) noexcept
Definition dimensions.h:60
constexpr Value(Value< U, Tag > const &value) noexcept
Definition dimensions.h:72
constexpr auto operator!=(Value< T, Tag > const &rhs) const -> bool
Definition dimensions.h:88
constexpr auto operator>(Value< T, Tag > const &rhs) const -> bool
Definition dimensions.h:108
constexpr std::enable_if< std::is_integral< Q >::value, int >::type as_int() const
Definition dimensions.h:42
constexpr Value(U const &value) noexcept
Definition dimensions.h:78
constexpr auto operator==(Value< T, Tag > const &rhs) const -> bool
Definition dimensions.h:83
T value
Definition dimensions.h:114