Skip to main content

Unit.ixx File

Included Headers

#include <string> #include <helios.math.types>

Namespaces Index

namespacehelios
namespaceengine
namespacecore
namespaceunits

File Listing

The file content with the documentation metadata removed is:

1
6module;
7
8#include <string>
9
10export module helios.engine.core.units.Unit;
11import helios.math.types;
12
14
18 enum class Unit {
23 Meter,
24
30
36
42 };
43
44
49
54
58 constexpr float CENTIMETERS = 0.01f;
59
63 constexpr float METERS = 1.0f;
64
68 constexpr float MILLISECONDS = 0.001f;
69
73 constexpr float SECONDS = 1.0f;
74
82 constexpr float fromCm(const float cm) noexcept {
83 return cm * CENTIMETERS;
84 };
85
93 constexpr float fromM(const float m) noexcept {
94 return m * METERS;
95 };
96
104 constexpr helios::math::vec3f fromM(helios::math::vec3f v) noexcept {
105 return helios::math::vec3f{v[0] * METERS, v[1] * METERS, v[2] * METERS};
106 };
107
115 constexpr helios::math::aabbf fromM(helios::math::aabbf v) noexcept {
116 return helios::math::aabbf{
117 v.min()[0] * METERS, v.min()[1] * METERS, v.min()[2] * METERS,
118 v.max()[0] * METERS, v.max()[1] * METERS, v.max()[2] * METERS
119 };
120 };
121
129 constexpr float fromS(const float s) noexcept {
130 return s * SECONDS;
131 }
132
140 constexpr float fromMs(const float ms) noexcept {
141 return ms * MILLISECONDS;
142 }
143
155 [[nodiscard]] constexpr float from(const float v, const Unit unit) noexcept {
156 switch (unit) {
157 case Unit::Meter:
158 return fromM(v);
160 return fromCm(v);
161 case Unit::Seconds:
162 return fromS(v);
164 return fromMs(v);
165 default:
166 std::unreachable();
167 }
168 }
169
178 [[nodiscard]] constexpr helios::math::aabbf from(helios::math::aabbf aabb, const Unit unit) noexcept {
179 switch (unit) {
180 case Unit::Meter:
181 return fromM(aabb);
182 default:
183 std::unreachable();
184 }
185 }
186
187}

Generated via doxygen2docusaurus 2.0.0 by Doxygen 1.9.8.