Browse Source

Math: ability to construct a Color3 from RG and B.

pull/617/head
Vladimír Vondruš 3 years ago
parent
commit
62c395708e
  1. 8
      src/Magnum/Math/Color.h
  2. 20
      src/Magnum/Math/Test/ColorTest.cpp

8
src/Magnum/Math/Color.h

@ -568,6 +568,14 @@ template<class T> class Color3: public Vector3<T> {
*/
constexpr /*implicit*/ Color3(T r, T g, T b) noexcept: Vector3<T>(r, g, b) {}
/**
* @brief Constructor
* @param rg RG value
* @param b B value
* @m_since_latest
*/
constexpr /*implicit*/ Color3(const Vector<2, T>& rg, T b) noexcept: Vector3<T>{rg, b} {}
/**
* @copydoc Vector::Vector(const Vector<size, U>&)
*

20
src/Magnum/Math/Test/ColorTest.cpp

@ -156,6 +156,7 @@ struct ColorTest: Corrade::TestSuite::Tester {
#endif
};
typedef Math::Vector2<Float> Vector2;
typedef Math::Vector3<Float> Vector3;
typedef Math::Vector3<UnsignedByte> Vector3ub;
typedef Math::Vector3<UnsignedShort> Vector3us;
@ -387,18 +388,21 @@ void ColorTest::constructOneValue() {
}
void ColorTest::constructParts() {
constexpr Color3 a(1.0f, 0.5f, 0.75f);
constexpr Vector2 a{1.0f, 0.5f};
constexpr Color3 b = {a, 0.75f};
CORRADE_COMPARE(b, (Color3{1.0f, 0.5f, 0.75f}));
constexpr Color4 b = {a, 0.25f};
CORRADE_COMPARE(b, Color4(1.0f, 0.5f, 0.75f, 0.25f));
constexpr Color4 c = {b, 0.25f};
CORRADE_COMPARE(c, (Color4{1.0f, 0.5f, 0.75f, 0.25f}));
/* Default alpha */
constexpr Color3ub c(10, 25, 176);
constexpr Color4 d = a;
constexpr Color4ub e = c;
CORRADE_COMPARE(d, Color4(1.0f, 0.5f, 0.75f, 1.0f));
CORRADE_COMPARE(e, Color4ub(10, 25, 176, 255));
constexpr Color3ub d(10, 25, 176);
constexpr Color4 e = b;
constexpr Color4ub f = d;
CORRADE_COMPARE(e, (Color4{1.0f, 0.5f, 0.75f, 1.0f}));
CORRADE_COMPARE(f, (Color4ub{10, 25, 176, 255}));
CORRADE_VERIFY(std::is_nothrow_constructible<Color3, Vector2, Float>::value);
CORRADE_VERIFY(std::is_nothrow_constructible<Color4, Color3, Float>::value);
}

Loading…
Cancel
Save