diff --git a/src/Math/Test/Vector3Test.cpp b/src/Math/Test/Vector3Test.cpp index 781dce425..05218b0d6 100644 --- a/src/Math/Test/Vector3Test.cpp +++ b/src/Math/Test/Vector3Test.cpp @@ -28,6 +28,7 @@ using namespace Corrade::Utility; namespace Magnum { namespace Math { namespace Test { typedef Math::Vector3 Vector3; +typedef Math::Vector2 Vector2; void Vector3Test::construct() { QVERIFY((Vector3(1, 2, 3) == Vector<3, float>(1.0f, 2.0f, 3.0f))); @@ -47,6 +48,10 @@ void Vector3Test::axis() { QVERIFY(Vector3::zAxis(7.0f) == Vector3(0.0f, 0.0f, 7.0f)); } +void Vector3Test::twoComponent() { + QVERIFY(Vector3(1.0f, 2.0f, 3.0f).xy() == Vector2(1.0f, 2.0f)); +} + void Vector3Test::debug() { ostringstream o; Debug(&o) << Vector3(0.5f, 15.0f, 1.0f); diff --git a/src/Math/Test/Vector3Test.h b/src/Math/Test/Vector3Test.h index 50a7b7a86..d3d77f737 100644 --- a/src/Math/Test/Vector3Test.h +++ b/src/Math/Test/Vector3Test.h @@ -26,6 +26,7 @@ class Vector3Test: public QObject { void construct(); void cross(); void axis(); + void twoComponent(); void debug(); }; diff --git a/src/Math/Test/Vector4Test.cpp b/src/Math/Test/Vector4Test.cpp index 90c739f02..dfcdc16b9 100644 --- a/src/Math/Test/Vector4Test.cpp +++ b/src/Math/Test/Vector4Test.cpp @@ -29,6 +29,7 @@ namespace Magnum { namespace Math { namespace Test { typedef Math::Vector4 Vector4; typedef Math::Vector3 Vector3; +typedef Math::Vector2 Vector2; void Vector4Test::construct() { QVERIFY(Vector4() == Vector4(0.0f, 0.0f, 0.0f, 1.0f)); @@ -40,6 +41,10 @@ void Vector4Test::threeComponent() { QVERIFY(Vector4(1.0f, 2.0f, 3.0f, 4.0f).xyz() == Vector3(1.0f, 2.0f, 3.0f)); } +void Vector4Test::twoComponent() { + QVERIFY(Vector4(1.0f, 2.0f, 3.0f, 4.0f).xy() == Vector2(1.0f, 2.0f)); +} + void Vector4Test::debug() { ostringstream o; Debug(&o) << Vector4(0.5f, 15.0f, 1.0f, 1.0f); diff --git a/src/Math/Test/Vector4Test.h b/src/Math/Test/Vector4Test.h index 2d65bd318..95247509e 100644 --- a/src/Math/Test/Vector4Test.h +++ b/src/Math/Test/Vector4Test.h @@ -25,6 +25,7 @@ class Vector4Test: public QObject { private slots: void construct(); void threeComponent(); + void twoComponent(); void debug(); }; diff --git a/src/Math/Vector3.h b/src/Math/Vector3.h index a9068c032..be9934043 100644 --- a/src/Math/Vector3.h +++ b/src/Math/Vector3.h @@ -19,7 +19,7 @@ * @brief Class Magnum::Math::Vector3 */ -#include "Vector.h" +#include "Vector2.h" namespace Magnum { namespace Math { @@ -78,6 +78,12 @@ template class Vector3: public Vector<3, T> { inline void setY(T value) { (*this)[1] = value; } /**< @brief Set Y component */ inline void setZ(T value) { (*this)[2] = value; } /**< @brief Set Z component */ + /** + * @brief XY part of the vector + * @return First two components of the vector + */ + inline constexpr Vector2 xy() const { return Vector2::from(Vector<3, T>::data()); } + inline constexpr T r() const { return x(); } /**< @brief R component */ inline constexpr T g() const { return x(); } /**< @brief G component */ inline constexpr T b() const { return z(); } /**< @brief B component */ diff --git a/src/Math/Vector4.h b/src/Math/Vector4.h index d41ecc01c..5b1e57418 100644 --- a/src/Math/Vector4.h +++ b/src/Math/Vector4.h @@ -71,6 +71,12 @@ template class Vector4: public Vector<4, T> { */ inline constexpr Vector3 xyz() const { return Vector3::from(Vector<4, T>::data()); } + /** + * @brief XY part of the vector + * @return First two components of the vector + */ + inline constexpr Vector2 xy() const { return Vector2::from(Vector<4, T>::data()); } + inline constexpr T r() const { return x(); } /**< @brief R component */ inline constexpr T g() const { return y(); } /**< @brief G component */ inline constexpr T b() const { return z(); } /**< @brief B component */