Browse Source

Moved RGB(A) accessors from swizzle() to Math::swizzle().

As Math::Vector now contains them, there is no need to restrict them
from the original swizzle implementation.
pull/23/head
Vladimír Vondruš 13 years ago
parent
commit
a2d31ef8d3
  1. 4
      src/Math/Swizzle.h
  2. 7
      src/Math/Test/SwizzleTest.cpp
  3. 7
      src/Swizzle.h
  4. 9
      src/Test/SwizzleTest.cpp

4
src/Math/Swizzle.h

@ -44,6 +44,10 @@ namespace Implementation {
template<std::size_t size> struct Component<size, 'y'>: public ComponentAtPosition<size, 1> {}; template<std::size_t size> struct Component<size, 'y'>: public ComponentAtPosition<size, 1> {};
template<std::size_t size> struct Component<size, 'z'>: public ComponentAtPosition<size, 2> {}; template<std::size_t size> struct Component<size, 'z'>: public ComponentAtPosition<size, 2> {};
template<std::size_t size> struct Component<size, 'w'>: public ComponentAtPosition<size, 3> {}; template<std::size_t size> struct Component<size, 'w'>: public ComponentAtPosition<size, 3> {};
template<std::size_t size> struct Component<size, 'r'>: public ComponentAtPosition<size, 0> {};
template<std::size_t size> struct Component<size, 'g'>: public ComponentAtPosition<size, 1> {};
template<std::size_t size> struct Component<size, 'b'>: public ComponentAtPosition<size, 2> {};
template<std::size_t size> struct Component<size, 'a'>: public ComponentAtPosition<size, 3> {};
template<std::size_t size> struct Component<size, '0'> { template<std::size_t size> struct Component<size, '0'> {
template<class T> constexpr static T value(const Math::Vector<size, T>&) { return T(0); } template<class T> constexpr static T value(const Math::Vector<size, T>&) { return T(0); }
}; };

7
src/Math/Test/SwizzleTest.cpp

@ -34,6 +34,7 @@ class SwizzleTest: public Corrade::TestSuite::Tester {
void components(); void components();
void constants(); void constants();
void rgba();
void sizes(); void sizes();
}; };
@ -42,6 +43,7 @@ typedef Vector<4, Int> Vector4i;
SwizzleTest::SwizzleTest() { SwizzleTest::SwizzleTest() {
addTests({&SwizzleTest::components, addTests({&SwizzleTest::components,
&SwizzleTest::constants, &SwizzleTest::constants,
&SwizzleTest::rgba,
&SwizzleTest::sizes}); &SwizzleTest::sizes});
} }
@ -55,6 +57,11 @@ void SwizzleTest::constants() {
CORRADE_COMPARE(a, Vector4i(1, 7, 0, 4)); CORRADE_COMPARE(a, Vector4i(1, 7, 0, 4));
} }
void SwizzleTest::rgba() {
constexpr auto a = swizzle<'b', 'r', 'a', 'g'>(Vector4i(2, 4, 5, 7));
CORRADE_COMPARE(a, Vector4i(5, 2, 7, 4));
}
void SwizzleTest::sizes() { void SwizzleTest::sizes() {
constexpr auto a = swizzle<'y', 'x', 'x'>(Math::Vector<2, Int>(1, 2)); constexpr auto a = swizzle<'y', 'x', 'x'>(Math::Vector<2, Int>(1, 2));
CORRADE_COMPARE(a, (Math::Vector<3, Int>(2, 1, 1))); CORRADE_COMPARE(a, (Math::Vector<3, Int>(2, 1, 1)));

7
src/Swizzle.h

@ -33,13 +33,6 @@
namespace Magnum { namespace Magnum {
namespace Math { namespace Implementation {
template<std::size_t size> struct Component<size, 'r'>: public ComponentAtPosition<size, 0> {};
template<std::size_t size> struct Component<size, 'g'>: public ComponentAtPosition<size, 1> {};
template<std::size_t size> struct Component<size, 'b'>: public ComponentAtPosition<size, 2> {};
template<std::size_t size> struct Component<size, 'a'>: public ComponentAtPosition<size, 3> {};
}}
namespace Implementation { namespace Implementation {
template<std::size_t size, class T> struct TypeForSize { template<std::size_t size, class T> struct TypeForSize {
typedef Math::Vector<size, typename T::Type> Type; typedef Math::Vector<size, typename T::Type> Type;

9
src/Test/SwizzleTest.cpp

@ -32,22 +32,15 @@ class SwizzleTest: public TestSuite::Tester {
public: public:
SwizzleTest(); SwizzleTest();
void rgba();
void type(); void type();
void defaultType(); void defaultType();
}; };
SwizzleTest::SwizzleTest() { SwizzleTest::SwizzleTest() {
addTests({&SwizzleTest::rgba, addTests({&SwizzleTest::type,
&SwizzleTest::type,
&SwizzleTest::defaultType}); &SwizzleTest::defaultType});
} }
void SwizzleTest::rgba() {
constexpr auto a = swizzle<'b', 'r', 'a', 'g'>(Vector4i(2, 4, 5, 7));
CORRADE_COMPARE(a, Vector4i(5, 2, 7, 4));
}
void SwizzleTest::type() { void SwizzleTest::type() {
constexpr Vector4i orig; constexpr Vector4i orig;
constexpr Color3 origColor3; constexpr Color3 origColor3;

Loading…
Cancel
Save