From c8afe0f7320f3e639a56263c6144bc6a8e751695 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vladim=C3=ADr=20Vondru=C5=A1?= Date: Sat, 22 Feb 2020 23:02:25 +0100 Subject: [PATCH] Math: make Vector::pad() default argument work with Half. Got lucky enough that the default zero-initialization constructor does exactly what I need. Otherwise ugh I don't know what I would do. --- src/Magnum/Math/Test/VectorTest.cpp | 12 ++++++++++++ src/Magnum/Math/Vector.h | 4 ++-- 2 files changed, 14 insertions(+), 2 deletions(-) diff --git a/src/Magnum/Math/Test/VectorTest.cpp b/src/Magnum/Math/Test/VectorTest.cpp index 61bbc38bc..790a1e240 100644 --- a/src/Magnum/Math/Test/VectorTest.cpp +++ b/src/Magnum/Math/Test/VectorTest.cpp @@ -27,6 +27,7 @@ #include #include +#include "Magnum/Math/Half.h" #include "Magnum/Math/Vector.h" #include "Magnum/Math/StrictWeakOrdering.h" @@ -58,6 +59,7 @@ struct VectorTest: Corrade::TestSuite::Tester { void construct(); void constructFromData(); void constructPad(); + void constructPadDefaultHalf(); void constructDefault(); void constructNoInit(); void constructOneValue(); @@ -118,14 +120,17 @@ struct VectorTest: Corrade::TestSuite::Tester { typedef Math::Constants Constants; typedef Math::Rad Rad; typedef Vector<2, Float> Vector2; +typedef Vector<2, Half> Vector2h; typedef Vector<3, Float> Vector3; typedef Vector<4, Float> Vector4; +typedef Vector<4, Half> Vector4h; typedef Vector<4, Int> Vector4i; VectorTest::VectorTest() { addTests({&VectorTest::construct, &VectorTest::constructFromData, &VectorTest::constructPad, + &VectorTest::constructPadDefaultHalf, &VectorTest::constructDefault, &VectorTest::constructNoInit, &VectorTest::constructOneValue, @@ -207,6 +212,13 @@ void VectorTest::constructPad() { CORRADE_COMPARE(e, Vector4(1.0f, -1.0f, 8.0f, 2.3f)); } +void VectorTest::constructPadDefaultHalf() { + using namespace Literals; + /* The default pad value should work also for the Half type */ + Vector4h a = Vector4h::pad(Vector2h{1.0_h, -1.0_h}); + CORRADE_COMPARE(a, (Vector4h{1.0_h, -1.0_h, 0.0_h, 0.0_h})); +} + void VectorTest::constructDefault() { constexpr Vector4 a; constexpr Vector4 b{ZeroInit}; diff --git a/src/Magnum/Math/Vector.h b/src/Magnum/Math/Vector.h index d4a02bc57..6a0ffc8f2 100644 --- a/src/Magnum/Math/Vector.h +++ b/src/Magnum/Math/Vector.h @@ -166,7 +166,7 @@ template class Vector { * with @p value, otherwise it's cut. * @see @ref Vector4::pad(const Vector&, T, T) */ - template constexpr static Vector pad(const Vector& a, T value = T(0)) { + template constexpr static Vector pad(const Vector& a, T value = T()) { return padInternal(typename Implementation::GenerateSequence::Type(), a, value); } @@ -1248,7 +1248,7 @@ extern template MAGNUM_EXPORT Corrade::Utility::Debug& operator<<(Corrade::Utili static const Type& from(const T* data) { \ return *reinterpret_cast*>(data); \ } \ - template constexpr static Type pad(const Math::Vector& a, T value = T(0)) { \ + template constexpr static Type pad(const Math::Vector& a, T value = T()) { \ return Math::Vector::pad(a, value); \ } \ \