vector: fix hypot implementation

This commit is contained in:
Danny Robson 2016-09-21 22:24:02 +10:00
parent 7db82e4b22
commit ede9b75bad
3 changed files with 5 additions and 6 deletions

View File

@ -115,7 +115,7 @@ main ()
tap.expect (!is_normalised (util::vector3f::ONES), "ones isn't normalised"); tap.expect (!is_normalised (util::vector3f::ONES), "ones isn't normalised");
tap.expect_eq ( tap.expect_eq (
util::hypot (util::vector3f{0,1,2}, util::vector3f{3,2,4}), util::hypot (util::vector3f{0,1,2} - util::vector3f{3,2,4}),
std::sqrt (14.f), std::sqrt (14.f),
"vector3f hypot" "vector3f hypot"
); );

View File

@ -50,11 +50,11 @@ namespace util {
template <typename T> vector<2,T> to_euler (vector<3,T>); template <typename T> vector<2,T> to_euler (vector<3,T>);
template <typename T> vector<3,T> from_euler (vector<2,T>); template <typename T> vector<3,T> from_euler (vector<2,T>);
// power functions // root of sum of squares
template <size_t S, typename T> template <size_t S, typename T>
constexpr constexpr
T T
hypot (util::vector<S,T>, util::vector<S,T>); hypot (util::vector<S,T>);
// output and serialisation operators // output and serialisation operators
template <size_t S, typename T> template <size_t S, typename T>

View File

@ -38,8 +38,7 @@ util::vector<S,T>::homog (void) const
template <size_t S, typename T> template <size_t S, typename T>
constexpr constexpr
T T
util::hypot (util::vector<S,T> a, util::vector<S,T> b) util::hypot (util::vector<S,T> v)
{ {
auto c = a - b; return std::sqrt (sum (v * v));
return std::sqrt (sum (c * c));
} }