1// Copyright (C) 2016 The Qt Company Ltd.
2// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
3
4#include "qgenericmatrix.h"
5
6QT_BEGIN_NAMESPACE
7
8QT_IMPL_METATYPE_EXTERN(QMatrix2x2)
9QT_IMPL_METATYPE_EXTERN(QMatrix2x3)
10QT_IMPL_METATYPE_EXTERN(QMatrix2x4)
11QT_IMPL_METATYPE_EXTERN(QMatrix3x2)
12QT_IMPL_METATYPE_EXTERN(QMatrix3x3)
13QT_IMPL_METATYPE_EXTERN(QMatrix3x4)
14QT_IMPL_METATYPE_EXTERN(QMatrix4x2)
15QT_IMPL_METATYPE_EXTERN(QMatrix4x3)
16
17/*!
18 \class QGenericMatrix
19 \brief The QGenericMatrix class is a template class that represents a NxM transformation matrix with N columns and M rows.
20 \since 4.6
21 \ingroup painting
22 \ingroup painting-3D
23 \inmodule QtGui
24
25 The QGenericMatrix template has three parameters:
26
27 \table
28 \row \li N \li Number of columns.
29 \row \li M \li Number of rows.
30 \row \li T \li Element type that is visible to users of the class.
31 \endtable
32
33 \sa QMatrix4x4
34*/
35
36/*!
37 \fn template <int N, int M, typename T> QGenericMatrix<N, M, T>::QGenericMatrix()
38
39 Constructs a NxM identity matrix.
40*/
41
42/*!
43 \fn template <int N, int M, typename T> QGenericMatrix<N, M, T>::QGenericMatrix(Qt::Initialization)
44 \since 5.5
45 \internal
46
47 Constructs a NxM matrix without initializing the contents.
48*/
49
50/*!
51 \fn template <int N, int M, typename T> QGenericMatrix<N, M, T>::QGenericMatrix(const T *values)
52
53 Constructs a matrix from the given N * M floating-point \a values.
54 The contents of the array \a values is assumed to be in
55 row-major order.
56
57 \sa copyDataTo()
58*/
59
60/*!
61 \fn template <int N, int M, typename T> const T& QGenericMatrix<N, M, T>::operator()(int row, int column) const
62
63 Returns a constant reference to the element at position
64 (\a row, \a column) in this matrix.
65*/
66
67/*!
68 \fn template <int N, int M, typename T> T& QGenericMatrix<N, M, T>::operator()(int row, int column)
69
70 Returns a reference to the element at position (\a row, \a column)
71 in this matrix so that the element can be assigned to.
72*/
73
74/*!
75 \fn template <int N, int M, typename T> bool QGenericMatrix<N, M, T>::isIdentity() const
76
77 Returns \c true if this matrix is the identity; false otherwise.
78
79 \sa setToIdentity()
80*/
81
82/*!
83 \fn template <int N, int M, typename T> void QGenericMatrix<N, M, T>::setToIdentity()
84
85 Sets this matrix to the identity.
86
87 \sa isIdentity()
88*/
89
90/*!
91 \fn template <int N, int M, typename T> void QGenericMatrix<N, M, T>::fill(T value)
92
93 Fills all elements of this matrix with \a value.
94*/
95
96/*!
97 \fn template <int N, int M, typename T> QGenericMatrix<M, N> QGenericMatrix<N, M, T>::transposed() const
98
99 Returns this matrix, transposed about its diagonal.
100*/
101
102/*!
103 \fn template <int N, int M, typename T> QGenericMatrix<N, M, T>& QGenericMatrix<N, M, T>::operator+=(const QGenericMatrix<N, M, T>& other)
104
105 Adds the contents of \a other to this matrix.
106*/
107
108/*!
109 \fn template <int N, int M, typename T> QGenericMatrix<N, M, T>& QGenericMatrix<N, M, T>::operator-=(const QGenericMatrix<N, M, T>& other)
110
111 Subtracts the contents of \a other from this matrix.
112*/
113
114/*!
115 \fn template <int N, int M, typename T> QGenericMatrix<N, M, T>& QGenericMatrix<N, M, T>::operator*=(T factor)
116
117 Multiplies all elements of this matrix by \a factor.
118*/
119
120/*!
121 \fn template <int N, int M, typename T> QGenericMatrix<N, M, T>& QGenericMatrix<N, M, T>::operator/=(T divisor)
122
123 Divides all elements of this matrix by \a divisor.
124*/
125
126/*!
127 \fn template <int N, int M, typename T> bool QGenericMatrix<N, M, T>::operator==(const QGenericMatrix<N, M, T>& other) const
128
129 Returns \c true if this matrix is identical to \a other; false otherwise.
130*/
131
132/*!
133 \fn template <int N, int M, typename T> bool QGenericMatrix<N, M, T>::operator!=(const QGenericMatrix<N, M, T>& other) const
134
135 Returns \c true if this matrix is not identical to \a other; false otherwise.
136*/
137
138/*!
139 \fn template <int N, int M, typename T> QGenericMatrix<N, M, T> operator+(const QGenericMatrix<N, M, T>& m1, const QGenericMatrix<N, M, T>& m2)
140 \relates QGenericMatrix
141
142 Returns the sum of \a m1 and \a m2.
143*/
144
145/*!
146 \fn template <int N, int M, typename T> QGenericMatrix<N, M, T> operator-(const QGenericMatrix<N, M, T>& m1, const QGenericMatrix<N, M, T>& m2)
147 \relates QGenericMatrix
148
149 Returns the difference of \a m1 and \a m2.
150*/
151
152/*!
153 \fn template <int N, int M, typename T> template<int NN, int M1, int M2, typename TT> QGenericMatrix<M1, M2, TT> QGenericMatrix<N, M, T>::operator*(const QGenericMatrix<NN, M2, TT>& m1, const QGenericMatrix<M1, NN, TT>& m2)
154
155 Returns the product of the NNxM2 matrix \a m1 and the M1xNN matrix \a m2
156 to produce a M1xM2 matrix result.
157*/
158
159/*!
160 \fn template <int N, int M, typename T> QGenericMatrix<N, M, T> operator-(const QGenericMatrix<N, M, T>& matrix)
161 \overload
162 \relates QGenericMatrix
163
164 Returns the negation of \a matrix.
165*/
166
167/*!
168 \fn template <int N, int M, typename T> QGenericMatrix<N, M, T> operator*(T factor, const QGenericMatrix<N, M, T>& matrix)
169 \relates QGenericMatrix
170
171 Returns the result of multiplying all elements of \a matrix by \a factor.
172*/
173
174/*!
175 \fn template <int N, int M, typename T> QGenericMatrix<N, M, T> operator*(const QGenericMatrix<N, M, T>& matrix, T factor)
176 \relates QGenericMatrix
177
178 Returns the result of multiplying all elements of \a matrix by \a factor.
179*/
180
181/*!
182 \fn template <int N, int M, typename T> QGenericMatrix<N, M, T> operator/(const QGenericMatrix<N, M, T>& matrix, T divisor)
183 \relates QGenericMatrix
184
185 Returns the result of dividing all elements of \a matrix by \a divisor.
186*/
187
188/*!
189 \fn template <int N, int M, typename T> void QGenericMatrix<N, M, T>::copyDataTo(T *values) const
190
191 Retrieves the N * M items in this matrix and copies them to \a values
192 in row-major order.
193*/
194
195/*!
196 \fn template <int N, int M, typename T> T *QGenericMatrix<N, M, T>::data()
197
198 Returns a pointer to the raw data of this matrix.
199
200 \sa constData()
201*/
202
203/*!
204 \fn template <int N, int M, typename T> const T *QGenericMatrix<N, M, T>::data() const
205
206 Returns a constant pointer to the raw data of this matrix.
207
208 \sa constData()
209*/
210
211/*!
212 \fn template <int N, int M, typename T> const T *QGenericMatrix<N, M, T>::constData() const
213
214 Returns a constant pointer to the raw data of this matrix.
215
216 \sa data()
217*/
218
219#ifndef QT_NO_DATASTREAM
220
221/*!
222 \fn template <int N, int M, typename T> QDataStream &operator<<(QDataStream &stream, const QGenericMatrix<N, M, T> &matrix)
223 \relates QGenericMatrix
224
225 Writes the given \a matrix to the given \a stream and returns a
226 reference to the stream.
227
228 \sa {Serializing Qt Data Types}
229*/
230
231/*!
232 \fn template <int N, int M, typename T> QDataStream &operator>>(QDataStream &stream, QGenericMatrix<N, M, T> &matrix)
233 \relates QGenericMatrix
234
235 Reads a NxM matrix from the given \a stream into the given \a matrix
236 and returns a reference to the stream.
237
238 \sa {Serializing Qt Data Types}
239*/
240
241#endif
242
243/*!
244 \typedef QMatrix2x2
245 \relates QGenericMatrix
246
247 The QMatrix2x2 type defines a convenient instantiation of the
248 QGenericMatrix template for 2 columns, 2 rows, and float as
249 the element type.
250*/
251
252/*!
253 \typedef QMatrix2x3
254 \relates QGenericMatrix
255
256 The QMatrix2x3 type defines a convenient instantiation of the
257 QGenericMatrix template for 2 columns, 3 rows, and float as
258 the element type.
259*/
260
261/*!
262 \typedef QMatrix2x4
263 \relates QGenericMatrix
264
265 The QMatrix2x4 type defines a convenient instantiation of the
266 QGenericMatrix template for 2 columns, 4 rows, and float as
267 the element type.
268*/
269
270/*!
271 \typedef QMatrix3x2
272 \relates QGenericMatrix
273
274 The QMatrix3x2 type defines a convenient instantiation of the
275 QGenericMatrix template for 3 columns, 2 rows, and float as
276 the element type.
277*/
278
279/*!
280 \typedef QMatrix3x3
281 \relates QGenericMatrix
282
283 The QMatrix3x3 type defines a convenient instantiation of the
284 QGenericMatrix template for 3 columns, 3 rows, and float as
285 the element type.
286*/
287
288/*!
289 \typedef QMatrix3x4
290 \relates QGenericMatrix
291
292 The QMatrix3x4 type defines a convenient instantiation of the
293 QGenericMatrix template for 3 columns, 4 rows, and float as
294 the element type.
295*/
296
297/*!
298 \typedef QMatrix4x2
299 \relates QGenericMatrix
300
301 The QMatrix4x2 type defines a convenient instantiation of the
302 QGenericMatrix template for 4 columns, 2 rows, and float as
303 the element type.
304*/
305
306/*!
307 \typedef QMatrix4x3
308 \relates QGenericMatrix
309
310 The QMatrix4x3 type defines a convenient instantiation of the
311 QGenericMatrix template for 4 columns, 3 rows, and float as
312 the element type.
313*/
314
315QT_END_NAMESPACE
316

source code of qtbase/src/gui/math3d/qgenericmatrix.cpp