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

temperature.hpp
Go to the documentation of this file.
1 
9 #ifndef EAGINE_UNITS_UNIT_SI_TEMPERATURE_HPP
10 #define EAGINE_UNITS_UNIT_SI_TEMPERATURE_HPP
11 
12 #include "common.hpp"
13 
14 namespace eagine::units {
15 namespace base {
16 
17 // kelvin
18 struct kelvin : unit<temperature, kelvin> {};
19 
20 } // namespace base
21 
22 template <>
23 struct name_of<base::kelvin> {
24  static constexpr const char mp_str[] = "kelvin";
25 };
26 template <>
27 struct symbol_of<base::kelvin> {
28  static constexpr const char mp_str[] = "K";
29 };
30 
31 // si::base_unit<temperature>
32 template <>
33 struct si::base_unit<base::temperature> : base::kelvin {};
34 
35 // kelvin
36 using kelvin = unit<temperature, si>;
37 
38 // derived
39 using millikelvin =
40  make_scaled_base_dim_unit_t<base::scaled_unit<scales::milli, base::kelvin>, si>;
41 
42 using kilokelvin =
43  make_scaled_base_dim_unit_t<base::scaled_unit<scales::kilo, base::kelvin>, si>;
44 
45 // celsius
46 struct celsius_conv {
47  template <typename T>
48  static constexpr auto to_base(T v) noexcept -> T {
49  return T(v + 273.15F);
50  }
51 
52  template <typename T>
53  static constexpr auto from_base(T v) noexcept -> T {
54  return T(v - 273.15F);
55  }
56 };
57 
58 using degree_celsius = make_custom_unit_t<celsius_conv, kelvin>;
59 
60 // fahrenheit
61 struct fahrenheit_conv {
62  template <typename T>
63  static constexpr auto to_base(T v) noexcept -> T {
64  return T((v - 32.F) / 1.8F + 273.15F);
65  }
66 
67  template <typename T>
68  static constexpr auto from_base(T v) noexcept -> T {
69  return T(v * 1.8F - 459.67F);
70  }
71 };
72 
73 using degree_fahrenheit = make_custom_unit_t<fahrenheit_conv, kelvin>;
74 
75 } // namespace eagine::units
76 
77 #endif // EAGINE_UNITS_UNIT_SI_TEMPERATURE_HPP

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