OGLplus  (0.59.0) a C++ wrapper for rendering APIs

scaled_unit.hpp
Go to the documentation of this file.
1 
9 #ifndef EAGINE_UNITS_SCALED_UNIT_HPP
10 #define EAGINE_UNITS_SCALED_UNIT_HPP
11 
12 // clang-format off
13 #include "dimension.hpp"
14 #include "base_scaled_unit.hpp"
15 #include "custom_unit.hpp"
16 #include "unit.hpp"
17 #include <cmath>
18 // clang-format on
19 
20 namespace eagine::units {
21 
22 template <typename Dims, typename Scales, typename System>
23 struct scaled_dim_unit_conv {
24  using type = scaled_dim_unit_conv;
25 
26  using _impl = bits::_sc_unit_sc_hlp<Scales, System>;
27  using _ndp = bits::dim_pow<nothing_t, 0>;
28 
29  template <typename T>
30  static constexpr auto to_base(T v) {
31  return _impl::_hlp(std::true_type(), v, bits::dims<_ndp, Dims>());
32  }
33 
34  template <typename T>
35  static constexpr auto from_base(T v) {
36  return _impl::_hlp(std::false_type(), v, bits::dims<_ndp, Dims>());
37  }
38 };
39 
40 // make_scaled_base_dim_unit
41 template <typename BaseScaledUnit, typename System>
42 struct make_scaled_base_dim_unit;
43 
44 template <typename BaseScaledUnit, typename System>
45 using make_scaled_base_dim_unit_t =
46  typename make_scaled_base_dim_unit<BaseScaledUnit, System>::type;
47 
48 template <typename Scale, typename BaseUnit, typename System>
49 struct make_scaled_base_dim_unit<base::scaled_unit<Scale, BaseUnit>, System>
50  : scaled_dim_unit<
51  dimension<dimension_of_t<BaseUnit>, 1>,
52  bits::unit_scales<bits::uni_sca<BaseUnit, Scale>, nothing_t>,
53  System> {};
54 
55 template <typename Scale, typename UnitScales>
56 using add_none_unit_scale_t =
57  bits::unit_scales<bits::uni_sca<nothing_t, Scale>, UnitScales>;
58 
59 // make_scaled_unit
60 template <typename Scale, typename Unit>
61 struct make_scaled_unit;
62 
63 template <typename Scale, typename Unit>
64 using make_scaled_unit_t = typename make_scaled_unit<Scale, Unit>::type;
65 
66 template <typename Scale, typename Dimension, typename System>
67 struct make_scaled_unit<Scale, unit<Dimension, System>>
68  : scaled_dim_unit<Dimension, add_none_unit_scale_t<Scale, nothing_t>, System> {
69 };
70 
71 // value_conv
72 template <typename D, typename AS, typename US, typename System>
73 struct value_conv<
74  scaled_dim_unit<D, add_none_unit_scale_t<AS, US>, System>,
75  unit<D, System>> {
76  template <typename T>
77  constexpr auto operator()(T v) const {
78  return AS::to_base(v);
79  }
80 };
81 
82 template <typename D, typename AS, typename US, typename System>
83 struct value_conv<
84  unit<D, System>,
85  scaled_dim_unit<D, add_none_unit_scale_t<AS, US>, System>> {
86  template <typename T>
87  constexpr auto operator()(T v) const {
88  return AS::from_base(v);
89  }
90 };
91 
92 template <typename D, typename AS1, typename AS2, typename US, typename System>
93 struct value_conv<
94  scaled_dim_unit<D, add_none_unit_scale_t<AS1, US>, System>,
95  scaled_dim_unit<D, add_none_unit_scale_t<AS2, US>, System>> {
96  template <typename T>
97  constexpr auto operator()(T v) const {
98  return AS2::from_base(AS1::to_base(v));
99  }
100 };
101 
102 // lit_result
103 template <typename D, typename S>
104 struct lit_result<unit<D, S>>
105  : scaled_dim_unit<D, bits::unit_scales<nothing_t, nothing_t>, S> {};
106 
107 template <typename D1, typename D2, typename US1, typename US2, typename S>
108 struct mul_l_operand<scaled_dim_unit<D1, US1, S>, scaled_dim_unit<D2, US2, S>>
109  : scaled_dim_unit<D1, bits::merge_t<US1, US2>, S> {};
110 
111 template <typename D1, typename D2, typename US1, typename US2, typename S>
112 struct mul_r_operand<scaled_dim_unit<D1, US1, S>, scaled_dim_unit<D2, US2, S>>
113  : scaled_dim_unit<D2, bits::merge_t<US1, US2>, S> {};
114 
115 template <typename D1, typename D2, typename US1, typename US2, typename S>
116 struct mul_result<scaled_dim_unit<D1, US1, S>, scaled_dim_unit<D2, US2, S>>
117  : scaled_dim_unit<bits::dim_add_t<D1, D2>, bits::merge_t<US1, US2>, S> {};
118 
119 template <typename D1, typename D2, typename US1, typename US2, typename S>
120 struct div_result<scaled_dim_unit<D1, US1, S>, scaled_dim_unit<D2, US2, S>>
121  : scaled_dim_unit<bits::dim_sub_t<D1, D2>, bits::merge_t<US1, US2>, S> {};
122 
123 } // namespace eagine::units
124 
125 #endif // EAGINE_UNITS_SCALED_UNIT_HPP

Copyright © 2015-2021 Matúš Chochlík.
<chochlik -at -gmail.com>
Documentation generated on Tue Apr 13 2021 by Doxygen (version 1.8.17).