From 996c707cbc66660a9118dc91a7d301bdbdadee7a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vladim=C3=ADr=20Vondru=C5=A1?= Date: Fri, 30 Dec 2016 00:32:56 +0100 Subject: [PATCH] Math: reduced code duplication in vector packing functions. This should also improve debug performance as there is less code to inline. --- src/Magnum/Math/Packing.h | 23 ++++++++++------------- 1 file changed, 10 insertions(+), 13 deletions(-) diff --git a/src/Magnum/Math/Packing.h b/src/Magnum/Math/Packing.h index fc3df3b08..5bb75e66b 100644 --- a/src/Magnum/Math/Packing.h +++ b/src/Magnum/Math/Packing.h @@ -70,15 +70,11 @@ template inline typename std::enable_if::max()), FloatingPoint(-1.0)); } -template inline typename std::enable_if::value, FloatingPoint>::type unpack(const Integral& value) { - static_assert(std::is_floating_point::value && std::is_integral::value, - "unpacking must be done from integral to floating-point type"); - return FloatingPoint(value)/typename FloatingPoint::Type(std::numeric_limits::max()); -} -template inline typename std::enable_if::value, FloatingPoint>::type unpack(const Integral& value) { - static_assert(std::is_floating_point::value && std::is_integral::value, - "unpacking must be done from integral to floating-point type"); - return Math::max(FloatingPoint(value)/typename FloatingPoint::Type(std::numeric_limits::max()), FloatingPoint(-1.0)); +template FloatingPoint unpack(const Vector& value) { + FloatingPoint out{NoInit}; + for(std::size_t i = 0; i != size; ++i) + out[i] = unpack(value[i]); + return out; } #endif @@ -116,10 +112,11 @@ template inline typename std::enable_if::max()); } -template inline typename std::enable_if::value, Integral>::type pack(const FloatingPoint& value) { - static_assert(std::is_floating_point::value && std::is_integral::value, - "packing must be done from floating-point to integral type"); - return Integral(value*std::numeric_limits::max()); +template Integral pack(const Vector& value) { + Integral out{NoInit}; + for(std::size_t i = 0; i != size; ++i) + out[i] = pack(value[i]); + return out; } #endif