From af781837df4a4fb1df63103cdeb6a3dfbab7b9d4 Mon Sep 17 00:00:00 2001 From: Aki Date: Sat, 4 Jun 2022 13:09:47 +0200 Subject: Renamed to VectorMath for now I still need to think about its place and how/if to address duplication from raymath.h --- VectorMath.h | 30 ++++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) create mode 100644 VectorMath.h (limited to 'VectorMath.h') 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 +#include + + +template static auto test_z(int) -> decltype(decltype(T::z){}, std::true_type{}); +template static auto test_z(...) -> std::false_type; +template struct has_z : decltype(test_z(0)) {}; + + +template ::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 ::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)); +} -- cgit v1.1