diff --git a/src/Math/Matrix3.h b/src/Math/Matrix3.h index 190aa9832..7ee74c4a7 100644 --- a/src/Math/Matrix3.h +++ b/src/Math/Matrix3.h @@ -50,7 +50,7 @@ template 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 scaling(const Vector2& vec) { return Matrix3( /* Column-major! */ diff --git a/src/Math/Matrix4.h b/src/Math/Matrix4.h index 172c05f70..602dfd98a 100644 --- a/src/Math/Matrix4.h +++ b/src/Math/Matrix4.h @@ -53,7 +53,7 @@ template 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 scaling(const Vector3& vec) { return Matrix4( /* Column-major! */ diff --git a/src/Math/Test/Vector2Test.cpp b/src/Math/Test/Vector2Test.cpp index 35999b7f2..a3a6e9753 100644 --- a/src/Math/Test/Vector2Test.cpp +++ b/src/Math/Test/Vector2Test.cpp @@ -31,6 +31,7 @@ typedef Math::Vector2 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); diff --git a/src/Math/Test/Vector2Test.h b/src/Math/Test/Vector2Test.h index ef91cf151..128f271be 100644 --- a/src/Math/Test/Vector2Test.h +++ b/src/Math/Test/Vector2Test.h @@ -25,6 +25,7 @@ class Vector2Test: public Corrade::TestSuite::Tester { void construct(); void axes(); + void scales(); void debug(); }; diff --git a/src/Math/Test/Vector3Test.cpp b/src/Math/Test/Vector3Test.cpp index 1a84a2012..1ea4ad574 100644 --- a/src/Math/Test/Vector3Test.cpp +++ b/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)); } diff --git a/src/Math/Test/Vector3Test.h b/src/Math/Test/Vector3Test.h index 4d817dc07..247c63e0d 100644 --- a/src/Math/Test/Vector3Test.h +++ b/src/Math/Test/Vector3Test.h @@ -26,6 +26,7 @@ class Vector3Test: public Corrade::TestSuite::Tester { void construct(); void cross(); void axes(); + void scales(); void twoComponent(); void debug(); diff --git a/src/Math/Vector2.h b/src/Math/Vector2.h index 0caa28b5b..8c81dce48 100644 --- a/src/Math/Vector2.h +++ b/src/Math/Vector2.h @@ -33,7 +33,7 @@ template 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 xAxis(T length = T(1)) { return Vector2(length, T()); } @@ -41,9 +41,29 @@ template class Vector2: public Vector<2, T> { * @brief %Vector in direction of Y axis * * See xAxis() for more information. + * @see yScale() */ inline constexpr static Vector2 yAxis(T length = T(1)) { return Vector2(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 xScale(T scale) { return Vector2(scale, T(1)); } + + /** + * @brief Scaling vector in direction of Y axis + * + * See xScale() for more information. + * @see yAxis() + */ + inline constexpr static Vector2 yScale(T scale) { return Vector2(T(1), scale); } + /** @copydoc Vector::Vector(T) */ inline constexpr explicit Vector2(T value = T()): Vector<2, T>(value, value) {} diff --git a/src/Math/Vector3.h b/src/Math/Vector3.h index 13c495332..2510c1f2e 100644 --- a/src/Math/Vector3.h +++ b/src/Math/Vector3.h @@ -34,7 +34,7 @@ template 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 xAxis(T length = T(1)) { return Vector3(length, T(), T()); } @@ -42,6 +42,7 @@ template class Vector3: public Vector<3, T> { * @brief %Vector in direction of Y axis * * See xAxis() for more information. + * @see yScale() */ inline constexpr static Vector3 yAxis(T length = T(1)) { return Vector3(T(), length, T()); } @@ -49,9 +50,37 @@ template class Vector3: public Vector<3, T> { * @brief %Vector in direction of Z axis * * See xAxis() for more information. + * @see zScale() */ inline constexpr static Vector3 zAxis(T length = T(1)) { return Vector3(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 xScale(T scale) { return Vector3(scale, T(1), T(1)); } + + /** + * @brief Scaling vector in direction of Y axis + * + * See xScale() for more information. + * @see yAxis() + */ + inline constexpr static Vector3 yScale(T scale) { return Vector3(T(1), scale, T(1)); } + + /** + * @brief Scaling vector in direction of Z axis + * + * See xScale() for more information. + * @see zAxis() + */ + inline constexpr static Vector3 zScale(T scale) { return Vector3(T(1), T(1), scale); } + /** * @brief Cross product *