diff --git a/src/Math/Test/Vector2Test.cpp b/src/Math/Test/Vector2Test.cpp index 636f19c72..35999b7f2 100644 --- a/src/Math/Test/Vector2Test.cpp +++ b/src/Math/Test/Vector2Test.cpp @@ -30,6 +30,7 @@ typedef Math::Vector2 Vector2; Vector2Test::Vector2Test() { addTests(&Vector2Test::construct, + &Vector2Test::axes, &Vector2Test::debug); } @@ -37,6 +38,11 @@ void Vector2Test::construct() { CORRADE_COMPARE(Vector2(1, 2), (Vector<2, float>(1.0f, 2.0f))); } +void Vector2Test::axes() { + CORRADE_COMPARE(Vector2::xAxis(5.0f), Vector2(5.0f, 0.0f)); + CORRADE_COMPARE(Vector2::yAxis(6.0f), Vector2(0.0f, 6.0f)); +} + void Vector2Test::debug() { ostringstream o; Debug(&o) << Vector2(0.5f, 15.0f); diff --git a/src/Math/Test/Vector2Test.h b/src/Math/Test/Vector2Test.h index 39515fbf9..ef91cf151 100644 --- a/src/Math/Test/Vector2Test.h +++ b/src/Math/Test/Vector2Test.h @@ -24,6 +24,7 @@ class Vector2Test: public Corrade::TestSuite::Tester { Vector2Test(); void construct(); + void axes(); void debug(); }; diff --git a/src/Math/Test/Vector3Test.cpp b/src/Math/Test/Vector3Test.cpp index 6df8a84e7..1a84a2012 100644 --- a/src/Math/Test/Vector3Test.cpp +++ b/src/Math/Test/Vector3Test.cpp @@ -32,7 +32,7 @@ typedef Math::Vector2 Vector2; Vector3Test::Vector3Test() { addTests(&Vector3Test::construct, &Vector3Test::cross, - &Vector3Test::axis, + &Vector3Test::axes, &Vector3Test::twoComponent, &Vector3Test::debug); } @@ -49,7 +49,7 @@ void Vector3Test::cross() { CORRADE_COMPARE(Vector3::cross(a, b), Vector3(-10, -3, 7)); } -void Vector3Test::axis() { +void Vector3Test::axes() { CORRADE_COMPARE(Vector3::xAxis(5.0f), Vector3(5.0f, 0.0f, 0.0f)); CORRADE_COMPARE(Vector3::yAxis(6.0f), Vector3(0.0f, 6.0f, 0.0f)); CORRADE_COMPARE(Vector3::zAxis(7.0f), Vector3(0.0f, 0.0f, 7.0f)); diff --git a/src/Math/Test/Vector3Test.h b/src/Math/Test/Vector3Test.h index 73de924e9..4d817dc07 100644 --- a/src/Math/Test/Vector3Test.h +++ b/src/Math/Test/Vector3Test.h @@ -25,7 +25,7 @@ class Vector3Test: public Corrade::TestSuite::Tester { void construct(); void cross(); - void axis(); + void axes(); void twoComponent(); void debug(); diff --git a/src/Math/Vector2.h b/src/Math/Vector2.h index 262fe58c8..8bd0e6f35 100644 --- a/src/Math/Vector2.h +++ b/src/Math/Vector2.h @@ -26,6 +26,12 @@ namespace Magnum { namespace Math { /** @brief Two-component vector */ template class Vector2: public Vector<2, T> { public: + /** @brief %Vector in direction of X axis */ + inline constexpr static Vector2 xAxis(T length = T(1)) { return Vector2(length, T()); } + + /** @brief %Vector in direction of Y axis */ + inline constexpr static Vector2 yAxis(T length = T(1)) { return Vector2(T(), length); } + /** @copydoc Vector::Vector(T) */ inline constexpr explicit Vector2(T value = T()): Vector<2, T>(value, value) {}