From 8637cbdc31a6aa26a0e1f766bb0868209a1500b1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vladim=C3=ADr=20Vondru=C5=A1?= Date: Sun, 19 Feb 2017 22:46:31 +0100 Subject: [PATCH] Math: Color4::{xyz,rgb}() should return Color3, not Vector3. --- src/Magnum/Math/Color.h | 11 ++++++++++- src/Magnum/Math/Test/ColorTest.cpp | 23 +++++++++++++++++++++++ 2 files changed, 33 insertions(+), 1 deletion(-) diff --git a/src/Magnum/Math/Color.h b/src/Magnum/Math/Color.h index 1ebc8f5a2..660259a0d 100644 --- a/src/Magnum/Math/Color.h +++ b/src/Magnum/Math/Color.h @@ -947,9 +947,18 @@ class Color4: public Vector4 { * @see @ref fromXyz() */ Vector3 toXyz() const { - return Implementation::toXyz(Vector4::rgb()); + return Implementation::toXyz(rgb()); } + /* Overloads to remove WTF-factor from return types */ + #ifndef DOXYGEN_GENERATING_OUTPUT + Color3& xyz() { return Color3::from(Vector4::data()); } + constexpr const Color3 xyz() const { return Vector4::xyz(); } + + Color3& rgb() { return xyz(); } + constexpr const Color3 rgb() const { return xyz(); } + #endif + MAGNUM_VECTOR_SUBCLASS_IMPLEMENTATION(4, Color4) }; diff --git a/src/Magnum/Math/Test/ColorTest.cpp b/src/Magnum/Math/Test/ColorTest.cpp index 0841ac155..fa085cefd 100644 --- a/src/Magnum/Math/Test/ColorTest.cpp +++ b/src/Magnum/Math/Test/ColorTest.cpp @@ -79,6 +79,8 @@ struct ColorTest: Corrade::TestSuite::Tester { void constructCopy(); void convert(); + void data(); + void literals(); void colors(); @@ -125,6 +127,8 @@ ColorTest::ColorTest() { &ColorTest::constructCopy, &ColorTest::convert, + &ColorTest::data, + &ColorTest::literals, &ColorTest::colors, @@ -333,6 +337,25 @@ void ColorTest::convert() { CORRADE_VERIFY(!(std::is_convertible::value)); } +void ColorTest::data() { + Color4 c{1.0f, 2.0f, 3.0f, 4.0f}; + constexpr const Color4 cc{1.0f, 2.0f, 3.0f, 4.0f}; + + Color3 c3a = c.rgb(); + Color3 c3b = c.xyz(); + constexpr Color3 cc3a{cc.rgb()}; + constexpr Color3 cc3b{cc.xyz()}; + CORRADE_COMPARE(c3a, (Color3{1.0f, 2.0f, 3.0f})); + CORRADE_COMPARE(c3b, (Color3{1.0f, 2.0f, 3.0f})); + CORRADE_COMPARE(cc3a, (Color3{1.0f, 2.0f, 3.0f})); + CORRADE_COMPARE(cc3b, (Color3{1.0f, 2.0f, 3.0f})); + + CORRADE_VERIFY((std::is_same::value)); + CORRADE_VERIFY((std::is_same::value)); + CORRADE_VERIFY((std::is_same::value)); + CORRADE_VERIFY((std::is_same::value)); +} + void ColorTest::literals() { using namespace Literals;