19 #ifndef MIR_GEOMETRY_DIMENSIONS_H_ 20 #define MIR_GEOMETRY_DIMENSIONS_H_ 35 template<
typename Tag>
45 template<
typename AnyInteger>
46 explicit constexpr
IntWrapper(AnyInteger value) : value(static_cast<ValueType>(value)) {}
50 return (uint32_t)value;
62 template<
typename Tag>
63 std::ostream& operator<<(std::ostream& out, IntWrapper<Tag>
const& value)
65 out << value.as_int();
69 template<
typename Tag>
75 template<
typename Tag>
81 template<
typename Tag>
82 inline constexpr
bool operator <= (IntWrapper<Tag>
const& lhs,
IntWrapper<Tag> const& rhs)
84 return lhs.
as_int() <= rhs.as_int();
87 template<
typename Tag>
93 template<
typename Tag>
94 inline constexpr
bool operator < (IntWrapper<Tag>
const& lhs,
IntWrapper<Tag> const& rhs)
96 return lhs.
as_int() < rhs.as_int();
99 template<
typename Tag>
121 inline DeltaX&
operator+=(DeltaX& lhs, DeltaX rhs) {
return lhs = lhs + rhs; }
122 inline DeltaY&
operator+=(DeltaY& lhs, DeltaY rhs) {
return lhs = lhs + rhs; }
123 inline DeltaX&
operator-=(DeltaX& lhs, DeltaX rhs) {
return lhs = lhs - rhs; }
124 inline DeltaY&
operator-=(DeltaY& lhs, DeltaY rhs) {
return lhs = lhs - rhs; }
131 inline X&
operator+=(X& lhs, DeltaX rhs) {
return lhs = lhs + rhs; }
132 inline Y&
operator+=(Y& lhs, DeltaY rhs) {
return lhs = lhs + rhs; }
133 inline X&
operator-=(X& lhs, DeltaX rhs) {
return lhs = lhs - rhs; }
134 inline Y&
operator-=(Y& lhs, DeltaY rhs) {
return lhs = lhs - rhs; }
141 inline Width&
operator+=(Width& lhs, DeltaX rhs) {
return lhs = lhs + rhs; }
142 inline Height&
operator+=(Height& lhs, DeltaY rhs) {
return lhs = lhs + rhs; }
143 inline Width&
operator-=(Width& lhs, DeltaX rhs) {
return lhs = lhs - rhs; }
144 inline Height&
operator-=(Height& lhs, DeltaY rhs) {
return lhs = lhs - rhs; }
149 inline Width&
operator+=(Width& lhs, Width rhs) {
return lhs = lhs + rhs; }
150 inline Height&
operator+=(Height& lhs, Height rhs) {
return lhs = lhs + rhs; }
161 template<
typename Scalar>
162 inline constexpr Width
operator*(Scalar scale, Width
const& w) {
return Width{scale*w.
as_int()}; }
163 template<
typename Scalar>
164 inline constexpr Height
operator*(Scalar scale, Height
const& h) {
return Height{scale*h.
as_int()}; }
165 template<
typename Scalar>
166 inline constexpr DeltaX
operator*(Scalar scale, DeltaX
const& dx) {
return DeltaX{scale*dx.
as_int()}; }
167 template<
typename Scalar>
168 inline constexpr DeltaY
operator*(Scalar scale, DeltaY
const& dy) {
return DeltaY{scale*dy.
as_int()}; }
169 template<
typename Scalar>
170 inline constexpr Width
operator*(Width
const& w, Scalar scale) {
return scale*w; }
171 template<
typename Scalar>
172 inline constexpr Height
operator*(Height
const& h, Scalar scale) {
return scale*h; }
173 template<
typename Scalar>
174 inline constexpr DeltaX
operator*(DeltaX
const& dx, Scalar scale) {
return scale*dx; }
175 template<
typename Scalar>
176 inline constexpr DeltaY
operator*(DeltaY
const& dy, Scalar scale) {
return scale*dy; }
179 template<
typename Scalar>
180 inline constexpr Width
operator/(Width
const& w, Scalar scale) {
return Width{w.
as_int() / scale}; }
181 template<
typename Scalar>
182 inline constexpr Height
operator/(Height
const& h, Scalar scale) {
return Height{h.
as_int() / scale}; }
183 template<
typename Scalar>
184 inline constexpr DeltaX
operator/(DeltaX
const& dx, Scalar scale) {
return DeltaX{dx.
as_int() / scale}; }
185 template<
typename Scalar>
186 inline constexpr DeltaY
operator/(DeltaY
const& dy, Scalar scale) {
return DeltaY{dy.
as_int() / scale}; }
191 inline constexpr X
as_x(DeltaX
const& dx) {
return X{dx.
as_int()}; }
192 inline constexpr Y
as_y(DeltaY
const& dy) {
return Y{dy.
as_int()}; }
195 inline constexpr X
as_x(Width
const& w) {
return X{w.
as_int()}; }
196 inline constexpr Y
as_y(Height
const& h) {
return Y{h.
as_int()}; }
202 template<
typename Target,
typename Source>
203 inline constexpr Target
dim_cast(Source s) {
return Target(s.as_int()); }
Definition: splash_session.h:24
constexpr Y as_y(DeltaY const &dy)
Definition: dimensions.h:192
int ValueType
Definition: dimensions.h:39
constexpr uint32_t as_uint32_t() const
Definition: dimensions.h:48
constexpr int as_int() const
Definition: dimensions.h:53
DeltaX & operator-=(DeltaX &lhs, DeltaX rhs)
Definition: dimensions.h:123
DeltaX & operator+=(DeltaX &lhs, DeltaX rhs)
Definition: dimensions.h:121
detail::IntWrapper< struct DeltaXTag > DeltaX
Definition: dimensions.h:113
detail::IntWrapper< struct YTag > Y
Definition: dimensions.h:112
detail::IntWrapper< struct WidthTag > Width
Definition: dimensions.h:106
constexpr DeltaX operator-(DeltaX lhs, DeltaX rhs)
Definition: dimensions.h:119
constexpr Height as_height(DeltaY const &dy)
Definition: dimensions.h:190
constexpr Width operator/(Width const &w, Scalar scale)
Definition: dimensions.h:180
constexpr Target dim_cast(Source s)
Definition: dimensions.h:203
constexpr X as_x(DeltaX const &dx)
Definition: dimensions.h:191
constexpr bool operator>(IntWrapper< Tag > const &lhs, IntWrapper< Tag > const &rhs)
Definition: dimensions.h:100
constexpr bool operator==(IntWrapper< Tag > const &lhs, IntWrapper< Tag > const &rhs)
Definition: dimensions.h:70
constexpr DeltaX as_delta(X const &x)
Definition: dimensions.h:193
constexpr DeltaX operator+(DeltaX lhs, DeltaX rhs)
Definition: dimensions.h:117
constexpr Width as_width(DeltaX const &dx)
Definition: dimensions.h:189
constexpr Width operator*(Scalar scale, Width const &w)
Definition: dimensions.h:162
constexpr bool operator!=(IntWrapper< Tag > const &lhs, IntWrapper< Tag > const &rhs)
Definition: dimensions.h:76
constexpr IntWrapper(AnyInteger value)
Definition: dimensions.h:46
constexpr IntWrapper()
Definition: dimensions.h:41
detail::IntWrapper< struct StrideTag > Stride
Definition: dimensions.h:109
IntWrapper & operator=(IntWrapper const &that)=default
detail::IntWrapper< struct XTag > X
Definition: dimensions.h:111
Definition: dimensions.h:36
constexpr bool operator>=(IntWrapper< Tag > const &lhs, IntWrapper< Tag > const &rhs)
Definition: dimensions.h:88
detail::IntWrapper< struct HeightTag > Height
Definition: dimensions.h:107
detail::IntWrapper< struct DeltaYTag > DeltaY
Definition: dimensions.h:114