Browse Source

Function for getting first two components of a vector.

vectorfields
Vladimír Vondruš 14 years ago
parent
commit
eddfb62c32
  1. 5
      src/Math/Test/Vector3Test.cpp
  2. 1
      src/Math/Test/Vector3Test.h
  3. 5
      src/Math/Test/Vector4Test.cpp
  4. 1
      src/Math/Test/Vector4Test.h
  5. 8
      src/Math/Vector3.h
  6. 6
      src/Math/Vector4.h

5
src/Math/Test/Vector3Test.cpp

@ -28,6 +28,7 @@ using namespace Corrade::Utility;
namespace Magnum { namespace Math { namespace Test {
typedef Math::Vector3<float> Vector3;
typedef Math::Vector2<float> 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);

1
src/Math/Test/Vector3Test.h

@ -26,6 +26,7 @@ class Vector3Test: public QObject {
void construct();
void cross();
void axis();
void twoComponent();
void debug();
};

5
src/Math/Test/Vector4Test.cpp

@ -29,6 +29,7 @@ namespace Magnum { namespace Math { namespace Test {
typedef Math::Vector4<float> Vector4;
typedef Math::Vector3<float> Vector3;
typedef Math::Vector2<float> 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);

1
src/Math/Test/Vector4Test.h

@ -25,6 +25,7 @@ class Vector4Test: public QObject {
private slots:
void construct();
void threeComponent();
void twoComponent();
void debug();
};

8
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 T> 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<T> xy() const { return Vector2<T>::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 */

6
src/Math/Vector4.h

@ -71,6 +71,12 @@ template<class T> class Vector4: public Vector<4, T> {
*/
inline constexpr Vector3<T> xyz() const { return Vector3<T>::from(Vector<4, T>::data()); }
/**
* @brief XY part of the vector
* @return First two components of the vector
*/
inline constexpr Vector2<T> xy() const { return Vector2<T>::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 */

Loading…
Cancel
Save