From d3720f01837e949ce7e7ea9b119358a5bb7b9666 Mon Sep 17 00:00:00 2001 From: Aki Date: Fri, 20 May 2022 19:51:40 +0200 Subject: Merged distance calculation functions --- Utils.h | 28 +++++++++++++++++++++++++--- 1 file changed, 25 insertions(+), 3 deletions(-) (limited to 'Utils.h') diff --git a/Utils.h b/Utils.h index b582540..72eab4d 100644 --- a/Utils.h +++ b/Utils.h @@ -1,8 +1,30 @@ #pragma once +#include +#include -template T dist2(const V& lhs, const V& rhs); -template T dist3(const V& lhs, const V& rhs); +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)) {}; -#include "Utils-inl.h" + +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