19 #ifndef MIR_GEOMETRY_DIMENSIONS_GENERIC_H_
20 #define MIR_GEOMETRY_DIMENSIONS_GENERIC_H_
23 #include <type_traits>
58 template<
typename Tag>
63 template<
typename OtherTag>
66 template <
typename Q = T>
67 constexpr
typename std::enable_if<std::is_integral<Q>::value,
int>::type
as_int()
const
90 template<typename W, typename std::enable_if<std::is_same<typename W::TagType, Tag>::value,
bool>::type =
true>
96 template<typename U, typename std::enable_if<std::is_scalar<U>::value,
bool>::type =
true>
104 return value == rhs.as_value();
109 return value != rhs.as_value();
114 return value <= rhs.as_value();
119 return value >= rhs.as_value();
124 return value < rhs.as_value();
129 return value > rhs.as_value();
140 template<
class GeometricType,
typename Tag>
143 template<typename W, typename std::enable_if<std::is_base_of<detail::ValueWrapperBase, W>::value,
bool>::type =
true>
146 out << value.as_value();
159 template<
template<
typename>
typename T>
160 inline constexpr T<DeltaXTag>
operator+(T<DeltaXTag> lhs, T<DeltaXTag> rhs){
return T<DeltaXTag>(lhs.as_value() + rhs.as_value()); }
161 template<
template<
typename>
typename T>
162 inline constexpr T<DeltaYTag>
operator+(T<DeltaYTag> lhs, T<DeltaYTag> rhs) {
return T<DeltaYTag>(lhs.as_value() + rhs.as_value()); }
163 template<
template<
typename>
typename T>
164 inline constexpr T<DeltaXTag>
operator-(T<DeltaXTag> lhs, T<DeltaXTag> rhs) {
return T<DeltaXTag>(lhs.as_value() - rhs.as_value()); }
165 template<
template<
typename>
typename T>
166 inline constexpr T<DeltaYTag>
operator-(T<DeltaYTag> lhs, T<DeltaYTag> rhs) {
return T<DeltaYTag>(lhs.as_value() - rhs.as_value()); }
167 template<
template<
typename>
typename T>
168 inline constexpr T<DeltaXTag>
operator-(T<DeltaXTag> rhs) {
return T<DeltaXTag>(-rhs.as_value()); }
169 template<
template<
typename>
typename T>
170 inline constexpr T<DeltaYTag>
operator-(T<DeltaYTag> rhs) {
return T<DeltaYTag>(-rhs.as_value()); }
171 template<
template<
typename>
typename T>
172 inline T<DeltaXTag>&
operator+=(T<DeltaXTag>& lhs, T<DeltaXTag> rhs) {
return lhs = lhs + rhs; }
173 template<
template<
typename>
typename T>
174 inline T<DeltaYTag>&
operator+=(T<DeltaYTag>& lhs, T<DeltaYTag> rhs) {
return lhs = lhs + rhs; }
175 template<
template<
typename>
typename T>
176 inline T<DeltaXTag>&
operator-=(T<DeltaXTag>& lhs, T<DeltaXTag> rhs) {
return lhs = lhs - rhs; }
177 template<
template<
typename>
typename T>
178 inline T<DeltaYTag>&
operator-=(T<DeltaYTag>& lhs, T<DeltaYTag> rhs) {
return lhs = lhs - rhs; }
181 template<
template<
typename>
typename T>
182 inline constexpr T<XTag>
operator+(T<XTag> lhs, T<DeltaXTag> rhs) {
return T<XTag>(lhs.as_value() + rhs.as_value()); }
183 template<
template<
typename>
typename T>
184 inline constexpr T<YTag>
operator+(T<YTag> lhs, T<DeltaYTag> rhs) {
return T<YTag>(lhs.as_value() + rhs.as_value()); }
185 template<
template<
typename>
typename T>
186 inline constexpr T<XTag>
operator-(T<XTag> lhs, T<DeltaXTag> rhs) {
return T<XTag>(lhs.as_value() - rhs.as_value()); }
187 template<
template<
typename>
typename T>
188 inline constexpr T<YTag>
operator-(T<YTag> lhs, T<DeltaYTag> rhs) {
return T<YTag>(lhs.as_value() - rhs.as_value()); }
189 template<
template<
typename>
typename T>
190 inline T<XTag>&
operator+=(T<XTag>& lhs, T<DeltaXTag> rhs) {
return lhs = lhs + rhs; }
191 template<
template<
typename>
typename T>
192 inline T<YTag>&
operator+=(T<YTag>& lhs, T<DeltaYTag> rhs) {
return lhs = lhs + rhs; }
193 template<
template<
typename>
typename T>
194 inline T<XTag>&
operator-=(T<XTag>& lhs, T<DeltaXTag> rhs) {
return lhs = lhs - rhs; }
195 template<
template<
typename>
typename T>
196 inline T<YTag>&
operator-=(T<YTag>& lhs, T<DeltaYTag> rhs) {
return lhs = lhs - rhs; }
199 template<
template<
typename>
typename T>
200 inline constexpr T<WidthTag>
operator+(T<WidthTag> lhs, T<DeltaXTag> rhs) {
return T<WidthTag>(lhs.as_value() + rhs.as_value()); }
201 template<
template<
typename>
typename T>
202 inline constexpr T<HeightTag>
operator+(T<HeightTag> lhs, T<DeltaYTag> rhs) {
return T<HeightTag>(lhs.as_value() + rhs.as_value()); }
203 template<
template<
typename>
typename T>
204 inline constexpr T<WidthTag>
operator-(T<WidthTag> lhs, T<DeltaXTag> rhs) {
return T<WidthTag>(lhs.as_value() - rhs.as_value()); }
205 template<
template<
typename>
typename T>
206 inline constexpr T<HeightTag>
operator-(T<HeightTag> lhs, T<DeltaYTag> rhs) {
return T<HeightTag>(lhs.as_value() - rhs.as_value()); }
207 template<
template<
typename>
typename T>
208 inline T<WidthTag>&
operator+=(T<WidthTag>& lhs, T<DeltaXTag> rhs) {
return lhs = lhs + rhs; }
209 template<
template<
typename>
typename T>
210 inline T<HeightTag>&
operator+=(T<HeightTag>& lhs, T<DeltaYTag> rhs) {
return lhs = lhs + rhs; }
211 template<
template<
typename>
typename T>
212 inline T<WidthTag>&
operator-=(T<WidthTag>& lhs, T<DeltaXTag> rhs) {
return lhs = lhs - rhs; }
213 template<
template<
typename>
typename T>
214 inline T<HeightTag>&
operator-=(T<HeightTag>& lhs, T<DeltaYTag> rhs) {
return lhs = lhs - rhs; }
217 template<
template<
typename>
typename T>
218 inline constexpr T<WidthTag>
operator+(T<WidthTag> lhs, T<WidthTag> rhs) {
return T<WidthTag>(lhs.as_value() + rhs.as_value()); }
219 template<
template<
typename>
typename T>
220 inline constexpr T<HeightTag>
operator+(T<HeightTag> lhs, T<HeightTag> rhs) {
return T<HeightTag>(lhs.as_value() + rhs.as_value()); }
221 template<
template<
typename>
typename T>
222 inline T<WidthTag>&
operator+=(T<WidthTag>& lhs, T<WidthTag> rhs) {
return lhs = lhs + rhs; }
223 template<
template<
typename>
typename T>
224 inline T<HeightTag>&
operator+=(T<HeightTag>& lhs, T<HeightTag> rhs) {
return lhs = lhs + rhs; }
227 template<
template<
typename>
typename T>
228 inline constexpr T<DeltaXTag>
operator-(T<XTag> lhs, T<XTag> rhs) {
return T<DeltaXTag>(lhs.as_value() - rhs.as_value()); }
229 template<
template<
typename>
typename T>
230 inline constexpr T<DeltaYTag>
operator-(T<YTag> lhs, T<YTag> rhs) {
return T<DeltaYTag>(lhs.as_value() - rhs.as_value()); }
233 template<
template<
typename>
typename T>
234 inline constexpr T<DeltaXTag>
operator-(T<WidthTag> lhs, T<WidthTag> rhs) {
return T<DeltaXTag>(lhs.as_value() - rhs.as_value()); }
235 template<
template<
typename>
typename T>
236 inline constexpr T<DeltaYTag>
operator-(T<HeightTag> lhs, T<HeightTag> rhs) {
return T<DeltaYTag>(lhs.as_value() - rhs.as_value()); }
239 template<
template<
typename>
typename T,
typename Scalar>
240 inline constexpr T<WidthTag>
operator*(Scalar scale, T<WidthTag>
const& w) {
return T<WidthTag>{scale*w.as_value()}; }
241 template<
template<
typename>
typename T,
typename Scalar>
242 inline constexpr T<HeightTag>
operator*(Scalar scale, T<HeightTag>
const& h) {
return T<HeightTag>{scale*h.as_value()}; }
243 template<
template<
typename>
typename T,
typename Scalar>
244 inline constexpr T<DeltaXTag>
operator*(Scalar scale, T<DeltaXTag>
const& dx) {
return T<DeltaXTag>{scale*dx.as_value()}; }
245 template<
template<
typename>
typename T,
typename Scalar>
246 inline constexpr T<DeltaYTag>
operator*(Scalar scale, T<DeltaYTag>
const& dy) {
return T<DeltaYTag>{scale*dy.as_value()}; }
247 template<
template<
typename>
typename T,
typename Scalar>
248 inline constexpr T<WidthTag>
operator*(T<WidthTag>
const& w, Scalar scale) {
return scale*w; }
249 template<
template<
typename>
typename T,
typename Scalar>
250 inline constexpr T<HeightTag>
operator*(T<HeightTag>
const& h, Scalar scale) {
return scale*h; }
251 template<
template<
typename>
typename T,
typename Scalar>
252 inline constexpr T<DeltaXTag>
operator*(T<DeltaXTag>
const& dx, Scalar scale) {
return scale*dx; }
253 template<
template<
typename>
typename T,
typename Scalar>
254 inline constexpr T<DeltaYTag>
operator*(T<DeltaYTag>
const& dy, Scalar scale) {
return scale*dy; }
257 template<
template<
typename>
typename T,
typename Scalar>
258 inline constexpr T<WidthTag>
operator/(T<WidthTag>
const& w, Scalar scale) {
return T<WidthTag>{w.as_value() / scale}; }
259 template<
template<
typename>
typename T,
typename Scalar>
260 inline constexpr T<HeightTag>
operator/(T<HeightTag>
const& h, Scalar scale) {
return T<HeightTag>{h.as_value() / scale}; }
261 template<
template<
typename>
typename T,
typename Scalar>
262 inline constexpr T<DeltaXTag>
operator/(T<DeltaXTag>
const& dx, Scalar scale) {
return T<DeltaXTag>{dx.as_value() / scale}; }
263 template<
template<
typename>
typename T,
typename Scalar>
264 inline constexpr T<DeltaYTag>
operator/(T<DeltaYTag>
const& dy, Scalar scale) {
return T<DeltaYTag>{dy.as_value() / scale}; }
267 template<
template<
typename>
typename T>
268 inline constexpr T<WidthTag>
as_width(T<DeltaXTag>
const& dx) {
return T<WidthTag>{dx.as_value()}; }
269 template<
template<
typename>
typename T>
270 inline constexpr T<HeightTag>
as_height(T<DeltaYTag>
const& dy) {
return T<HeightTag>{dy.as_value()}; }
271 template<
template<
typename>
typename T>
272 inline constexpr T<XTag>
as_x(T<DeltaXTag>
const& dx) {
return T<XTag>{dx.as_value()}; }
273 template<
template<
typename>
typename T>
274 inline constexpr T<YTag>
as_y(T<DeltaYTag>
const& dy) {
return T<YTag>{dy.as_value()}; }
275 template<
template<
typename>
typename T>
276 inline constexpr T<DeltaXTag>
as_delta(T<XTag>
const& x) {
return T<DeltaXTag>{x.as_value()}; }
277 template<
template<
typename>
typename T>
278 inline constexpr T<DeltaYTag>
as_delta(T<YTag>
const& y) {
return T<DeltaYTag>{y.as_value()}; }
279 template<
template<
typename>
typename T>
280 inline constexpr T<XTag>
as_x(T<WidthTag>
const& w) {
return T<XTag>{w.as_value()}; }
281 template<
template<
typename>
typename T>
282 inline constexpr T<YTag>
as_y(T<HeightTag>
const& h) {
return T<YTag>{h.as_value()}; }
283 template<
template<
typename>
typename T>
284 inline constexpr T<WidthTag>
as_width(T<XTag>
const& x) {
return T<WidthTag>{x.as_value()}; }
285 template<
template<
typename>
typename T>
286 inline constexpr T<HeightTag>
as_height(T<YTag>
const& y) {
return T<HeightTag>{y.as_value()}; }
287 template<
template<
typename>
typename T>
288 inline constexpr T<DeltaXTag>
as_delta(T<WidthTag>
const& w) {
return T<DeltaXTag>{w.as_value()}; }
289 template<
template<
typename>
typename T>
290 inline constexpr T<DeltaYTag>
as_delta(T<HeightTag>
const& h) {
return T<DeltaYTag>{h.as_value()}; }
292 template<
typename Target,
typename Source>
293 inline constexpr Target
dim_cast(Source s) {
return Target(s.as_value()); }
297 #endif // MIR_GEOMETRY_DIMENSIONS_GENERIC_H_