diff --git a/doc/changelog.dox b/doc/changelog.dox index 4afa18cf6..963a4401d 100644 --- a/doc/changelog.dox +++ b/doc/changelog.dox @@ -77,6 +77,9 @@ See also: - New @ref Range1Dui, @ref Range2Dui and @ref Range3Dui typedefs for unsigned integer ranges - New @ref Nanoseconds and @ref Seconds typedefs for time values +- New @ref Matrix2x1, @ref Matrix3x1, @ref Matrix4x1 typedefs for single-row + matrices as a counterpart for column vectors, together with corresponding + double variants and type aliases in the @ref Math library - Added MSVC Natvis files and pretty-printers for GDB. See @ref debuggers, [mosra/magnum#589](https://github.com/mosra/magnum/pull/589), [mosra/magnum#595](https://github.com/mosra/magnum/pull/595), diff --git a/doc/snippets/Math.cpp b/doc/snippets/Math.cpp index 62d955232..57d5b7099 100644 --- a/doc/snippets/Math.cpp +++ b/doc/snippets/Math.cpp @@ -1328,6 +1328,19 @@ Float a = m[2][1]; static_cast(a); } +{ +/* [RectangularMatrix-multiply-vector] */ +Matrix3x4 m = DOXYGEN_ELLIPSIS({}); +Vector3 v = DOXYGEN_ELLIPSIS({}); + +/* a1 and a2 contain the same data, just transposed */ +Vector4 a1 = m*v; +Matrix4x1 a2 = Matrix3x1::fromVector(v)*m.transposed(); +/* [RectangularMatrix-multiply-vector] */ +static_cast(a1); +static_cast(a2); +} + { /* [gather] */ Vector4i original(-1, 2, 3, 4); diff --git a/doc/types.dox b/doc/types.dox index ca6fb1095..244f77f73 100644 --- a/doc/types.dox +++ b/doc/types.dox @@ -86,29 +86,36 @@ after type name means @ref Float underlying type, `h` means @ref Half, `d` is | Magnum matrix type | Equivalent GLSL type | | ---------------------------------------------------------------- | ------------------------------------- | +| @ref Matrix2x1 or @ref Matrix2x1d | (*none*) | | @ref Matrix2x2 or @ref Matrix2x2d | @glsl mat2 @ce / @glsl mat2x2 @ce or @glsl dmat2 @ce / @glsl dmat2x2 @ce | | @ref Matrix2x2h, @ref Matrix2x2b, @ref Matrix2x2s | (*none*) | -| @ref Matrix3 / @ref Matrix3x3 or @ref Matrix3d / @ref Matrix3x3d | @glsl mat3 @ce / @glsl mat3x3 @ce or @glsl dmat3 @ce / @glsl dmat3x3 @ce | -| @ref Matrix3x3h, @ref Matrix3x3b, @ref Matrix3x3s | (*none*) | -| @ref Matrix4 / @ref Matrix4x4 or @ref Matrix4d / @ref Matrix4x4d | @glsl mat4 @ce / @glsl mat4x4 @ce or @glsl dmat4 @ce / @glsl dmat4x4 @ce | -| @ref Matrix4x4h, @ref Matrix4x4b, @ref Matrix4x4s | (*none*) | | @ref Matrix2x3 or @ref Matrix2x3d | @glsl mat2x3 @ce or @glsl dmat2x3 @ce | | @ref Matrix2x3h, @ref Matrix2x3b, @ref Matrix2x3s | (*none*) | -| @ref Matrix3x2 or @ref Matrix3x2d | @glsl mat3x2 @ce or @glsl dmat3x2 @ce | -| @ref Matrix3x2h, @ref Matrix3x2b, @ref Matrix3x2s | (*none*) | | @ref Matrix2x4 or @ref Matrix2x4d | @glsl mat2x4 @ce or @glsl dmat2x4 @ce | | @ref Matrix2x4h, @ref Matrix2x4b, @ref Matrix2x4s | (*none*) | -| @ref Matrix4x2 or @ref Matrix4x2d | @glsl mat4x2 @ce or @glsl dmat4x2 @ce | -| @ref Matrix4x2h, @ref Matrix4x2b, @ref Matrix4x2s | (*none*) | +| @ref Matrix3x1 or @ref Matrix3x1d | (*none*) | +| @ref Matrix3x2 or @ref Matrix3x2d | @glsl mat3x2 @ce or @glsl dmat3x2 @ce | +| @ref Matrix3x2h, @ref Matrix3x2b, @ref Matrix3x2s | (*none*) | +| @ref Matrix3 / @ref Matrix3x3 or @ref Matrix3d / @ref Matrix3x3d | @glsl mat3 @ce / @glsl mat3x3 @ce or @glsl dmat3 @ce / @glsl dmat3x3 @ce | +| @ref Matrix3x3h, @ref Matrix3x3b, @ref Matrix3x3s | (*none*) | | @ref Matrix3x4 or @ref Matrix3x4d | @glsl mat3x4 @ce or @glsl dmat3x4 @ce | | @ref Matrix3x4h, @ref Matrix3x4b, @ref Matrix3x4s | (*none*) | +| @ref Matrix4x1 or @ref Matrix4x1d | (*none*) | +| @ref Matrix4x2 or @ref Matrix4x2d | @glsl mat4x2 @ce or @glsl dmat4x2 @ce | +| @ref Matrix4x2h, @ref Matrix4x2b, @ref Matrix4x2s | (*none*) | | @ref Matrix4x3 or @ref Matrix4x3d | @glsl mat4x3 @ce or @glsl dmat4x3 @ce | | @ref Matrix4x3h, @ref Matrix4x3b, @ref Matrix4x3s | (*none*) | +| @ref Matrix4 / @ref Matrix4x4 or @ref Matrix4d / @ref Matrix4x4d | @glsl mat4 @ce / @glsl mat4x4 @ce or @glsl dmat4 @ce / @glsl dmat4x4 @ce | +| @ref Matrix4x4h, @ref Matrix4x4b, @ref Matrix4x4s | (*none*) | Any super- or sub-class of the same size and underlying type can be used equivalently (e.g. @ref Math::Vector "Math::Vector" or @ref Color3 instead of @ref Vector3). +Vectors are columns and are usable in all contexts where single-column matrices +would be, such as matrix multiplication. The @ref Matrix2x1, @ref Matrix3x1 and +@ref Matrix4x1 typedefs are then their transposed single-row counterparts. + For easier entering of (s)RGB colors in hexadecimal format there are @link Math::Literals::ColorLiterals::operator""_srgb() _srgb @endlink / @link Math::Literals::ColorLiterals::operator""_srgbf() _srgbf @endlink, diff --git a/src/Magnum/Magnum.h b/src/Magnum/Magnum.h index f7adde2ce..e8b829fce 100644 --- a/src/Magnum/Magnum.h +++ b/src/Magnum/Magnum.h @@ -526,22 +526,10 @@ typedef Math::Color4 Color4ub; typedef Math::Color4 Color4us; /** -@brief 3x3 float transformation matrix - -Equivalent to GLSL @glsl mat3 @ce. -@see @ref Matrix3x3 -@m_keyword{mat3,GLSL mat3,} -*/ -typedef Math::Matrix3 Matrix3; - -/** -@brief 4x4 float transformation matrix - -Equivalent to GLSL @glsl mat4 @ce. -@see @ref Matrix4x4 -@m_keyword{mat4,GLSL mat4,} +@brief Float matrix with 2 columns and 1 row +@m_since_latest */ -typedef Math::Matrix4 Matrix4; +typedef Math::Matrix2x1 Matrix2x1; /** @brief 2x2 float matrix @@ -552,30 +540,26 @@ Equivalent to GLSL @glsl mat2x2 @ce. typedef Math::Matrix2x2 Matrix2x2; /** -@brief 3x3 float matrix +@brief Float matrix with 2 columns and 3 rows -Equivalent to GLSL @glsl mat3x3 @ce. Note that this is different from -@ref Matrix3, which contains additional functions for transformations in 2D. -@m_keyword{mat3x3,GLSL mat3x3,} +Equivalent to GLSL @glsl mat2x3 @ce. +@m_keyword{mat2x3,GLSL mat2x3,} */ -typedef Math::Matrix3x3 Matrix3x3; +typedef Math::Matrix2x3 Matrix2x3; /** -@brief 4x4 float matrix +@brief Float matrix with 2 columns and 4 rows -Equivalent to GLSL @glsl mat4x4 @ce. Note that this is different from -@ref Matrix4, which contains additional functions for transformations in 3D. -@m_keyword{mat4x4,GLSL mat4x4,} +Equivalent to GLSL @glsl mat2x4 @ce. +@m_keyword{mat2x4,GLSL mat2x4,} */ -typedef Math::Matrix4x4 Matrix4x4; +typedef Math::Matrix2x4 Matrix2x4; /** -@brief Float matrix with 2 columns and 3 rows - -Equivalent to GLSL @glsl mat2x3 @ce. -@m_keyword{mat2x3,GLSL mat2x3,} +@brief Float matrix with 3 columns and 1 row +@m_since_latest */ -typedef Math::Matrix2x3 Matrix2x3; +typedef Math::Matrix3x1 Matrix3x1; /** @brief Float matrix with 3 columns and 2 rows @@ -586,20 +570,13 @@ Equivalent to GLSL @glsl mat3x2 @ce. typedef Math::Matrix3x2 Matrix3x2; /** -@brief Float matrix with 2 columns and 4 rows - -Equivalent to GLSL @glsl mat2x4 @ce. -@m_keyword{mat2x4,GLSL mat2x4,} -*/ -typedef Math::Matrix2x4 Matrix2x4; - -/** -@brief Float matrix with 4 columns and 2 rows +@brief 3x3 float matrix -Equivalent to GLSL @glsl mat2x4 @ce. -@m_keyword{mat2x4,GLSL mat2x4,} +Equivalent to GLSL @glsl mat3x3 @ce. Note that this is different from +@ref Matrix3, which contains additional functions for transformations in 2D. +@m_keyword{mat3x3,GLSL mat3x3,} */ -typedef Math::Matrix4x2 Matrix4x2; +typedef Math::Matrix3x3 Matrix3x3; /** @brief Float matrix with 3 columns and 4 rows @@ -609,6 +586,20 @@ Equivalent to GLSL @glsl mat3x4 @ce. */ typedef Math::Matrix3x4 Matrix3x4; +/** +@brief Float matrix with 4 columns and 1 row +@m_since_latest +*/ +typedef Math::Matrix4x1 Matrix4x1; + +/** +@brief Float matrix with 4 columns and 2 rows + +Equivalent to GLSL @glsl mat2x4 @ce. +@m_keyword{mat2x4,GLSL mat2x4,} +*/ +typedef Math::Matrix4x2 Matrix4x2; + /** @brief Float matrix with 4 columns and 3 rows @@ -617,6 +608,33 @@ Equivalent to GLSL @glsl mat4x3 @ce. */ typedef Math::Matrix4x3 Matrix4x3; +/** +@brief 4x4 float matrix + +Equivalent to GLSL @glsl mat4x4 @ce. Note that this is different from +@ref Matrix4, which contains additional functions for transformations in 3D. +@m_keyword{mat4x4,GLSL mat4x4,} +*/ +typedef Math::Matrix4x4 Matrix4x4; + +/** +@brief 3x3 float transformation matrix + +Equivalent to GLSL @glsl mat3 @ce. +@see @ref Matrix3x3 +@m_keyword{mat3,GLSL mat3,} +*/ +typedef Math::Matrix3 Matrix3; + +/** +@brief 4x4 float transformation matrix + +Equivalent to GLSL @glsl mat4 @ce. +@see @ref Matrix4x4 +@m_keyword{mat4,GLSL mat4,} +*/ +typedef Math::Matrix4 Matrix4; + /** @brief Signed byte matrix with 2 columns and 2 rows @m_since{2020,06} @@ -1133,6 +1151,12 @@ Equivalent to GLSL @glsl dmat4 @ce. */ typedef Math::Matrix4 Matrix4d; +/** +@brief Double matrix with 2 columns and 1 row +@m_since_latest +*/ +typedef Math::Matrix2x1 Matrix2x1d; + /** @brief 2x2 double matrix @@ -1142,30 +1166,26 @@ Equivalent to GLSL @glsl dmat2x2 @ce. typedef Math::Matrix2x2 Matrix2x2d; /** -@brief 3x3 double matrix +@brief Double matrix with 2 columns and 3 rows -Equivalent to GLSL @glsl dmat3x3 @ce. Note that this is different from -@ref Matrix3d, which contains additional functions for transformations in 2D. -@m_keyword{dmat3x3,GLSL dmat3x3,} +Equivalent to GLSL @glsl dmat2x3 @ce. +@m_keyword{dmat2x3,GLSL dmat2x3,} */ -typedef Math::Matrix3x3 Matrix3x3d; +typedef Math::Matrix2x3 Matrix2x3d; /** -@brief 4x4 double matrix +@brief Double matrix with 2 columns and 4 rows -Equivalent to GLSL @glsl dmat4x4 @ce. Note that this is different from -@ref Matrix4d, which contains additional functions for transformations in 3D. -@m_keyword{dmat4x4,GLSL dmat4x4,} +Equivalent to GLSL @glsl dmat2x4 @ce. +@m_keyword{dmat2x4,GLSL dmat2x4,} */ -typedef Math::Matrix4x4 Matrix4x4d; +typedef Math::Matrix2x4 Matrix2x4d; /** -@brief Double matrix with 2 columns and 3 rows - -Equivalent to GLSL @glsl dmat2x3 @ce. -@m_keyword{dmat2x3,GLSL dmat2x3,} +@brief Double matrix with 3 columns and 1 row +@m_since_latest */ -typedef Math::Matrix2x3 Matrix2x3d; +typedef Math::Matrix3x1 Matrix3x1d; /** @brief Double matrix with 3 columns and 2 rows @@ -1176,20 +1196,13 @@ Equivalent to GLSL @glsl dmat3x2 @ce. typedef Math::Matrix3x2 Matrix3x2d; /** -@brief Double matrix with 2 columns and 4 rows - -Equivalent to GLSL @glsl dmat2x4 @ce. -@m_keyword{dmat2x4,GLSL dmat2x4,} -*/ -typedef Math::Matrix2x4 Matrix2x4d; - -/** -@brief Double matrix with 4 columns and 2 rows +@brief 3x3 double matrix -Equivalent to GLSL @glsl dmat4x2 @ce. -@m_keyword{dmat4x2,GLSL dmat4x2,} +Equivalent to GLSL @glsl dmat3x3 @ce. Note that this is different from +@ref Matrix3d, which contains additional functions for transformations in 2D. +@m_keyword{dmat3x3,GLSL dmat3x3,} */ -typedef Math::Matrix4x2 Matrix4x2d; +typedef Math::Matrix3x3 Matrix3x3d; /** @brief Double matrix with 3 columns and 4 rows @@ -1199,6 +1212,20 @@ Equivalent to GLSL @glsl dmat3x4 @ce. */ typedef Math::Matrix3x4 Matrix3x4d; +/** +@brief Double matrix with 4 columns and 1 row +@m_since_latest +*/ +typedef Math::Matrix4x1 Matrix4x1d; + +/** +@brief Double matrix with 4 columns and 2 rows + +Equivalent to GLSL @glsl dmat4x2 @ce. +@m_keyword{dmat4x2,GLSL dmat4x2,} +*/ +typedef Math::Matrix4x2 Matrix4x2d; + /** @brief Double matrix with 4 columns and 3 rows @@ -1207,6 +1234,15 @@ Equivalent to GLSL @glsl dmat4x3 @ce. */ typedef Math::Matrix4x3 Matrix4x3d; +/** +@brief 4x4 double matrix + +Equivalent to GLSL @glsl dmat4x4 @ce. Note that this is different from +@ref Matrix4d, which contains additional functions for transformations in 3D. +@m_keyword{dmat4x4,GLSL dmat4x4,} +*/ +typedef Math::Matrix4x4 Matrix4x4d; + /** @brief Double two-dimensional quadratic Bézier curve */ typedef Math::QuadraticBezier2D QuadraticBezier2Dd; diff --git a/src/Magnum/Math/Math.h b/src/Magnum/Math/Math.h index e0b25e988..89be3bf0b 100644 --- a/src/Magnum/Math/Math.h +++ b/src/Magnum/Math/Math.h @@ -67,11 +67,14 @@ template class Matrix4; template class Quaternion; template class RectangularMatrix; +template using Matrix2x1 = RectangularMatrix<2, 1, T>; template using Matrix2x3 = RectangularMatrix<2, 3, T>; -template using Matrix3x2 = RectangularMatrix<3, 2, T>; template using Matrix2x4 = RectangularMatrix<2, 4, T>; -template using Matrix4x2 = RectangularMatrix<4, 2, T>; +template using Matrix3x1 = RectangularMatrix<3, 1, T>; +template using Matrix3x2 = RectangularMatrix<3, 2, T>; template using Matrix3x4 = RectangularMatrix<3, 4, T>; +template using Matrix4x1 = RectangularMatrix<4, 1, T>; +template using Matrix4x2 = RectangularMatrix<4, 2, T>; template using Matrix4x3 = RectangularMatrix<4, 3, T>; template class, class> class Unit; diff --git a/src/Magnum/Math/RectangularMatrix.h b/src/Magnum/Math/RectangularMatrix.h index b64b39556..77ea6d11a 100644 --- a/src/Magnum/Math/RectangularMatrix.h +++ b/src/Magnum/Math/RectangularMatrix.h @@ -64,22 +64,25 @@ namespace Implementation { @tparam rows Row count @tparam T Underlying data type -See @ref matrix-vector for brief introduction. See also @ref Matrix (square) -and @ref Vector. +See @ref matrix-vector for brief introduction. See also @ref Matrix (square), +@ref Matrix3, @ref Matrix4 and @ref Vector. The data are stored in column-major order, to reflect that, all indices in math formulas are in reverse order (i.e. @f$ \boldsymbol A_{ji} @f$ instead of @f$ \boldsymbol A_{ij} @f$). -@see @ref Matrix2x3, @ref Matrix3x2, @ref Matrix2x4, @ref Matrix4x2, - @ref Matrix3x4, @ref Matrix4x3, @ref Magnum::Matrix2x3, - @ref Magnum::Matrix2x3d, @ref Magnum::Matrix2x3h, @ref Magnum::Matrix2x3b, - @ref Magnum::Matrix2x3s, @ref Magnum::Matrix3x2, @ref Magnum::Matrix3x2d, - @ref Magnum::Matrix3x2h, @ref Magnum::Matrix3x2b, @ref Magnum::Matrix3x2s, - @ref Magnum::Matrix2x4, @ref Magnum::Matrix2x4d, @ref Magnum::Matrix2x4h, - @ref Magnum::Matrix2x4b, @ref Magnum::Matrix2x4s, @ref Magnum::Matrix4x2, - @ref Magnum::Matrix4x2d, @ref Magnum::Matrix4x2h, @ref Magnum::Matrix4x2b, - @ref Magnum::Matrix4x2s, @ref Magnum::Matrix3x4, @ref Magnum::Matrix3x4d, - @ref Magnum::Matrix3x4h, @ref Magnum::Matrix3x4b, @ref Magnum::Matrix3x4s, +@see @ref Matrix2x1, @ref Matrix2x3, @ref Matrix2x4, @ref Matrix3x1, + @ref Matrix3x2, @ref Matrix3x4, @ref Matrix4x1, @ref Matrix4x2, + @ref Matrix4x3, @ref Magnum::Matrix2x1, @ref Magnum::Matrix2x1d, + @ref Magnum::Matrix2x3, @ref Magnum::Matrix2x3d, @ref Magnum::Matrix2x3h, + @ref Magnum::Matrix2x3b, @ref Magnum::Matrix2x3s, @ref Magnum::Matrix2x4, + @ref Magnum::Matrix2x4d, @ref Magnum::Matrix2x4h, @ref Magnum::Matrix2x4b, + @ref Magnum::Matrix2x4s, @ref Magnum::Matrix3x1, @ref Magnum::Matrix3x1d, + @ref Magnum::Matrix3x2, @ref Magnum::Matrix3x2d, @ref Magnum::Matrix3x2h, + @ref Magnum::Matrix3x2b, @ref Magnum::Matrix3x2s, @ref Magnum::Matrix3x4, + @ref Magnum::Matrix3x4d, @ref Magnum::Matrix3x4h, @ref Magnum::Matrix3x4b, + @ref Magnum::Matrix3x4s, @ref Magnum::Matrix4x1, @ref Magnum::Matrix4x1, + @ref Magnum::Matrix4x1d, @ref Magnum::Matrix4x2, @ref Magnum::Matrix4x2d, + @ref Magnum::Matrix4x2h, @ref Magnum::Matrix4x2b, @ref Magnum::Matrix4x2s, @ref Magnum::Matrix4x3, @ref Magnum::Matrix4x3d, @ref Magnum::Matrix4x3h, @ref Magnum::Matrix4x3b, @ref Magnum::Matrix4x3s */ @@ -501,10 +504,16 @@ template class RectangularMatrix { /** * @brief Multiply a vector * - * Internally the same as multiplying with one-column matrix, but - * returns vector. @f[ + * Internally the same as multiplying with a one-column matrix, but + * returns a vector instead of a one-column matrix. @f[ * (\boldsymbol {Aa})_i = \sum_{k=0}^{m-1} \boldsymbol A_{ki} \boldsymbol a_k * @f] + * + * Vectors are treated as columns. An equivalent operation is + * multiplying a transposed matrix with an one-row matrix from the left + * side instead: + * + * @snippet Math.cpp RectangularMatrix-multiply-vector */ Vector operator*(const Vector& other) const { return operator*(RectangularMatrix<1, cols, T>(other))[0]; @@ -606,27 +615,27 @@ template class RectangularMatrix { }; /** -@brief Matrix with 2 columns and 3 rows +@brief Matrix with 2 columns and 1 row +@m_since_latest -Convenience alternative to @cpp RectangularMatrix<2, 3, T> @ce. See -@ref RectangularMatrix for more information. -@see @ref Magnum::Matrix2x3, @ref Magnum::Matrix2x3d, @ref Magnum::Matrix2x3h, - @ref Magnum::Matrix2x3b, @ref Magnum::Matrix2x3s +Convenience alternative to @cpp RectangularMatrix<2, 1, T> @ce. See +@ref RectangularMatrix for more information. There's no 1-column 2-row matrix typedef, use @ref Vector2 instead. +@see @ref Magnum::Matrix2x1, @ref Magnum::Matrix2x1d */ #ifndef CORRADE_MSVC2015_COMPATIBILITY /* Multiple definitions still broken */ -template using Matrix2x3 = RectangularMatrix<2, 3, T>; +template using Matrix2x1 = RectangularMatrix<2, 1, T>; #endif /** -@brief Matrix with 3 columns and 2 rows +@brief Matrix with 2 columns and 3 rows -Convenience alternative to @cpp RectangularMatrix<3, 2, T> @ce. See +Convenience alternative to @cpp RectangularMatrix<2, 3, T> @ce. See @ref RectangularMatrix for more information. -@see @ref Magnum::Matrix3x2, @ref Magnum::Matrix3x2d, @ref Magnum::Matrix3x2h, - @ref Magnum::Matrix3x2b, @ref Magnum::Matrix3x2s +@see @ref Magnum::Matrix2x3, @ref Magnum::Matrix2x3d, @ref Magnum::Matrix2x3h, + @ref Magnum::Matrix2x3b, @ref Magnum::Matrix2x3s */ #ifndef CORRADE_MSVC2015_COMPATIBILITY /* Multiple definitions still broken */ -template using Matrix3x2 = RectangularMatrix<3, 2, T>; +template using Matrix2x3 = RectangularMatrix<2, 3, T>; #endif /** @@ -642,15 +651,27 @@ template using Matrix2x4 = RectangularMatrix<2, 4, T>; #endif /** -@brief Matrix with 4 columns and 2 rows +@brief Matrix with 3 columns and 1 row +@m_since_latest -Convenience alternative to @cpp RectangularMatrix<4, 2, T> @ce. See +Convenience alternative to @cpp RectangularMatrix<3, 1, T> @ce. See +@ref RectangularMatrix for more information. There's no 1-column 3-row matrix typedef, use @ref Vector3 instead. +@see @ref Magnum::Matrix3x1, @ref Magnum::Matrix3x1d +*/ +#ifndef CORRADE_MSVC2015_COMPATIBILITY /* Multiple definitions still broken */ +template using Matrix3x1 = RectangularMatrix<3, 1, T>; +#endif + +/** +@brief Matrix with 3 columns and 2 rows + +Convenience alternative to @cpp RectangularMatrix<3, 2, T> @ce. See @ref RectangularMatrix for more information. -@see @ref Magnum::Matrix4x2, @ref Magnum::Matrix4x2d, @ref Magnum::Matrix4x2h, - @ref Magnum::Matrix4x2b, @ref Magnum::Matrix4x2s +@see @ref Magnum::Matrix3x2, @ref Magnum::Matrix3x2d, @ref Magnum::Matrix3x2h, + @ref Magnum::Matrix3x2b, @ref Magnum::Matrix3x2s */ #ifndef CORRADE_MSVC2015_COMPATIBILITY /* Multiple definitions still broken */ -template using Matrix4x2 = RectangularMatrix<4, 2, T>; +template using Matrix3x2 = RectangularMatrix<3, 2, T>; #endif /** @@ -665,6 +686,30 @@ Convenience alternative to @cpp RectangularMatrix<3, 4, T> @ce. See template using Matrix3x4 = RectangularMatrix<3, 4, T>; #endif +/** +@brief Matrix with 4 columns and 1 row +@m_since_latest + +Convenience alternative to @cpp RectangularMatrix<4, 1, T> @ce. See +@ref RectangularMatrix for more information. There's no 1-column 4-row matrix typedef, use @ref Vector4 instead. +@see @ref Magnum::Matrix4x1, @ref Magnum::Matrix4x1d +*/ +#ifndef CORRADE_MSVC2015_COMPATIBILITY /* Multiple definitions still broken */ +template using Matrix4x1 = RectangularMatrix<4, 1, T>; +#endif + +/** +@brief Matrix with 4 columns and 2 rows + +Convenience alternative to @cpp RectangularMatrix<4, 2, T> @ce. See +@ref RectangularMatrix for more information. +@see @ref Magnum::Matrix4x2, @ref Magnum::Matrix4x2d, @ref Magnum::Matrix4x2h, + @ref Magnum::Matrix4x2b, @ref Magnum::Matrix4x2s +*/ +#ifndef CORRADE_MSVC2015_COMPATIBILITY /* Multiple definitions still broken */ +template using Matrix4x2 = RectangularMatrix<4, 2, T>; +#endif + /** @brief Matrix with 4 columns and 3 rows diff --git a/src/Magnum/Math/Test/RectangularMatrixTest.cpp b/src/Magnum/Math/Test/RectangularMatrixTest.cpp index 9cf7f888f..8b40c6786 100644 --- a/src/Magnum/Math/Test/RectangularMatrixTest.cpp +++ b/src/Magnum/Math/Test/RectangularMatrixTest.cpp @@ -82,6 +82,7 @@ struct RectangularMatrixTest: TestSuite::Tester { void multiplyDivide(); void multiply(); void multiplyVector(); + void multiplyRowVector(); void transposed(); void flippedCols(); @@ -115,8 +116,10 @@ typedef Vector<3, Float> Vector3; typedef Vector<2, Float> Vector2; using Magnum::BitVector3; -typedef RectangularMatrix<4, 3, Int> Matrix4x3i; -typedef RectangularMatrix<3, 4, Int> Matrix3x4i; +typedef Math::Matrix3x1 Matrix3x1i; +typedef Math::Matrix4x1 Matrix4x1i; +typedef Math::Matrix4x3 Matrix4x3i; +typedef Math::Matrix3x4 Matrix3x4i; typedef Vector<4, Int> Vector4i; typedef Vector<3, Int> Vector3i; typedef Vector<2, Int> Vector2i; @@ -146,6 +149,7 @@ RectangularMatrixTest::RectangularMatrixTest() { &RectangularMatrixTest::multiplyDivide, &RectangularMatrixTest::multiply, &RectangularMatrixTest::multiplyVector, + &RectangularMatrixTest::multiplyRowVector, &RectangularMatrixTest::transposed, &RectangularMatrixTest::flippedCols, @@ -606,6 +610,19 @@ void RectangularMatrixTest::multiplyVector() { /* There's no *= for vector and matrix multiplication either */ } +void RectangularMatrixTest::multiplyRowVector() { + /* Like multiplyVector() above, just transposed */ + + const Vector3i d{2, -2, 3}; + const Matrix4x3i c{Vector3i{ 0, 1, 3}, + Vector3i{ 4, 5, 7}, + Vector3i{ 8, 9, 11}, + Vector3i{12, 13, 15}}; + CORRADE_COMPARE(Matrix3x1i::fromVector(d)*c, (Matrix4x1i{ + 7, 19, 31, 43 + })); +} + void RectangularMatrixTest::transposed() { Matrix4x3 original(Vector3( 0.0f, 1.0f, 3.0f), Vector3( 4.0f, 5.0f, 7.0f), diff --git a/src/Magnum/Math/Vector2.h b/src/Magnum/Math/Vector2.h index 84f04e20c..7b5f1903d 100644 --- a/src/Magnum/Math/Vector2.h +++ b/src/Magnum/Math/Vector2.h @@ -66,7 +66,8 @@ template inline T cross(const Vector2& a, const Vector2& b) { @brief Two-component vector @tparam T Data type -See @ref matrix-vector for brief introduction. +See @ref matrix-vector for brief introduction. The vectors are columns, see +@ref Matrix2x1 for a row vector. @see @ref Magnum::Vector2, @ref Magnum::Vector3h, @ref Magnum::Vector2d, @ref Magnum::Vector2ub, @ref Magnum::Vector2b, @ref Magnum::Vector2us, @ref Magnum::Vector2s, @ref Magnum::Vector2ui, @ref Magnum::Vector2i diff --git a/src/Magnum/Math/Vector3.h b/src/Magnum/Math/Vector3.h index 2bbf7ff8b..45db79529 100644 --- a/src/Magnum/Math/Vector3.h +++ b/src/Magnum/Math/Vector3.h @@ -68,7 +68,8 @@ template inline Vector3 cross(const Vector3& a, const Vector3& @brief Three-component vector @tparam T Data type -See @ref matrix-vector for brief introduction. +See @ref matrix-vector for brief introduction. The vectors are columns, see +@ref Matrix3x1 for a row vector. @see @ref Magnum::Vector3, @ref Magnum::Vector3h, @ref Magnum::Vector3d, @ref Magnum::Vector3ub, @ref Magnum::Vector3b, @ref Magnum::Vector3us, @ref Magnum::Vector3s, @ref Magnum::Vector3ui, @ref Magnum::Vector3i diff --git a/src/Magnum/Math/Vector4.h b/src/Magnum/Math/Vector4.h index 1c1402908..08d639cd4 100644 --- a/src/Magnum/Math/Vector4.h +++ b/src/Magnum/Math/Vector4.h @@ -41,7 +41,8 @@ namespace Magnum { namespace Math { @brief Four-component vector @tparam T Data type -See @ref matrix-vector for brief introduction. +See @ref matrix-vector for brief introduction. The vectors are columns, see +@ref Matrix4x1 for a row vector. @see @ref Magnum::Vector4, @ref Magnum::Vector4h, @ref Magnum::Vector4d, @ref Magnum::Vector4ub, @ref Magnum::Vector4b, @ref Magnum::Vector4us, @ref Magnum::Vector4s, @ref Magnum::Vector4ui, @ref Magnum::Vector4i