Browse Source

Added Vector2::*Axis(), similar to those in Vector3.

vectorfields
Vladimír Vondruš 14 years ago
parent
commit
b8750d3702
  1. 6
      src/Math/Test/Vector2Test.cpp
  2. 1
      src/Math/Test/Vector2Test.h
  3. 4
      src/Math/Test/Vector3Test.cpp
  4. 2
      src/Math/Test/Vector3Test.h
  5. 6
      src/Math/Vector2.h

6
src/Math/Test/Vector2Test.cpp

@ -30,6 +30,7 @@ typedef Math::Vector2<float> Vector2;
Vector2Test::Vector2Test() { Vector2Test::Vector2Test() {
addTests(&Vector2Test::construct, addTests(&Vector2Test::construct,
&Vector2Test::axes,
&Vector2Test::debug); &Vector2Test::debug);
} }
@ -37,6 +38,11 @@ void Vector2Test::construct() {
CORRADE_COMPARE(Vector2(1, 2), (Vector<2, float>(1.0f, 2.0f))); 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() { void Vector2Test::debug() {
ostringstream o; ostringstream o;
Debug(&o) << Vector2(0.5f, 15.0f); Debug(&o) << Vector2(0.5f, 15.0f);

1
src/Math/Test/Vector2Test.h

@ -24,6 +24,7 @@ class Vector2Test: public Corrade::TestSuite::Tester<Vector2Test> {
Vector2Test(); Vector2Test();
void construct(); void construct();
void axes();
void debug(); void debug();
}; };

4
src/Math/Test/Vector3Test.cpp

@ -32,7 +32,7 @@ typedef Math::Vector2<float> Vector2;
Vector3Test::Vector3Test() { Vector3Test::Vector3Test() {
addTests(&Vector3Test::construct, addTests(&Vector3Test::construct,
&Vector3Test::cross, &Vector3Test::cross,
&Vector3Test::axis, &Vector3Test::axes,
&Vector3Test::twoComponent, &Vector3Test::twoComponent,
&Vector3Test::debug); &Vector3Test::debug);
} }
@ -49,7 +49,7 @@ void Vector3Test::cross() {
CORRADE_COMPARE(Vector3::cross(a, b), Vector3(-10, -3, 7)); 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::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::yAxis(6.0f), Vector3(0.0f, 6.0f, 0.0f));
CORRADE_COMPARE(Vector3::zAxis(7.0f), Vector3(0.0f, 0.0f, 7.0f)); CORRADE_COMPARE(Vector3::zAxis(7.0f), Vector3(0.0f, 0.0f, 7.0f));

2
src/Math/Test/Vector3Test.h

@ -25,7 +25,7 @@ class Vector3Test: public Corrade::TestSuite::Tester<Vector3Test> {
void construct(); void construct();
void cross(); void cross();
void axis(); void axes();
void twoComponent(); void twoComponent();
void debug(); void debug();

6
src/Math/Vector2.h

@ -26,6 +26,12 @@ namespace Magnum { namespace Math {
/** @brief Two-component vector */ /** @brief Two-component vector */
template<class T> class Vector2: public Vector<2, T> { template<class T> class Vector2: public Vector<2, T> {
public: public:
/** @brief %Vector in direction of X axis */
inline constexpr static Vector2<T> xAxis(T length = T(1)) { return Vector2<T>(length, T()); }
/** @brief %Vector in direction of Y axis */
inline constexpr static Vector2<T> yAxis(T length = T(1)) { return Vector2<T>(T(), length); }
/** @copydoc Vector::Vector(T) */ /** @copydoc Vector::Vector(T) */
inline constexpr explicit Vector2(T value = T()): Vector<2, T>(value, value) {} inline constexpr explicit Vector2(T value = T()): Vector<2, T>(value, value) {}

Loading…
Cancel
Save