summaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorDan Goodliffe <dan@randomdan.homeip.net>2021-03-07 18:55:28 +0000
committerDan Goodliffe <dan@randomdan.homeip.net>2021-03-07 18:55:28 +0000
commitdb92ed183a8328a775323d7d4478397b907297d8 (patch)
treeb37a3a716592ff0d445609b3ed6873ed3573934f /lib
parentCarve up the mess in game/vehicles (diff)
downloadilt-db92ed183a8328a775323d7d4478397b907297d8.tar.bz2
ilt-db92ed183a8328a775323d7d4478397b907297d8.tar.xz
ilt-db92ed183a8328a775323d7d4478397b907297d8.zip
Speed conversions and literals
Diffstat (limited to 'lib')
-rw-r--r--lib/maths.cpp10
-rw-r--r--lib/maths.h19
2 files changed, 29 insertions, 0 deletions
diff --git a/lib/maths.cpp b/lib/maths.cpp
index 4ae0693..26eae47 100644
--- a/lib/maths.cpp
+++ b/lib/maths.cpp
@@ -173,3 +173,13 @@ find_arcs_radius(glm::vec2 start, glm::vec2 ad, glm::vec2 end, glm::vec2 bd)
* (sq(m) - 2 * m * o + sq(o) + sq(n) - 2 * n * p + sq(p)))))
/ (2 * (sq(X) - 2 * X * Z + sq(Z) + sq(Y) - 2 * Y * W + sq(W) - 4));
}
+
+float operator"" _mph(const long double v)
+{
+ return mph_to_ms(v);
+}
+
+float operator"" _kph(const long double v)
+{
+ return kph_to_ms(v);
+}
diff --git a/lib/maths.h b/lib/maths.h
index dc0c617..c4c1a51 100644
--- a/lib/maths.h
+++ b/lib/maths.h
@@ -87,4 +87,23 @@ std::pair<glm::vec2, bool> find_arc_centre(glm::vec2 start, glm::vec2 ad, glm::v
std::pair<float, float> find_arcs_radius(glm::vec2 start, float entrys, glm::vec2 end, float entrye);
float find_arcs_radius(glm::vec2 start, glm::vec2 ad, glm::vec2 end, glm::vec2 bd);
+// Conversions
+template<typename T>
+inline constexpr float
+mph_to_ms(T v)
+{
+ return v / 2.237;
+}
+
+template<typename T>
+inline constexpr float
+kph_to_ms(T v)
+{
+ return v / 3.6;
+}
+
+// ... literals are handy for now, probably go away when we load stuff externally
+float operator"" _mph(const long double v);
+float operator"" _kph(const long double v);
+
#endif