Browse Source

Added Vector2::*Scale() and Vector3::*Scale().

Complements to *Axis for scaling.
pull/279/head
Vladimír Vondruš 14 years ago
parent
commit
a5b8afa122
  1. 2
      src/Math/Matrix3.h
  2. 2
      src/Math/Matrix4.h
  3. 6
      src/Math/Test/Vector2Test.cpp
  4. 1
      src/Math/Test/Vector2Test.h
  5. 7
      src/Math/Test/Vector3Test.cpp
  6. 1
      src/Math/Test/Vector3Test.h
  7. 22
      src/Math/Vector2.h
  8. 31
      src/Math/Vector3.h

2
src/Math/Matrix3.h

@ -50,7 +50,7 @@ template<class T> class Matrix3: public Matrix<3, T> {
* @brief 2D scaling matrix
* @param vec Scaling vector
*
* @see Matrix4::scaling()
* @see Matrix4::scaling(), Vector2::xScale(), Vector2::yScale()
*/
inline constexpr static Matrix3<T> scaling(const Vector2<T>& vec) {
return Matrix3<T>( /* Column-major! */

2
src/Math/Matrix4.h

@ -53,7 +53,7 @@ template<class T> class Matrix4: public Matrix<4, T> {
* @brief 3D scaling matrix
* @param vec Scaling vector
*
* @see Matrix3::scaling()
* @see Matrix3::scaling(), Vector3::xScale(), Vector3::yScale(), Vector3::zScale()
*/
inline constexpr static Matrix4<T> scaling(const Vector3<T>& vec) {
return Matrix4<T>( /* Column-major! */

6
src/Math/Test/Vector2Test.cpp

@ -31,6 +31,7 @@ typedef Math::Vector2<float> Vector2;
Vector2Test::Vector2Test() {
addTests(&Vector2Test::construct,
&Vector2Test::axes,
&Vector2Test::scales,
&Vector2Test::debug);
}
@ -43,6 +44,11 @@ void Vector2Test::axes() {
CORRADE_COMPARE(Vector2::yAxis(6.0f), Vector2(0.0f, 6.0f));
}
void Vector2Test::scales() {
CORRADE_COMPARE(Vector2::xScale(-5.0f), Vector2(-5.0f, 1.0f));
CORRADE_COMPARE(Vector2::yScale(-0.2f), Vector2(1.0f, -0.2f));
}
void Vector2Test::debug() {
ostringstream o;
Debug(&o) << Vector2(0.5f, 15.0f);

1
src/Math/Test/Vector2Test.h

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

7
src/Math/Test/Vector3Test.cpp

@ -33,6 +33,7 @@ Vector3Test::Vector3Test() {
addTests(&Vector3Test::construct,
&Vector3Test::cross,
&Vector3Test::axes,
&Vector3Test::scales,
&Vector3Test::twoComponent,
&Vector3Test::debug);
}
@ -55,6 +56,12 @@ void Vector3Test::axes() {
CORRADE_COMPARE(Vector3::zAxis(7.0f), Vector3(0.0f, 0.0f, 7.0f));
}
void Vector3Test::scales() {
CORRADE_COMPARE(Vector3::xScale(-5.0f), Vector3(-5.0f, 1.0f, 1.0f));
CORRADE_COMPARE(Vector3::yScale(-0.2f), Vector3(1.0f, -0.2f, 1.0f));
CORRADE_COMPARE(Vector3::zScale(71.0f), Vector3(1.0f, 1.0f, 71.0f));
}
void Vector3Test::twoComponent() {
CORRADE_COMPARE(Vector3(1.0f, 2.0f, 3.0f).xy(), Vector2(1.0f, 2.0f));
}

1
src/Math/Test/Vector3Test.h

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

22
src/Math/Vector2.h

@ -33,7 +33,7 @@ template<class T> class Vector2: public Vector<2, T> {
* @code
* Matrix3::translation(Vector2::xAxis(5.0f)); // same as Matrix3::translation({5.0f, 0.0f});
* @endcode
* @see yAxis()
* @see yAxis(), xScale()
*/
inline constexpr static Vector2<T> xAxis(T length = T(1)) { return Vector2<T>(length, T()); }
@ -41,9 +41,29 @@ template<class T> class Vector2: public Vector<2, T> {
* @brief %Vector in direction of Y axis
*
* See xAxis() for more information.
* @see yScale()
*/
inline constexpr static Vector2<T> yAxis(T length = T(1)) { return Vector2<T>(T(), length); }
/**
* @brief Scaling vector in direction of X axis
*
* Usable for scaling along given direction, for example:
* @code
* Matrix3::scaling(Vector2::xScale(-2.0f)); // same as Matrix3::scaling({-2.0f, 1.0f});
* @endcode
* @see yScale(), xAxis()
*/
inline constexpr static Vector2<T> xScale(T scale) { return Vector2<T>(scale, T(1)); }
/**
* @brief Scaling vector in direction of Y axis
*
* See xScale() for more information.
* @see yAxis()
*/
inline constexpr static Vector2<T> yScale(T scale) { return Vector2<T>(T(1), scale); }
/** @copydoc Vector::Vector(T) */
inline constexpr explicit Vector2(T value = T()): Vector<2, T>(value, value) {}

31
src/Math/Vector3.h

@ -34,7 +34,7 @@ template<class T> class Vector3: public Vector<3, T> {
* Matrix4::translation(Vector3::xAxis(5.0f)); // same as Matrix4::translation({5.0f, 0.0f, 0.0f});
* Matrix4::rotation(deg(30.0f), Vector3::xAxis()); // same as Matrix::rotation(deg(30.0f), {1.0f, 0.0f, 0.0f});
* @endcode
* @see yAxis(), zAxis()
* @see yAxis(), zAxis(), xScale()
*/
inline constexpr static Vector3<T> xAxis(T length = T(1)) { return Vector3<T>(length, T(), T()); }
@ -42,6 +42,7 @@ template<class T> class Vector3: public Vector<3, T> {
* @brief %Vector in direction of Y axis
*
* See xAxis() for more information.
* @see yScale()
*/
inline constexpr static Vector3<T> yAxis(T length = T(1)) { return Vector3<T>(T(), length, T()); }
@ -49,9 +50,37 @@ template<class T> class Vector3: public Vector<3, T> {
* @brief %Vector in direction of Z axis
*
* See xAxis() for more information.
* @see zScale()
*/
inline constexpr static Vector3<T> zAxis(T length = T(1)) { return Vector3<T>(T(), T(), length); }
/**
* @brief Scaling vector in direction of X axis
*
* Usable for scaling along given direction, for example:
* @code
* Matrix4::scaling(Vector3::xScale(-2.0f)); // same as Matrix4::scaling({-2.0f, 1.0f, 1.0f});
* @endcode
* @see yScale(), zScale(), xAxis()
*/
inline constexpr static Vector3<T> xScale(T scale) { return Vector3<T>(scale, T(1), T(1)); }
/**
* @brief Scaling vector in direction of Y axis
*
* See xScale() for more information.
* @see yAxis()
*/
inline constexpr static Vector3<T> yScale(T scale) { return Vector3<T>(T(1), scale, T(1)); }
/**
* @brief Scaling vector in direction of Z axis
*
* See xScale() for more information.
* @see zAxis()
*/
inline constexpr static Vector3<T> zScale(T scale) { return Vector3<T>(T(1), T(1), scale); }
/**
* @brief Cross product
*

Loading…
Cancel
Save