diff options
author | Aki <please@ignore.pl> | 2022-06-04 13:09:47 +0200 |
---|---|---|
committer | Aki <please@ignore.pl> | 2022-06-04 13:10:04 +0200 |
commit | af781837df4a4fb1df63103cdeb6a3dfbab7b9d4 (patch) | |
tree | 660475d934827189c10f037d488f732394518ad2 /VectorMath.h | |
parent | dd1cd8c9647e5e16ae531c6da01ff9d261fdbe2a (diff) | |
download | derelict-af781837df4a4fb1df63103cdeb6a3dfbab7b9d4.zip derelict-af781837df4a4fb1df63103cdeb6a3dfbab7b9d4.tar.gz derelict-af781837df4a4fb1df63103cdeb6a3dfbab7b9d4.tar.bz2 |
Renamed to VectorMath for now
I still need to think about its place and how/if to address duplication
from raymath.h
Diffstat (limited to 'VectorMath.h')
-rw-r--r-- | VectorMath.h | 30 |
1 files changed, 30 insertions, 0 deletions
diff --git a/VectorMath.h b/VectorMath.h new file mode 100644 index 0000000..72eab4d --- /dev/null +++ b/VectorMath.h @@ -0,0 +1,30 @@ +#pragma once + +#include <cmath> +#include <type_traits> + + +template <typename T> static auto test_z(int) -> decltype(decltype(T::z){}, std::true_type{}); +template <typename> static auto test_z(...) -> std::false_type; +template <typename T> struct has_z : decltype(test_z<T>(0)) {}; + + +template <typename V, typename T=decltype(V::x), typename std::enable_if<has_z<V>::value, bool>::type=true> +T +dist(const V& lhs, const V& rhs) +{ + return std::sqrt( + std::pow(lhs.x - rhs.x, 2) + + std::pow(lhs.y - rhs.y, 2) + + std::pow(lhs.z - rhs.z, 2)); +} + + +template <typename V, typename T=decltype(V::x), typename std::enable_if<!has_z<V>::value, bool>::type=true> +T +dist(const V& lhs, const V& rhs) +{ + return std::sqrt( + std::pow(lhs.x - rhs.x, 2) + + std::pow(lhs.y - rhs.y, 2)); +} |