1 /****************************************************************************
3 ** Copyright (C) 2012 Digia Plc and/or its subsidiary(-ies).
4 ** Contact: http://www.qt-project.org/legal
6 ** This file is part of the QtGui module of the Qt Toolkit.
8 ** $QT_BEGIN_LICENSE:LGPL$
9 ** Commercial License Usage
10 ** Licensees holding valid commercial Qt licenses may use this file in
11 ** accordance with the commercial license agreement provided with the
12 ** Software or, alternatively, in accordance with the terms contained in
13 ** a written agreement between you and Digia. For licensing terms and
14 ** conditions see http://qt.digia.com/licensing. For further information
15 ** use the contact form at http://qt.digia.com/contact-us.
17 ** GNU Lesser General Public License Usage
18 ** Alternatively, this file may be used under the terms of the GNU Lesser
19 ** General Public License version 2.1 as published by the Free Software
20 ** Foundation and appearing in the file LICENSE.LGPL included in the
21 ** packaging of this file. Please review the following information to
22 ** ensure the GNU Lesser General Public License version 2.1 requirements
23 ** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
25 ** In addition, as a special exception, Digia gives you certain additional
26 ** rights. These rights are described in the Digia Qt LGPL Exception
27 ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
29 ** GNU General Public License Usage
30 ** Alternatively, this file may be used under the terms of the GNU
31 ** General Public License version 3.0 as published by the Free Software
32 ** Foundation and appearing in the file LICENSE.GPL included in the
33 ** packaging of this file. Please review the following information to
34 ** ensure the GNU General Public License version 3.0 requirements will be
35 ** met: http://www.gnu.org/copyleft/gpl.html.
40 ****************************************************************************/
42 #include "qgenericmatrix.h"
48 \brief The QGenericMatrix class is a template class that represents a NxM transformation matrix with N columns and M rows.
54 The QGenericMatrix template has three parameters:
57 \row \li N \li Number of columns.
58 \row \li M \li Number of rows.
59 \row \li T \li Element type that is visible to users of the class.
66 \fn QGenericMatrix::QGenericMatrix()
68 Constructs a NxM identity matrix.
72 \fn QGenericMatrix::QGenericMatrix(const QGenericMatrix<N, M, T>& other)
74 Constructs a copy of \a other.
78 \fn QGenericMatrix::QGenericMatrix(const T *values)
80 Constructs a matrix from the given N * M floating-point \a values.
81 The contents of the array \a values is assumed to be in
88 \fn const T& QGenericMatrix::operator()(int row, int column) const
90 Returns a constant reference to the element at position
91 (\a row, \a column) in this matrix.
95 \fn T& QGenericMatrix::operator()(int row, int column)
97 Returns a reference to the element at position (\a row, \a column)
98 in this matrix so that the element can be assigned to.
102 \fn bool QGenericMatrix::isIdentity() const
104 Returns true if this matrix is the identity; false otherwise.
110 \fn void QGenericMatrix::setToIdentity()
112 Sets this matrix to the identity.
118 \fn void QGenericMatrix::fill(T value)
120 Fills all elements of this matrix with \a value.
124 \fn QGenericMatrix<M, N> QGenericMatrix::transposed() const
126 Returns this matrix, transposed about its diagonal.
130 \fn QGenericMatrix<N, M, T>& QGenericMatrix::operator+=(const QGenericMatrix<N, M, T>& other)
132 Adds the contents of \a other to this matrix.
136 \fn QGenericMatrix<N, M, T>& QGenericMatrix::operator-=(const QGenericMatrix<N, M, T>& other)
138 Subtracts the contents of \a other from this matrix.
142 \fn QGenericMatrix<N, M, T>& QGenericMatrix::operator*=(T factor)
144 Multiplies all elements of this matrix by \a factor.
148 \fn QGenericMatrix<N, M, T>& QGenericMatrix::operator/=(T divisor)
150 Divides all elements of this matrix by \a divisor.
154 \fn bool QGenericMatrix::operator==(const QGenericMatrix<N, M, T>& other) const
156 Returns true if this matrix is identical to \a other; false otherwise.
160 \fn bool QGenericMatrix::operator!=(const QGenericMatrix<N, M, T>& other) const
162 Returns true if this matrix is not identical to \a other; false otherwise.
166 \fn QGenericMatrix<N, M, T> operator+(const QGenericMatrix<N, M, T>& m1, const QGenericMatrix<N, M, T>& m2)
167 \relates QGenericMatrix
169 Returns the sum of \a m1 and \a m2.
173 \fn QGenericMatrix<N, M, T> operator-(const QGenericMatrix<N, M, T>& m1, const QGenericMatrix<N, M, T>& m2)
174 \relates QGenericMatrix
176 Returns the difference of \a m1 and \a m2.
180 \fn QGenericMatrix<M1, M2, T> operator*(const QGenericMatrix<N, M2, T>& m1, const QGenericMatrix<M1, N, T>& m2)
181 \relates QGenericMatrix
183 Returns the product of the NxM2 matrix \a m1 and the M1xN matrix \a m2
184 to produce a M1xM2 matrix result.
188 \fn QGenericMatrix<N, M, T> operator-(const QGenericMatrix<N, M, T>& matrix)
190 \relates QGenericMatrix
192 Returns the negation of \a matrix.
196 \fn QGenericMatrix<N, M, T> operator*(T factor, const QGenericMatrix<N, M, T>& matrix)
197 \relates QGenericMatrix
199 Returns the result of multiplying all elements of \a matrix by \a factor.
203 \fn QGenericMatrix<N, M, T> operator*(const QGenericMatrix<N, M, T>& matrix, T factor)
204 \relates QGenericMatrix
206 Returns the result of multiplying all elements of \a matrix by \a factor.
210 \fn QGenericMatrix<N, M, T> operator/(const QGenericMatrix<N, M, T>& matrix, T divisor)
211 \relates QGenericMatrix
213 Returns the result of dividing all elements of \a matrix by \a divisor.
217 \fn void QGenericMatrix::copyDataTo(T *values) const
219 Retrieves the N * M items in this matrix and copies them to \a values
224 \fn T *QGenericMatrix::data()
226 Returns a pointer to the raw data of this matrix.
232 \fn const T *QGenericMatrix::data() const
234 Returns a constant pointer to the raw data of this matrix.
240 \fn const T *QGenericMatrix::constData() const
242 Returns a constant pointer to the raw data of this matrix.
247 #ifndef QT_NO_DATASTREAM
250 \fn QDataStream &operator<<(QDataStream &stream, const QGenericMatrix<N, M, T> &matrix)
251 \relates QGenericMatrix
253 Writes the given \a matrix to the given \a stream and returns a
254 reference to the stream.
256 \sa {Serializing Qt Data Types}
260 \fn QDataStream &operator>>(QDataStream &stream, QGenericMatrix<N, M, T> &matrix)
261 \relates QGenericMatrix
263 Reads a NxM matrix from the given \a stream into the given \a matrix
264 and returns a reference to the stream.
266 \sa {Serializing Qt Data Types}
273 \relates QGenericMatrix
275 The QMatrix2x2 type defines a convenient instantiation of the
276 QGenericMatrix template for 2 columns, 2 rows, and float as
282 \relates QGenericMatrix
284 The QMatrix2x3 type defines a convenient instantiation of the
285 QGenericMatrix template for 2 columns, 3 rows, and float as
291 \relates QGenericMatrix
293 The QMatrix2x4 type defines a convenient instantiation of the
294 QGenericMatrix template for 2 columns, 4 rows, and float as
300 \relates QGenericMatrix
302 The QMatrix3x2 type defines a convenient instantiation of the
303 QGenericMatrix template for 3 columns, 2 rows, and float as
309 \relates QGenericMatrix
311 The QMatrix3x3 type defines a convenient instantiation of the
312 QGenericMatrix template for 3 columns, 3 rows, and float as
318 \relates QGenericMatrix
320 The QMatrix3x4 type defines a convenient instantiation of the
321 QGenericMatrix template for 3 columns, 4 rows, and float as
327 \relates QGenericMatrix
329 The QMatrix4x2 type defines a convenient instantiation of the
330 QGenericMatrix template for 4 columns, 2 rows, and float as
336 \relates QGenericMatrix
338 The QMatrix4x3 type defines a convenient instantiation of the
339 QGenericMatrix template for 4 columns, 3 rows, and float as