| 
									
										
										
										
											2009-06-17 20:33:34 +00:00
										 |  |  | /*
 | 
					
						
							|  |  |  |  * This program is free software; you can redistribute it and/or | 
					
						
							|  |  |  |  * modify it under the terms of the GNU General Public License | 
					
						
							|  |  |  |  * as published by the Free Software Foundation; either version 2 | 
					
						
							|  |  |  |  * of the License, or (at your option) any later version. | 
					
						
							|  |  |  |  * | 
					
						
							|  |  |  |  * This program is distributed in the hope that it will be useful, | 
					
						
							|  |  |  |  * but WITHOUT ANY WARRANTY; without even the implied warranty of | 
					
						
							|  |  |  |  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the | 
					
						
							|  |  |  |  * GNU General Public License for more details. | 
					
						
							|  |  |  |  * | 
					
						
							|  |  |  |  * You should have received a copy of the GNU General Public License | 
					
						
							|  |  |  |  * along with this program; if not, write to the Free Software Foundation, | 
					
						
							| 
									
										
										
										
											2010-02-12 13:34:04 +00:00
										 |  |  |  * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. | 
					
						
							| 
									
										
										
										
											2009-06-17 20:33:34 +00:00
										 |  |  |  */ | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-02-18 08:08:12 +11:00
										 |  |  | /** \file
 | 
					
						
							|  |  |  |  * \ingroup pymathutils | 
					
						
							| 
									
										
										
										
											2011-02-27 20:10:08 +00:00
										 |  |  |  */ | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2011-02-14 04:15:25 +00:00
										 |  |  | #include <Python.h>
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2010-04-11 12:05:27 +00:00
										 |  |  | #include "mathutils.h"
 | 
					
						
							| 
									
										
										
										
											2009-06-17 20:33:34 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2009-11-10 20:43:45 +00:00
										 |  |  | #include "BLI_math.h"
 | 
					
						
							| 
									
										
										
										
											2011-01-07 18:36:47 +00:00
										 |  |  | #include "BLI_utildefines.h"
 | 
					
						
							| 
									
										
										
										
											2012-12-08 01:16:59 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-06-26 09:26:52 +02:00
										 |  |  | #include "../generic/py_capi_utils.h"
 | 
					
						
							| 
									
										
										
										
											2020-03-19 09:33:03 +01:00
										 |  |  | #include "../generic/python_utildefines.h"
 | 
					
						
							| 
									
										
										
										
											2015-01-06 16:42:22 +11:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-12-08 01:16:59 +00:00
										 |  |  | #ifndef MATH_STANDALONE
 | 
					
						
							|  |  |  | #  include "BLI_dynstr.h"
 | 
					
						
							| 
									
										
										
										
											2020-03-19 09:33:03 +01:00
										 |  |  | #  include "BLI_string.h"
 | 
					
						
							| 
									
										
										
										
											2012-12-08 01:16:59 +00:00
										 |  |  | #endif
 | 
					
						
							| 
									
										
										
										
											2011-01-07 18:36:47 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2011-12-24 07:03:19 +00:00
										 |  |  | typedef enum eMatrixAccess_t { | 
					
						
							|  |  |  |   MAT_ACCESS_ROW, | 
					
						
							| 
									
										
										
										
											2019-04-16 16:40:47 +02:00
										 |  |  |   MAT_ACCESS_COL, | 
					
						
							| 
									
										
										
										
											2011-12-24 07:03:19 +00:00
										 |  |  | } eMatrixAccess_t; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-04-29 20:41:28 +10:00
										 |  |  | static PyObject *Matrix_copy_notest(MatrixObject *self, const float *matrix); | 
					
						
							| 
									
										
										
										
											2011-02-05 06:14:50 +00:00
										 |  |  | static PyObject *Matrix_copy(MatrixObject *self); | 
					
						
							| 
									
										
										
										
											2012-03-30 11:35:58 +00:00
										 |  |  | static PyObject *Matrix_deepcopy(MatrixObject *self, PyObject *args); | 
					
						
							| 
									
										
										
										
											2011-02-04 03:06:23 +00:00
										 |  |  | static int Matrix_ass_slice(MatrixObject *self, int begin, int end, PyObject *value); | 
					
						
							| 
									
										
										
										
											2020-06-22 14:51:20 +10:00
										 |  |  | static PyObject *matrix__apply_to_copy(PyObject *(*matrix_func)(MatrixObject *), | 
					
						
							|  |  |  |                                        MatrixObject *self); | 
					
						
							| 
									
										
										
										
											2011-12-24 07:03:19 +00:00
										 |  |  | static PyObject *MatrixAccess_CreatePyObject(MatrixObject *matrix, const eMatrixAccess_t type); | 
					
						
							| 
									
										
										
										
											2009-06-17 20:33:34 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2011-12-26 00:05:41 +00:00
										 |  |  | static int matrix_row_vector_check(MatrixObject *mat, VectorObject *vec, int row) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  |   if ((vec->size != mat->num_col) || (row >= mat->num_row)) { | 
					
						
							|  |  |  |     PyErr_SetString(PyExc_AttributeError, | 
					
						
							|  |  |  |                     "Matrix(): " | 
					
						
							|  |  |  |                     "owner matrix has been resized since this row vector was created"); | 
					
						
							|  |  |  |     return 0; | 
					
						
							|  |  |  |   } | 
					
						
							| 
									
										
										
										
											2020-08-07 12:41:06 +02:00
										 |  |  | 
 | 
					
						
							|  |  |  |   return 1; | 
					
						
							| 
									
										
										
										
											2011-12-26 00:05:41 +00:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | static int matrix_col_vector_check(MatrixObject *mat, VectorObject *vec, int col) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  |   if ((vec->size != mat->num_row) || (col >= mat->num_col)) { | 
					
						
							|  |  |  |     PyErr_SetString(PyExc_AttributeError, | 
					
						
							|  |  |  |                     "Matrix(): " | 
					
						
							|  |  |  |                     "owner matrix has been resized since this column vector was created"); | 
					
						
							|  |  |  |     return 0; | 
					
						
							|  |  |  |   } | 
					
						
							| 
									
										
										
										
											2020-08-07 12:41:06 +02:00
										 |  |  | 
 | 
					
						
							|  |  |  |   return 1; | 
					
						
							| 
									
										
										
										
											2011-12-26 00:05:41 +00:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | /* ----------------------------------------------------------------------------
 | 
					
						
							|  |  |  |  * matrix row callbacks | 
					
						
							|  |  |  |  * this is so you can do matrix[i][j] = val OR matrix.row[i][j] = val */ | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-02-20 15:38:58 +11:00
										 |  |  | uchar mathutils_matrix_row_cb_index = -1; | 
					
						
							| 
									
										
										
										
											2009-06-23 13:34:45 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2011-12-26 00:05:41 +00:00
										 |  |  | static int mathutils_matrix_row_check(BaseMathObject *bmo) | 
					
						
							| 
									
										
										
										
											2009-06-23 13:34:45 +00:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2011-12-24 13:26:30 +00:00
										 |  |  |   MatrixObject *self = (MatrixObject *)bmo->cb_user; | 
					
						
							| 
									
										
										
										
											2009-06-25 10:11:37 +00:00
										 |  |  |   return BaseMath_ReadCallback(self); | 
					
						
							| 
									
										
										
										
											2009-06-23 13:34:45 +00:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2011-12-26 00:05:41 +00:00
										 |  |  | static int mathutils_matrix_row_get(BaseMathObject *bmo, int row) | 
					
						
							| 
									
										
										
										
											2009-06-23 13:34:45 +00:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2011-12-24 13:26:30 +00:00
										 |  |  |   MatrixObject *self = (MatrixObject *)bmo->cb_user; | 
					
						
							| 
									
										
										
										
											2011-12-22 01:05:03 +00:00
										 |  |  |   int col; | 
					
						
							| 
									
										
										
										
											2009-08-15 16:36:25 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-03-30 06:12:48 +11:00
										 |  |  |   if (BaseMath_ReadCallback(self) == -1) { | 
					
						
							| 
									
										
										
										
											2011-02-28 18:42:41 +00:00
										 |  |  |     return -1; | 
					
						
							| 
									
										
										
										
											2019-03-30 06:12:48 +11:00
										 |  |  |   } | 
					
						
							|  |  |  |   if (!matrix_row_vector_check(self, (VectorObject *)bmo, row)) { | 
					
						
							| 
									
										
										
										
											2011-12-26 00:05:41 +00:00
										 |  |  |     return -1; | 
					
						
							| 
									
										
										
										
											2019-03-30 06:12:48 +11:00
										 |  |  |   } | 
					
						
							| 
									
										
										
										
											2009-06-23 13:34:45 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2011-12-24 13:26:30 +00:00
										 |  |  |   for (col = 0; col < self->num_col; col++) { | 
					
						
							| 
									
										
										
										
											2011-12-22 01:05:03 +00:00
										 |  |  |     bmo->data[col] = MATRIX_ITEM(self, row, col); | 
					
						
							| 
									
										
										
										
											2011-12-19 03:12:10 +00:00
										 |  |  |   } | 
					
						
							| 
									
										
										
										
											2009-06-23 13:34:45 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2011-02-28 18:42:41 +00:00
										 |  |  |   return 0; | 
					
						
							| 
									
										
										
										
											2009-06-23 13:34:45 +00:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2011-12-26 00:05:41 +00:00
										 |  |  | static int mathutils_matrix_row_set(BaseMathObject *bmo, int row) | 
					
						
							| 
									
										
										
										
											2009-06-23 13:34:45 +00:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2011-12-24 13:26:30 +00:00
										 |  |  |   MatrixObject *self = (MatrixObject *)bmo->cb_user; | 
					
						
							| 
									
										
										
										
											2011-12-22 01:05:03 +00:00
										 |  |  |   int col; | 
					
						
							| 
									
										
										
										
											2009-08-15 16:36:25 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-03-30 06:12:48 +11:00
										 |  |  |   if (BaseMath_ReadCallback_ForWrite(self) == -1) { | 
					
						
							| 
									
										
										
										
											2011-02-28 18:42:41 +00:00
										 |  |  |     return -1; | 
					
						
							| 
									
										
										
										
											2019-03-30 06:12:48 +11:00
										 |  |  |   } | 
					
						
							|  |  |  |   if (!matrix_row_vector_check(self, (VectorObject *)bmo, row)) { | 
					
						
							| 
									
										
										
										
											2011-12-26 00:05:41 +00:00
										 |  |  |     return -1; | 
					
						
							| 
									
										
										
										
											2019-03-30 06:12:48 +11:00
										 |  |  |   } | 
					
						
							| 
									
										
										
										
											2009-06-23 13:34:45 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2011-12-24 13:26:30 +00:00
										 |  |  |   for (col = 0; col < self->num_col; col++) { | 
					
						
							| 
									
										
										
										
											2011-12-22 01:05:03 +00:00
										 |  |  |     MATRIX_ITEM(self, row, col) = bmo->data[col]; | 
					
						
							| 
									
										
										
										
											2011-12-19 03:12:10 +00:00
										 |  |  |   } | 
					
						
							| 
									
										
										
										
											2009-06-23 13:34:45 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2010-10-20 12:11:09 +00:00
										 |  |  |   (void)BaseMath_WriteCallback(self); | 
					
						
							| 
									
										
										
										
											2011-02-28 18:42:41 +00:00
										 |  |  |   return 0; | 
					
						
							| 
									
										
										
										
											2009-06-23 13:34:45 +00:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2011-12-26 00:05:41 +00:00
										 |  |  | static int mathutils_matrix_row_get_index(BaseMathObject *bmo, int row, int col) | 
					
						
							| 
									
										
										
										
											2009-06-23 13:34:45 +00:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2011-12-24 13:26:30 +00:00
										 |  |  |   MatrixObject *self = (MatrixObject *)bmo->cb_user; | 
					
						
							| 
									
										
										
										
											2009-08-15 16:36:25 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-03-30 06:12:48 +11:00
										 |  |  |   if (BaseMath_ReadCallback(self) == -1) { | 
					
						
							| 
									
										
										
										
											2011-02-28 18:42:41 +00:00
										 |  |  |     return -1; | 
					
						
							| 
									
										
										
										
											2019-03-30 06:12:48 +11:00
										 |  |  |   } | 
					
						
							|  |  |  |   if (!matrix_row_vector_check(self, (VectorObject *)bmo, row)) { | 
					
						
							| 
									
										
										
										
											2011-12-26 00:05:41 +00:00
										 |  |  |     return -1; | 
					
						
							| 
									
										
										
										
											2019-03-30 06:12:48 +11:00
										 |  |  |   } | 
					
						
							| 
									
										
										
										
											2009-06-23 13:34:45 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2011-12-24 13:26:30 +00:00
										 |  |  |   bmo->data[col] = MATRIX_ITEM(self, row, col); | 
					
						
							| 
									
										
										
										
											2011-02-28 18:42:41 +00:00
										 |  |  |   return 0; | 
					
						
							| 
									
										
										
										
											2009-06-23 13:34:45 +00:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2011-12-26 00:05:41 +00:00
										 |  |  | static int mathutils_matrix_row_set_index(BaseMathObject *bmo, int row, int col) | 
					
						
							| 
									
										
										
										
											2009-06-23 13:34:45 +00:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2011-12-24 13:26:30 +00:00
										 |  |  |   MatrixObject *self = (MatrixObject *)bmo->cb_user; | 
					
						
							| 
									
										
										
										
											2009-08-15 16:36:25 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-03-30 06:12:48 +11:00
										 |  |  |   if (BaseMath_ReadCallback_ForWrite(self) == -1) { | 
					
						
							| 
									
										
										
										
											2011-02-28 18:42:41 +00:00
										 |  |  |     return -1; | 
					
						
							| 
									
										
										
										
											2019-03-30 06:12:48 +11:00
										 |  |  |   } | 
					
						
							|  |  |  |   if (!matrix_row_vector_check(self, (VectorObject *)bmo, row)) { | 
					
						
							| 
									
										
										
										
											2011-12-26 00:05:41 +00:00
										 |  |  |     return -1; | 
					
						
							| 
									
										
										
										
											2019-03-30 06:12:48 +11:00
										 |  |  |   } | 
					
						
							| 
									
										
										
										
											2009-06-23 13:34:45 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2011-12-22 01:05:03 +00:00
										 |  |  |   MATRIX_ITEM(self, row, col) = bmo->data[col]; | 
					
						
							| 
									
										
										
										
											2009-06-23 13:34:45 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2010-10-20 12:11:09 +00:00
										 |  |  |   (void)BaseMath_WriteCallback(self); | 
					
						
							| 
									
										
										
										
											2011-02-28 18:42:41 +00:00
										 |  |  |   return 0; | 
					
						
							| 
									
										
										
										
											2009-06-23 13:34:45 +00:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2011-12-24 06:13:58 +00:00
										 |  |  | Mathutils_Callback mathutils_matrix_row_cb = { | 
					
						
							| 
									
										
										
										
											2011-12-26 00:05:41 +00:00
										 |  |  |     mathutils_matrix_row_check, | 
					
						
							|  |  |  |     mathutils_matrix_row_get, | 
					
						
							|  |  |  |     mathutils_matrix_row_set, | 
					
						
							|  |  |  |     mathutils_matrix_row_get_index, | 
					
						
							| 
									
										
										
										
											2019-01-19 13:21:18 +11:00
										 |  |  |     mathutils_matrix_row_set_index, | 
					
						
							| 
									
										
										
										
											2009-06-23 13:34:45 +00:00
										 |  |  | }; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2011-12-26 00:05:41 +00:00
										 |  |  | /* ----------------------------------------------------------------------------
 | 
					
						
							|  |  |  |  * matrix row callbacks | 
					
						
							|  |  |  |  * this is so you can do matrix.col[i][j] = val */ | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-02-20 15:38:58 +11:00
										 |  |  | uchar mathutils_matrix_col_cb_index = -1; | 
					
						
							| 
									
										
										
										
											2011-12-21 23:12:16 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2011-12-26 00:05:41 +00:00
										 |  |  | static int mathutils_matrix_col_check(BaseMathObject *bmo) | 
					
						
							| 
									
										
										
										
											2011-12-21 23:12:16 +00:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2011-12-24 13:26:30 +00:00
										 |  |  |   MatrixObject *self = (MatrixObject *)bmo->cb_user; | 
					
						
							| 
									
										
										
										
											2011-12-21 23:12:16 +00:00
										 |  |  |   return BaseMath_ReadCallback(self); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2011-12-26 00:05:41 +00:00
										 |  |  | static int mathutils_matrix_col_get(BaseMathObject *bmo, int col) | 
					
						
							| 
									
										
										
										
											2011-12-21 23:12:16 +00:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2011-12-24 13:26:30 +00:00
										 |  |  |   MatrixObject *self = (MatrixObject *)bmo->cb_user; | 
					
						
							| 
									
										
										
										
											2011-12-21 23:12:16 +00:00
										 |  |  |   int num_row; | 
					
						
							|  |  |  |   int row; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-03-30 06:12:48 +11:00
										 |  |  |   if (BaseMath_ReadCallback(self) == -1) { | 
					
						
							| 
									
										
										
										
											2011-12-21 23:12:16 +00:00
										 |  |  |     return -1; | 
					
						
							| 
									
										
										
										
											2019-03-30 06:12:48 +11:00
										 |  |  |   } | 
					
						
							|  |  |  |   if (!matrix_col_vector_check(self, (VectorObject *)bmo, col)) { | 
					
						
							| 
									
										
										
										
											2011-12-26 00:05:41 +00:00
										 |  |  |     return -1; | 
					
						
							| 
									
										
										
										
											2019-03-30 06:12:48 +11:00
										 |  |  |   } | 
					
						
							| 
									
										
										
										
											2011-12-21 23:12:16 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  |   /* for 'translation' size will always be '3' even on 4x4 vec */ | 
					
						
							| 
									
										
										
										
											2021-05-18 14:13:20 +10:00
										 |  |  |   num_row = min_ii(self->num_row, ((const VectorObject *)bmo)->size); | 
					
						
							| 
									
										
										
										
											2011-12-21 23:12:16 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  |   for (row = 0; row < num_row; row++) { | 
					
						
							|  |  |  |     bmo->data[row] = MATRIX_ITEM(self, row, col); | 
					
						
							|  |  |  |   } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   return 0; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2011-12-26 00:05:41 +00:00
										 |  |  | static int mathutils_matrix_col_set(BaseMathObject *bmo, int col) | 
					
						
							| 
									
										
										
										
											2011-12-21 23:12:16 +00:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2011-12-24 13:26:30 +00:00
										 |  |  |   MatrixObject *self = (MatrixObject *)bmo->cb_user; | 
					
						
							| 
									
										
										
										
											2011-12-21 23:12:16 +00:00
										 |  |  |   int num_row; | 
					
						
							|  |  |  |   int row; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-03-30 06:12:48 +11:00
										 |  |  |   if (BaseMath_ReadCallback_ForWrite(self) == -1) { | 
					
						
							| 
									
										
										
										
											2011-12-21 23:12:16 +00:00
										 |  |  |     return -1; | 
					
						
							| 
									
										
										
										
											2019-03-30 06:12:48 +11:00
										 |  |  |   } | 
					
						
							|  |  |  |   if (!matrix_col_vector_check(self, (VectorObject *)bmo, col)) { | 
					
						
							| 
									
										
										
										
											2011-12-26 00:05:41 +00:00
										 |  |  |     return -1; | 
					
						
							| 
									
										
										
										
											2019-03-30 06:12:48 +11:00
										 |  |  |   } | 
					
						
							| 
									
										
										
										
											2011-12-21 23:12:16 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  |   /* for 'translation' size will always be '3' even on 4x4 vec */ | 
					
						
							| 
									
										
										
										
											2021-05-18 14:13:20 +10:00
										 |  |  |   num_row = min_ii(self->num_row, ((const VectorObject *)bmo)->size); | 
					
						
							| 
									
										
										
										
											2011-12-21 23:12:16 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  |   for (row = 0; row < num_row; row++) { | 
					
						
							|  |  |  |     MATRIX_ITEM(self, row, col) = bmo->data[row]; | 
					
						
							|  |  |  |   } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   (void)BaseMath_WriteCallback(self); | 
					
						
							|  |  |  |   return 0; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2011-12-26 00:05:41 +00:00
										 |  |  | static int mathutils_matrix_col_get_index(BaseMathObject *bmo, int col, int row) | 
					
						
							| 
									
										
										
										
											2011-12-21 23:12:16 +00:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2011-12-24 13:26:30 +00:00
										 |  |  |   MatrixObject *self = (MatrixObject *)bmo->cb_user; | 
					
						
							| 
									
										
										
										
											2011-12-21 23:12:16 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-03-30 06:12:48 +11:00
										 |  |  |   if (BaseMath_ReadCallback(self) == -1) { | 
					
						
							| 
									
										
										
										
											2011-12-21 23:12:16 +00:00
										 |  |  |     return -1; | 
					
						
							| 
									
										
										
										
											2019-03-30 06:12:48 +11:00
										 |  |  |   } | 
					
						
							|  |  |  |   if (!matrix_col_vector_check(self, (VectorObject *)bmo, col)) { | 
					
						
							| 
									
										
										
										
											2011-12-26 00:05:41 +00:00
										 |  |  |     return -1; | 
					
						
							| 
									
										
										
										
											2019-03-30 06:12:48 +11:00
										 |  |  |   } | 
					
						
							| 
									
										
										
										
											2011-12-21 23:12:16 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2011-12-24 13:26:30 +00:00
										 |  |  |   bmo->data[row] = MATRIX_ITEM(self, row, col); | 
					
						
							| 
									
										
										
										
											2011-12-21 23:12:16 +00:00
										 |  |  |   return 0; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2011-12-26 00:05:41 +00:00
										 |  |  | static int mathutils_matrix_col_set_index(BaseMathObject *bmo, int col, int row) | 
					
						
							| 
									
										
										
										
											2011-12-21 23:12:16 +00:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2011-12-24 13:26:30 +00:00
										 |  |  |   MatrixObject *self = (MatrixObject *)bmo->cb_user; | 
					
						
							| 
									
										
										
										
											2011-12-21 23:12:16 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-03-30 06:12:48 +11:00
										 |  |  |   if (BaseMath_ReadCallback_ForWrite(self) == -1) { | 
					
						
							| 
									
										
										
										
											2011-12-21 23:12:16 +00:00
										 |  |  |     return -1; | 
					
						
							| 
									
										
										
										
											2019-03-30 06:12:48 +11:00
										 |  |  |   } | 
					
						
							|  |  |  |   if (!matrix_col_vector_check(self, (VectorObject *)bmo, col)) { | 
					
						
							| 
									
										
										
										
											2011-12-26 00:05:41 +00:00
										 |  |  |     return -1; | 
					
						
							| 
									
										
										
										
											2019-03-30 06:12:48 +11:00
										 |  |  |   } | 
					
						
							| 
									
										
										
										
											2011-12-21 23:12:16 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  |   MATRIX_ITEM(self, row, col) = bmo->data[row]; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   (void)BaseMath_WriteCallback(self); | 
					
						
							|  |  |  |   return 0; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2011-12-24 06:13:58 +00:00
										 |  |  | Mathutils_Callback mathutils_matrix_col_cb = { | 
					
						
							| 
									
										
										
										
											2011-12-26 00:05:41 +00:00
										 |  |  |     mathutils_matrix_col_check, | 
					
						
							|  |  |  |     mathutils_matrix_col_get, | 
					
						
							|  |  |  |     mathutils_matrix_col_set, | 
					
						
							|  |  |  |     mathutils_matrix_col_get_index, | 
					
						
							| 
									
										
										
										
											2019-01-19 13:21:18 +11:00
										 |  |  |     mathutils_matrix_col_set_index, | 
					
						
							| 
									
										
										
										
											2011-12-26 00:05:41 +00:00
										 |  |  | }; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | /* ----------------------------------------------------------------------------
 | 
					
						
							|  |  |  |  * matrix row callbacks | 
					
						
							|  |  |  |  * this is so you can do matrix.translation = val | 
					
						
							| 
									
										
										
										
											2021-07-03 23:08:40 +10:00
										 |  |  |  * NOTE: this is _exactly like matrix.col except the 4th component is always omitted. */ | 
					
						
							| 
									
										
										
										
											2011-12-26 00:05:41 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-02-20 15:38:58 +11:00
										 |  |  | uchar mathutils_matrix_translation_cb_index = -1; | 
					
						
							| 
									
										
										
										
											2011-12-26 00:05:41 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  | static int mathutils_matrix_translation_check(BaseMathObject *bmo) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  |   MatrixObject *self = (MatrixObject *)bmo->cb_user; | 
					
						
							|  |  |  |   return BaseMath_ReadCallback(self); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | static int mathutils_matrix_translation_get(BaseMathObject *bmo, int col) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  |   MatrixObject *self = (MatrixObject *)bmo->cb_user; | 
					
						
							|  |  |  |   int row; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-03-30 06:12:48 +11:00
										 |  |  |   if (BaseMath_ReadCallback(self) == -1) { | 
					
						
							| 
									
										
										
										
											2011-12-26 00:05:41 +00:00
										 |  |  |     return -1; | 
					
						
							| 
									
										
										
										
											2019-03-30 06:12:48 +11:00
										 |  |  |   } | 
					
						
							| 
									
										
										
										
											2011-12-26 00:05:41 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  |   for (row = 0; row < 3; row++) { | 
					
						
							|  |  |  |     bmo->data[row] = MATRIX_ITEM(self, row, col); | 
					
						
							|  |  |  |   } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   return 0; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | static int mathutils_matrix_translation_set(BaseMathObject *bmo, int col) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  |   MatrixObject *self = (MatrixObject *)bmo->cb_user; | 
					
						
							|  |  |  |   int row; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-03-30 06:12:48 +11:00
										 |  |  |   if (BaseMath_ReadCallback_ForWrite(self) == -1) { | 
					
						
							| 
									
										
										
										
											2011-12-26 00:05:41 +00:00
										 |  |  |     return -1; | 
					
						
							| 
									
										
										
										
											2019-03-30 06:12:48 +11:00
										 |  |  |   } | 
					
						
							| 
									
										
										
										
											2011-12-26 00:05:41 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  |   for (row = 0; row < 3; row++) { | 
					
						
							|  |  |  |     MATRIX_ITEM(self, row, col) = bmo->data[row]; | 
					
						
							|  |  |  |   } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   (void)BaseMath_WriteCallback(self); | 
					
						
							|  |  |  |   return 0; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | static int mathutils_matrix_translation_get_index(BaseMathObject *bmo, int col, int row) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  |   MatrixObject *self = (MatrixObject *)bmo->cb_user; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-03-30 06:12:48 +11:00
										 |  |  |   if (BaseMath_ReadCallback(self) == -1) { | 
					
						
							| 
									
										
										
										
											2011-12-26 00:05:41 +00:00
										 |  |  |     return -1; | 
					
						
							| 
									
										
										
										
											2019-03-30 06:12:48 +11:00
										 |  |  |   } | 
					
						
							| 
									
										
										
										
											2011-12-26 00:05:41 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  |   bmo->data[row] = MATRIX_ITEM(self, row, col); | 
					
						
							|  |  |  |   return 0; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | static int mathutils_matrix_translation_set_index(BaseMathObject *bmo, int col, int row) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  |   MatrixObject *self = (MatrixObject *)bmo->cb_user; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-03-30 06:12:48 +11:00
										 |  |  |   if (BaseMath_ReadCallback_ForWrite(self) == -1) { | 
					
						
							| 
									
										
										
										
											2011-12-26 00:05:41 +00:00
										 |  |  |     return -1; | 
					
						
							| 
									
										
										
										
											2019-03-30 06:12:48 +11:00
										 |  |  |   } | 
					
						
							| 
									
										
										
										
											2011-12-26 00:05:41 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  |   MATRIX_ITEM(self, row, col) = bmo->data[row]; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   (void)BaseMath_WriteCallback(self); | 
					
						
							|  |  |  |   return 0; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | Mathutils_Callback mathutils_matrix_translation_cb = { | 
					
						
							|  |  |  |     mathutils_matrix_translation_check, | 
					
						
							|  |  |  |     mathutils_matrix_translation_get, | 
					
						
							|  |  |  |     mathutils_matrix_translation_set, | 
					
						
							|  |  |  |     mathutils_matrix_translation_get_index, | 
					
						
							| 
									
										
										
										
											2019-01-19 13:21:18 +11:00
										 |  |  |     mathutils_matrix_translation_set_index, | 
					
						
							| 
									
										
										
										
											2011-12-21 23:12:16 +00:00
										 |  |  | }; | 
					
						
							| 
									
										
										
										
											2011-12-26 00:05:41 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-06-24 15:56:58 +10:00
										 |  |  | /* matrix column callbacks, this is so you can do `matrix.translation = Vector()`. */ | 
					
						
							| 
									
										
										
										
											2011-12-21 23:12:16 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-10-20 20:20:02 +00:00
										 |  |  | /* ----------------------------------mathutils.Matrix() ----------------- */ | 
					
						
							|  |  |  | /* mat is a 1D array of floats - row[0][0], row[0][1], row[1][0], etc. */ | 
					
						
							|  |  |  | /* create a new matrix type */ | 
					
						
							| 
									
										
										
										
											2010-11-28 06:03:30 +00:00
										 |  |  | static PyObject *Matrix_new(PyTypeObject *type, PyObject *args, PyObject *kwds) | 
					
						
							| 
									
										
										
										
											2009-06-20 02:44:57 +00:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2011-10-13 01:29:08 +00:00
										 |  |  |   if (kwds && PyDict_Size(kwds)) { | 
					
						
							| 
									
										
										
										
											2011-07-14 01:25:05 +00:00
										 |  |  |     PyErr_SetString(PyExc_TypeError, | 
					
						
							| 
									
										
										
										
											2011-09-19 14:29:21 +00:00
										 |  |  |                     "Matrix(): " | 
					
						
							| 
									
										
										
										
											2011-07-14 01:25:05 +00:00
										 |  |  |                     "takes no keyword args"); | 
					
						
							| 
									
										
										
										
											2010-10-13 23:25:08 +00:00
										 |  |  |     return NULL; | 
					
						
							|  |  |  |   } | 
					
						
							| 
									
										
										
										
											2019-04-17 06:17:24 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2011-12-18 08:50:06 +00:00
										 |  |  |   switch (PyTuple_GET_SIZE(args)) { | 
					
						
							| 
									
										
										
										
											2011-01-09 14:30:16 +00:00
										 |  |  |     case 0: | 
					
						
							| 
									
										
										
										
											2015-01-04 17:03:54 +11:00
										 |  |  |       return Matrix_CreatePyObject(NULL, 4, 4, type); | 
					
						
							| 
									
										
										
										
											2011-01-09 14:30:16 +00:00
										 |  |  |     case 1: { | 
					
						
							| 
									
										
										
										
											2011-12-24 13:26:30 +00:00
										 |  |  |       PyObject *arg = PyTuple_GET_ITEM(args, 0); | 
					
						
							| 
									
										
										
										
											2019-04-17 06:17:24 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2011-12-22 01:05:03 +00:00
										 |  |  |       /* Input is now as a sequence of rows so length of sequence
 | 
					
						
							|  |  |  |        * is the number of rows */ | 
					
						
							| 
									
										
										
										
											2018-12-19 10:16:08 +11:00
										 |  |  |       /* -1 is an error, size checks will account for this */ | 
					
						
							| 
									
										
										
										
											2020-02-20 15:38:58 +11:00
										 |  |  |       const ushort num_row = PySequence_Size(arg); | 
					
						
							| 
									
										
										
										
											2019-04-17 06:17:24 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2011-12-22 01:05:03 +00:00
										 |  |  |       if (num_row >= 2 && num_row <= 4) { | 
					
						
							| 
									
										
										
										
											2011-12-24 13:26:30 +00:00
										 |  |  |         PyObject *item = PySequence_GetItem(arg, 0); | 
					
						
							| 
									
										
										
										
											2011-12-22 01:05:03 +00:00
										 |  |  |         /* Since each item is a row, number of items is the
 | 
					
						
							|  |  |  |          * same as the number of columns */ | 
					
						
							| 
									
										
										
										
											2020-02-20 15:38:58 +11:00
										 |  |  |         const ushort num_col = PySequence_Size(item); | 
					
						
							| 
									
										
										
										
											2011-01-09 14:30:16 +00:00
										 |  |  |         Py_XDECREF(item); | 
					
						
							| 
									
										
										
										
											2019-04-17 06:17:24 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2011-12-22 01:05:03 +00:00
										 |  |  |         if (num_col >= 2 && num_col <= 4) { | 
					
						
							| 
									
										
										
										
											2021-06-24 15:56:58 +10:00
										 |  |  |           /* Sane row & col size, new matrix and assign as slice. */ | 
					
						
							| 
									
										
										
										
											2015-01-04 17:03:54 +11:00
										 |  |  |           PyObject *matrix = Matrix_CreatePyObject(NULL, num_col, num_row, type); | 
					
						
							| 
									
										
										
										
											2011-10-13 01:29:08 +00:00
										 |  |  |           if (Matrix_ass_slice((MatrixObject *)matrix, 0, INT_MAX, arg) == 0) { | 
					
						
							| 
									
										
										
										
											2011-01-09 14:30:16 +00:00
										 |  |  |             return matrix; | 
					
						
							|  |  |  |           } | 
					
						
							| 
									
										
										
										
											2020-08-07 12:41:06 +02:00
										 |  |  |           /* matrix ok, slice assignment not */ | 
					
						
							|  |  |  |           Py_DECREF(matrix); | 
					
						
							| 
									
										
										
										
											2011-01-09 14:30:16 +00:00
										 |  |  |         } | 
					
						
							| 
									
										
										
										
											2009-06-20 02:44:57 +00:00
										 |  |  |       } | 
					
						
							| 
									
										
										
										
											2013-07-21 08:16:37 +00:00
										 |  |  |       break; | 
					
						
							| 
									
										
										
										
											2009-06-20 02:44:57 +00:00
										 |  |  |     } | 
					
						
							|  |  |  |   } | 
					
						
							| 
									
										
										
										
											2019-04-17 06:17:24 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2011-01-09 14:30:16 +00:00
										 |  |  |   /* will overwrite error */ | 
					
						
							| 
									
										
										
										
											2011-07-14 01:25:05 +00:00
										 |  |  |   PyErr_SetString(PyExc_TypeError, | 
					
						
							| 
									
										
										
										
											2011-09-19 14:29:21 +00:00
										 |  |  |                   "Matrix(): " | 
					
						
							| 
									
										
										
										
											2013-11-29 09:47:11 +11:00
										 |  |  |                   "expects no args or a single arg containing 2-4 numeric sequences"); | 
					
						
							| 
									
										
										
										
											2011-01-09 14:30:16 +00:00
										 |  |  |   return NULL; | 
					
						
							| 
									
										
										
										
											2009-06-20 02:44:57 +00:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-06-22 14:51:20 +10:00
										 |  |  | static PyObject *matrix__apply_to_copy(PyObject *(*matrix_func)(MatrixObject *), | 
					
						
							|  |  |  |                                        MatrixObject *self) | 
					
						
							| 
									
										
										
										
											2011-02-09 09:20:17 +00:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2011-12-24 13:26:30 +00:00
										 |  |  |   PyObject *ret = Matrix_copy(self); | 
					
						
							| 
									
										
										
										
											2012-10-31 03:21:13 +00:00
										 |  |  |   if (ret) { | 
					
						
							| 
									
										
										
										
											2020-06-22 14:51:20 +10:00
										 |  |  |     PyObject *ret_dummy = matrix_func((MatrixObject *)ret); | 
					
						
							| 
									
										
										
										
											2012-10-31 03:21:13 +00:00
										 |  |  |     if (ret_dummy) { | 
					
						
							|  |  |  |       Py_DECREF(ret_dummy); | 
					
						
							| 
									
										
										
										
											2020-06-22 14:51:20 +10:00
										 |  |  |       return ret; | 
					
						
							| 
									
										
										
										
											2012-10-31 03:21:13 +00:00
										 |  |  |     } | 
					
						
							| 
									
										
										
										
											2020-08-07 12:41:06 +02:00
										 |  |  |     /* error */ | 
					
						
							|  |  |  |     Py_DECREF(ret); | 
					
						
							| 
									
										
										
										
											2011-02-09 09:20:17 +00:00
										 |  |  |     return NULL; | 
					
						
							|  |  |  |   } | 
					
						
							| 
									
										
										
										
											2020-08-07 12:41:06 +02:00
										 |  |  | 
 | 
					
						
							|  |  |  |   /* copy may fail if the read callback errors out */ | 
					
						
							|  |  |  |   return NULL; | 
					
						
							| 
									
										
										
										
											2011-02-09 09:20:17 +00:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2011-02-06 11:17:22 +00:00
										 |  |  | /* when a matrix is 4x4 size but initialized as a 3x3, re-assign values for 4x4 */ | 
					
						
							|  |  |  | static void matrix_3x3_as_4x4(float mat[16]) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  |   mat[10] = mat[8]; | 
					
						
							|  |  |  |   mat[9] = mat[7]; | 
					
						
							|  |  |  |   mat[8] = mat[6]; | 
					
						
							|  |  |  |   mat[7] = 0.0f; | 
					
						
							|  |  |  |   mat[6] = mat[5]; | 
					
						
							|  |  |  |   mat[5] = mat[4]; | 
					
						
							|  |  |  |   mat[4] = mat[3]; | 
					
						
							|  |  |  |   mat[3] = 0.0f; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2010-08-11 16:40:36 +00:00
										 |  |  | /*-----------------------CLASS-METHODS----------------------------*/ | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-10-20 20:20:02 +00:00
										 |  |  | /* mat is a 1D array of floats - row[0][0], row[0][1], row[1][0], etc. */ | 
					
						
							| 
									
										
										
										
											2012-01-24 01:56:44 +00:00
										 |  |  | PyDoc_STRVAR(C_Matrix_Identity_doc, | 
					
						
							|  |  |  |              ".. classmethod:: Identity(size)\n" | 
					
						
							|  |  |  |              "\n" | 
					
						
							|  |  |  |              "   Create an identity matrix.\n" | 
					
						
							|  |  |  |              "\n" | 
					
						
							|  |  |  |              "   :arg size: The size of the identity matrix to construct [2, 4].\n" | 
					
						
							|  |  |  |              "   :type size: int\n" | 
					
						
							|  |  |  |              "   :return: A new identity matrix.\n" | 
					
						
							|  |  |  |              "   :rtype: :class:`Matrix`\n"); | 
					
						
							|  |  |  | static PyObject *C_Matrix_Identity(PyObject *cls, PyObject *args) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  |   int matSize; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   if (!PyArg_ParseTuple(args, "i:Matrix.Identity", &matSize)) { | 
					
						
							|  |  |  |     return NULL; | 
					
						
							|  |  |  |   } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   if (matSize < 2 || matSize > 4) { | 
					
						
							|  |  |  |     PyErr_SetString(PyExc_RuntimeError, | 
					
						
							| 
									
										
										
										
											2012-03-26 06:55:09 +00:00
										 |  |  |                     "Matrix.Identity(): " | 
					
						
							|  |  |  |                     "size must be between 2 and 4"); | 
					
						
							| 
									
										
										
										
											2012-01-24 01:56:44 +00:00
										 |  |  |     return NULL; | 
					
						
							|  |  |  |   } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-01-04 17:03:54 +11:00
										 |  |  |   return Matrix_CreatePyObject(NULL, matSize, matSize, (PyTypeObject *)cls); | 
					
						
							| 
									
										
										
										
											2012-01-24 01:56:44 +00:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2011-05-24 16:05:51 +00:00
										 |  |  | PyDoc_STRVAR(C_Matrix_Rotation_doc, | 
					
						
							| 
									
										
										
										
											2010-08-11 16:40:36 +00:00
										 |  |  |              ".. classmethod:: Rotation(angle, size, axis)\n" | 
					
						
							|  |  |  |              "\n" | 
					
						
							|  |  |  |              "   Create a matrix representing a rotation.\n" | 
					
						
							|  |  |  |              "\n" | 
					
						
							|  |  |  |              "   :arg angle: The angle of rotation desired, in radians.\n" | 
					
						
							|  |  |  |              "   :type angle: float\n" | 
					
						
							|  |  |  |              "   :arg size: The size of the rotation matrix to construct [2, 4].\n" | 
					
						
							|  |  |  |              "   :type size: int\n" | 
					
						
							| 
									
										
										
										
											2011-05-26 19:13:01 +00:00
										 |  |  |              "   :arg axis: a string in ['X', 'Y', 'Z'] or a 3D Vector Object\n" | 
					
						
							|  |  |  |              "      (optional when size is 2).\n" | 
					
						
							| 
									
										
										
										
											2010-08-11 16:40:36 +00:00
										 |  |  |              "   :type axis: string or :class:`Vector`\n" | 
					
						
							|  |  |  |              "   :return: A new rotation matrix.\n" | 
					
						
							| 
									
										
										
										
											2011-02-04 09:35:20 +00:00
										 |  |  |              "   :rtype: :class:`Matrix`\n"); | 
					
						
							| 
									
										
										
										
											2010-08-11 16:40:36 +00:00
										 |  |  | static PyObject *C_Matrix_Rotation(PyObject *cls, PyObject *args) | 
					
						
							|  |  |  | { | 
					
						
							| 
									
										
										
										
											2011-12-24 13:26:30 +00:00
										 |  |  |   PyObject *vec = NULL; | 
					
						
							|  |  |  |   const char *axis = NULL; | 
					
						
							| 
									
										
										
										
											2010-08-11 16:40:36 +00:00
										 |  |  |   int matSize; | 
					
						
							| 
									
										
										
										
											2011-01-21 03:18:01 +00:00
										 |  |  |   double angle; /* use double because of precision problems at high values */ | 
					
						
							| 
									
										
										
										
											2019-03-15 08:53:22 +11:00
										 |  |  |   float mat[16] = { | 
					
						
							|  |  |  |       0.0f, | 
					
						
							|  |  |  |       0.0f, | 
					
						
							|  |  |  |       0.0f, | 
					
						
							|  |  |  |       0.0f, | 
					
						
							|  |  |  |       0.0f, | 
					
						
							|  |  |  |       0.0f, | 
					
						
							|  |  |  |       0.0f, | 
					
						
							| 
									
										
										
										
											2019-04-17 06:17:24 +02:00
										 |  |  |       0.0f, | 
					
						
							|  |  |  |       0.0f, | 
					
						
							|  |  |  |       0.0f, | 
					
						
							|  |  |  |       0.0f, | 
					
						
							|  |  |  |       0.0f, | 
					
						
							|  |  |  |       0.0f, | 
					
						
							|  |  |  |       0.0f, | 
					
						
							|  |  |  |       0.0f, | 
					
						
							| 
									
										
										
										
											2019-03-15 08:53:22 +11:00
										 |  |  |       1.0f, | 
					
						
							|  |  |  |   }; | 
					
						
							| 
									
										
										
										
											2019-04-17 06:17:24 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2011-12-26 00:42:35 +00:00
										 |  |  |   if (!PyArg_ParseTuple(args, "di|O:Matrix.Rotation", &angle, &matSize, &vec)) { | 
					
						
							| 
									
										
										
										
											2010-08-11 16:40:36 +00:00
										 |  |  |     return NULL; | 
					
						
							|  |  |  |   } | 
					
						
							| 
									
										
										
										
											2019-04-17 06:17:24 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2011-10-13 01:29:08 +00:00
										 |  |  |   if (vec && PyUnicode_Check(vec)) { | 
					
						
							| 
									
										
										
										
											2021-02-13 22:57:01 +11:00
										 |  |  |     axis = PyUnicode_AsUTF8((PyObject *)vec); | 
					
						
							| 
									
										
										
										
											2011-12-24 13:26:30 +00:00
										 |  |  |     if (axis == NULL || axis[0] == '\0' || axis[1] != '\0' || axis[0] < 'X' || axis[0] > 'Z') { | 
					
						
							| 
									
										
										
										
											2011-07-14 09:54:03 +00:00
										 |  |  |       PyErr_SetString(PyExc_ValueError, | 
					
						
							| 
									
										
										
										
											2011-09-19 14:29:21 +00:00
										 |  |  |                       "Matrix.Rotation(): " | 
					
						
							| 
									
										
										
										
											2011-07-14 01:25:05 +00:00
										 |  |  |                       "3rd argument axis value must be a 3D vector " | 
					
						
							|  |  |  |                       "or a string in 'X', 'Y', 'Z'"); | 
					
						
							| 
									
										
										
										
											2010-08-11 16:40:36 +00:00
										 |  |  |       return NULL; | 
					
						
							|  |  |  |     } | 
					
						
							| 
									
										
										
										
											2020-08-07 12:41:06 +02:00
										 |  |  | 
 | 
					
						
							|  |  |  |     /* use the string */ | 
					
						
							|  |  |  |     vec = NULL; | 
					
						
							| 
									
										
										
										
											2019-04-17 06:17:24 +02:00
										 |  |  |   } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2011-12-24 13:26:30 +00:00
										 |  |  |   angle = angle_wrap_rad(angle); | 
					
						
							| 
									
										
										
										
											2019-04-17 06:17:24 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-11-06 12:51:49 +11:00
										 |  |  |   if (!ELEM(matSize, 2, 3, 4)) { | 
					
						
							| 
									
										
										
										
											2011-07-14 09:54:03 +00:00
										 |  |  |     PyErr_SetString(PyExc_ValueError, | 
					
						
							| 
									
										
										
										
											2011-09-19 14:29:21 +00:00
										 |  |  |                     "Matrix.Rotation(): " | 
					
						
							| 
									
										
										
										
											2011-07-14 01:25:05 +00:00
										 |  |  |                     "can only return a 2x2 3x3 or 4x4 matrix"); | 
					
						
							| 
									
										
										
										
											2010-08-11 16:40:36 +00:00
										 |  |  |     return NULL; | 
					
						
							|  |  |  |   } | 
					
						
							| 
									
										
										
										
											2011-10-13 01:29:08 +00:00
										 |  |  |   if (matSize == 2 && (vec != NULL)) { | 
					
						
							| 
									
										
										
										
											2011-07-14 09:54:03 +00:00
										 |  |  |     PyErr_SetString(PyExc_ValueError, | 
					
						
							| 
									
										
										
										
											2011-09-19 14:29:21 +00:00
										 |  |  |                     "Matrix.Rotation(): " | 
					
						
							| 
									
										
										
										
											2011-07-14 01:25:05 +00:00
										 |  |  |                     "cannot create a 2x2 rotation matrix around arbitrary axis"); | 
					
						
							| 
									
										
										
										
											2010-08-11 16:40:36 +00:00
										 |  |  |     return NULL; | 
					
						
							|  |  |  |   } | 
					
						
							| 
									
										
										
										
											2011-10-13 01:29:08 +00:00
										 |  |  |   if ((matSize == 3 || matSize == 4) && (axis == NULL) && (vec == NULL)) { | 
					
						
							| 
									
										
										
										
											2011-07-14 09:54:03 +00:00
										 |  |  |     PyErr_SetString(PyExc_ValueError, | 
					
						
							| 
									
										
										
										
											2011-09-19 14:29:21 +00:00
										 |  |  |                     "Matrix.Rotation(): " | 
					
						
							| 
									
										
										
										
											2011-07-14 01:25:05 +00:00
										 |  |  |                     "axis of rotation for 3d and 4d matrices is required"); | 
					
						
							| 
									
										
										
										
											2010-08-11 16:40:36 +00:00
										 |  |  |     return NULL; | 
					
						
							|  |  |  |   } | 
					
						
							| 
									
										
										
										
											2019-04-17 06:17:24 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2010-08-11 16:40:36 +00:00
										 |  |  |   /* check for valid vector/axis above */ | 
					
						
							| 
									
										
										
										
											2011-10-13 01:29:08 +00:00
										 |  |  |   if (vec) { | 
					
						
							| 
									
										
										
										
											2011-02-04 03:06:23 +00:00
										 |  |  |     float tvec[3]; | 
					
						
							| 
									
										
										
										
											2019-04-17 06:17:24 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-03-30 06:12:48 +11:00
										 |  |  |     if (mathutils_array_parse( | 
					
						
							|  |  |  |             tvec, 3, 3, vec, "Matrix.Rotation(angle, size, axis), invalid 'axis' arg") == -1) { | 
					
						
							| 
									
										
										
										
											2011-02-04 03:06:23 +00:00
										 |  |  |       return NULL; | 
					
						
							| 
									
										
										
										
											2019-03-30 06:12:48 +11:00
										 |  |  |     } | 
					
						
							| 
									
										
										
										
											2019-04-17 06:17:24 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2011-02-04 03:06:23 +00:00
										 |  |  |     axis_angle_to_mat3((float(*)[3])mat, tvec, angle); | 
					
						
							| 
									
										
										
										
											2010-08-11 16:40:36 +00:00
										 |  |  |   } | 
					
						
							| 
									
										
										
										
											2011-09-19 13:08:01 +00:00
										 |  |  |   else if (matSize == 2) { | 
					
						
							| 
									
										
										
										
											2013-09-10 20:45:47 +00:00
										 |  |  |     angle_to_mat2((float(*)[2])mat, angle); | 
					
						
							| 
									
										
										
										
											2010-08-11 16:40:36 +00:00
										 |  |  |   } | 
					
						
							|  |  |  |   else { | 
					
						
							| 
									
										
										
										
											2011-09-19 13:08:01 +00:00
										 |  |  |     /* valid axis checked above */ | 
					
						
							| 
									
										
										
										
											2013-09-10 20:45:47 +00:00
										 |  |  |     axis_angle_to_mat3_single((float(*)[3])mat, axis[0], angle); | 
					
						
							| 
									
										
										
										
											2010-08-11 16:40:36 +00:00
										 |  |  |   } | 
					
						
							| 
									
										
										
										
											2019-04-17 06:17:24 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2011-10-13 01:29:08 +00:00
										 |  |  |   if (matSize == 4) { | 
					
						
							| 
									
										
										
										
											2011-02-06 11:17:22 +00:00
										 |  |  |     matrix_3x3_as_4x4(mat); | 
					
						
							| 
									
										
										
										
											2010-08-11 16:40:36 +00:00
										 |  |  |   } | 
					
						
							| 
									
										
										
										
											2012-10-20 20:20:02 +00:00
										 |  |  |   /* pass to matrix creation */ | 
					
						
							| 
									
										
										
										
											2015-01-04 17:03:54 +11:00
										 |  |  |   return Matrix_CreatePyObject(mat, matSize, matSize, (PyTypeObject *)cls); | 
					
						
							| 
									
										
										
										
											2010-08-11 16:40:36 +00:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2011-05-24 16:05:51 +00:00
										 |  |  | PyDoc_STRVAR(C_Matrix_Translation_doc, | 
					
						
							| 
									
										
										
										
											2010-08-11 16:40:36 +00:00
										 |  |  |              ".. classmethod:: Translation(vector)\n" | 
					
						
							|  |  |  |              "\n" | 
					
						
							|  |  |  |              "   Create a matrix representing a translation.\n" | 
					
						
							|  |  |  |              "\n" | 
					
						
							|  |  |  |              "   :arg vector: The translation vector.\n" | 
					
						
							|  |  |  |              "   :type vector: :class:`Vector`\n" | 
					
						
							|  |  |  |              "   :return: An identity matrix with a translation.\n" | 
					
						
							| 
									
										
										
										
											2011-02-04 09:35:20 +00:00
										 |  |  |              "   :rtype: :class:`Matrix`\n"); | 
					
						
							| 
									
										
										
										
											2011-02-04 03:06:23 +00:00
										 |  |  | static PyObject *C_Matrix_Translation(PyObject *cls, PyObject *value) | 
					
						
							| 
									
										
										
										
											2010-08-11 16:40:36 +00:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2014-04-29 18:12:44 +10:00
										 |  |  |   float mat[4][4]; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   unit_m4(mat); | 
					
						
							| 
									
										
										
										
											2011-02-04 03:06:23 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-03-30 06:12:48 +11:00
										 |  |  |   if (mathutils_array_parse( | 
					
						
							|  |  |  |           mat[3], 3, 4, value, "mathutils.Matrix.Translation(vector), invalid vector arg") == -1) { | 
					
						
							| 
									
										
										
										
											2010-08-11 16:40:36 +00:00
										 |  |  |     return NULL; | 
					
						
							| 
									
										
										
										
											2019-03-30 06:12:48 +11:00
										 |  |  |   } | 
					
						
							| 
									
										
										
										
											2010-08-11 16:40:36 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-01-04 17:03:54 +11:00
										 |  |  |   return Matrix_CreatePyObject(&mat[0][0], 4, 4, (PyTypeObject *)cls); | 
					
						
							| 
									
										
										
										
											2010-08-11 16:40:36 +00:00
										 |  |  | } | 
					
						
							| 
									
										
										
										
											2019-05-19 14:52:11 +03:00
										 |  |  | /* ----------------------------------mathutils.Matrix.Diagonal() ------------- */ | 
					
						
							|  |  |  | PyDoc_STRVAR(C_Matrix_Diagonal_doc, | 
					
						
							|  |  |  |              ".. classmethod:: Diagonal(vector)\n" | 
					
						
							|  |  |  |              "\n" | 
					
						
							|  |  |  |              "   Create a diagonal (scaling) matrix using the values from the vector.\n" | 
					
						
							|  |  |  |              "\n" | 
					
						
							|  |  |  |              "   :arg vector: The vector of values for the diagonal.\n" | 
					
						
							|  |  |  |              "   :type vector: :class:`Vector`\n" | 
					
						
							|  |  |  |              "   :return: A diagonal matrix.\n" | 
					
						
							|  |  |  |              "   :rtype: :class:`Matrix`\n"); | 
					
						
							|  |  |  | static PyObject *C_Matrix_Diagonal(PyObject *cls, PyObject *value) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  |   float mat[16] = {0.0f}; | 
					
						
							|  |  |  |   float vec[4]; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   int size = mathutils_array_parse( | 
					
						
							|  |  |  |       vec, 2, 4, value, "mathutils.Matrix.Diagonal(vector), invalid vector arg"); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   if (size == -1) { | 
					
						
							|  |  |  |     return NULL; | 
					
						
							|  |  |  |   } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   for (int i = 0; i < size; i++) { | 
					
						
							|  |  |  |     mat[size * i + i] = vec[i]; | 
					
						
							|  |  |  |   } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   return Matrix_CreatePyObject(mat, size, size, (PyTypeObject *)cls); | 
					
						
							|  |  |  | } | 
					
						
							| 
									
										
										
										
											2012-10-20 20:20:02 +00:00
										 |  |  | /* ----------------------------------mathutils.Matrix.Scale() ------------- */ | 
					
						
							|  |  |  | /* mat is a 1D array of floats - row[0][0], row[0][1], row[1][0], etc. */ | 
					
						
							| 
									
										
										
										
											2011-05-24 16:05:51 +00:00
										 |  |  | PyDoc_STRVAR(C_Matrix_Scale_doc, | 
					
						
							| 
									
										
										
										
											2010-08-11 16:40:36 +00:00
										 |  |  |              ".. classmethod:: Scale(factor, size, axis)\n" | 
					
						
							|  |  |  |              "\n" | 
					
						
							|  |  |  |              "   Create a matrix representing a scaling.\n" | 
					
						
							|  |  |  |              "\n" | 
					
						
							|  |  |  |              "   :arg factor: The factor of scaling to apply.\n" | 
					
						
							|  |  |  |              "   :type factor: float\n" | 
					
						
							|  |  |  |              "   :arg size: The size of the scale matrix to construct [2, 4].\n" | 
					
						
							|  |  |  |              "   :type size: int\n" | 
					
						
							|  |  |  |              "   :arg axis: Direction to influence scale. (optional).\n" | 
					
						
							|  |  |  |              "   :type axis: :class:`Vector`\n" | 
					
						
							|  |  |  |              "   :return: A new scale matrix.\n" | 
					
						
							| 
									
										
										
										
											2011-02-04 09:35:20 +00:00
										 |  |  |              "   :rtype: :class:`Matrix`\n"); | 
					
						
							| 
									
										
										
										
											2010-08-11 16:40:36 +00:00
										 |  |  | static PyObject *C_Matrix_Scale(PyObject *cls, PyObject *args) | 
					
						
							|  |  |  | { | 
					
						
							| 
									
										
										
										
											2011-12-24 13:26:30 +00:00
										 |  |  |   PyObject *vec = NULL; | 
					
						
							| 
									
										
										
										
											2011-02-06 11:17:22 +00:00
										 |  |  |   int vec_size; | 
					
						
							|  |  |  |   float tvec[3]; | 
					
						
							|  |  |  |   float factor; | 
					
						
							|  |  |  |   int matSize; | 
					
						
							| 
									
										
										
										
											2019-03-24 16:24:29 +11:00
										 |  |  |   float mat[16] = { | 
					
						
							|  |  |  |       0.0f, | 
					
						
							|  |  |  |       0.0f, | 
					
						
							|  |  |  |       0.0f, | 
					
						
							|  |  |  |       0.0f, | 
					
						
							|  |  |  |       0.0f, | 
					
						
							|  |  |  |       0.0f, | 
					
						
							|  |  |  |       0.0f, | 
					
						
							|  |  |  |       0.0f, | 
					
						
							| 
									
										
										
										
											2019-04-17 06:17:24 +02:00
										 |  |  |       0.0f, | 
					
						
							|  |  |  |       0.0f, | 
					
						
							|  |  |  |       0.0f, | 
					
						
							|  |  |  |       0.0f, | 
					
						
							|  |  |  |       0.0f, | 
					
						
							|  |  |  |       0.0f, | 
					
						
							|  |  |  |       0.0f, | 
					
						
							| 
									
										
										
										
											2019-03-24 16:24:29 +11:00
										 |  |  |       1.0f, | 
					
						
							|  |  |  |   }; | 
					
						
							| 
									
										
										
										
											2019-04-17 06:17:24 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2011-10-13 01:29:08 +00:00
										 |  |  |   if (!PyArg_ParseTuple(args, "fi|O:Matrix.Scale", &factor, &matSize, &vec)) { | 
					
						
							| 
									
										
										
										
											2010-08-11 16:40:36 +00:00
										 |  |  |     return NULL; | 
					
						
							|  |  |  |   } | 
					
						
							| 
									
										
										
										
											2020-11-06 12:51:49 +11:00
										 |  |  |   if (!ELEM(matSize, 2, 3, 4)) { | 
					
						
							| 
									
										
										
										
											2011-07-14 09:54:03 +00:00
										 |  |  |     PyErr_SetString(PyExc_ValueError, | 
					
						
							| 
									
										
										
										
											2011-07-14 01:25:05 +00:00
										 |  |  |                     "Matrix.Scale(): " | 
					
						
							|  |  |  |                     "can only return a 2x2 3x3 or 4x4 matrix"); | 
					
						
							| 
									
										
										
										
											2010-08-11 16:40:36 +00:00
										 |  |  |     return NULL; | 
					
						
							|  |  |  |   } | 
					
						
							| 
									
										
										
										
											2011-10-13 01:29:08 +00:00
										 |  |  |   if (vec) { | 
					
						
							| 
									
										
										
										
											2011-12-24 13:26:30 +00:00
										 |  |  |     vec_size = (matSize == 2 ? 2 : 3); | 
					
						
							| 
									
										
										
										
											2011-12-26 00:42:35 +00:00
										 |  |  |     if (mathutils_array_parse(tvec, | 
					
						
							|  |  |  |                               vec_size, | 
					
						
							|  |  |  |                               vec_size, | 
					
						
							|  |  |  |                               vec, | 
					
						
							|  |  |  |                               "Matrix.Scale(factor, size, axis), invalid 'axis' arg") == -1) { | 
					
						
							| 
									
										
										
										
											2010-08-11 16:40:36 +00:00
										 |  |  |       return NULL; | 
					
						
							|  |  |  |     } | 
					
						
							| 
									
										
										
										
											2019-04-17 06:17:24 +02:00
										 |  |  |   } | 
					
						
							| 
									
										
										
										
											2012-10-20 20:20:02 +00:00
										 |  |  |   if (vec == NULL) { /* scaling along axis */ | 
					
						
							| 
									
										
										
										
											2011-10-13 01:29:08 +00:00
										 |  |  |     if (matSize == 2) { | 
					
						
							| 
									
										
										
										
											2010-08-11 16:40:36 +00:00
										 |  |  |       mat[0] = factor; | 
					
						
							|  |  |  |       mat[3] = factor; | 
					
						
							| 
									
										
										
										
											2011-07-14 01:25:05 +00:00
										 |  |  |     } | 
					
						
							|  |  |  |     else { | 
					
						
							| 
									
										
										
										
											2010-08-11 16:40:36 +00:00
										 |  |  |       mat[0] = factor; | 
					
						
							|  |  |  |       mat[4] = factor; | 
					
						
							|  |  |  |       mat[8] = factor; | 
					
						
							| 
									
										
										
										
											2011-02-06 11:17:22 +00:00
										 |  |  |     } | 
					
						
							| 
									
										
										
										
											2019-04-17 06:17:24 +02:00
										 |  |  |   } | 
					
						
							| 
									
										
										
										
											2012-03-26 06:55:09 +00:00
										 |  |  |   else { | 
					
						
							|  |  |  |     /* scaling in arbitrary direction
 | 
					
						
							|  |  |  |      * normalize arbitrary axis */ | 
					
						
							| 
									
										
										
										
											2011-02-06 11:17:22 +00:00
										 |  |  |     float norm = 0.0f; | 
					
						
							|  |  |  |     int x; | 
					
						
							| 
									
										
										
										
											2011-10-13 01:29:08 +00:00
										 |  |  |     for (x = 0; x < vec_size; x++) { | 
					
						
							| 
									
										
										
										
											2011-02-06 11:17:22 +00:00
										 |  |  |       norm += tvec[x] * tvec[x]; | 
					
						
							| 
									
										
										
										
											2010-08-11 16:40:36 +00:00
										 |  |  |     } | 
					
						
							| 
									
										
										
										
											2014-03-28 14:53:37 +11:00
										 |  |  |     norm = sqrtf(norm); | 
					
						
							| 
									
										
										
										
											2011-10-13 01:29:08 +00:00
										 |  |  |     for (x = 0; x < vec_size; x++) { | 
					
						
							| 
									
										
										
										
											2011-02-06 11:17:22 +00:00
										 |  |  |       tvec[x] /= norm; | 
					
						
							| 
									
										
										
										
											2010-08-11 16:40:36 +00:00
										 |  |  |     } | 
					
						
							| 
									
										
										
										
											2011-10-13 01:29:08 +00:00
										 |  |  |     if (matSize == 2) { | 
					
						
							| 
									
										
										
										
											2012-03-26 06:55:09 +00:00
										 |  |  |       mat[0] = 1 + ((factor - 1) * (tvec[0] * tvec[0])); | 
					
						
							|  |  |  |       mat[1] = ((factor - 1) * (tvec[0] * tvec[1])); | 
					
						
							|  |  |  |       mat[2] = ((factor - 1) * (tvec[0] * tvec[1])); | 
					
						
							|  |  |  |       mat[3] = 1 + ((factor - 1) * (tvec[1] * tvec[1])); | 
					
						
							| 
									
										
										
										
											2011-07-14 01:25:05 +00:00
										 |  |  |     } | 
					
						
							|  |  |  |     else { | 
					
						
							| 
									
										
										
										
											2012-03-26 06:55:09 +00:00
										 |  |  |       mat[0] = 1 + ((factor - 1) * (tvec[0] * tvec[0])); | 
					
						
							|  |  |  |       mat[1] = ((factor - 1) * (tvec[0] * tvec[1])); | 
					
						
							|  |  |  |       mat[2] = ((factor - 1) * (tvec[0] * tvec[2])); | 
					
						
							|  |  |  |       mat[3] = ((factor - 1) * (tvec[0] * tvec[1])); | 
					
						
							|  |  |  |       mat[4] = 1 + ((factor - 1) * (tvec[1] * tvec[1])); | 
					
						
							|  |  |  |       mat[5] = ((factor - 1) * (tvec[1] * tvec[2])); | 
					
						
							|  |  |  |       mat[6] = ((factor - 1) * (tvec[0] * tvec[2])); | 
					
						
							|  |  |  |       mat[7] = ((factor - 1) * (tvec[1] * tvec[2])); | 
					
						
							|  |  |  |       mat[8] = 1 + ((factor - 1) * (tvec[2] * tvec[2])); | 
					
						
							| 
									
										
										
										
											2010-08-11 16:40:36 +00:00
										 |  |  |     } | 
					
						
							| 
									
										
										
										
											2019-04-17 06:17:24 +02:00
										 |  |  |   } | 
					
						
							| 
									
										
										
										
											2011-10-13 01:29:08 +00:00
										 |  |  |   if (matSize == 4) { | 
					
						
							| 
									
										
										
										
											2011-02-06 11:17:22 +00:00
										 |  |  |     matrix_3x3_as_4x4(mat); | 
					
						
							| 
									
										
										
										
											2010-08-11 16:40:36 +00:00
										 |  |  |   } | 
					
						
							| 
									
										
										
										
											2012-10-20 20:20:02 +00:00
										 |  |  |   /* pass to matrix creation */ | 
					
						
							| 
									
										
										
										
											2015-01-04 17:03:54 +11:00
										 |  |  |   return Matrix_CreatePyObject(mat, matSize, matSize, (PyTypeObject *)cls); | 
					
						
							| 
									
										
										
										
											2010-08-11 16:40:36 +00:00
										 |  |  | } | 
					
						
							| 
									
										
										
										
											2012-10-20 20:20:02 +00:00
										 |  |  | /* ----------------------------------mathutils.Matrix.OrthoProjection() --- */ | 
					
						
							|  |  |  | /* mat is a 1D array of floats - row[0][0], row[0][1], row[1][0], etc. */ | 
					
						
							| 
									
										
										
										
											2011-05-24 16:05:51 +00:00
										 |  |  | PyDoc_STRVAR(C_Matrix_OrthoProjection_doc, | 
					
						
							| 
									
										
										
										
											2011-02-04 09:35:20 +00:00
										 |  |  |              ".. classmethod:: OrthoProjection(axis, size)\n" | 
					
						
							| 
									
										
										
										
											2010-08-11 16:40:36 +00:00
										 |  |  |              "\n" | 
					
						
							|  |  |  |              "   Create a matrix to represent an orthographic projection.\n" | 
					
						
							|  |  |  |              "\n" | 
					
						
							| 
									
										
										
										
											2011-05-26 19:13:01 +00:00
										 |  |  |              "   :arg axis: Can be any of the following: ['X', 'Y', 'XY', 'XZ', 'YZ'],\n" | 
					
						
							|  |  |  |              "      where a single axis is for a 2D matrix.\n" | 
					
						
							|  |  |  |              "      Or a vector for an arbitrary axis\n" | 
					
						
							| 
									
										
										
										
											2011-02-04 09:35:20 +00:00
										 |  |  |              "   :type axis: string or :class:`Vector`\n" | 
					
						
							| 
									
										
										
										
											2010-08-11 16:40:36 +00:00
										 |  |  |              "   :arg size: The size of the projection matrix to construct [2, 4].\n" | 
					
						
							|  |  |  |              "   :type size: int\n" | 
					
						
							|  |  |  |              "   :return: A new projection matrix.\n" | 
					
						
							| 
									
										
										
										
											2011-02-04 09:35:20 +00:00
										 |  |  |              "   :rtype: :class:`Matrix`\n"); | 
					
						
							| 
									
										
										
										
											2010-08-11 16:40:36 +00:00
										 |  |  | static PyObject *C_Matrix_OrthoProjection(PyObject *cls, PyObject *args) | 
					
						
							|  |  |  | { | 
					
						
							| 
									
										
										
										
											2011-02-04 09:35:20 +00:00
										 |  |  |   PyObject *axis; | 
					
						
							| 
									
										
										
										
											2019-04-17 06:17:24 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2010-08-11 16:40:36 +00:00
										 |  |  |   int matSize, x; | 
					
						
							|  |  |  |   float norm = 0.0f; | 
					
						
							| 
									
										
										
										
											2019-03-24 16:24:29 +11:00
										 |  |  |   float mat[16] = { | 
					
						
							|  |  |  |       0.0f, | 
					
						
							|  |  |  |       0.0f, | 
					
						
							|  |  |  |       0.0f, | 
					
						
							|  |  |  |       0.0f, | 
					
						
							|  |  |  |       0.0f, | 
					
						
							|  |  |  |       0.0f, | 
					
						
							|  |  |  |       0.0f, | 
					
						
							| 
									
										
										
										
											2019-04-17 06:17:24 +02:00
										 |  |  |       0.0f, | 
					
						
							|  |  |  |       0.0f, | 
					
						
							|  |  |  |       0.0f, | 
					
						
							|  |  |  |       0.0f, | 
					
						
							|  |  |  |       0.0f, | 
					
						
							|  |  |  |       0.0f, | 
					
						
							|  |  |  |       0.0f, | 
					
						
							|  |  |  |       0.0f, | 
					
						
							| 
									
										
										
										
											2019-03-24 16:24:29 +11:00
										 |  |  |       1.0f, | 
					
						
							|  |  |  |   }; | 
					
						
							| 
									
										
										
										
											2019-04-17 06:17:24 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2011-10-13 01:29:08 +00:00
										 |  |  |   if (!PyArg_ParseTuple(args, "Oi:Matrix.OrthoProjection", &axis, &matSize)) { | 
					
						
							| 
									
										
										
										
											2010-08-11 16:40:36 +00:00
										 |  |  |     return NULL; | 
					
						
							|  |  |  |   } | 
					
						
							| 
									
										
										
										
											2020-11-06 12:51:49 +11:00
										 |  |  |   if (!ELEM(matSize, 2, 3, 4)) { | 
					
						
							| 
									
										
										
										
											2011-07-14 09:54:03 +00:00
										 |  |  |     PyErr_SetString(PyExc_ValueError, | 
					
						
							| 
									
										
										
										
											2011-09-19 14:29:21 +00:00
										 |  |  |                     "Matrix.OrthoProjection(): " | 
					
						
							| 
									
										
										
										
											2011-07-14 01:25:05 +00:00
										 |  |  |                     "can only return a 2x2 3x3 or 4x4 matrix"); | 
					
						
							| 
									
										
										
										
											2010-08-11 16:40:36 +00:00
										 |  |  |     return NULL; | 
					
						
							|  |  |  |   } | 
					
						
							| 
									
										
										
										
											2019-04-17 06:17:24 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-10-20 20:20:02 +00:00
										 |  |  |   if (PyUnicode_Check(axis)) { /* ortho projection onto cardinal plane */ | 
					
						
							| 
									
										
										
										
											2011-02-04 09:35:20 +00:00
										 |  |  |     Py_ssize_t plane_len; | 
					
						
							| 
									
										
										
										
											2021-02-13 22:57:01 +11:00
										 |  |  |     const char *plane = PyUnicode_AsUTF8AndSize(axis, &plane_len); | 
					
						
							| 
									
										
										
										
											2011-10-13 01:29:08 +00:00
										 |  |  |     if (matSize == 2) { | 
					
						
							| 
									
										
										
										
											2011-12-24 13:26:30 +00:00
										 |  |  |       if (plane_len == 1 && plane[0] == 'X') { | 
					
						
							|  |  |  |         mat[0] = 1.0f; | 
					
						
							| 
									
										
										
										
											2011-02-04 09:35:20 +00:00
										 |  |  |       } | 
					
						
							| 
									
										
										
										
											2011-12-24 13:26:30 +00:00
										 |  |  |       else if (plane_len == 1 && plane[0] == 'Y') { | 
					
						
							|  |  |  |         mat[3] = 1.0f; | 
					
						
							| 
									
										
										
										
											2011-02-04 09:35:20 +00:00
										 |  |  |       } | 
					
						
							|  |  |  |       else { | 
					
						
							| 
									
										
										
										
											2011-07-14 01:25:05 +00:00
										 |  |  |         PyErr_Format(PyExc_ValueError, | 
					
						
							| 
									
										
										
										
											2011-09-19 14:29:21 +00:00
										 |  |  |                      "Matrix.OrthoProjection(): " | 
					
						
							| 
									
										
										
										
											2011-07-14 01:25:05 +00:00
										 |  |  |                      "unknown plane, expected: X, Y, not '%.200s'", | 
					
						
							|  |  |  |                      plane); | 
					
						
							| 
									
										
										
										
											2011-02-04 09:35:20 +00:00
										 |  |  |         return NULL; | 
					
						
							|  |  |  |       } | 
					
						
							| 
									
										
										
										
											2019-04-17 06:17:24 +02:00
										 |  |  |     } | 
					
						
							| 
									
										
										
										
											2011-02-04 09:35:20 +00:00
										 |  |  |     else { | 
					
						
							| 
									
										
										
										
											2011-12-24 13:26:30 +00:00
										 |  |  |       if (plane_len == 2 && plane[0] == 'X' && plane[1] == 'Y') { | 
					
						
							|  |  |  |         mat[0] = 1.0f; | 
					
						
							|  |  |  |         mat[4] = 1.0f; | 
					
						
							| 
									
										
										
										
											2011-02-04 09:35:20 +00:00
										 |  |  |       } | 
					
						
							| 
									
										
										
										
											2011-12-24 13:26:30 +00:00
										 |  |  |       else if (plane_len == 2 && plane[0] == 'X' && plane[1] == 'Z') { | 
					
						
							|  |  |  |         mat[0] = 1.0f; | 
					
						
							|  |  |  |         mat[8] = 1.0f; | 
					
						
							| 
									
										
										
										
											2011-02-04 09:35:20 +00:00
										 |  |  |       } | 
					
						
							| 
									
										
										
										
											2011-12-24 13:26:30 +00:00
										 |  |  |       else if (plane_len == 2 && plane[0] == 'Y' && plane[1] == 'Z') { | 
					
						
							|  |  |  |         mat[4] = 1.0f; | 
					
						
							|  |  |  |         mat[8] = 1.0f; | 
					
						
							| 
									
										
										
										
											2011-02-04 09:35:20 +00:00
										 |  |  |       } | 
					
						
							|  |  |  |       else { | 
					
						
							| 
									
										
										
										
											2011-07-14 01:25:05 +00:00
										 |  |  |         PyErr_Format(PyExc_ValueError, | 
					
						
							| 
									
										
										
										
											2011-09-19 14:29:21 +00:00
										 |  |  |                      "Matrix.OrthoProjection(): " | 
					
						
							| 
									
										
										
										
											2011-07-14 01:25:05 +00:00
										 |  |  |                      "unknown plane, expected: XY, XZ, YZ, not '%.200s'", | 
					
						
							|  |  |  |                      plane); | 
					
						
							| 
									
										
										
										
											2011-02-04 09:35:20 +00:00
										 |  |  |         return NULL; | 
					
						
							| 
									
										
										
										
											2011-02-04 03:06:23 +00:00
										 |  |  |       } | 
					
						
							| 
									
										
										
										
											2019-04-17 06:17:24 +02:00
										 |  |  |     } | 
					
						
							|  |  |  |   } | 
					
						
							| 
									
										
										
										
											2011-02-04 03:06:23 +00:00
										 |  |  |   else { | 
					
						
							| 
									
										
										
										
											2012-10-20 20:20:02 +00:00
										 |  |  |     /* arbitrary plane */ | 
					
						
							| 
									
										
										
										
											2019-04-17 06:17:24 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-08-20 16:10:13 +10:00
										 |  |  |     const int vec_size = (matSize == 2 ? 2 : 3); | 
					
						
							| 
									
										
										
										
											2011-02-04 03:06:23 +00:00
										 |  |  |     float tvec[4]; | 
					
						
							| 
									
										
										
										
											2019-04-17 06:17:24 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2011-11-29 20:22:35 +00:00
										 |  |  |     if (mathutils_array_parse(tvec, | 
					
						
							|  |  |  |                               vec_size, | 
					
						
							|  |  |  |                               vec_size, | 
					
						
							|  |  |  |                               axis, | 
					
						
							|  |  |  |                               "Matrix.OrthoProjection(axis, size), invalid 'axis' arg") == -1) { | 
					
						
							| 
									
										
										
										
											2011-02-04 03:06:23 +00:00
										 |  |  |       return NULL; | 
					
						
							|  |  |  |     } | 
					
						
							| 
									
										
										
										
											2019-04-17 06:17:24 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-10-20 20:20:02 +00:00
										 |  |  |     /* normalize arbitrary axis */ | 
					
						
							| 
									
										
										
										
											2011-10-13 01:29:08 +00:00
										 |  |  |     for (x = 0; x < vec_size; x++) { | 
					
						
							| 
									
										
										
										
											2011-02-04 03:06:23 +00:00
										 |  |  |       norm += tvec[x] * tvec[x]; | 
					
						
							| 
									
										
										
										
											2010-08-11 16:40:36 +00:00
										 |  |  |     } | 
					
						
							| 
									
										
										
										
											2014-03-28 14:53:37 +11:00
										 |  |  |     norm = sqrtf(norm); | 
					
						
							| 
									
										
										
										
											2011-10-13 01:29:08 +00:00
										 |  |  |     for (x = 0; x < vec_size; x++) { | 
					
						
							| 
									
										
										
										
											2011-02-04 03:06:23 +00:00
										 |  |  |       tvec[x] /= norm; | 
					
						
							| 
									
										
										
										
											2010-08-11 16:40:36 +00:00
										 |  |  |     } | 
					
						
							| 
									
										
										
										
											2011-10-13 01:29:08 +00:00
										 |  |  |     if (matSize == 2) { | 
					
						
							| 
									
										
										
										
											2011-02-04 03:06:23 +00:00
										 |  |  |       mat[0] = 1 - (tvec[0] * tvec[0]); | 
					
						
							| 
									
										
										
										
											2011-12-24 04:58:01 +00:00
										 |  |  |       mat[1] = -(tvec[0] * tvec[1]); | 
					
						
							|  |  |  |       mat[2] = -(tvec[0] * tvec[1]); | 
					
						
							| 
									
										
										
										
											2011-02-04 03:06:23 +00:00
										 |  |  |       mat[3] = 1 - (tvec[1] * tvec[1]); | 
					
						
							| 
									
										
										
										
											2011-02-04 09:35:20 +00:00
										 |  |  |     } | 
					
						
							| 
									
										
										
										
											2011-10-13 01:29:08 +00:00
										 |  |  |     else if (matSize > 2) { | 
					
						
							| 
									
										
										
										
											2011-02-04 03:06:23 +00:00
										 |  |  |       mat[0] = 1 - (tvec[0] * tvec[0]); | 
					
						
							| 
									
										
										
										
											2011-12-24 04:58:01 +00:00
										 |  |  |       mat[1] = -(tvec[0] * tvec[1]); | 
					
						
							|  |  |  |       mat[2] = -(tvec[0] * tvec[2]); | 
					
						
							|  |  |  |       mat[3] = -(tvec[0] * tvec[1]); | 
					
						
							| 
									
										
										
										
											2011-02-04 03:06:23 +00:00
										 |  |  |       mat[4] = 1 - (tvec[1] * tvec[1]); | 
					
						
							| 
									
										
										
										
											2011-12-24 04:58:01 +00:00
										 |  |  |       mat[5] = -(tvec[1] * tvec[2]); | 
					
						
							|  |  |  |       mat[6] = -(tvec[0] * tvec[2]); | 
					
						
							|  |  |  |       mat[7] = -(tvec[1] * tvec[2]); | 
					
						
							| 
									
										
										
										
											2011-02-04 03:06:23 +00:00
										 |  |  |       mat[8] = 1 - (tvec[2] * tvec[2]); | 
					
						
							| 
									
										
										
										
											2010-08-11 16:40:36 +00:00
										 |  |  |     } | 
					
						
							| 
									
										
										
										
											2019-04-17 06:17:24 +02:00
										 |  |  |   } | 
					
						
							| 
									
										
										
										
											2011-10-13 01:29:08 +00:00
										 |  |  |   if (matSize == 4) { | 
					
						
							| 
									
										
										
										
											2011-02-06 11:17:22 +00:00
										 |  |  |     matrix_3x3_as_4x4(mat); | 
					
						
							| 
									
										
										
										
											2010-08-11 16:40:36 +00:00
										 |  |  |   } | 
					
						
							| 
									
										
										
										
											2012-10-20 20:20:02 +00:00
										 |  |  |   /* pass to matrix creation */ | 
					
						
							| 
									
										
										
										
											2015-01-04 17:03:54 +11:00
										 |  |  |   return Matrix_CreatePyObject(mat, matSize, matSize, (PyTypeObject *)cls); | 
					
						
							| 
									
										
										
										
											2010-08-11 16:40:36 +00:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2011-05-24 16:05:51 +00:00
										 |  |  | PyDoc_STRVAR(C_Matrix_Shear_doc, | 
					
						
							| 
									
										
										
										
											2011-02-04 09:41:59 +00:00
										 |  |  |              ".. classmethod:: Shear(plane, size, factor)\n" | 
					
						
							| 
									
										
										
										
											2010-08-11 16:40:36 +00:00
										 |  |  |              "\n" | 
					
						
							|  |  |  |              "   Create a matrix to represent an shear transformation.\n" | 
					
						
							|  |  |  |              "\n" | 
					
						
							| 
									
										
										
										
											2011-05-26 19:13:01 +00:00
										 |  |  |              "   :arg plane: Can be any of the following: ['X', 'Y', 'XY', 'XZ', 'YZ'],\n" | 
					
						
							|  |  |  |              "      where a single axis is for a 2D matrix only.\n" | 
					
						
							| 
									
										
										
										
											2010-08-11 16:40:36 +00:00
										 |  |  |              "   :type plane: string\n" | 
					
						
							|  |  |  |              "   :arg size: The size of the shear matrix to construct [2, 4].\n" | 
					
						
							|  |  |  |              "   :type size: int\n" | 
					
						
							| 
									
										
										
										
											2011-05-26 19:13:01 +00:00
										 |  |  |              "   :arg factor: The factor of shear to apply. For a 3 or 4 *size* matrix\n" | 
					
						
							| 
									
										
										
										
											2012-03-13 06:22:43 +00:00
										 |  |  |              "      pass a pair of floats corresponding with the *plane* axis.\n" | 
					
						
							| 
									
										
										
										
											2011-02-04 09:41:59 +00:00
										 |  |  |              "   :type factor: float or float pair\n" | 
					
						
							| 
									
										
										
										
											2010-08-11 16:40:36 +00:00
										 |  |  |              "   :return: A new shear matrix.\n" | 
					
						
							| 
									
										
										
										
											2011-01-21 03:18:01 +00:00
										 |  |  |              "   :rtype: :class:`Matrix`\n"); | 
					
						
							| 
									
										
										
										
											2010-08-11 16:40:36 +00:00
										 |  |  | static PyObject *C_Matrix_Shear(PyObject *cls, PyObject *args) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  |   int matSize; | 
					
						
							| 
									
										
										
										
											2011-02-04 03:06:23 +00:00
										 |  |  |   const char *plane; | 
					
						
							| 
									
										
										
										
											2011-01-21 03:18:01 +00:00
										 |  |  |   PyObject *fac; | 
					
						
							| 
									
										
										
										
											2019-03-24 16:24:29 +11:00
										 |  |  |   float mat[16] = { | 
					
						
							|  |  |  |       0.0f, | 
					
						
							|  |  |  |       0.0f, | 
					
						
							|  |  |  |       0.0f, | 
					
						
							|  |  |  |       0.0f, | 
					
						
							|  |  |  |       0.0f, | 
					
						
							|  |  |  |       0.0f, | 
					
						
							|  |  |  |       0.0f, | 
					
						
							| 
									
										
										
										
											2019-04-17 06:17:24 +02:00
										 |  |  |       0.0f, | 
					
						
							|  |  |  |       0.0f, | 
					
						
							|  |  |  |       0.0f, | 
					
						
							|  |  |  |       0.0f, | 
					
						
							|  |  |  |       0.0f, | 
					
						
							|  |  |  |       0.0f, | 
					
						
							|  |  |  |       0.0f, | 
					
						
							|  |  |  |       0.0f, | 
					
						
							| 
									
										
										
										
											2019-03-24 16:24:29 +11:00
										 |  |  |       1.0f, | 
					
						
							|  |  |  |   }; | 
					
						
							| 
									
										
										
										
											2019-04-17 06:17:24 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2011-10-13 01:29:08 +00:00
										 |  |  |   if (!PyArg_ParseTuple(args, "siO:Matrix.Shear", &plane, &matSize, &fac)) { | 
					
						
							| 
									
										
										
										
											2010-08-11 16:40:36 +00:00
										 |  |  |     return NULL; | 
					
						
							|  |  |  |   } | 
					
						
							| 
									
										
										
										
											2020-11-06 12:51:49 +11:00
										 |  |  |   if (!ELEM(matSize, 2, 3, 4)) { | 
					
						
							| 
									
										
										
										
											2011-07-14 09:54:03 +00:00
										 |  |  |     PyErr_SetString(PyExc_ValueError, | 
					
						
							| 
									
										
										
										
											2011-09-19 14:29:21 +00:00
										 |  |  |                     "Matrix.Shear(): " | 
					
						
							| 
									
										
										
										
											2011-07-14 01:25:05 +00:00
										 |  |  |                     "can only return a 2x2 3x3 or 4x4 matrix"); | 
					
						
							| 
									
										
										
										
											2010-08-11 16:40:36 +00:00
										 |  |  |     return NULL; | 
					
						
							|  |  |  |   } | 
					
						
							| 
									
										
										
										
											2019-04-17 06:17:24 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2011-10-13 01:29:08 +00:00
										 |  |  |   if (matSize == 2) { | 
					
						
							| 
									
										
										
										
											2011-12-24 13:26:30 +00:00
										 |  |  |     float const factor = PyFloat_AsDouble(fac); | 
					
						
							| 
									
										
										
										
											2019-04-17 06:17:24 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2011-12-24 13:26:30 +00:00
										 |  |  |     if (factor == -1.0f && PyErr_Occurred()) { | 
					
						
							| 
									
										
										
										
											2011-07-14 09:54:03 +00:00
										 |  |  |       PyErr_SetString(PyExc_TypeError, | 
					
						
							| 
									
										
										
										
											2011-09-19 14:29:21 +00:00
										 |  |  |                       "Matrix.Shear(): " | 
					
						
							| 
									
										
										
										
											2011-07-14 01:25:05 +00:00
										 |  |  |                       "the factor to be a float"); | 
					
						
							| 
									
										
										
										
											2011-01-21 03:18:01 +00:00
										 |  |  |       return NULL; | 
					
						
							|  |  |  |     } | 
					
						
							| 
									
										
										
										
											2019-04-17 06:17:24 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2011-01-21 03:18:01 +00:00
										 |  |  |     /* unit */ | 
					
						
							| 
									
										
										
										
											2010-08-11 16:40:36 +00:00
										 |  |  |     mat[0] = 1.0f; | 
					
						
							|  |  |  |     mat[3] = 1.0f; | 
					
						
							| 
									
										
										
										
											2019-04-17 06:17:24 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-03-10 06:18:03 +00:00
										 |  |  |     if (STREQ(plane, "X")) { | 
					
						
							| 
									
										
										
										
											2011-01-21 03:18:01 +00:00
										 |  |  |       mat[2] = factor; | 
					
						
							|  |  |  |     } | 
					
						
							| 
									
										
										
										
											2013-03-10 06:18:03 +00:00
										 |  |  |     else if (STREQ(plane, "Y")) { | 
					
						
							| 
									
										
										
										
											2011-01-21 03:18:01 +00:00
										 |  |  |       mat[1] = factor; | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  |     else { | 
					
						
							| 
									
										
										
										
											2011-07-14 09:54:03 +00:00
										 |  |  |       PyErr_SetString(PyExc_ValueError, | 
					
						
							| 
									
										
										
										
											2011-07-14 01:25:05 +00:00
										 |  |  |                       "Matrix.Shear(): " | 
					
						
							|  |  |  |                       "expected: X, Y or wrong matrix size for shearing plane"); | 
					
						
							| 
									
										
										
										
											2011-01-21 03:18:01 +00:00
										 |  |  |       return NULL; | 
					
						
							|  |  |  |     } | 
					
						
							| 
									
										
										
										
											2019-04-17 06:17:24 +02:00
										 |  |  |   } | 
					
						
							| 
									
										
										
										
											2011-01-21 03:18:01 +00:00
										 |  |  |   else { | 
					
						
							|  |  |  |     /* 3 or 4, apply as 3x3, resize later if needed */ | 
					
						
							|  |  |  |     float factor[2]; | 
					
						
							| 
									
										
										
										
											2019-04-17 06:17:24 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-07-29 10:37:39 +10:00
										 |  |  |     if (mathutils_array_parse(factor, 2, 2, fac, "Matrix.Shear()") == -1) { | 
					
						
							| 
									
										
										
										
											2011-01-21 03:18:01 +00:00
										 |  |  |       return NULL; | 
					
						
							|  |  |  |     } | 
					
						
							| 
									
										
										
										
											2019-04-17 06:17:24 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2011-01-21 03:18:01 +00:00
										 |  |  |     /* unit */ | 
					
						
							| 
									
										
										
										
											2010-08-11 16:40:36 +00:00
										 |  |  |     mat[0] = 1.0f; | 
					
						
							|  |  |  |     mat[4] = 1.0f; | 
					
						
							|  |  |  |     mat[8] = 1.0f; | 
					
						
							| 
									
										
										
										
											2019-04-17 06:17:24 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-03-10 06:18:03 +00:00
										 |  |  |     if (STREQ(plane, "XY")) { | 
					
						
							| 
									
										
										
										
											2011-01-21 03:18:01 +00:00
										 |  |  |       mat[6] = factor[0]; | 
					
						
							|  |  |  |       mat[7] = factor[1]; | 
					
						
							|  |  |  |     } | 
					
						
							| 
									
										
										
										
											2013-03-10 06:18:03 +00:00
										 |  |  |     else if (STREQ(plane, "XZ")) { | 
					
						
							| 
									
										
										
										
											2011-01-21 03:18:01 +00:00
										 |  |  |       mat[3] = factor[0]; | 
					
						
							|  |  |  |       mat[5] = factor[1]; | 
					
						
							|  |  |  |     } | 
					
						
							| 
									
										
										
										
											2013-03-10 06:18:03 +00:00
										 |  |  |     else if (STREQ(plane, "YZ")) { | 
					
						
							| 
									
										
										
										
											2011-01-21 03:18:01 +00:00
										 |  |  |       mat[1] = factor[0]; | 
					
						
							|  |  |  |       mat[2] = factor[1]; | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  |     else { | 
					
						
							| 
									
										
										
										
											2011-07-14 09:54:03 +00:00
										 |  |  |       PyErr_SetString(PyExc_ValueError, | 
					
						
							| 
									
										
										
										
											2011-09-19 14:29:21 +00:00
										 |  |  |                       "Matrix.Shear(): " | 
					
						
							| 
									
										
										
										
											2011-07-14 01:25:05 +00:00
										 |  |  |                       "expected: X, Y, XY, XZ, YZ"); | 
					
						
							| 
									
										
										
										
											2011-01-21 03:18:01 +00:00
										 |  |  |       return NULL; | 
					
						
							| 
									
										
										
										
											2010-08-11 16:40:36 +00:00
										 |  |  |     } | 
					
						
							| 
									
										
										
										
											2019-04-17 06:17:24 +02:00
										 |  |  |   } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2011-10-13 01:29:08 +00:00
										 |  |  |   if (matSize == 4) { | 
					
						
							| 
									
										
										
										
											2011-02-06 11:17:22 +00:00
										 |  |  |     matrix_3x3_as_4x4(mat); | 
					
						
							| 
									
										
										
										
											2010-08-11 16:40:36 +00:00
										 |  |  |   } | 
					
						
							| 
									
										
										
										
											2012-10-20 20:20:02 +00:00
										 |  |  |   /* pass to matrix creation */ | 
					
						
							| 
									
										
										
										
											2015-01-04 17:03:54 +11:00
										 |  |  |   return Matrix_CreatePyObject(mat, matSize, matSize, (PyTypeObject *)cls); | 
					
						
							| 
									
										
										
										
											2010-08-11 16:40:36 +00:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-05-14 19:46:19 +03:00
										 |  |  | PyDoc_STRVAR( | 
					
						
							|  |  |  |     C_Matrix_LocRotScale_doc, | 
					
						
							|  |  |  |     ".. classmethod:: LocRotScale(location, rotation, scale)\n" | 
					
						
							|  |  |  |     "\n" | 
					
						
							|  |  |  |     "   Create a matrix combining translation, rotation and scale,\n" | 
					
						
							|  |  |  |     "   acting as the inverse of the decompose() method.\n" | 
					
						
							|  |  |  |     "\n" | 
					
						
							|  |  |  |     "   Any of the inputs may be replaced with None if not needed.\n" | 
					
						
							|  |  |  |     "\n" | 
					
						
							|  |  |  |     "   :arg location: The translation component.\n" | 
					
						
							|  |  |  |     "   :type location: :class:`Vector` or None\n" | 
					
						
							|  |  |  |     "   :arg rotation: The rotation component.\n" | 
					
						
							|  |  |  |     "   :type rotation: 3x3 :class:`Matrix`, :class:`Quaternion`, :class:`Euler` or None\n" | 
					
						
							|  |  |  |     "   :arg scale: The scale component.\n" | 
					
						
							|  |  |  |     "   :type scale: :class:`Vector` or None\n" | 
					
						
							|  |  |  |     "   :return: Combined transformation matrix. \n" | 
					
						
							|  |  |  |     "   :rtype: 4x4 :class:`Matrix`\n"); | 
					
						
							|  |  |  | static PyObject *C_Matrix_LocRotScale(PyObject *cls, PyObject *args) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  |   PyObject *loc_obj, *rot_obj, *scale_obj; | 
					
						
							|  |  |  |   float mat[4][4], loc[3]; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   if (!PyArg_ParseTuple(args, "OOO:Matrix.LocRotScale", &loc_obj, &rot_obj, &scale_obj)) { | 
					
						
							|  |  |  |     return NULL; | 
					
						
							|  |  |  |   } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   /* Decode location. */ | 
					
						
							|  |  |  |   if (loc_obj == Py_None) { | 
					
						
							|  |  |  |     zero_v3(loc); | 
					
						
							|  |  |  |   } | 
					
						
							|  |  |  |   else if (mathutils_array_parse( | 
					
						
							|  |  |  |                loc, 3, 3, loc_obj, "Matrix.LocRotScale(), invalid location argument") == -1) { | 
					
						
							|  |  |  |     return NULL; | 
					
						
							|  |  |  |   } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   /* Decode rotation. */ | 
					
						
							|  |  |  |   if (rot_obj == Py_None) { | 
					
						
							|  |  |  |     unit_m4(mat); | 
					
						
							|  |  |  |   } | 
					
						
							|  |  |  |   else if (QuaternionObject_Check(rot_obj)) { | 
					
						
							|  |  |  |     QuaternionObject *quat_obj = (QuaternionObject *)rot_obj; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     if (BaseMath_ReadCallback(quat_obj) == -1) { | 
					
						
							|  |  |  |       return NULL; | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     quat_to_mat4(mat, quat_obj->quat); | 
					
						
							|  |  |  |   } | 
					
						
							|  |  |  |   else if (EulerObject_Check(rot_obj)) { | 
					
						
							|  |  |  |     EulerObject *eul_obj = (EulerObject *)rot_obj; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     if (BaseMath_ReadCallback(eul_obj) == -1) { | 
					
						
							|  |  |  |       return NULL; | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     eulO_to_mat4(mat, eul_obj->eul, eul_obj->order); | 
					
						
							|  |  |  |   } | 
					
						
							|  |  |  |   else if (MatrixObject_Check(rot_obj)) { | 
					
						
							|  |  |  |     MatrixObject *mat_obj = (MatrixObject *)rot_obj; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     if (BaseMath_ReadCallback(mat_obj) == -1) { | 
					
						
							|  |  |  |       return NULL; | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     if (mat_obj->num_col == 3 && mat_obj->num_row == 3) { | 
					
						
							| 
									
										
										
										
											2021-05-18 14:13:20 +10:00
										 |  |  |       copy_m4_m3(mat, (const float(*)[3])mat_obj->matrix); | 
					
						
							| 
									
										
										
										
											2021-05-14 19:46:19 +03:00
										 |  |  |     } | 
					
						
							|  |  |  |     else { | 
					
						
							|  |  |  |       PyErr_SetString(PyExc_ValueError, | 
					
						
							|  |  |  |                       "Matrix.LocRotScale(): " | 
					
						
							|  |  |  |                       "inappropriate rotation matrix size - expects 3x3 matrix"); | 
					
						
							|  |  |  |       return NULL; | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  |   } | 
					
						
							|  |  |  |   else { | 
					
						
							|  |  |  |     PyErr_SetString(PyExc_ValueError, | 
					
						
							|  |  |  |                     "Matrix.LocRotScale(): " | 
					
						
							|  |  |  |                     "rotation argument must be Matrix, Quaternion, Euler or None"); | 
					
						
							|  |  |  |     return NULL; | 
					
						
							|  |  |  |   } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   /* Decode scale. */ | 
					
						
							|  |  |  |   if (scale_obj != Py_None) { | 
					
						
							|  |  |  |     float scale[3]; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     if (mathutils_array_parse( | 
					
						
							|  |  |  |             scale, 3, 3, scale_obj, "Matrix.LocRotScale(), invalid scale argument") == -1) { | 
					
						
							|  |  |  |       return NULL; | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     rescale_m4(mat, scale); | 
					
						
							|  |  |  |   } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   copy_v3_v3(mat[3], loc); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   return Matrix_CreatePyObject(&mat[0][0], 4, 4, (PyTypeObject *)cls); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2011-02-05 09:57:02 +00:00
										 |  |  | void matrix_as_3x3(float mat[3][3], MatrixObject *self) | 
					
						
							| 
									
										
										
										
											2011-01-25 16:32:41 +00:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2011-12-20 05:48:35 +00:00
										 |  |  |   copy_v3_v3(mat[0], MATRIX_COL_PTR(self, 0)); | 
					
						
							|  |  |  |   copy_v3_v3(mat[1], MATRIX_COL_PTR(self, 1)); | 
					
						
							|  |  |  |   copy_v3_v3(mat[2], MATRIX_COL_PTR(self, 2)); | 
					
						
							| 
									
										
										
										
											2011-01-25 16:32:41 +00:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-04-29 19:58:37 +10:00
										 |  |  | static void matrix_copy(MatrixObject *mat_dst, const MatrixObject *mat_src) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  |   BLI_assert((mat_dst->num_col == mat_src->num_col) && (mat_dst->num_row == mat_src->num_row)); | 
					
						
							|  |  |  |   BLI_assert(mat_dst != mat_src); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   memcpy(mat_dst->matrix, mat_src->matrix, sizeof(float) * (mat_dst->num_col * mat_dst->num_row)); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-02-20 15:09:44 +11:00
										 |  |  | static void matrix_unit_internal(MatrixObject *self) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  |   const int mat_size = sizeof(float) * (self->num_col * self->num_row); | 
					
						
							|  |  |  |   memset(self->matrix, 0x0, mat_size); | 
					
						
							|  |  |  |   const int col_row_max = min_ii(self->num_col, self->num_row); | 
					
						
							|  |  |  |   const int num_row = self->num_row; | 
					
						
							|  |  |  |   for (int col = 0; col < col_row_max; col++) { | 
					
						
							|  |  |  |     self->matrix[(col * num_row) + col] = 1.0f; | 
					
						
							|  |  |  |   } | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-02-15 10:46:14 +11:00
										 |  |  | /* transposes memory layout, rol/col's don't have to match */ | 
					
						
							|  |  |  | static void matrix_transpose_internal(float mat_dst_fl[], const MatrixObject *mat_src) | 
					
						
							|  |  |  | { | 
					
						
							| 
									
										
										
										
											2020-02-20 15:38:58 +11:00
										 |  |  |   ushort col, row; | 
					
						
							|  |  |  |   uint i = 0; | 
					
						
							| 
									
										
										
										
											2015-02-15 10:46:14 +11:00
										 |  |  | 
 | 
					
						
							|  |  |  |   for (row = 0; row < mat_src->num_row; row++) { | 
					
						
							|  |  |  |     for (col = 0; col < mat_src->num_col; col++) { | 
					
						
							|  |  |  |       mat_dst_fl[i++] = MATRIX_ITEM(mat_src, row, col); | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  |   } | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
											
												Mathutils refactor & include in sphinx generated docs, (TODO, include getset'ers in docs)
 - Mathutils.MidpointVecs --> vector.lerp(other, fac)
 - Mathutils.AngleBetweenVecs --> vector.angle(other)
 - Mathutils.ProjectVecs --> vector.project(other)
 - Mathutils.DifferenceQuats --> quat.difference(other)
 - Mathutils.Slerp --> quat.slerp(other, fac)
 - Mathutils.Rand: removed, use pythons random module
 - Mathutils.RotationMatrix(angle, size, axis_flag, axis) --> Mathutils.RotationMatrix(angle, size, axis); merge axis & axis_flag args
 - Matrix.scalePart --> Matrix.scale_part
 - Matrix.translationPart --> Matrix.translation_part
 - Matrix.rotationPart --> Matrix.rotation_part
 - toMatrix --> to_matrix
 - toEuler --> to_euler
 - toQuat --> to_quat
 - Vector.toTrackQuat --> Vector.to_track_quat
											
										 
											2010-01-25 09:44:04 +00:00
										 |  |  | /* assumes rowsize == colsize is checked and the read callback has run */ | 
					
						
							| 
									
										
										
										
											2014-04-29 20:41:28 +10:00
										 |  |  | static float matrix_determinant_internal(const MatrixObject *self) | 
					
						
							| 
									
										
										
											
												Mathutils refactor & include in sphinx generated docs, (TODO, include getset'ers in docs)
 - Mathutils.MidpointVecs --> vector.lerp(other, fac)
 - Mathutils.AngleBetweenVecs --> vector.angle(other)
 - Mathutils.ProjectVecs --> vector.project(other)
 - Mathutils.DifferenceQuats --> quat.difference(other)
 - Mathutils.Slerp --> quat.slerp(other, fac)
 - Mathutils.Rand: removed, use pythons random module
 - Mathutils.RotationMatrix(angle, size, axis_flag, axis) --> Mathutils.RotationMatrix(angle, size, axis); merge axis & axis_flag args
 - Matrix.scalePart --> Matrix.scale_part
 - Matrix.translationPart --> Matrix.translation_part
 - Matrix.rotationPart --> Matrix.rotation_part
 - toMatrix --> to_matrix
 - toEuler --> to_euler
 - toQuat --> to_quat
 - Vector.toTrackQuat --> Vector.to_track_quat
											
										 
											2010-01-25 09:44:04 +00:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2011-12-20 04:11:23 +00:00
										 |  |  |   if (self->num_col == 2) { | 
					
						
							| 
									
										
										
										
											2011-12-19 03:12:10 +00:00
										 |  |  |     return determinant_m2(MATRIX_ITEM(self, 0, 0), | 
					
						
							|  |  |  |                           MATRIX_ITEM(self, 0, 1), | 
					
						
							|  |  |  |                           MATRIX_ITEM(self, 1, 0), | 
					
						
							|  |  |  |                           MATRIX_ITEM(self, 1, 1)); | 
					
						
							| 
									
										
										
										
											2011-03-19 11:12:48 +00:00
										 |  |  |   } | 
					
						
							| 
									
										
										
										
											2020-08-07 12:41:06 +02:00
										 |  |  |   if (self->num_col == 3) { | 
					
						
							| 
									
										
										
										
											2011-12-19 03:12:10 +00:00
										 |  |  |     return determinant_m3(MATRIX_ITEM(self, 0, 0), | 
					
						
							|  |  |  |                           MATRIX_ITEM(self, 0, 1), | 
					
						
							|  |  |  |                           MATRIX_ITEM(self, 0, 2), | 
					
						
							|  |  |  |                           MATRIX_ITEM(self, 1, 0), | 
					
						
							|  |  |  |                           MATRIX_ITEM(self, 1, 1), | 
					
						
							|  |  |  |                           MATRIX_ITEM(self, 1, 2), | 
					
						
							|  |  |  |                           MATRIX_ITEM(self, 2, 0), | 
					
						
							|  |  |  |                           MATRIX_ITEM(self, 2, 1), | 
					
						
							|  |  |  |                           MATRIX_ITEM(self, 2, 2)); | 
					
						
							| 
									
										
										
										
											2011-07-14 01:25:05 +00:00
										 |  |  |   } | 
					
						
							| 
									
										
										
										
											2020-08-07 12:41:06 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-05-18 14:13:20 +10:00
										 |  |  |   return determinant_m4((const float(*)[4])self->matrix); | 
					
						
							| 
									
										
										
											
												Mathutils refactor & include in sphinx generated docs, (TODO, include getset'ers in docs)
 - Mathutils.MidpointVecs --> vector.lerp(other, fac)
 - Mathutils.AngleBetweenVecs --> vector.angle(other)
 - Mathutils.ProjectVecs --> vector.project(other)
 - Mathutils.DifferenceQuats --> quat.difference(other)
 - Mathutils.Slerp --> quat.slerp(other, fac)
 - Mathutils.Rand: removed, use pythons random module
 - Mathutils.RotationMatrix(angle, size, axis_flag, axis) --> Mathutils.RotationMatrix(angle, size, axis); merge axis & axis_flag args
 - Matrix.scalePart --> Matrix.scale_part
 - Matrix.translationPart --> Matrix.translation_part
 - Matrix.rotationPart --> Matrix.rotation_part
 - toMatrix --> to_matrix
 - toEuler --> to_euler
 - toQuat --> to_quat
 - Vector.toTrackQuat --> Vector.to_track_quat
											
										 
											2010-01-25 09:44:04 +00:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-02-20 15:38:58 +11:00
										 |  |  | static void adjoint_matrix_n(float *mat_dst, const float *mat_src, const ushort dim) | 
					
						
							| 
									
										
										
										
											2014-09-06 14:54:08 +02:00
										 |  |  | { | 
					
						
							|  |  |  |   /* calculate the classical adjoint */ | 
					
						
							|  |  |  |   switch (dim) { | 
					
						
							|  |  |  |     case 2: { | 
					
						
							| 
									
										
										
										
											2021-05-18 14:13:20 +10:00
										 |  |  |       adjoint_m2_m2((float(*)[2])mat_dst, (const float(*)[2])mat_src); | 
					
						
							| 
									
										
										
										
											2014-09-06 14:54:08 +02:00
										 |  |  |       break; | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  |     case 3: { | 
					
						
							| 
									
										
										
										
											2021-05-18 14:13:20 +10:00
										 |  |  |       adjoint_m3_m3((float(*)[3])mat_dst, (const float(*)[3])mat_src); | 
					
						
							| 
									
										
										
										
											2014-09-06 14:54:08 +02:00
										 |  |  |       break; | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  |     case 4: { | 
					
						
							| 
									
										
										
										
											2021-05-18 14:13:20 +10:00
										 |  |  |       adjoint_m4_m4((float(*)[4])mat_dst, (const float(*)[4])mat_src); | 
					
						
							| 
									
										
										
										
											2014-09-06 14:54:08 +02:00
										 |  |  |       break; | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  |     default: | 
					
						
							| 
									
										
										
										
											2021-03-24 12:38:08 +11:00
										 |  |  |       BLI_assert_unreachable(); | 
					
						
							|  |  |  |       break; | 
					
						
							| 
									
										
										
										
											2019-04-17 06:17:24 +02:00
										 |  |  |   } | 
					
						
							| 
									
										
										
										
											2014-09-06 14:54:08 +02:00
										 |  |  | } | 
					
						
							| 
									
										
										
										
											2019-04-17 06:17:24 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-09-06 14:54:08 +02:00
										 |  |  | static void matrix_invert_with_det_n_internal(float *mat_dst, | 
					
						
							|  |  |  |                                               const float *mat_src, | 
					
						
							|  |  |  |                                               const float det, | 
					
						
							| 
									
										
										
										
											2020-02-20 15:38:58 +11:00
										 |  |  |                                               const ushort dim) | 
					
						
							| 
									
										
										
										
											2014-09-06 14:54:08 +02:00
										 |  |  | { | 
					
						
							|  |  |  |   float mat[MATRIX_MAX_DIM * MATRIX_MAX_DIM]; | 
					
						
							| 
									
										
										
										
											2020-02-20 15:38:58 +11:00
										 |  |  |   ushort i, j, k; | 
					
						
							| 
									
										
										
										
											2019-04-17 06:17:24 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-09-06 14:54:08 +02:00
										 |  |  |   BLI_assert(det != 0.0f); | 
					
						
							| 
									
										
										
										
											2019-04-17 06:17:24 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-09-06 14:54:08 +02:00
										 |  |  |   adjoint_matrix_n(mat, mat_src, dim); | 
					
						
							| 
									
										
										
										
											2019-04-17 06:17:24 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-09-06 14:54:08 +02:00
										 |  |  |   /* divide by determinant & set values */ | 
					
						
							|  |  |  |   k = 0; | 
					
						
							|  |  |  |   for (i = 0; i < dim; i++) {   /* num_col */ | 
					
						
							|  |  |  |     for (j = 0; j < dim; j++) { /* num_row */ | 
					
						
							|  |  |  |       mat_dst[MATRIX_ITEM_INDEX_NUMROW(dim, j, i)] = mat[k++] / det; | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  |   } | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-04-29 20:41:28 +10:00
										 |  |  | /**
 | 
					
						
							| 
									
										
										
										
											2021-07-20 22:52:31 +10:00
										 |  |  |  * \param r_mat: can be from `self->matrix` or not. | 
					
						
							| 
									
										
										
										
											2014-09-06 14:54:08 +02:00
										 |  |  |  */ | 
					
						
							| 
									
										
										
										
											2014-04-29 20:41:28 +10:00
										 |  |  | static bool matrix_invert_internal(const MatrixObject *self, float *r_mat) | 
					
						
							| 
									
										
										
										
											2014-04-29 19:58:37 +10:00
										 |  |  | { | 
					
						
							|  |  |  |   float det; | 
					
						
							| 
									
										
										
										
											2014-09-06 14:54:08 +02:00
										 |  |  |   BLI_assert(self->num_col == self->num_row); | 
					
						
							| 
									
										
										
										
											2014-04-29 19:58:37 +10:00
										 |  |  |   det = matrix_determinant_internal(self); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   if (det != 0.0f) { | 
					
						
							| 
									
										
										
										
											2014-09-06 14:54:08 +02:00
										 |  |  |     matrix_invert_with_det_n_internal(r_mat, self->matrix, det, self->num_col); | 
					
						
							|  |  |  |     return true; | 
					
						
							|  |  |  |   } | 
					
						
							| 
									
										
										
										
											2020-08-07 12:41:06 +02:00
										 |  |  | 
 | 
					
						
							|  |  |  |   return false; | 
					
						
							| 
									
										
										
										
											2014-09-06 14:54:08 +02:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | /**
 | 
					
						
							| 
									
										
										
										
											2021-07-20 22:52:31 +10:00
										 |  |  |  * Similar to `matrix_invert_internal` but should never error. | 
					
						
							|  |  |  |  * \param r_mat: can be from `self->matrix` or not. | 
					
						
							| 
									
										
										
										
											2014-09-06 14:54:08 +02:00
										 |  |  |  */ | 
					
						
							|  |  |  | static void matrix_invert_safe_internal(const MatrixObject *self, float *r_mat) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  |   float det; | 
					
						
							|  |  |  |   float *in_mat = self->matrix; | 
					
						
							|  |  |  |   BLI_assert(self->num_col == self->num_row); | 
					
						
							|  |  |  |   det = matrix_determinant_internal(self); | 
					
						
							| 
									
										
										
										
											2019-04-17 06:17:24 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-09-06 14:54:08 +02:00
										 |  |  |   if (det == 0.0f) { | 
					
						
							|  |  |  |     const float eps = PSEUDOINVERSE_EPSILON; | 
					
						
							| 
									
										
										
										
											2019-04-17 06:17:24 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-04-29 19:59:13 +10:00
										 |  |  |     /* We will copy self->matrix into r_mat (if needed),
 | 
					
						
							|  |  |  |      * and modify it in place to add diagonal epsilon. */ | 
					
						
							| 
									
										
										
										
											2014-09-06 14:54:08 +02:00
										 |  |  |     in_mat = r_mat; | 
					
						
							| 
									
										
										
										
											2019-04-17 06:17:24 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-04-29 19:58:37 +10:00
										 |  |  |     switch (self->num_col) { | 
					
						
							|  |  |  |       case 2: { | 
					
						
							| 
									
										
										
										
											2014-09-06 14:54:08 +02:00
										 |  |  |         float(*mat)[2] = (float(*)[2])in_mat; | 
					
						
							| 
									
										
										
										
											2019-04-17 06:17:24 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-09-06 14:54:08 +02:00
										 |  |  |         if (in_mat != self->matrix) { | 
					
						
							| 
									
										
										
										
											2021-05-18 14:13:20 +10:00
										 |  |  |           copy_m2_m2(mat, (const float(*)[2])self->matrix); | 
					
						
							| 
									
										
										
										
											2014-09-06 14:54:08 +02:00
										 |  |  |         } | 
					
						
							|  |  |  |         mat[0][0] += eps; | 
					
						
							|  |  |  |         mat[1][1] += eps; | 
					
						
							| 
									
										
										
										
											2019-04-17 06:17:24 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-09-06 14:54:08 +02:00
										 |  |  |         if (UNLIKELY((det = determinant_m2(mat[0][0], mat[0][1], mat[1][0], mat[1][1])) == 0.0f)) { | 
					
						
							|  |  |  |           unit_m2(mat); | 
					
						
							|  |  |  |           det = 1.0f; | 
					
						
							|  |  |  |         } | 
					
						
							| 
									
										
										
										
											2014-04-29 19:58:37 +10:00
										 |  |  |         break; | 
					
						
							|  |  |  |       } | 
					
						
							|  |  |  |       case 3: { | 
					
						
							| 
									
										
										
										
											2014-09-06 14:54:08 +02:00
										 |  |  |         float(*mat)[3] = (float(*)[3])in_mat; | 
					
						
							| 
									
										
										
										
											2019-04-17 06:17:24 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-09-06 14:54:08 +02:00
										 |  |  |         if (in_mat != self->matrix) { | 
					
						
							| 
									
										
										
										
											2021-05-18 14:13:20 +10:00
										 |  |  |           copy_m3_m3(mat, (const float(*)[3])self->matrix); | 
					
						
							| 
									
										
										
										
											2014-09-06 14:54:08 +02:00
										 |  |  |         } | 
					
						
							|  |  |  |         mat[0][0] += eps; | 
					
						
							|  |  |  |         mat[1][1] += eps; | 
					
						
							|  |  |  |         mat[2][2] += eps; | 
					
						
							| 
									
										
										
										
											2019-04-17 06:17:24 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-09-06 14:54:08 +02:00
										 |  |  |         if (UNLIKELY((det = determinant_m3_array(mat)) == 0.0f)) { | 
					
						
							|  |  |  |           unit_m3(mat); | 
					
						
							|  |  |  |           det = 1.0f; | 
					
						
							|  |  |  |         } | 
					
						
							| 
									
										
										
										
											2014-04-29 19:58:37 +10:00
										 |  |  |         break; | 
					
						
							|  |  |  |       } | 
					
						
							|  |  |  |       case 4: { | 
					
						
							| 
									
										
										
										
											2014-09-06 14:54:08 +02:00
										 |  |  |         float(*mat)[4] = (float(*)[4])in_mat; | 
					
						
							| 
									
										
										
										
											2019-04-17 06:17:24 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-09-06 14:54:08 +02:00
										 |  |  |         if (in_mat != self->matrix) { | 
					
						
							| 
									
										
										
										
											2021-05-18 14:13:20 +10:00
										 |  |  |           copy_m4_m4(mat, (const float(*)[4])self->matrix); | 
					
						
							| 
									
										
										
										
											2014-09-06 14:54:08 +02:00
										 |  |  |         } | 
					
						
							|  |  |  |         mat[0][0] += eps; | 
					
						
							|  |  |  |         mat[1][1] += eps; | 
					
						
							|  |  |  |         mat[2][2] += eps; | 
					
						
							|  |  |  |         mat[3][3] += eps; | 
					
						
							| 
									
										
										
										
											2019-04-17 06:17:24 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-09-06 14:54:08 +02:00
										 |  |  |         if (UNLIKELY(det = determinant_m4(mat)) == 0.0f) { | 
					
						
							|  |  |  |           unit_m4(mat); | 
					
						
							|  |  |  |           det = 1.0f; | 
					
						
							|  |  |  |         } | 
					
						
							| 
									
										
										
										
											2014-04-29 19:58:37 +10:00
										 |  |  |         break; | 
					
						
							|  |  |  |       } | 
					
						
							|  |  |  |       default: | 
					
						
							| 
									
										
										
										
											2021-03-24 12:38:08 +11:00
										 |  |  |         BLI_assert_unreachable(); | 
					
						
							| 
									
										
										
										
											2014-04-29 19:58:37 +10:00
										 |  |  |     } | 
					
						
							|  |  |  |   } | 
					
						
							| 
									
										
										
										
											2019-04-17 06:17:24 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-09-06 14:54:08 +02:00
										 |  |  |   matrix_invert_with_det_n_internal(r_mat, in_mat, det, self->num_col); | 
					
						
							| 
									
										
										
										
											2014-04-29 19:58:37 +10:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2009-06-17 20:33:34 +00:00
										 |  |  | /*-----------------------------METHODS----------------------------*/ | 
					
						
							| 
									
										
										
										
											2011-05-24 16:05:51 +00:00
										 |  |  | PyDoc_STRVAR(Matrix_to_quaternion_doc, | 
					
						
							| 
									
										
										
										
											2011-02-06 10:18:20 +00:00
										 |  |  |              ".. method:: to_quaternion()\n" | 
					
						
							| 
									
										
										
											
												Mathutils refactor & include in sphinx generated docs, (TODO, include getset'ers in docs)
 - Mathutils.MidpointVecs --> vector.lerp(other, fac)
 - Mathutils.AngleBetweenVecs --> vector.angle(other)
 - Mathutils.ProjectVecs --> vector.project(other)
 - Mathutils.DifferenceQuats --> quat.difference(other)
 - Mathutils.Slerp --> quat.slerp(other, fac)
 - Mathutils.Rand: removed, use pythons random module
 - Mathutils.RotationMatrix(angle, size, axis_flag, axis) --> Mathutils.RotationMatrix(angle, size, axis); merge axis & axis_flag args
 - Matrix.scalePart --> Matrix.scale_part
 - Matrix.translationPart --> Matrix.translation_part
 - Matrix.rotationPart --> Matrix.rotation_part
 - toMatrix --> to_matrix
 - toEuler --> to_euler
 - toQuat --> to_quat
 - Vector.toTrackQuat --> Vector.to_track_quat
											
										 
											2010-01-25 09:44:04 +00:00
										 |  |  |              "\n" | 
					
						
							|  |  |  |              "   Return a quaternion representation of the rotation matrix.\n" | 
					
						
							|  |  |  |              "\n" | 
					
						
							|  |  |  |              "   :return: Quaternion representation of the rotation matrix.\n" | 
					
						
							| 
									
										
										
										
											2011-02-04 09:35:20 +00:00
										 |  |  |              "   :rtype: :class:`Quaternion`\n"); | 
					
						
							| 
									
										
										
										
											2011-02-04 03:06:23 +00:00
										 |  |  | static PyObject *Matrix_to_quaternion(MatrixObject *self) | 
					
						
							| 
									
										
										
										
											2009-06-17 20:33:34 +00:00
										 |  |  | { | 
					
						
							|  |  |  |   float quat[4]; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-03-30 06:12:48 +11:00
										 |  |  |   if (BaseMath_ReadCallback(self) == -1) { | 
					
						
							| 
									
										
										
										
											2009-06-23 13:34:45 +00:00
										 |  |  |     return NULL; | 
					
						
							| 
									
										
										
										
											2019-03-30 06:12:48 +11:00
										 |  |  |   } | 
					
						
							| 
									
										
										
										
											2011-02-04 03:06:23 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2011-12-24 13:26:30 +00:00
										 |  |  |   /* must be 3-4 cols, 3-4 rows, square matrix */ | 
					
						
							| 
									
										
										
										
											2011-12-20 04:11:23 +00:00
										 |  |  |   if ((self->num_row < 3) || (self->num_col < 3) || (self->num_row != self->num_col)) { | 
					
						
							| 
									
										
										
										
											2011-07-14 09:54:03 +00:00
										 |  |  |     PyErr_SetString(PyExc_ValueError, | 
					
						
							| 
									
										
										
										
											2011-09-19 14:29:21 +00:00
										 |  |  |                     "Matrix.to_quat(): " | 
					
						
							| 
									
										
										
										
											2011-07-14 01:25:05 +00:00
										 |  |  |                     "inappropriate matrix size - expects 3x3 or 4x4 matrix"); | 
					
						
							| 
									
										
										
										
											2009-06-17 20:33:34 +00:00
										 |  |  |     return NULL; | 
					
						
							| 
									
										
										
										
											2011-02-04 03:06:23 +00:00
										 |  |  |   } | 
					
						
							| 
									
										
										
										
											2011-12-20 04:11:23 +00:00
										 |  |  |   if (self->num_row == 3) { | 
					
						
							|  |  |  |     mat3_to_quat(quat, (float(*)[3])self->matrix); | 
					
						
							| 
									
										
										
										
											2011-03-19 11:12:48 +00:00
										 |  |  |   } | 
					
						
							|  |  |  |   else { | 
					
						
							| 
									
										
										
										
											2021-05-18 14:13:20 +10:00
										 |  |  |     mat4_to_quat(quat, (const float(*)[4])self->matrix); | 
					
						
							| 
									
										
										
										
											2009-06-17 20:33:34 +00:00
										 |  |  |   } | 
					
						
							| 
									
										
										
										
											2011-02-04 03:06:23 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-01-04 17:03:54 +11:00
										 |  |  |   return Quaternion_CreatePyObject(quat, NULL); | 
					
						
							| 
									
										
										
										
											2009-06-17 20:33:34 +00:00
										 |  |  | } | 
					
						
							| 
									
										
										
										
											2010-02-20 19:49:04 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2011-07-14 01:25:05 +00:00
										 |  |  | /*---------------------------matrix.toEuler() --------------------*/ | 
					
						
							| 
									
										
										
										
											2011-05-24 16:05:51 +00:00
										 |  |  | PyDoc_STRVAR(Matrix_to_euler_doc, | 
					
						
							| 
									
										
										
										
											2010-02-20 19:49:04 +00:00
										 |  |  |              ".. method:: to_euler(order, euler_compat)\n" | 
					
						
							| 
									
										
										
											
												Mathutils refactor & include in sphinx generated docs, (TODO, include getset'ers in docs)
 - Mathutils.MidpointVecs --> vector.lerp(other, fac)
 - Mathutils.AngleBetweenVecs --> vector.angle(other)
 - Mathutils.ProjectVecs --> vector.project(other)
 - Mathutils.DifferenceQuats --> quat.difference(other)
 - Mathutils.Slerp --> quat.slerp(other, fac)
 - Mathutils.Rand: removed, use pythons random module
 - Mathutils.RotationMatrix(angle, size, axis_flag, axis) --> Mathutils.RotationMatrix(angle, size, axis); merge axis & axis_flag args
 - Matrix.scalePart --> Matrix.scale_part
 - Matrix.translationPart --> Matrix.translation_part
 - Matrix.rotationPart --> Matrix.rotation_part
 - toMatrix --> to_matrix
 - toEuler --> to_euler
 - toQuat --> to_quat
 - Vector.toTrackQuat --> Vector.to_track_quat
											
										 
											2010-01-25 09:44:04 +00:00
										 |  |  |              "\n" | 
					
						
							| 
									
										
										
										
											2011-05-26 19:13:01 +00:00
										 |  |  |              "   Return an Euler representation of the rotation matrix\n" | 
					
						
							|  |  |  |              "   (3x3 or 4x4 matrix only).\n" | 
					
						
							| 
									
										
										
											
												Mathutils refactor & include in sphinx generated docs, (TODO, include getset'ers in docs)
 - Mathutils.MidpointVecs --> vector.lerp(other, fac)
 - Mathutils.AngleBetweenVecs --> vector.angle(other)
 - Mathutils.ProjectVecs --> vector.project(other)
 - Mathutils.DifferenceQuats --> quat.difference(other)
 - Mathutils.Slerp --> quat.slerp(other, fac)
 - Mathutils.Rand: removed, use pythons random module
 - Mathutils.RotationMatrix(angle, size, axis_flag, axis) --> Mathutils.RotationMatrix(angle, size, axis); merge axis & axis_flag args
 - Matrix.scalePart --> Matrix.scale_part
 - Matrix.translationPart --> Matrix.translation_part
 - Matrix.rotationPart --> Matrix.rotation_part
 - toMatrix --> to_matrix
 - toEuler --> to_euler
 - toQuat --> to_quat
 - Vector.toTrackQuat --> Vector.to_track_quat
											
										 
											2010-01-25 09:44:04 +00:00
										 |  |  |              "\n" | 
					
						
							| 
									
										
										
										
											2011-05-26 19:13:01 +00:00
										 |  |  |              "   :arg order: Optional rotation order argument in\n" | 
					
						
							|  |  |  |              "      ['XYZ', 'XZY', 'YXZ', 'YZX', 'ZXY', 'ZYX'].\n" | 
					
						
							| 
									
										
										
										
											2010-02-20 19:49:04 +00:00
										 |  |  |              "   :type order: string\n" | 
					
						
							| 
									
										
										
										
											2011-05-26 19:13:01 +00:00
										 |  |  |              "   :arg euler_compat: Optional euler argument the new euler will be made\n" | 
					
						
							|  |  |  |              "      compatible with (no axis flipping between them).\n" | 
					
						
							|  |  |  |              "      Useful for converting a series of matrices to animation curves.\n" | 
					
						
							| 
									
										
										
										
											2010-01-27 21:33:39 +00:00
										 |  |  |              "   :type euler_compat: :class:`Euler`\n" | 
					
						
							| 
									
										
										
											
												Mathutils refactor & include in sphinx generated docs, (TODO, include getset'ers in docs)
 - Mathutils.MidpointVecs --> vector.lerp(other, fac)
 - Mathutils.AngleBetweenVecs --> vector.angle(other)
 - Mathutils.ProjectVecs --> vector.project(other)
 - Mathutils.DifferenceQuats --> quat.difference(other)
 - Mathutils.Slerp --> quat.slerp(other, fac)
 - Mathutils.Rand: removed, use pythons random module
 - Mathutils.RotationMatrix(angle, size, axis_flag, axis) --> Mathutils.RotationMatrix(angle, size, axis); merge axis & axis_flag args
 - Matrix.scalePart --> Matrix.scale_part
 - Matrix.translationPart --> Matrix.translation_part
 - Matrix.rotationPart --> Matrix.rotation_part
 - toMatrix --> to_matrix
 - toEuler --> to_euler
 - toQuat --> to_quat
 - Vector.toTrackQuat --> Vector.to_track_quat
											
										 
											2010-01-25 09:44:04 +00:00
										 |  |  |              "   :return: Euler representation of the matrix.\n" | 
					
						
							| 
									
										
										
										
											2011-02-04 09:35:20 +00:00
										 |  |  |              "   :rtype: :class:`Euler`\n"); | 
					
						
							| 
									
										
										
										
											2011-02-05 06:14:50 +00:00
										 |  |  | static PyObject *Matrix_to_euler(MatrixObject *self, PyObject *args) | 
					
						
							| 
									
										
										
										
											2009-06-17 20:33:34 +00:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2011-12-24 13:26:30 +00:00
										 |  |  |   const char *order_str = NULL; | 
					
						
							|  |  |  |   short order = EULER_ORDER_XYZ; | 
					
						
							| 
									
										
										
										
											2009-06-17 20:33:34 +00:00
										 |  |  |   float eul[3], eul_compatf[3]; | 
					
						
							|  |  |  |   EulerObject *eul_compat = NULL; | 
					
						
							| 
									
										
										
										
											2019-04-17 06:17:24 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-10-24 07:02:51 +11:00
										 |  |  |   float mat[3][3]; | 
					
						
							| 
									
										
										
										
											2019-04-17 06:17:24 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-03-30 06:12:48 +11:00
										 |  |  |   if (BaseMath_ReadCallback(self) == -1) { | 
					
						
							| 
									
										
										
										
											2009-06-23 13:34:45 +00:00
										 |  |  |     return NULL; | 
					
						
							| 
									
										
										
										
											2019-03-30 06:12:48 +11:00
										 |  |  |   } | 
					
						
							| 
									
										
										
										
											2019-04-17 06:17:24 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-03-30 06:12:48 +11:00
										 |  |  |   if (!PyArg_ParseTuple(args, "|sO!:to_euler", &order_str, &euler_Type, &eul_compat)) { | 
					
						
							| 
									
										
										
										
											2009-06-17 20:33:34 +00:00
										 |  |  |     return NULL; | 
					
						
							| 
									
										
										
										
											2019-03-30 06:12:48 +11:00
										 |  |  |   } | 
					
						
							| 
									
										
										
										
											2019-04-17 06:17:24 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2011-10-13 01:29:08 +00:00
										 |  |  |   if (eul_compat) { | 
					
						
							| 
									
										
										
										
											2019-03-30 06:12:48 +11:00
										 |  |  |     if (BaseMath_ReadCallback(eul_compat) == -1) { | 
					
						
							| 
									
										
										
										
											2009-06-25 10:11:37 +00:00
										 |  |  |       return NULL; | 
					
						
							| 
									
										
										
										
											2019-03-30 06:12:48 +11:00
										 |  |  |     } | 
					
						
							| 
									
										
										
										
											2019-04-17 06:17:24 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2010-04-25 23:33:09 +00:00
										 |  |  |     copy_v3_v3(eul_compatf, eul_compat->eul); | 
					
						
							| 
									
										
										
										
											2009-06-17 20:33:34 +00:00
										 |  |  |   } | 
					
						
							| 
									
										
										
										
											2019-04-17 06:17:24 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-06-26 21:35:18 +10:00
										 |  |  |   /* Must be 3-4 cols, 3-4 rows, square matrix. */ | 
					
						
							| 
									
										
										
										
											2012-03-26 06:55:09 +00:00
										 |  |  |   if (self->num_row == 3 && self->num_col == 3) { | 
					
						
							| 
									
										
										
										
											2021-05-18 14:13:20 +10:00
										 |  |  |     copy_m3_m3(mat, (const float(*)[3])self->matrix); | 
					
						
							| 
									
										
										
										
											2011-03-19 11:12:48 +00:00
										 |  |  |   } | 
					
						
							| 
									
										
										
										
											2012-03-26 06:55:09 +00:00
										 |  |  |   else if (self->num_row == 4 && self->num_col == 4) { | 
					
						
							| 
									
										
										
										
											2021-05-18 14:13:20 +10:00
										 |  |  |     copy_m3_m4(mat, (const float(*)[4])self->matrix); | 
					
						
							| 
									
										
										
										
											2011-03-19 11:12:48 +00:00
										 |  |  |   } | 
					
						
							|  |  |  |   else { | 
					
						
							| 
									
										
										
										
											2011-07-14 09:54:03 +00:00
										 |  |  |     PyErr_SetString(PyExc_ValueError, | 
					
						
							| 
									
										
										
										
											2011-09-19 14:29:21 +00:00
										 |  |  |                     "Matrix.to_euler(): " | 
					
						
							| 
									
										
										
										
											2011-07-14 01:25:05 +00:00
										 |  |  |                     "inappropriate matrix size - expects 3x3 or 4x4 matrix"); | 
					
						
							| 
									
										
										
										
											2009-06-17 20:33:34 +00:00
										 |  |  |     return NULL; | 
					
						
							|  |  |  |   } | 
					
						
							| 
									
										
										
										
											2019-04-17 06:17:24 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2011-10-13 01:29:08 +00:00
										 |  |  |   if (order_str) { | 
					
						
							| 
									
										
										
										
											2011-12-24 13:26:30 +00:00
										 |  |  |     order = euler_order_from_string(order_str, "Matrix.to_euler()"); | 
					
						
							| 
									
										
										
										
											2019-04-17 06:17:24 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-03-30 06:12:48 +11:00
										 |  |  |     if (order == -1) { | 
					
						
							| 
									
										
										
										
											2010-02-20 19:49:04 +00:00
										 |  |  |       return NULL; | 
					
						
							| 
									
										
										
										
											2019-03-30 06:12:48 +11:00
										 |  |  |     } | 
					
						
							| 
									
										
										
										
											2010-02-20 19:49:04 +00:00
										 |  |  |   } | 
					
						
							| 
									
										
										
										
											2019-04-17 06:17:24 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-10-24 07:02:51 +11:00
										 |  |  |   normalize_m3(mat); | 
					
						
							| 
									
										
										
										
											2019-04-17 06:17:24 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2011-10-13 01:29:08 +00:00
										 |  |  |   if (eul_compat) { | 
					
						
							| 
									
										
										
										
											2019-03-30 06:12:48 +11:00
										 |  |  |     if (order == 1) { | 
					
						
							|  |  |  |       mat3_normalized_to_compatible_eul(eul, eul_compatf, mat); | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  |     else { | 
					
						
							|  |  |  |       mat3_normalized_to_compatible_eulO(eul, eul_compatf, order, mat); | 
					
						
							|  |  |  |     } | 
					
						
							| 
									
										
										
										
											2010-02-20 19:49:04 +00:00
										 |  |  |   } | 
					
						
							|  |  |  |   else { | 
					
						
							| 
									
										
										
										
											2019-03-30 06:12:48 +11:00
										 |  |  |     if (order == 1) { | 
					
						
							|  |  |  |       mat3_normalized_to_eul(eul, mat); | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  |     else { | 
					
						
							|  |  |  |       mat3_normalized_to_eulO(eul, order, mat); | 
					
						
							|  |  |  |     } | 
					
						
							| 
									
										
										
										
											2009-06-17 20:33:34 +00:00
										 |  |  |   } | 
					
						
							| 
									
										
										
										
											2019-04-17 06:17:24 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-01-04 17:03:54 +11:00
										 |  |  |   return Euler_CreatePyObject(eul, order, NULL); | 
					
						
							| 
									
										
										
										
											2009-06-17 20:33:34 +00:00
										 |  |  | } | 
					
						
							| 
									
										
										
										
											2011-02-05 06:14:50 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2011-05-24 16:05:51 +00:00
										 |  |  | PyDoc_STRVAR(Matrix_resize_4x4_doc, | 
					
						
							| 
									
										
										
										
											2011-02-05 06:14:50 +00:00
										 |  |  |              ".. method:: resize_4x4()\n" | 
					
						
							| 
									
										
										
											
												Mathutils refactor & include in sphinx generated docs, (TODO, include getset'ers in docs)
 - Mathutils.MidpointVecs --> vector.lerp(other, fac)
 - Mathutils.AngleBetweenVecs --> vector.angle(other)
 - Mathutils.ProjectVecs --> vector.project(other)
 - Mathutils.DifferenceQuats --> quat.difference(other)
 - Mathutils.Slerp --> quat.slerp(other, fac)
 - Mathutils.Rand: removed, use pythons random module
 - Mathutils.RotationMatrix(angle, size, axis_flag, axis) --> Mathutils.RotationMatrix(angle, size, axis); merge axis & axis_flag args
 - Matrix.scalePart --> Matrix.scale_part
 - Matrix.translationPart --> Matrix.translation_part
 - Matrix.rotationPart --> Matrix.rotation_part
 - toMatrix --> to_matrix
 - toEuler --> to_euler
 - toQuat --> to_quat
 - Vector.toTrackQuat --> Vector.to_track_quat
											
										 
											2010-01-25 09:44:04 +00:00
										 |  |  |              "\n" | 
					
						
							|  |  |  |              "   Resize the matrix to 4x4.\n"); | 
					
						
							| 
									
										
										
										
											2011-02-05 06:14:50 +00:00
										 |  |  | static PyObject *Matrix_resize_4x4(MatrixObject *self) | 
					
						
							| 
									
										
										
										
											2009-06-17 20:33:34 +00:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2014-04-29 18:12:44 +10:00
										 |  |  |   float mat[4][4]; | 
					
						
							| 
									
										
										
										
											2011-12-21 21:21:27 +00:00
										 |  |  |   int col; | 
					
						
							| 
									
										
										
										
											2009-06-17 20:33:34 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-01-04 17:03:54 +11:00
										 |  |  |   if (self->flag & BASE_MATH_FLAG_IS_WRAP) { | 
					
						
							| 
									
										
										
										
											2012-12-16 04:10:57 +00:00
										 |  |  |     PyErr_SetString(PyExc_ValueError, | 
					
						
							| 
									
										
										
										
											2011-09-19 14:29:21 +00:00
										 |  |  |                     "Matrix.resize_4x4(): " | 
					
						
							| 
									
										
										
										
											2011-07-14 01:25:05 +00:00
										 |  |  |                     "cannot resize wrapped data - make a copy and resize that"); | 
					
						
							| 
									
										
										
										
											2009-06-17 20:33:34 +00:00
										 |  |  |     return NULL; | 
					
						
							|  |  |  |   } | 
					
						
							| 
									
										
										
										
											2011-10-13 01:29:08 +00:00
										 |  |  |   if (self->cb_user) { | 
					
						
							| 
									
										
										
										
											2012-12-16 04:10:57 +00:00
										 |  |  |     PyErr_SetString(PyExc_ValueError, | 
					
						
							| 
									
										
										
										
											2011-09-19 14:29:21 +00:00
										 |  |  |                     "Matrix.resize_4x4(): " | 
					
						
							| 
									
										
										
										
											2011-07-14 01:25:05 +00:00
										 |  |  |                     "cannot resize owned data - make a copy and resize that"); | 
					
						
							| 
									
										
										
										
											2009-06-23 13:34:45 +00:00
										 |  |  |     return NULL; | 
					
						
							|  |  |  |   } | 
					
						
							| 
									
										
										
										
											2011-02-04 03:06:23 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-04-29 18:12:44 +10:00
										 |  |  |   self->matrix = PyMem_Realloc(self->matrix, (sizeof(float) * (MATRIX_MAX_DIM * MATRIX_MAX_DIM))); | 
					
						
							| 
									
										
										
										
											2011-12-20 04:11:23 +00:00
										 |  |  |   if (self->matrix == NULL) { | 
					
						
							| 
									
										
										
										
											2011-07-14 01:25:05 +00:00
										 |  |  |     PyErr_SetString(PyExc_MemoryError, | 
					
						
							| 
									
										
										
										
											2011-09-19 14:29:21 +00:00
										 |  |  |                     "Matrix.resize_4x4(): " | 
					
						
							|  |  |  |                     "problem allocating pointer space"); | 
					
						
							| 
									
										
										
										
											2009-06-17 20:33:34 +00:00
										 |  |  |     return NULL; | 
					
						
							|  |  |  |   } | 
					
						
							| 
									
										
										
										
											2011-12-19 03:12:10 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-04-29 18:12:44 +10:00
										 |  |  |   unit_m4(mat); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2011-12-21 21:21:27 +00:00
										 |  |  |   for (col = 0; col < self->num_col; col++) { | 
					
						
							| 
									
										
										
										
											2011-12-24 04:58:01 +00:00
										 |  |  |     memcpy(mat[col], MATRIX_COL_PTR(self, col), self->num_row * sizeof(float)); | 
					
						
							| 
									
										
										
										
											2009-06-17 20:33:34 +00:00
										 |  |  |   } | 
					
						
							| 
									
										
										
										
											2011-12-21 21:21:27 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-05-18 14:13:20 +10:00
										 |  |  |   copy_m4_m4((float(*)[4])self->matrix, (const float(*)[4])mat); | 
					
						
							| 
									
										
										
										
											2011-12-21 21:21:27 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2011-12-20 04:11:23 +00:00
										 |  |  |   self->num_col = 4; | 
					
						
							|  |  |  |   self->num_row = 4; | 
					
						
							| 
									
										
										
										
											2011-02-04 03:06:23 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2011-02-05 09:57:02 +00:00
										 |  |  |   Py_RETURN_NONE; | 
					
						
							| 
									
										
										
										
											2009-06-17 20:33:34 +00:00
										 |  |  | } | 
					
						
							| 
									
										
										
										
											2010-02-23 09:39:47 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-02-20 15:09:44 +11:00
										 |  |  | static PyObject *Matrix_to_NxN(MatrixObject *self, const int num_col, const int num_row) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  |   const int mat_size = sizeof(float) * (num_col * num_row); | 
					
						
							|  |  |  |   MatrixObject *pymat = (MatrixObject *)Matrix_CreatePyObject_alloc( | 
					
						
							|  |  |  |       PyMem_Malloc(mat_size), num_col, num_row, Py_TYPE(self)); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   if ((self->num_row == num_row) && (self->num_col == num_col)) { | 
					
						
							|  |  |  |     memcpy(pymat->matrix, self->matrix, mat_size); | 
					
						
							|  |  |  |   } | 
					
						
							|  |  |  |   else { | 
					
						
							|  |  |  |     if ((self->num_col < num_col) || (self->num_row < num_row)) { | 
					
						
							|  |  |  |       matrix_unit_internal(pymat); | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  |     const int col_len_src = min_ii(num_col, self->num_col); | 
					
						
							|  |  |  |     const int row_len_src = min_ii(num_row, self->num_row); | 
					
						
							|  |  |  |     for (int col = 0; col < col_len_src; col++) { | 
					
						
							|  |  |  |       memcpy( | 
					
						
							|  |  |  |           &pymat->matrix[col * num_row], MATRIX_COL_PTR(self, col), sizeof(float) * row_len_src); | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  |   } | 
					
						
							|  |  |  |   return (PyObject *)pymat; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | PyDoc_STRVAR(Matrix_to_2x2_doc, | 
					
						
							|  |  |  |              ".. method:: to_2x2()\n" | 
					
						
							| 
									
										
										
										
											2010-02-23 09:39:47 +00:00
										 |  |  |              "\n" | 
					
						
							| 
									
										
										
										
											2020-02-20 15:09:44 +11:00
										 |  |  |              "   Return a 2x2 copy of this matrix.\n" | 
					
						
							| 
									
										
										
										
											2010-02-23 09:39:47 +00:00
										 |  |  |              "\n" | 
					
						
							|  |  |  |              "   :return: a new matrix.\n" | 
					
						
							| 
									
										
										
										
											2011-02-04 09:35:20 +00:00
										 |  |  |              "   :rtype: :class:`Matrix`\n"); | 
					
						
							| 
									
										
										
										
											2020-02-20 15:09:44 +11:00
										 |  |  | static PyObject *Matrix_to_2x2(MatrixObject *self) | 
					
						
							| 
									
										
										
										
											2010-02-23 09:39:47 +00:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2019-03-30 06:12:48 +11:00
										 |  |  |   if (BaseMath_ReadCallback(self) == -1) { | 
					
						
							| 
									
										
										
										
											2010-02-23 09:39:47 +00:00
										 |  |  |     return NULL; | 
					
						
							| 
									
										
										
										
											2019-03-30 06:12:48 +11:00
										 |  |  |   } | 
					
						
							| 
									
										
										
										
											2020-02-20 15:09:44 +11:00
										 |  |  |   return Matrix_to_NxN(self, 2, 2); | 
					
						
							| 
									
										
										
										
											2010-02-23 09:39:47 +00:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2011-05-24 16:05:51 +00:00
										 |  |  | PyDoc_STRVAR(Matrix_to_3x3_doc, | 
					
						
							| 
									
										
										
										
											2010-02-23 09:39:47 +00:00
										 |  |  |              ".. method:: to_3x3()\n" | 
					
						
							|  |  |  |              "\n" | 
					
						
							|  |  |  |              "   Return a 3x3 copy of this matrix.\n" | 
					
						
							|  |  |  |              "\n" | 
					
						
							|  |  |  |              "   :return: a new matrix.\n" | 
					
						
							| 
									
										
										
										
											2011-02-04 09:35:20 +00:00
										 |  |  |              "   :rtype: :class:`Matrix`\n"); | 
					
						
							| 
									
										
										
										
											2011-02-05 06:14:50 +00:00
										 |  |  | static PyObject *Matrix_to_3x3(MatrixObject *self) | 
					
						
							| 
									
										
										
										
											2010-02-23 09:39:47 +00:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2019-03-30 06:12:48 +11:00
										 |  |  |   if (BaseMath_ReadCallback(self) == -1) { | 
					
						
							| 
									
										
										
										
											2010-02-23 09:39:47 +00:00
										 |  |  |     return NULL; | 
					
						
							| 
									
										
										
										
											2019-03-30 06:12:48 +11:00
										 |  |  |   } | 
					
						
							| 
									
										
										
										
											2020-02-20 15:09:44 +11:00
										 |  |  |   return Matrix_to_NxN(self, 3, 3); | 
					
						
							|  |  |  | } | 
					
						
							| 
									
										
										
										
											2010-02-23 09:39:47 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-02-20 15:09:44 +11:00
										 |  |  | PyDoc_STRVAR(Matrix_to_4x4_doc, | 
					
						
							|  |  |  |              ".. method:: to_4x4()\n" | 
					
						
							|  |  |  |              "\n" | 
					
						
							|  |  |  |              "   Return a 4x4 copy of this matrix.\n" | 
					
						
							|  |  |  |              "\n" | 
					
						
							|  |  |  |              "   :return: a new matrix.\n" | 
					
						
							|  |  |  |              "   :rtype: :class:`Matrix`\n"); | 
					
						
							|  |  |  | static PyObject *Matrix_to_4x4(MatrixObject *self) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   if (BaseMath_ReadCallback(self) == -1) { | 
					
						
							| 
									
										
										
										
											2011-01-25 16:32:41 +00:00
										 |  |  |     return NULL; | 
					
						
							| 
									
										
										
										
											2010-02-23 09:39:47 +00:00
										 |  |  |   } | 
					
						
							| 
									
										
										
										
											2020-02-20 15:09:44 +11:00
										 |  |  |   return Matrix_to_NxN(self, 4, 4); | 
					
						
							| 
									
										
										
										
											2010-02-23 09:39:47 +00:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2011-05-24 16:05:51 +00:00
										 |  |  | PyDoc_STRVAR(Matrix_to_translation_doc, | 
					
						
							| 
									
										
										
										
											2011-02-05 06:14:50 +00:00
										 |  |  |              ".. method:: to_translation()\n" | 
					
						
							| 
									
										
										
											
												Mathutils refactor & include in sphinx generated docs, (TODO, include getset'ers in docs)
 - Mathutils.MidpointVecs --> vector.lerp(other, fac)
 - Mathutils.AngleBetweenVecs --> vector.angle(other)
 - Mathutils.ProjectVecs --> vector.project(other)
 - Mathutils.DifferenceQuats --> quat.difference(other)
 - Mathutils.Slerp --> quat.slerp(other, fac)
 - Mathutils.Rand: removed, use pythons random module
 - Mathutils.RotationMatrix(angle, size, axis_flag, axis) --> Mathutils.RotationMatrix(angle, size, axis); merge axis & axis_flag args
 - Matrix.scalePart --> Matrix.scale_part
 - Matrix.translationPart --> Matrix.translation_part
 - Matrix.rotationPart --> Matrix.rotation_part
 - toMatrix --> to_matrix
 - toEuler --> to_euler
 - toQuat --> to_quat
 - Vector.toTrackQuat --> Vector.to_track_quat
											
										 
											2010-01-25 09:44:04 +00:00
										 |  |  |              "\n" | 
					
						
							| 
									
										
										
										
											2014-12-19 00:42:50 +09:00
										 |  |  |              "   Return the translation part of a 4 row matrix.\n" | 
					
						
							| 
									
										
										
										
											2010-01-27 21:33:39 +00:00
										 |  |  |              "\n" | 
					
						
							| 
									
										
										
										
											2014-12-19 00:42:50 +09:00
										 |  |  |              "   :return: Return the translation of a matrix.\n" | 
					
						
							| 
									
										
										
										
											2011-01-07 06:39:48 +00:00
										 |  |  |              "   :rtype: :class:`Vector`\n"); | 
					
						
							| 
									
										
										
										
											2011-02-05 06:14:50 +00:00
										 |  |  | static PyObject *Matrix_to_translation(MatrixObject *self) | 
					
						
							| 
									
										
										
										
											2009-06-17 20:33:34 +00:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2019-03-30 06:12:48 +11:00
										 |  |  |   if (BaseMath_ReadCallback(self) == -1) { | 
					
						
							| 
									
										
										
										
											2009-06-23 13:34:45 +00:00
										 |  |  |     return NULL; | 
					
						
							| 
									
										
										
										
											2019-03-30 06:12:48 +11:00
										 |  |  |   } | 
					
						
							| 
									
										
										
										
											2011-02-04 03:06:23 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2011-12-20 04:11:23 +00:00
										 |  |  |   if ((self->num_row < 3) || self->num_col < 4) { | 
					
						
							| 
									
										
										
										
											2012-12-16 04:10:57 +00:00
										 |  |  |     PyErr_SetString(PyExc_ValueError, | 
					
						
							| 
									
										
										
										
											2011-09-19 14:29:21 +00:00
										 |  |  |                     "Matrix.to_translation(): " | 
					
						
							| 
									
										
										
										
											2011-07-14 01:25:05 +00:00
										 |  |  |                     "inappropriate matrix size"); | 
					
						
							| 
									
										
										
										
											2009-06-17 20:33:34 +00:00
										 |  |  |     return NULL; | 
					
						
							|  |  |  |   } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-01-04 17:03:54 +11:00
										 |  |  |   return Vector_CreatePyObject(MATRIX_COL_PTR(self, 3), 3, NULL); | 
					
						
							| 
									
										
										
										
											2009-06-17 20:33:34 +00:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2011-05-24 16:05:51 +00:00
										 |  |  | PyDoc_STRVAR(Matrix_to_scale_doc, | 
					
						
							| 
									
										
										
										
											2011-02-05 06:14:50 +00:00
										 |  |  |              ".. method:: to_scale()\n" | 
					
						
							| 
									
										
										
											
												Mathutils refactor & include in sphinx generated docs, (TODO, include getset'ers in docs)
 - Mathutils.MidpointVecs --> vector.lerp(other, fac)
 - Mathutils.AngleBetweenVecs --> vector.angle(other)
 - Mathutils.ProjectVecs --> vector.project(other)
 - Mathutils.DifferenceQuats --> quat.difference(other)
 - Mathutils.Slerp --> quat.slerp(other, fac)
 - Mathutils.Rand: removed, use pythons random module
 - Mathutils.RotationMatrix(angle, size, axis_flag, axis) --> Mathutils.RotationMatrix(angle, size, axis); merge axis & axis_flag args
 - Matrix.scalePart --> Matrix.scale_part
 - Matrix.translationPart --> Matrix.translation_part
 - Matrix.rotationPart --> Matrix.rotation_part
 - toMatrix --> to_matrix
 - toEuler --> to_euler
 - toQuat --> to_quat
 - Vector.toTrackQuat --> Vector.to_track_quat
											
										 
											2010-01-25 09:44:04 +00:00
										 |  |  |              "\n" | 
					
						
							| 
									
										
										
										
											2014-12-19 00:42:50 +09:00
										 |  |  |              "   Return the scale part of a 3x3 or 4x4 matrix.\n" | 
					
						
							| 
									
										
										
										
											2010-01-27 21:33:39 +00:00
										 |  |  |              "\n" | 
					
						
							| 
									
										
										
										
											2014-12-19 00:42:50 +09:00
										 |  |  |              "   :return: Return the scale of a matrix.\n" | 
					
						
							| 
									
										
										
										
											2010-01-27 21:33:39 +00:00
										 |  |  |              "   :rtype: :class:`Vector`\n" | 
					
						
							| 
									
										
										
											
												Mathutils refactor & include in sphinx generated docs, (TODO, include getset'ers in docs)
 - Mathutils.MidpointVecs --> vector.lerp(other, fac)
 - Mathutils.AngleBetweenVecs --> vector.angle(other)
 - Mathutils.ProjectVecs --> vector.project(other)
 - Mathutils.DifferenceQuats --> quat.difference(other)
 - Mathutils.Slerp --> quat.slerp(other, fac)
 - Mathutils.Rand: removed, use pythons random module
 - Mathutils.RotationMatrix(angle, size, axis_flag, axis) --> Mathutils.RotationMatrix(angle, size, axis); merge axis & axis_flag args
 - Matrix.scalePart --> Matrix.scale_part
 - Matrix.translationPart --> Matrix.translation_part
 - Matrix.rotationPart --> Matrix.rotation_part
 - toMatrix --> to_matrix
 - toEuler --> to_euler
 - toQuat --> to_quat
 - Vector.toTrackQuat --> Vector.to_track_quat
											
										 
											2010-01-25 09:44:04 +00:00
										 |  |  |              "\n" | 
					
						
							| 
									
										
										
										
											2017-03-22 14:49:12 -04:00
										 |  |  |              "   .. note:: This method does not return a negative scale on any axis because it is " | 
					
						
							|  |  |  |              "not possible to obtain this data from the matrix alone.\n"); | 
					
						
							| 
									
										
										
										
											2011-02-05 06:14:50 +00:00
										 |  |  | static PyObject *Matrix_to_scale(MatrixObject *self) | 
					
						
							| 
									
										
										
										
											2009-06-17 20:33:34 +00:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2011-01-25 16:32:41 +00:00
										 |  |  |   float rot[3][3]; | 
					
						
							|  |  |  |   float mat[3][3]; | 
					
						
							|  |  |  |   float size[3]; | 
					
						
							| 
									
										
										
										
											2009-06-17 20:33:34 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-03-30 06:12:48 +11:00
										 |  |  |   if (BaseMath_ReadCallback(self) == -1) { | 
					
						
							| 
									
										
										
										
											2009-06-23 13:34:45 +00:00
										 |  |  |     return NULL; | 
					
						
							| 
									
										
										
										
											2019-03-30 06:12:48 +11:00
										 |  |  |   } | 
					
						
							| 
									
										
										
										
											2011-01-25 16:32:41 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-06-26 21:35:18 +10:00
										 |  |  |   /* Must be 3-4 cols, 3-4 rows, square matrix. */ | 
					
						
							| 
									
										
										
										
											2011-12-20 04:11:23 +00:00
										 |  |  |   if ((self->num_row < 3) || (self->num_col < 3)) { | 
					
						
							| 
									
										
										
										
											2012-12-16 04:10:57 +00:00
										 |  |  |     PyErr_SetString(PyExc_ValueError, | 
					
						
							| 
									
										
										
										
											2011-09-19 14:29:21 +00:00
										 |  |  |                     "Matrix.to_scale(): " | 
					
						
							| 
									
										
										
										
											2011-07-14 01:25:05 +00:00
										 |  |  |                     "inappropriate matrix size, 3x3 minimum size"); | 
					
						
							| 
									
										
										
										
											2009-06-17 20:33:34 +00:00
										 |  |  |     return NULL; | 
					
						
							|  |  |  |   } | 
					
						
							| 
									
										
										
										
											2011-01-25 16:32:41 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  |   matrix_as_3x3(mat, self); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   /* compatible mat4_to_loc_rot_size */ | 
					
						
							|  |  |  |   mat3_to_rot_size(rot, size, mat); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-01-04 17:03:54 +11:00
										 |  |  |   return Vector_CreatePyObject(size, 3, NULL); | 
					
						
							| 
									
										
										
										
											2009-06-17 20:33:34 +00:00
										 |  |  | } | 
					
						
							| 
									
										
										
										
											2010-10-26 12:48:07 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2011-07-14 01:25:05 +00:00
										 |  |  | /*---------------------------matrix.invert() ---------------------*/ | 
					
						
							| 
									
										
										
										
											2014-04-29 19:58:37 +10:00
										 |  |  | 
 | 
					
						
							|  |  |  | /* re-usable checks for invert */ | 
					
						
							|  |  |  | static bool matrix_invert_is_compat(const MatrixObject *self) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  |   if (self->num_col != self->num_row) { | 
					
						
							|  |  |  |     PyErr_SetString(PyExc_ValueError, | 
					
						
							|  |  |  |                     "Matrix.invert(ed): " | 
					
						
							|  |  |  |                     "only square matrices are supported"); | 
					
						
							|  |  |  |     return false; | 
					
						
							|  |  |  |   } | 
					
						
							| 
									
										
										
										
											2020-08-07 12:41:06 +02:00
										 |  |  | 
 | 
					
						
							|  |  |  |   return true; | 
					
						
							| 
									
										
										
										
											2014-04-29 19:58:37 +10:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | static bool matrix_invert_args_check(const MatrixObject *self, PyObject *args, bool check_type) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  |   switch (PyTuple_GET_SIZE(args)) { | 
					
						
							|  |  |  |     case 0: | 
					
						
							|  |  |  |       return true; | 
					
						
							|  |  |  |     case 1: | 
					
						
							|  |  |  |       if (check_type) { | 
					
						
							| 
									
										
										
										
											2021-05-18 14:13:20 +10:00
										 |  |  |         const MatrixObject *fallback = (const MatrixObject *)PyTuple_GET_ITEM(args, 0); | 
					
						
							| 
									
										
										
										
											2014-04-29 19:58:37 +10:00
										 |  |  |         if (!MatrixObject_Check(fallback)) { | 
					
						
							|  |  |  |           PyErr_SetString(PyExc_TypeError, | 
					
						
							|  |  |  |                           "Matrix.invert: " | 
					
						
							|  |  |  |                           "expects a matrix argument or nothing"); | 
					
						
							|  |  |  |           return false; | 
					
						
							|  |  |  |         } | 
					
						
							| 
									
										
										
										
											2019-04-17 06:17:24 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-04-29 19:58:37 +10:00
										 |  |  |         if ((self->num_col != fallback->num_col) || (self->num_row != fallback->num_row)) { | 
					
						
							|  |  |  |           PyErr_SetString(PyExc_TypeError, | 
					
						
							|  |  |  |                           "Matrix.invert: " | 
					
						
							|  |  |  |                           "matrix argument has different dimensions"); | 
					
						
							|  |  |  |           return false; | 
					
						
							| 
									
										
										
										
											2019-04-17 06:17:24 +02:00
										 |  |  |         } | 
					
						
							| 
									
										
										
										
											2014-04-29 19:58:37 +10:00
										 |  |  |       } | 
					
						
							| 
									
										
										
										
											2019-04-17 06:17:24 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-04-29 19:58:37 +10:00
										 |  |  |       return true; | 
					
						
							|  |  |  |     default: | 
					
						
							|  |  |  |       PyErr_SetString(PyExc_ValueError, | 
					
						
							|  |  |  |                       "Matrix.invert(ed): " | 
					
						
							|  |  |  |                       "takes at most one argument"); | 
					
						
							|  |  |  |       return false; | 
					
						
							|  |  |  |   } | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | static void matrix_invert_raise_degenerate(void) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  |   PyErr_SetString(PyExc_ValueError, | 
					
						
							|  |  |  |                   "Matrix.invert(ed): " | 
					
						
							|  |  |  |                   "matrix does not have an inverse"); | 
					
						
							|  |  |  | } | 
					
						
							| 
									
										
										
										
											2019-04-17 06:17:24 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2011-05-24 16:05:51 +00:00
										 |  |  | PyDoc_STRVAR( | 
					
						
							|  |  |  |     Matrix_invert_doc, | 
					
						
							| 
									
										
										
										
											2014-04-29 19:58:37 +10:00
										 |  |  |     ".. method:: invert(fallback=None)\n" | 
					
						
							| 
									
										
										
											
												Mathutils refactor & include in sphinx generated docs, (TODO, include getset'ers in docs)
 - Mathutils.MidpointVecs --> vector.lerp(other, fac)
 - Mathutils.AngleBetweenVecs --> vector.angle(other)
 - Mathutils.ProjectVecs --> vector.project(other)
 - Mathutils.DifferenceQuats --> quat.difference(other)
 - Mathutils.Slerp --> quat.slerp(other, fac)
 - Mathutils.Rand: removed, use pythons random module
 - Mathutils.RotationMatrix(angle, size, axis_flag, axis) --> Mathutils.RotationMatrix(angle, size, axis); merge axis & axis_flag args
 - Matrix.scalePart --> Matrix.scale_part
 - Matrix.translationPart --> Matrix.translation_part
 - Matrix.rotationPart --> Matrix.rotation_part
 - toMatrix --> to_matrix
 - toEuler --> to_euler
 - toQuat --> to_quat
 - Vector.toTrackQuat --> Vector.to_track_quat
											
										 
											2010-01-25 09:44:04 +00:00
										 |  |  |     "\n" | 
					
						
							|  |  |  |     "   Set the matrix to its inverse.\n" | 
					
						
							| 
									
										
										
										
											2010-01-27 21:33:39 +00:00
										 |  |  |     "\n" | 
					
						
							| 
									
										
										
										
											2017-03-22 14:49:12 -04:00
										 |  |  |     "   :arg fallback: Set the matrix to this value when the inverse cannot be calculated\n" | 
					
						
							| 
									
										
										
										
											2014-04-29 19:58:37 +10:00
										 |  |  |     "      (instead of raising a :exc:`ValueError` exception).\n" | 
					
						
							|  |  |  |     "   :type fallback: :class:`Matrix`\n" | 
					
						
							| 
									
										
										
											
												Mathutils refactor & include in sphinx generated docs, (TODO, include getset'ers in docs)
 - Mathutils.MidpointVecs --> vector.lerp(other, fac)
 - Mathutils.AngleBetweenVecs --> vector.angle(other)
 - Mathutils.ProjectVecs --> vector.project(other)
 - Mathutils.DifferenceQuats --> quat.difference(other)
 - Mathutils.Slerp --> quat.slerp(other, fac)
 - Mathutils.Rand: removed, use pythons random module
 - Mathutils.RotationMatrix(angle, size, axis_flag, axis) --> Mathutils.RotationMatrix(angle, size, axis); merge axis & axis_flag args
 - Matrix.scalePart --> Matrix.scale_part
 - Matrix.translationPart --> Matrix.translation_part
 - Matrix.rotationPart --> Matrix.rotation_part
 - toMatrix --> to_matrix
 - toEuler --> to_euler
 - toQuat --> to_quat
 - Vector.toTrackQuat --> Vector.to_track_quat
											
										 
											2010-01-25 09:44:04 +00:00
										 |  |  |     "\n" | 
					
						
							| 
									
										
										
										
											2020-06-14 19:14:26 -04:00
										 |  |  |     "   .. seealso:: `Inverse matrix <https://en.wikipedia.org/wiki/Inverse_matrix>`__ on " | 
					
						
							| 
									
										
										
										
											2017-03-22 14:49:12 -04:00
										 |  |  |     "Wikipedia.\n"); | 
					
						
							| 
									
										
										
										
											2014-04-29 19:58:37 +10:00
										 |  |  | static PyObject *Matrix_invert(MatrixObject *self, PyObject *args) | 
					
						
							| 
									
										
										
										
											2009-06-17 20:33:34 +00:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2019-03-30 06:12:48 +11:00
										 |  |  |   if (BaseMath_ReadCallback_ForWrite(self) == -1) { | 
					
						
							| 
									
										
										
										
											2009-06-23 13:34:45 +00:00
										 |  |  |     return NULL; | 
					
						
							| 
									
										
										
										
											2019-03-30 06:12:48 +11:00
										 |  |  |   } | 
					
						
							| 
									
										
										
										
											2009-06-23 13:34:45 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-04-29 19:58:37 +10:00
										 |  |  |   if (matrix_invert_is_compat(self) == false) { | 
					
						
							| 
									
										
										
										
											2009-06-17 20:33:34 +00:00
										 |  |  |     return NULL; | 
					
						
							|  |  |  |   } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-04-29 19:58:37 +10:00
										 |  |  |   if (matrix_invert_args_check(self, args, true) == false) { | 
					
						
							|  |  |  |     return NULL; | 
					
						
							|  |  |  |   } | 
					
						
							| 
									
										
										
										
											2009-06-17 20:33:34 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-04-29 20:41:28 +10:00
										 |  |  |   if (matrix_invert_internal(self, self->matrix)) { | 
					
						
							| 
									
										
										
										
											2014-04-29 19:58:37 +10:00
										 |  |  |     /* pass */ | 
					
						
							|  |  |  |   } | 
					
						
							|  |  |  |   else { | 
					
						
							|  |  |  |     if (PyTuple_GET_SIZE(args) == 1) { | 
					
						
							| 
									
										
										
										
											2014-04-29 22:37:05 +10:00
										 |  |  |       MatrixObject *fallback = (MatrixObject *)PyTuple_GET_ITEM(args, 0); | 
					
						
							| 
									
										
										
										
											2014-04-29 19:58:37 +10:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-03-30 06:12:48 +11:00
										 |  |  |       if (BaseMath_ReadCallback(fallback) == -1) { | 
					
						
							| 
									
										
										
										
											2012-10-29 03:36:55 +00:00
										 |  |  |         return NULL; | 
					
						
							| 
									
										
										
										
											2019-03-30 06:12:48 +11:00
										 |  |  |       } | 
					
						
							| 
									
										
										
										
											2014-04-29 19:58:37 +10:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-04-29 20:41:28 +10:00
										 |  |  |       if (self != fallback) { | 
					
						
							|  |  |  |         matrix_copy(self, fallback); | 
					
						
							|  |  |  |       } | 
					
						
							| 
									
										
										
										
											2009-06-17 20:33:34 +00:00
										 |  |  |     } | 
					
						
							| 
									
										
										
										
											2014-04-29 19:58:37 +10:00
										 |  |  |     else { | 
					
						
							|  |  |  |       matrix_invert_raise_degenerate(); | 
					
						
							|  |  |  |       return NULL; | 
					
						
							| 
									
										
										
										
											2009-06-17 20:33:34 +00:00
										 |  |  |     } | 
					
						
							| 
									
										
										
										
											2011-07-14 01:25:05 +00:00
										 |  |  |   } | 
					
						
							| 
									
										
										
										
											2011-02-04 03:06:23 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2010-10-20 12:11:09 +00:00
										 |  |  |   (void)BaseMath_WriteCallback(self); | 
					
						
							| 
									
										
										
										
											2011-02-05 06:14:50 +00:00
										 |  |  |   Py_RETURN_NONE; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2011-05-24 16:05:51 +00:00
										 |  |  | PyDoc_STRVAR(Matrix_inverted_doc, | 
					
						
							| 
									
										
										
										
											2014-04-29 19:58:37 +10:00
										 |  |  |              ".. method:: inverted(fallback=None)\n" | 
					
						
							| 
									
										
										
										
											2011-02-05 06:14:50 +00:00
										 |  |  |              "\n" | 
					
						
							|  |  |  |              "   Return an inverted copy of the matrix.\n" | 
					
						
							|  |  |  |              "\n" | 
					
						
							| 
									
										
										
										
											2015-03-06 18:50:58 +11:00
										 |  |  |              "   :arg fallback: return this when the inverse can't be calculated\n" | 
					
						
							|  |  |  |              "      (instead of raising a :exc:`ValueError`).\n" | 
					
						
							| 
									
										
										
										
											2014-04-29 19:58:37 +10:00
										 |  |  |              "   :type fallback: any\n" | 
					
						
							|  |  |  |              "   :return: the inverted matrix or fallback when given.\n" | 
					
						
							| 
									
										
										
										
											2011-02-05 06:14:50 +00:00
										 |  |  |              "   :rtype: :class:`Matrix`\n"); | 
					
						
							| 
									
										
										
										
											2014-04-29 19:58:37 +10:00
										 |  |  | static PyObject *Matrix_inverted(MatrixObject *self, PyObject *args) | 
					
						
							|  |  |  | { | 
					
						
							| 
									
										
										
										
											2014-04-29 20:41:28 +10:00
										 |  |  |   float mat[MATRIX_MAX_DIM * MATRIX_MAX_DIM]; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-03-30 06:12:48 +11:00
										 |  |  |   if (BaseMath_ReadCallback(self) == -1) { | 
					
						
							| 
									
										
										
										
											2014-04-29 19:58:37 +10:00
										 |  |  |     return NULL; | 
					
						
							| 
									
										
										
										
											2019-03-30 06:12:48 +11:00
										 |  |  |   } | 
					
						
							| 
									
										
										
										
											2014-04-29 19:58:37 +10:00
										 |  |  | 
 | 
					
						
							|  |  |  |   if (matrix_invert_args_check(self, args, false) == false) { | 
					
						
							|  |  |  |     return NULL; | 
					
						
							|  |  |  |   } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   if (matrix_invert_is_compat(self) == false) { | 
					
						
							|  |  |  |     return NULL; | 
					
						
							|  |  |  |   } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-04-29 20:41:28 +10:00
										 |  |  |   if (matrix_invert_internal(self, mat)) { | 
					
						
							| 
									
										
										
										
											2014-04-29 19:58:37 +10:00
										 |  |  |     /* pass */ | 
					
						
							|  |  |  |   } | 
					
						
							|  |  |  |   else { | 
					
						
							|  |  |  |     if (PyTuple_GET_SIZE(args) == 1) { | 
					
						
							|  |  |  |       PyObject *fallback = PyTuple_GET_ITEM(args, 0); | 
					
						
							|  |  |  |       Py_INCREF(fallback); | 
					
						
							|  |  |  |       return fallback; | 
					
						
							|  |  |  |     } | 
					
						
							| 
									
										
										
										
											2020-08-07 12:41:06 +02:00
										 |  |  | 
 | 
					
						
							|  |  |  |     matrix_invert_raise_degenerate(); | 
					
						
							|  |  |  |     return NULL; | 
					
						
							| 
									
										
										
										
											2014-04-29 19:58:37 +10:00
										 |  |  |   } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-04-29 20:41:28 +10:00
										 |  |  |   return Matrix_copy_notest(self, mat); | 
					
						
							| 
									
										
										
										
											2014-04-29 19:58:37 +10:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | static PyObject *Matrix_inverted_noargs(MatrixObject *self) | 
					
						
							| 
									
										
										
										
											2011-02-05 06:14:50 +00:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2019-03-30 06:12:48 +11:00
										 |  |  |   if (BaseMath_ReadCallback_ForWrite(self) == -1) { | 
					
						
							| 
									
										
										
										
											2014-04-29 19:58:37 +10:00
										 |  |  |     return NULL; | 
					
						
							| 
									
										
										
										
											2019-03-30 06:12:48 +11:00
										 |  |  |   } | 
					
						
							| 
									
										
										
										
											2014-04-29 19:58:37 +10:00
										 |  |  | 
 | 
					
						
							|  |  |  |   if (matrix_invert_is_compat(self) == false) { | 
					
						
							|  |  |  |     return NULL; | 
					
						
							|  |  |  |   } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-04-29 20:41:28 +10:00
										 |  |  |   if (matrix_invert_internal(self, self->matrix)) { | 
					
						
							| 
									
										
										
										
											2014-04-29 19:58:37 +10:00
										 |  |  |     /* pass */ | 
					
						
							|  |  |  |   } | 
					
						
							|  |  |  |   else { | 
					
						
							|  |  |  |     matrix_invert_raise_degenerate(); | 
					
						
							|  |  |  |     return NULL; | 
					
						
							|  |  |  |   } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   (void)BaseMath_WriteCallback(self); | 
					
						
							|  |  |  |   Py_RETURN_NONE; | 
					
						
							| 
									
										
										
										
											2009-06-17 20:33:34 +00:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-06-17 16:07:26 +02:00
										 |  |  | PyDoc_STRVAR( | 
					
						
							|  |  |  |     Matrix_invert_safe_doc, | 
					
						
							|  |  |  |     ".. method:: invert_safe()\n" | 
					
						
							|  |  |  |     "\n" | 
					
						
							|  |  |  |     "   Set the matrix to its inverse, will never error.\n" | 
					
						
							|  |  |  |     "   If degenerated (e.g. zero scale on an axis), add some epsilon to its diagonal, " | 
					
						
							|  |  |  |     "to get an invertible one.\n" | 
					
						
							|  |  |  |     "   If tweaked matrix is still degenerated, set to the identity matrix instead.\n" | 
					
						
							|  |  |  |     "\n" | 
					
						
							|  |  |  |     "   .. seealso:: `Inverse Matrix <https://en.wikipedia.org/wiki/Inverse_matrix>`__ on " | 
					
						
							|  |  |  |     "Wikipedia.\n"); | 
					
						
							| 
									
										
										
										
											2014-09-06 14:54:08 +02:00
										 |  |  | static PyObject *Matrix_invert_safe(MatrixObject *self) | 
					
						
							|  |  |  | { | 
					
						
							| 
									
										
										
										
											2019-03-30 06:12:48 +11:00
										 |  |  |   if (BaseMath_ReadCallback_ForWrite(self) == -1) { | 
					
						
							| 
									
										
										
										
											2014-09-06 14:54:08 +02:00
										 |  |  |     return NULL; | 
					
						
							| 
									
										
										
										
											2019-03-30 06:12:48 +11:00
										 |  |  |   } | 
					
						
							| 
									
										
										
										
											2014-09-06 14:54:08 +02:00
										 |  |  | 
 | 
					
						
							|  |  |  |   if (matrix_invert_is_compat(self) == false) { | 
					
						
							|  |  |  |     return NULL; | 
					
						
							|  |  |  |   } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   matrix_invert_safe_internal(self, self->matrix); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   (void)BaseMath_WriteCallback(self); | 
					
						
							|  |  |  |   Py_RETURN_NONE; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | PyDoc_STRVAR(Matrix_inverted_safe_doc, | 
					
						
							|  |  |  |              ".. method:: inverted_safe()\n" | 
					
						
							|  |  |  |              "\n" | 
					
						
							|  |  |  |              "   Return an inverted copy of the matrix, will never error.\n" | 
					
						
							|  |  |  |              "   If degenerated (e.g. zero scale on an axis), add some epsilon to its diagonal, " | 
					
						
							|  |  |  |              "to get an invertible one.\n" | 
					
						
							|  |  |  |              "   If tweaked matrix is still degenerated, return the identity matrix instead.\n" | 
					
						
							|  |  |  |              "\n" | 
					
						
							|  |  |  |              "   :return: the inverted matrix.\n" | 
					
						
							|  |  |  |              "   :rtype: :class:`Matrix`\n"); | 
					
						
							|  |  |  | static PyObject *Matrix_inverted_safe(MatrixObject *self) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  |   float mat[MATRIX_MAX_DIM * MATRIX_MAX_DIM]; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-03-30 06:12:48 +11:00
										 |  |  |   if (BaseMath_ReadCallback(self) == -1) { | 
					
						
							| 
									
										
										
										
											2014-09-06 14:54:08 +02:00
										 |  |  |     return NULL; | 
					
						
							| 
									
										
										
										
											2019-03-30 06:12:48 +11:00
										 |  |  |   } | 
					
						
							| 
									
										
										
										
											2014-09-06 14:54:08 +02:00
										 |  |  | 
 | 
					
						
							|  |  |  |   if (matrix_invert_is_compat(self) == false) { | 
					
						
							|  |  |  |     return NULL; | 
					
						
							|  |  |  |   } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   matrix_invert_safe_internal(self, mat); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   return Matrix_copy_notest(self, mat); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-10-29 03:36:55 +00:00
										 |  |  | /*---------------------------matrix.adjugate() ---------------------*/ | 
					
						
							|  |  |  | PyDoc_STRVAR( | 
					
						
							|  |  |  |     Matrix_adjugate_doc, | 
					
						
							|  |  |  |     ".. method:: adjugate()\n" | 
					
						
							|  |  |  |     "\n" | 
					
						
							|  |  |  |     "   Set the matrix to its adjugate.\n" | 
					
						
							|  |  |  |     "\n" | 
					
						
							| 
									
										
										
										
											2020-09-29 15:05:45 -04:00
										 |  |  |     "   :raises ValueError: if the matrix cannot be adjugate.\n" | 
					
						
							| 
									
										
										
										
											2012-10-29 03:36:55 +00:00
										 |  |  |     "\n" | 
					
						
							| 
									
										
										
										
											2020-06-14 19:14:26 -04:00
										 |  |  |     "   .. seealso:: `Adjugate matrix <https://en.wikipedia.org/wiki/Adjugate_matrix>`__ on " | 
					
						
							| 
									
										
										
										
											2017-03-22 14:49:12 -04:00
										 |  |  |     "Wikipedia.\n"); | 
					
						
							| 
									
										
										
										
											2012-10-29 03:36:55 +00:00
										 |  |  | static PyObject *Matrix_adjugate(MatrixObject *self) | 
					
						
							|  |  |  | { | 
					
						
							| 
									
										
										
										
											2019-03-30 06:12:48 +11:00
										 |  |  |   if (BaseMath_ReadCallback_ForWrite(self) == -1) { | 
					
						
							| 
									
										
										
										
											2012-10-29 03:36:55 +00:00
										 |  |  |     return NULL; | 
					
						
							| 
									
										
										
										
											2019-03-30 06:12:48 +11:00
										 |  |  |   } | 
					
						
							| 
									
										
										
										
											2019-04-17 06:17:24 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-10-29 03:36:55 +00:00
										 |  |  |   if (self->num_col != self->num_row) { | 
					
						
							| 
									
										
										
										
											2012-12-16 04:10:57 +00:00
										 |  |  |     PyErr_SetString(PyExc_ValueError, | 
					
						
							| 
									
										
										
										
											2012-10-29 03:36:55 +00:00
										 |  |  |                     "Matrix.adjugate(d): " | 
					
						
							|  |  |  |                     "only square matrices are supported"); | 
					
						
							|  |  |  |     return NULL; | 
					
						
							|  |  |  |   } | 
					
						
							| 
									
										
										
										
											2019-04-17 06:17:24 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-10-29 03:36:55 +00:00
										 |  |  |   /* calculate the classical adjoint */ | 
					
						
							| 
									
										
										
										
											2014-09-06 14:54:08 +02:00
										 |  |  |   if (self->num_col <= 4) { | 
					
						
							|  |  |  |     adjoint_matrix_n(self->matrix, self->matrix, self->num_col); | 
					
						
							|  |  |  |   } | 
					
						
							|  |  |  |   else { | 
					
						
							| 
									
										
										
										
											2014-09-08 11:22:40 +10:00
										 |  |  |     PyErr_Format( | 
					
						
							|  |  |  |         PyExc_ValueError, "Matrix adjugate(d): size (%d) unsupported", (int)self->num_col); | 
					
						
							|  |  |  |     return NULL; | 
					
						
							| 
									
										
										
										
											2012-10-29 03:36:55 +00:00
										 |  |  |   } | 
					
						
							| 
									
										
										
										
											2019-04-17 06:17:24 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-10-29 03:36:55 +00:00
										 |  |  |   (void)BaseMath_WriteCallback(self); | 
					
						
							|  |  |  |   Py_RETURN_NONE; | 
					
						
							|  |  |  | } | 
					
						
							| 
									
										
										
										
											2019-04-17 06:17:24 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-10-01 14:29:26 +02:00
										 |  |  | PyDoc_STRVAR(Matrix_adjugated_doc, | 
					
						
							|  |  |  |              ".. method:: adjugated()\n" | 
					
						
							|  |  |  |              "\n" | 
					
						
							|  |  |  |              "   Return an adjugated copy of the matrix.\n" | 
					
						
							|  |  |  |              "\n" | 
					
						
							|  |  |  |              "   :return: the adjugated matrix.\n" | 
					
						
							|  |  |  |              "   :rtype: :class:`Matrix`\n" | 
					
						
							|  |  |  |              "   :raises ValueError: if the matrix cannot be adjugated\n"); | 
					
						
							| 
									
										
										
										
											2012-10-29 03:36:55 +00:00
										 |  |  | static PyObject *Matrix_adjugated(MatrixObject *self) | 
					
						
							|  |  |  | { | 
					
						
							| 
									
										
										
										
											2020-06-22 14:51:20 +10:00
										 |  |  |   return matrix__apply_to_copy(Matrix_adjugate, self); | 
					
						
							| 
									
										
										
										
											2012-10-29 03:36:55 +00:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2011-05-24 16:05:51 +00:00
										 |  |  | PyDoc_STRVAR( | 
					
						
							|  |  |  |     Matrix_rotate_doc, | 
					
						
							| 
									
										
										
										
											2011-02-05 09:57:02 +00:00
										 |  |  |     ".. method:: rotate(other)\n" | 
					
						
							|  |  |  |     "\n" | 
					
						
							| 
									
										
										
										
											2014-12-19 00:42:50 +09:00
										 |  |  |     "   Rotates the matrix by another mathutils value.\n" | 
					
						
							| 
									
										
										
										
											2011-02-05 09:57:02 +00:00
										 |  |  |     "\n" | 
					
						
							|  |  |  |     "   :arg other: rotation component of mathutils value\n" | 
					
						
							|  |  |  |     "   :type other: :class:`Euler`, :class:`Quaternion` or :class:`Matrix`\n" | 
					
						
							|  |  |  |     "\n" | 
					
						
							|  |  |  |     "   .. note:: If any of the columns are not unit length this may not have desired results.\n"); | 
					
						
							|  |  |  | static PyObject *Matrix_rotate(MatrixObject *self, PyObject *value) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  |   float self_rmat[3][3], other_rmat[3][3], rmat[3][3]; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-03-30 06:12:48 +11:00
										 |  |  |   if (BaseMath_ReadCallback_ForWrite(self) == -1) { | 
					
						
							| 
									
										
										
										
											2011-02-05 09:57:02 +00:00
										 |  |  |     return NULL; | 
					
						
							| 
									
										
										
										
											2019-03-30 06:12:48 +11:00
										 |  |  |   } | 
					
						
							| 
									
										
										
										
											2011-02-05 09:57:02 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-03-30 06:12:48 +11:00
										 |  |  |   if (mathutils_any_to_rotmat(other_rmat, value, "matrix.rotate(value)") == -1) { | 
					
						
							| 
									
										
										
										
											2011-02-05 09:57:02 +00:00
										 |  |  |     return NULL; | 
					
						
							| 
									
										
										
										
											2019-03-30 06:12:48 +11:00
										 |  |  |   } | 
					
						
							| 
									
										
										
										
											2011-02-05 09:57:02 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2011-12-20 04:11:23 +00:00
										 |  |  |   if (self->num_row != 3 || self->num_col != 3) { | 
					
						
							| 
									
										
										
										
											2012-12-16 04:10:57 +00:00
										 |  |  |     PyErr_SetString(PyExc_ValueError, | 
					
						
							| 
									
										
										
										
											2011-09-19 14:29:21 +00:00
										 |  |  |                     "Matrix.rotate(): " | 
					
						
							|  |  |  |                     "must have 3x3 dimensions"); | 
					
						
							| 
									
										
										
										
											2011-02-05 09:57:02 +00:00
										 |  |  |     return NULL; | 
					
						
							|  |  |  |   } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   matrix_as_3x3(self_rmat, self); | 
					
						
							| 
									
										
										
										
											2011-11-24 19:36:12 +00:00
										 |  |  |   mul_m3_m3m3(rmat, other_rmat, self_rmat); | 
					
						
							| 
									
										
										
										
											2011-02-05 09:57:02 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2011-12-20 04:11:23 +00:00
										 |  |  |   copy_m3_m3((float(*)[3])(self->matrix), rmat); | 
					
						
							| 
									
										
										
										
											2011-02-05 09:57:02 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  |   (void)BaseMath_WriteCallback(self); | 
					
						
							|  |  |  |   Py_RETURN_NONE; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2011-07-14 01:25:05 +00:00
										 |  |  | /*---------------------------matrix.decompose() ---------------------*/ | 
					
						
							| 
									
										
										
										
											2011-05-24 16:05:51 +00:00
										 |  |  | PyDoc_STRVAR(Matrix_decompose_doc, | 
					
						
							| 
									
										
										
										
											2010-10-26 12:48:07 +00:00
										 |  |  |              ".. method:: decompose()\n" | 
					
						
							|  |  |  |              "\n" | 
					
						
							| 
									
										
										
										
											2018-01-18 09:37:54 +01:00
										 |  |  |              "   Return the translation, rotation, and scale components of this matrix.\n" | 
					
						
							| 
									
										
										
										
											2010-10-26 12:48:07 +00:00
										 |  |  |              "\n" | 
					
						
							| 
									
										
										
										
											2018-01-18 09:37:54 +01:00
										 |  |  |              "   :return: tuple of translation, rotation, and scale\n" | 
					
						
							| 
									
										
										
										
											2011-02-04 09:35:20 +00:00
										 |  |  |              "   :rtype: (:class:`Vector`, :class:`Quaternion`, :class:`Vector`)"); | 
					
						
							| 
									
										
										
										
											2011-02-04 03:06:23 +00:00
										 |  |  | static PyObject *Matrix_decompose(MatrixObject *self) | 
					
						
							| 
									
										
										
										
											2010-10-26 12:48:07 +00:00
										 |  |  | { | 
					
						
							|  |  |  |   PyObject *ret; | 
					
						
							|  |  |  |   float loc[3]; | 
					
						
							|  |  |  |   float rot[3][3]; | 
					
						
							|  |  |  |   float quat[4]; | 
					
						
							|  |  |  |   float size[3]; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2011-12-20 04:11:23 +00:00
										 |  |  |   if (self->num_row != 4 || self->num_col != 4) { | 
					
						
							| 
									
										
										
										
											2012-12-16 04:10:57 +00:00
										 |  |  |     PyErr_SetString(PyExc_ValueError, | 
					
						
							| 
									
										
										
										
											2011-09-19 14:29:21 +00:00
										 |  |  |                     "Matrix.decompose(): " | 
					
						
							| 
									
										
										
										
											2011-07-14 01:25:05 +00:00
										 |  |  |                     "inappropriate matrix size - expects 4x4 matrix"); | 
					
						
							| 
									
										
										
										
											2010-10-26 12:48:07 +00:00
										 |  |  |     return NULL; | 
					
						
							|  |  |  |   } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-03-30 06:12:48 +11:00
										 |  |  |   if (BaseMath_ReadCallback(self) == -1) { | 
					
						
							| 
									
										
										
										
											2010-10-26 12:48:07 +00:00
										 |  |  |     return NULL; | 
					
						
							| 
									
										
										
										
											2019-03-30 06:12:48 +11:00
										 |  |  |   } | 
					
						
							| 
									
										
										
										
											2010-10-26 12:48:07 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-05-18 14:13:20 +10:00
										 |  |  |   mat4_to_loc_rot_size(loc, rot, size, (const float(*)[4])self->matrix); | 
					
						
							| 
									
										
										
										
											2010-10-26 12:48:07 +00:00
										 |  |  |   mat3_to_quat(quat, rot); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2011-12-24 13:26:30 +00:00
										 |  |  |   ret = PyTuple_New(3); | 
					
						
							| 
									
										
										
										
											2015-01-06 16:42:22 +11:00
										 |  |  |   PyTuple_SET_ITEMS(ret, | 
					
						
							|  |  |  |                     Vector_CreatePyObject(loc, 3, NULL), | 
					
						
							|  |  |  |                     Quaternion_CreatePyObject(quat, NULL), | 
					
						
							|  |  |  |                     Vector_CreatePyObject(size, 3, NULL)); | 
					
						
							| 
									
										
										
										
											2010-10-26 12:48:07 +00:00
										 |  |  |   return ret; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2011-05-24 16:05:51 +00:00
										 |  |  | PyDoc_STRVAR(Matrix_lerp_doc, | 
					
						
							| 
									
										
										
										
											2010-11-22 10:39:28 +00:00
										 |  |  |              ".. function:: lerp(other, factor)\n" | 
					
						
							|  |  |  |              "\n" | 
					
						
							| 
									
										
										
										
											2018-01-18 09:58:14 +01:00
										 |  |  |              "   Returns the interpolation of two matrices. Uses polar decomposition, see" | 
					
						
							|  |  |  |              "   \"Matrix Animation and Polar Decomposition\", Shoemake and Duff, 1992.\n" | 
					
						
							| 
									
										
										
										
											2010-11-22 10:39:28 +00:00
										 |  |  |              "\n" | 
					
						
							|  |  |  |              "   :arg other: value to interpolate with.\n" | 
					
						
							|  |  |  |              "   :type other: :class:`Matrix`\n" | 
					
						
							|  |  |  |              "   :arg factor: The interpolation value in [0.0, 1.0].\n" | 
					
						
							|  |  |  |              "   :type factor: float\n" | 
					
						
							| 
									
										
										
										
											2014-01-09 21:48:41 +11:00
										 |  |  |              "   :return: The interpolated matrix.\n" | 
					
						
							| 
									
										
										
										
											2011-02-04 09:35:20 +00:00
										 |  |  |              "   :rtype: :class:`Matrix`\n"); | 
					
						
							| 
									
										
										
										
											2011-02-04 03:06:23 +00:00
										 |  |  | static PyObject *Matrix_lerp(MatrixObject *self, PyObject *args) | 
					
						
							| 
									
										
										
										
											2010-11-22 10:39:28 +00:00
										 |  |  | { | 
					
						
							|  |  |  |   MatrixObject *mat2 = NULL; | 
					
						
							| 
									
										
										
										
											2011-12-24 13:26:30 +00:00
										 |  |  |   float fac, mat[MATRIX_MAX_DIM * MATRIX_MAX_DIM]; | 
					
						
							| 
									
										
										
										
											2010-11-22 10:39:28 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-03-30 06:12:48 +11:00
										 |  |  |   if (!PyArg_ParseTuple(args, "O!f:lerp", &matrix_Type, &mat2, &fac)) { | 
					
						
							| 
									
										
										
										
											2010-11-22 10:39:28 +00:00
										 |  |  |     return NULL; | 
					
						
							| 
									
										
										
										
											2019-03-30 06:12:48 +11:00
										 |  |  |   } | 
					
						
							| 
									
										
										
										
											2010-11-22 10:39:28 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2011-12-20 04:11:23 +00:00
										 |  |  |   if (self->num_col != mat2->num_col || self->num_row != mat2->num_row) { | 
					
						
							| 
									
										
										
										
											2011-07-14 09:54:03 +00:00
										 |  |  |     PyErr_SetString(PyExc_ValueError, | 
					
						
							| 
									
										
										
										
											2011-09-19 14:29:21 +00:00
										 |  |  |                     "Matrix.lerp(): " | 
					
						
							| 
									
										
										
										
											2011-07-14 01:25:05 +00:00
										 |  |  |                     "expects both matrix objects of the same dimensions"); | 
					
						
							| 
									
										
										
										
											2010-11-22 10:39:28 +00:00
										 |  |  |     return NULL; | 
					
						
							|  |  |  |   } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-03-30 06:12:48 +11:00
										 |  |  |   if (BaseMath_ReadCallback(self) == -1 || BaseMath_ReadCallback(mat2) == -1) { | 
					
						
							| 
									
										
										
										
											2010-11-22 10:39:28 +00:00
										 |  |  |     return NULL; | 
					
						
							| 
									
										
										
										
											2019-03-30 06:12:48 +11:00
										 |  |  |   } | 
					
						
							| 
									
										
										
										
											2010-11-22 10:39:28 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-07-03 23:08:40 +10:00
										 |  |  |   /* TODO: different sized matrix. */ | 
					
						
							| 
									
										
										
										
											2011-12-24 13:26:30 +00:00
										 |  |  |   if (self->num_col == 4 && self->num_row == 4) { | 
					
						
							| 
									
										
										
										
											2018-03-18 05:01:30 +01:00
										 |  |  | #ifdef MATH_STANDALONE
 | 
					
						
							|  |  |  |     blend_m4_m4m4((float(*)[4])mat, (float(*)[4])self->matrix, (float(*)[4])mat2->matrix, fac); | 
					
						
							|  |  |  | #else
 | 
					
						
							| 
									
										
										
										
											2017-05-26 17:00:20 +10:00
										 |  |  |     interp_m4_m4m4((float(*)[4])mat, (float(*)[4])self->matrix, (float(*)[4])mat2->matrix, fac); | 
					
						
							| 
									
										
										
										
											2018-03-18 05:01:30 +01:00
										 |  |  | #endif
 | 
					
						
							| 
									
										
										
										
											2010-11-22 10:39:28 +00:00
										 |  |  |   } | 
					
						
							| 
									
										
										
										
											2011-12-24 13:26:30 +00:00
										 |  |  |   else if (self->num_col == 3 && self->num_row == 3) { | 
					
						
							| 
									
										
										
										
											2018-03-18 05:01:30 +01:00
										 |  |  | #ifdef MATH_STANDALONE
 | 
					
						
							|  |  |  |     blend_m3_m3m3((float(*)[3])mat, (float(*)[3])self->matrix, (float(*)[3])mat2->matrix, fac); | 
					
						
							|  |  |  | #else
 | 
					
						
							| 
									
										
										
										
											2017-05-26 17:00:20 +10:00
										 |  |  |     interp_m3_m3m3((float(*)[3])mat, (float(*)[3])self->matrix, (float(*)[3])mat2->matrix, fac); | 
					
						
							| 
									
										
										
										
											2018-03-18 05:01:30 +01:00
										 |  |  | #endif
 | 
					
						
							| 
									
										
										
										
											2010-11-22 10:39:28 +00:00
										 |  |  |   } | 
					
						
							|  |  |  |   else { | 
					
						
							| 
									
										
										
										
											2011-07-14 09:54:03 +00:00
										 |  |  |     PyErr_SetString(PyExc_ValueError, | 
					
						
							| 
									
										
										
										
											2011-09-19 14:29:21 +00:00
										 |  |  |                     "Matrix.lerp(): " | 
					
						
							| 
									
										
										
										
											2011-07-14 01:25:05 +00:00
										 |  |  |                     "only 3x3 and 4x4 matrices supported"); | 
					
						
							| 
									
										
										
										
											2010-11-22 10:39:28 +00:00
										 |  |  |     return NULL; | 
					
						
							|  |  |  |   } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-01-04 17:03:54 +11:00
										 |  |  |   return Matrix_CreatePyObject(mat, self->num_col, self->num_row, Py_TYPE(self)); | 
					
						
							| 
									
										
										
										
											2010-11-22 10:39:28 +00:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2011-07-14 01:25:05 +00:00
										 |  |  | /*---------------------------matrix.determinant() ----------------*/ | 
					
						
							| 
									
										
										
										
											2011-05-24 16:05:51 +00:00
										 |  |  | PyDoc_STRVAR( | 
					
						
							|  |  |  |     Matrix_determinant_doc, | 
					
						
							| 
									
										
										
											
												Mathutils refactor & include in sphinx generated docs, (TODO, include getset'ers in docs)
 - Mathutils.MidpointVecs --> vector.lerp(other, fac)
 - Mathutils.AngleBetweenVecs --> vector.angle(other)
 - Mathutils.ProjectVecs --> vector.project(other)
 - Mathutils.DifferenceQuats --> quat.difference(other)
 - Mathutils.Slerp --> quat.slerp(other, fac)
 - Mathutils.Rand: removed, use pythons random module
 - Mathutils.RotationMatrix(angle, size, axis_flag, axis) --> Mathutils.RotationMatrix(angle, size, axis); merge axis & axis_flag args
 - Matrix.scalePart --> Matrix.scale_part
 - Matrix.translationPart --> Matrix.translation_part
 - Matrix.rotationPart --> Matrix.rotation_part
 - toMatrix --> to_matrix
 - toEuler --> to_euler
 - toQuat --> to_quat
 - Vector.toTrackQuat --> Vector.to_track_quat
											
										 
											2010-01-25 09:44:04 +00:00
										 |  |  |     ".. method:: determinant()\n" | 
					
						
							|  |  |  |     "\n" | 
					
						
							|  |  |  |     "   Return the determinant of a matrix.\n" | 
					
						
							| 
									
										
										
										
											2010-01-27 21:33:39 +00:00
										 |  |  |     "\n" | 
					
						
							| 
									
										
										
										
											2014-12-19 00:42:50 +09:00
										 |  |  |     "   :return: Return the determinant of a matrix.\n" | 
					
						
							| 
									
										
										
											
												Mathutils refactor & include in sphinx generated docs, (TODO, include getset'ers in docs)
 - Mathutils.MidpointVecs --> vector.lerp(other, fac)
 - Mathutils.AngleBetweenVecs --> vector.angle(other)
 - Mathutils.ProjectVecs --> vector.project(other)
 - Mathutils.DifferenceQuats --> quat.difference(other)
 - Mathutils.Slerp --> quat.slerp(other, fac)
 - Mathutils.Rand: removed, use pythons random module
 - Mathutils.RotationMatrix(angle, size, axis_flag, axis) --> Mathutils.RotationMatrix(angle, size, axis); merge axis & axis_flag args
 - Matrix.scalePart --> Matrix.scale_part
 - Matrix.translationPart --> Matrix.translation_part
 - Matrix.rotationPart --> Matrix.rotation_part
 - toMatrix --> to_matrix
 - toEuler --> to_euler
 - toQuat --> to_quat
 - Vector.toTrackQuat --> Vector.to_track_quat
											
										 
											2010-01-25 09:44:04 +00:00
										 |  |  |     "   :rtype: float\n" | 
					
						
							|  |  |  |     "\n" | 
					
						
							| 
									
										
										
										
											2020-06-14 19:14:26 -04:00
										 |  |  |     "   .. seealso:: `Determinant <https://en.wikipedia.org/wiki/Determinant>`__ on Wikipedia.\n"); | 
					
						
							| 
									
										
										
										
											2011-02-05 06:14:50 +00:00
										 |  |  | static PyObject *Matrix_determinant(MatrixObject *self) | 
					
						
							| 
									
										
										
										
											2009-06-17 20:33:34 +00:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2019-03-30 06:12:48 +11:00
										 |  |  |   if (BaseMath_ReadCallback(self) == -1) { | 
					
						
							| 
									
										
										
										
											2009-06-23 13:34:45 +00:00
										 |  |  |     return NULL; | 
					
						
							| 
									
										
										
										
											2019-03-30 06:12:48 +11:00
										 |  |  |   } | 
					
						
							| 
									
										
										
										
											2011-02-04 03:06:23 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2011-12-20 04:11:23 +00:00
										 |  |  |   if (self->num_col != self->num_row) { | 
					
						
							| 
									
										
										
										
											2012-12-16 04:10:57 +00:00
										 |  |  |     PyErr_SetString(PyExc_ValueError, | 
					
						
							| 
									
										
										
										
											2011-09-19 14:29:21 +00:00
										 |  |  |                     "Matrix.determinant(): " | 
					
						
							| 
									
										
										
										
											2011-07-14 01:25:05 +00:00
										 |  |  |                     "only square matrices are supported"); | 
					
						
							| 
									
										
										
										
											2009-06-17 20:33:34 +00:00
										 |  |  |     return NULL; | 
					
						
							|  |  |  |   } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2011-02-04 03:06:23 +00:00
										 |  |  |   return PyFloat_FromDouble((double)matrix_determinant_internal(self)); | 
					
						
							| 
									
										
										
										
											2009-06-17 20:33:34 +00:00
										 |  |  | } | 
					
						
							| 
									
										
										
										
											2011-07-14 01:25:05 +00:00
										 |  |  | /*---------------------------matrix.transpose() ------------------*/ | 
					
						
							| 
									
										
										
										
											2011-05-24 16:05:51 +00:00
										 |  |  | PyDoc_STRVAR( | 
					
						
							|  |  |  |     Matrix_transpose_doc, | 
					
						
							| 
									
										
										
											
												Mathutils refactor & include in sphinx generated docs, (TODO, include getset'ers in docs)
 - Mathutils.MidpointVecs --> vector.lerp(other, fac)
 - Mathutils.AngleBetweenVecs --> vector.angle(other)
 - Mathutils.ProjectVecs --> vector.project(other)
 - Mathutils.DifferenceQuats --> quat.difference(other)
 - Mathutils.Slerp --> quat.slerp(other, fac)
 - Mathutils.Rand: removed, use pythons random module
 - Mathutils.RotationMatrix(angle, size, axis_flag, axis) --> Mathutils.RotationMatrix(angle, size, axis); merge axis & axis_flag args
 - Matrix.scalePart --> Matrix.scale_part
 - Matrix.translationPart --> Matrix.translation_part
 - Matrix.rotationPart --> Matrix.rotation_part
 - toMatrix --> to_matrix
 - toEuler --> to_euler
 - toQuat --> to_quat
 - Vector.toTrackQuat --> Vector.to_track_quat
											
										 
											2010-01-25 09:44:04 +00:00
										 |  |  |     ".. method:: transpose()\n" | 
					
						
							|  |  |  |     "\n" | 
					
						
							|  |  |  |     "   Set the matrix to its transpose.\n" | 
					
						
							| 
									
										
										
										
											2010-01-27 21:33:39 +00:00
										 |  |  |     "\n" | 
					
						
							| 
									
										
										
										
											2020-06-14 19:14:26 -04:00
										 |  |  |     "   .. seealso:: `Transpose <https://en.wikipedia.org/wiki/Transpose>`__ on Wikipedia.\n"); | 
					
						
							| 
									
										
										
										
											2011-02-05 06:14:50 +00:00
										 |  |  | static PyObject *Matrix_transpose(MatrixObject *self) | 
					
						
							| 
									
										
										
										
											2009-06-17 20:33:34 +00:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2019-03-30 06:12:48 +11:00
										 |  |  |   if (BaseMath_ReadCallback_ForWrite(self) == -1) { | 
					
						
							| 
									
										
										
										
											2009-06-23 13:34:45 +00:00
										 |  |  |     return NULL; | 
					
						
							| 
									
										
										
										
											2019-03-30 06:12:48 +11:00
										 |  |  |   } | 
					
						
							| 
									
										
										
										
											2019-04-17 06:17:24 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2011-12-20 04:11:23 +00:00
										 |  |  |   if (self->num_col != self->num_row) { | 
					
						
							| 
									
										
										
										
											2012-12-16 04:10:57 +00:00
										 |  |  |     PyErr_SetString(PyExc_ValueError, | 
					
						
							| 
									
										
										
										
											2011-09-19 14:29:21 +00:00
										 |  |  |                     "Matrix.transpose(d): " | 
					
						
							| 
									
										
										
										
											2011-07-14 01:25:05 +00:00
										 |  |  |                     "only square matrices are supported"); | 
					
						
							| 
									
										
										
										
											2009-06-17 20:33:34 +00:00
										 |  |  |     return NULL; | 
					
						
							|  |  |  |   } | 
					
						
							| 
									
										
										
										
											2019-04-17 06:17:24 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2011-12-20 04:11:23 +00:00
										 |  |  |   if (self->num_col == 2) { | 
					
						
							| 
									
										
										
										
											2011-12-19 03:12:10 +00:00
										 |  |  |     const float t = MATRIX_ITEM(self, 1, 0); | 
					
						
							|  |  |  |     MATRIX_ITEM(self, 1, 0) = MATRIX_ITEM(self, 0, 1); | 
					
						
							|  |  |  |     MATRIX_ITEM(self, 0, 1) = t; | 
					
						
							| 
									
										
										
										
											2011-11-16 03:56:34 +00:00
										 |  |  |   } | 
					
						
							| 
									
										
										
										
											2011-12-20 04:11:23 +00:00
										 |  |  |   else if (self->num_col == 3) { | 
					
						
							|  |  |  |     transpose_m3((float(*)[3])self->matrix); | 
					
						
							| 
									
										
										
										
											2011-07-14 01:25:05 +00:00
										 |  |  |   } | 
					
						
							|  |  |  |   else { | 
					
						
							| 
									
										
										
										
											2011-12-20 04:11:23 +00:00
										 |  |  |     transpose_m4((float(*)[4])self->matrix); | 
					
						
							| 
									
										
										
										
											2009-06-17 20:33:34 +00:00
										 |  |  |   } | 
					
						
							| 
									
										
										
										
											2019-04-17 06:17:24 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2010-10-20 12:11:09 +00:00
										 |  |  |   (void)BaseMath_WriteCallback(self); | 
					
						
							| 
									
										
										
										
											2011-02-05 06:14:50 +00:00
										 |  |  |   Py_RETURN_NONE; | 
					
						
							| 
									
										
										
										
											2009-06-17 20:33:34 +00:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2011-05-24 16:05:51 +00:00
										 |  |  | PyDoc_STRVAR(Matrix_transposed_doc, | 
					
						
							| 
									
										
										
										
											2011-02-05 06:14:50 +00:00
										 |  |  |              ".. method:: transposed()\n" | 
					
						
							|  |  |  |              "\n" | 
					
						
							|  |  |  |              "   Return a new, transposed matrix.\n" | 
					
						
							|  |  |  |              "\n" | 
					
						
							|  |  |  |              "   :return: a transposed matrix\n" | 
					
						
							|  |  |  |              "   :rtype: :class:`Matrix`\n"); | 
					
						
							|  |  |  | static PyObject *Matrix_transposed(MatrixObject *self) | 
					
						
							|  |  |  | { | 
					
						
							| 
									
										
										
										
											2020-06-22 14:51:20 +10:00
										 |  |  |   return matrix__apply_to_copy(Matrix_transpose, self); | 
					
						
							| 
									
										
										
										
											2011-02-05 06:14:50 +00:00
										 |  |  | } | 
					
						
							| 
									
										
										
										
											2009-06-17 20:33:34 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-12-16 04:05:16 +00:00
										 |  |  | /*---------------------------matrix.normalize() ------------------*/ | 
					
						
							|  |  |  | PyDoc_STRVAR(Matrix_normalize_doc, | 
					
						
							|  |  |  |              ".. method:: normalize()\n" | 
					
						
							|  |  |  |              "\n" | 
					
						
							| 
									
										
										
										
											2012-12-16 10:28:52 +00:00
										 |  |  |              "   Normalize each of the matrix columns.\n"); | 
					
						
							| 
									
										
										
										
											2012-12-16 04:05:16 +00:00
										 |  |  | static PyObject *Matrix_normalize(MatrixObject *self) | 
					
						
							|  |  |  | { | 
					
						
							| 
									
										
										
										
											2019-03-30 06:12:48 +11:00
										 |  |  |   if (BaseMath_ReadCallback_ForWrite(self) == -1) { | 
					
						
							| 
									
										
										
										
											2012-12-16 04:05:16 +00:00
										 |  |  |     return NULL; | 
					
						
							| 
									
										
										
										
											2019-03-30 06:12:48 +11:00
										 |  |  |   } | 
					
						
							| 
									
										
										
										
											2019-04-17 06:17:24 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-12-16 04:05:16 +00:00
										 |  |  |   if (self->num_col != self->num_row) { | 
					
						
							|  |  |  |     PyErr_SetString(PyExc_ValueError, | 
					
						
							|  |  |  |                     "Matrix.normalize(): " | 
					
						
							|  |  |  |                     "only square matrices are supported"); | 
					
						
							|  |  |  |     return NULL; | 
					
						
							|  |  |  |   } | 
					
						
							| 
									
										
										
										
											2019-04-17 06:17:24 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-12-16 04:05:16 +00:00
										 |  |  |   if (self->num_col == 3) { | 
					
						
							|  |  |  |     normalize_m3((float(*)[3])self->matrix); | 
					
						
							|  |  |  |   } | 
					
						
							|  |  |  |   else if (self->num_col == 4) { | 
					
						
							|  |  |  |     normalize_m4((float(*)[4])self->matrix); | 
					
						
							|  |  |  |   } | 
					
						
							|  |  |  |   else { | 
					
						
							|  |  |  |     PyErr_SetString(PyExc_ValueError, | 
					
						
							|  |  |  |                     "Matrix.normalize(): " | 
					
						
							|  |  |  |                     "can only use a 3x3 or 4x4 matrix"); | 
					
						
							|  |  |  |   } | 
					
						
							| 
									
										
										
										
											2019-04-17 06:17:24 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-12-16 04:05:16 +00:00
										 |  |  |   (void)BaseMath_WriteCallback(self); | 
					
						
							|  |  |  |   Py_RETURN_NONE; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | PyDoc_STRVAR(Matrix_normalized_doc, | 
					
						
							|  |  |  |              ".. method:: normalized()\n" | 
					
						
							|  |  |  |              "\n" | 
					
						
							| 
									
										
										
										
											2012-12-16 04:10:57 +00:00
										 |  |  |              "   Return a column normalized matrix\n" | 
					
						
							| 
									
										
										
										
											2012-12-16 04:05:16 +00:00
										 |  |  |              "\n" | 
					
						
							| 
									
										
										
										
											2012-12-16 04:10:57 +00:00
										 |  |  |              "   :return: a column normalized matrix\n" | 
					
						
							| 
									
										
										
										
											2012-12-16 04:05:16 +00:00
										 |  |  |              "   :rtype: :class:`Matrix`\n"); | 
					
						
							|  |  |  | static PyObject *Matrix_normalized(MatrixObject *self) | 
					
						
							|  |  |  | { | 
					
						
							| 
									
										
										
										
											2020-06-22 14:51:20 +10:00
										 |  |  |   return matrix__apply_to_copy(Matrix_normalize, self); | 
					
						
							| 
									
										
										
										
											2012-12-16 04:05:16 +00:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2011-07-14 01:25:05 +00:00
										 |  |  | /*---------------------------matrix.zero() -----------------------*/ | 
					
						
							| 
									
										
										
										
											2011-05-24 16:05:51 +00:00
										 |  |  | PyDoc_STRVAR(Matrix_zero_doc, | 
					
						
							| 
									
										
										
											
												Mathutils refactor & include in sphinx generated docs, (TODO, include getset'ers in docs)
 - Mathutils.MidpointVecs --> vector.lerp(other, fac)
 - Mathutils.AngleBetweenVecs --> vector.angle(other)
 - Mathutils.ProjectVecs --> vector.project(other)
 - Mathutils.DifferenceQuats --> quat.difference(other)
 - Mathutils.Slerp --> quat.slerp(other, fac)
 - Mathutils.Rand: removed, use pythons random module
 - Mathutils.RotationMatrix(angle, size, axis_flag, axis) --> Mathutils.RotationMatrix(angle, size, axis); merge axis & axis_flag args
 - Matrix.scalePart --> Matrix.scale_part
 - Matrix.translationPart --> Matrix.translation_part
 - Matrix.rotationPart --> Matrix.rotation_part
 - toMatrix --> to_matrix
 - toEuler --> to_euler
 - toQuat --> to_quat
 - Vector.toTrackQuat --> Vector.to_track_quat
											
										 
											2010-01-25 09:44:04 +00:00
										 |  |  |              ".. method:: zero()\n" | 
					
						
							|  |  |  |              "\n" | 
					
						
							|  |  |  |              "   Set all the matrix values to zero.\n" | 
					
						
							| 
									
										
										
										
											2010-01-27 21:33:39 +00:00
										 |  |  |              "\n" | 
					
						
							| 
									
										
										
										
											2011-02-04 09:35:20 +00:00
										 |  |  |              "   :rtype: :class:`Matrix`\n"); | 
					
						
							| 
									
										
										
										
											2011-02-05 06:14:50 +00:00
										 |  |  | static PyObject *Matrix_zero(MatrixObject *self) | 
					
						
							| 
									
										
										
										
											2009-06-17 20:33:34 +00:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2019-03-30 06:12:48 +11:00
										 |  |  |   if (BaseMath_Prepare_ForWrite(self) == -1) { | 
					
						
							| 
									
										
										
										
											2015-02-15 11:26:31 +11:00
										 |  |  |     return NULL; | 
					
						
							| 
									
										
										
										
											2019-03-30 06:12:48 +11:00
										 |  |  |   } | 
					
						
							| 
									
										
										
										
											2011-02-04 03:06:23 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-03-30 06:12:48 +11:00
										 |  |  |   copy_vn_fl(self->matrix, self->num_col * self->num_row, 0.0f); | 
					
						
							| 
									
										
										
										
											2011-02-04 03:06:23 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-03-30 06:12:48 +11:00
										 |  |  |   if (BaseMath_WriteCallback(self) == -1) { | 
					
						
							| 
									
										
										
										
											2011-02-05 06:14:50 +00:00
										 |  |  |     return NULL; | 
					
						
							| 
									
										
										
										
											2019-04-17 06:17:24 +02:00
										 |  |  |   } | 
					
						
							| 
									
										
										
										
											2014-12-28 15:13:01 +11:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2011-02-05 06:14:50 +00:00
										 |  |  |   Py_RETURN_NONE; | 
					
						
							| 
									
										
										
										
											2009-06-17 20:33:34 +00:00
										 |  |  | } | 
					
						
							| 
									
										
										
										
											2011-07-14 01:25:05 +00:00
										 |  |  | /*---------------------------matrix.identity(() ------------------*/ | 
					
						
							| 
									
										
										
										
											2014-12-28 15:13:01 +11:00
										 |  |  | static void matrix_identity_internal(MatrixObject *self) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  |   BLI_assert((self->num_col == self->num_row) && (self->num_row <= 4)); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   if (self->num_col == 2) { | 
					
						
							|  |  |  |     unit_m2((float(*)[2])self->matrix); | 
					
						
							|  |  |  |   } | 
					
						
							|  |  |  |   else if (self->num_col == 3) { | 
					
						
							|  |  |  |     unit_m3((float(*)[3])self->matrix); | 
					
						
							|  |  |  |   } | 
					
						
							|  |  |  |   else { | 
					
						
							|  |  |  |     unit_m4((float(*)[4])self->matrix); | 
					
						
							|  |  |  |   } | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2011-05-24 16:05:51 +00:00
										 |  |  | PyDoc_STRVAR(Matrix_identity_doc, | 
					
						
							| 
									
										
										
											
												Mathutils refactor & include in sphinx generated docs, (TODO, include getset'ers in docs)
 - Mathutils.MidpointVecs --> vector.lerp(other, fac)
 - Mathutils.AngleBetweenVecs --> vector.angle(other)
 - Mathutils.ProjectVecs --> vector.project(other)
 - Mathutils.DifferenceQuats --> quat.difference(other)
 - Mathutils.Slerp --> quat.slerp(other, fac)
 - Mathutils.Rand: removed, use pythons random module
 - Mathutils.RotationMatrix(angle, size, axis_flag, axis) --> Mathutils.RotationMatrix(angle, size, axis); merge axis & axis_flag args
 - Matrix.scalePart --> Matrix.scale_part
 - Matrix.translationPart --> Matrix.translation_part
 - Matrix.rotationPart --> Matrix.rotation_part
 - toMatrix --> to_matrix
 - toEuler --> to_euler
 - toQuat --> to_quat
 - Vector.toTrackQuat --> Vector.to_track_quat
											
										 
											2010-01-25 09:44:04 +00:00
										 |  |  |              ".. method:: identity()\n" | 
					
						
							|  |  |  |              "\n" | 
					
						
							|  |  |  |              "   Set the matrix to the identity matrix.\n" | 
					
						
							| 
									
										
										
										
											2010-01-27 21:33:39 +00:00
										 |  |  |              "\n" | 
					
						
							| 
									
										
										
										
											2017-03-22 14:49:12 -04:00
										 |  |  |              "   .. note:: An object with a location and rotation of zero, and a scale of one\n" | 
					
						
							| 
									
										
										
										
											2011-05-26 19:13:01 +00:00
										 |  |  |              "      will have an identity matrix.\n" | 
					
						
							| 
									
										
										
											
												Mathutils refactor & include in sphinx generated docs, (TODO, include getset'ers in docs)
 - Mathutils.MidpointVecs --> vector.lerp(other, fac)
 - Mathutils.AngleBetweenVecs --> vector.angle(other)
 - Mathutils.ProjectVecs --> vector.project(other)
 - Mathutils.DifferenceQuats --> quat.difference(other)
 - Mathutils.Slerp --> quat.slerp(other, fac)
 - Mathutils.Rand: removed, use pythons random module
 - Mathutils.RotationMatrix(angle, size, axis_flag, axis) --> Mathutils.RotationMatrix(angle, size, axis); merge axis & axis_flag args
 - Matrix.scalePart --> Matrix.scale_part
 - Matrix.translationPart --> Matrix.translation_part
 - Matrix.rotationPart --> Matrix.rotation_part
 - toMatrix --> to_matrix
 - toEuler --> to_euler
 - toQuat --> to_quat
 - Vector.toTrackQuat --> Vector.to_track_quat
											
										 
											2010-01-25 09:44:04 +00:00
										 |  |  |              "\n" | 
					
						
							| 
									
										
										
										
											2020-06-14 19:14:26 -04:00
										 |  |  |              "   .. seealso:: `Identity matrix <https://en.wikipedia.org/wiki/Identity_matrix>`__ " | 
					
						
							| 
									
										
										
										
											2017-03-22 14:49:12 -04:00
										 |  |  |              "on Wikipedia.\n"); | 
					
						
							| 
									
										
										
										
											2011-02-05 06:14:50 +00:00
										 |  |  | static PyObject *Matrix_identity(MatrixObject *self) | 
					
						
							| 
									
										
										
										
											2009-06-17 20:33:34 +00:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2019-03-30 06:12:48 +11:00
										 |  |  |   if (BaseMath_ReadCallback_ForWrite(self) == -1) { | 
					
						
							| 
									
										
										
										
											2009-06-23 13:34:45 +00:00
										 |  |  |     return NULL; | 
					
						
							| 
									
										
										
										
											2019-03-30 06:12:48 +11:00
										 |  |  |   } | 
					
						
							| 
									
										
										
										
											2011-02-04 03:06:23 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2011-12-20 04:11:23 +00:00
										 |  |  |   if (self->num_col != self->num_row) { | 
					
						
							| 
									
										
										
										
											2012-12-16 04:10:57 +00:00
										 |  |  |     PyErr_SetString(PyExc_ValueError, | 
					
						
							| 
									
										
										
										
											2011-09-19 14:29:21 +00:00
										 |  |  |                     "Matrix.identity(): " | 
					
						
							| 
									
										
										
										
											2011-07-14 01:25:05 +00:00
										 |  |  |                     "only square matrices are supported"); | 
					
						
							| 
									
										
										
										
											2009-06-17 20:33:34 +00:00
										 |  |  |     return NULL; | 
					
						
							|  |  |  |   } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-12-28 15:13:01 +11:00
										 |  |  |   matrix_identity_internal(self); | 
					
						
							| 
									
										
										
										
											2009-06-17 20:33:34 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-03-30 06:12:48 +11:00
										 |  |  |   if (BaseMath_WriteCallback(self) == -1) { | 
					
						
							| 
									
										
										
										
											2009-06-23 13:34:45 +00:00
										 |  |  |     return NULL; | 
					
						
							| 
									
										
										
										
											2019-03-30 06:12:48 +11:00
										 |  |  |   } | 
					
						
							| 
									
										
										
										
											2011-02-04 03:06:23 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2011-02-05 06:14:50 +00:00
										 |  |  |   Py_RETURN_NONE; | 
					
						
							| 
									
										
										
										
											2009-06-17 20:33:34 +00:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
											
												Mathutils refactor & include in sphinx generated docs, (TODO, include getset'ers in docs)
 - Mathutils.MidpointVecs --> vector.lerp(other, fac)
 - Mathutils.AngleBetweenVecs --> vector.angle(other)
 - Mathutils.ProjectVecs --> vector.project(other)
 - Mathutils.DifferenceQuats --> quat.difference(other)
 - Mathutils.Slerp --> quat.slerp(other, fac)
 - Mathutils.Rand: removed, use pythons random module
 - Mathutils.RotationMatrix(angle, size, axis_flag, axis) --> Mathutils.RotationMatrix(angle, size, axis); merge axis & axis_flag args
 - Matrix.scalePart --> Matrix.scale_part
 - Matrix.translationPart --> Matrix.translation_part
 - Matrix.rotationPart --> Matrix.rotation_part
 - toMatrix --> to_matrix
 - toEuler --> to_euler
 - toQuat --> to_quat
 - Vector.toTrackQuat --> Vector.to_track_quat
											
										 
											2010-01-25 09:44:04 +00:00
										 |  |  | /*---------------------------Matrix.copy() ------------------*/ | 
					
						
							| 
									
										
										
										
											2014-04-29 20:41:28 +10:00
										 |  |  | 
 | 
					
						
							|  |  |  | static PyObject *Matrix_copy_notest(MatrixObject *self, const float *matrix) | 
					
						
							|  |  |  | { | 
					
						
							| 
									
										
										
										
											2021-05-18 14:13:20 +10:00
										 |  |  |   return Matrix_CreatePyObject((const float *)matrix, self->num_col, self->num_row, Py_TYPE(self)); | 
					
						
							| 
									
										
										
										
											2014-04-29 20:41:28 +10:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2011-05-24 16:05:51 +00:00
										 |  |  | PyDoc_STRVAR(Matrix_copy_doc, | 
					
						
							| 
									
										
										
											
												Mathutils refactor & include in sphinx generated docs, (TODO, include getset'ers in docs)
 - Mathutils.MidpointVecs --> vector.lerp(other, fac)
 - Mathutils.AngleBetweenVecs --> vector.angle(other)
 - Mathutils.ProjectVecs --> vector.project(other)
 - Mathutils.DifferenceQuats --> quat.difference(other)
 - Mathutils.Slerp --> quat.slerp(other, fac)
 - Mathutils.Rand: removed, use pythons random module
 - Mathutils.RotationMatrix(angle, size, axis_flag, axis) --> Mathutils.RotationMatrix(angle, size, axis); merge axis & axis_flag args
 - Matrix.scalePart --> Matrix.scale_part
 - Matrix.translationPart --> Matrix.translation_part
 - Matrix.rotationPart --> Matrix.rotation_part
 - toMatrix --> to_matrix
 - toEuler --> to_euler
 - toQuat --> to_quat
 - Vector.toTrackQuat --> Vector.to_track_quat
											
										 
											2010-01-25 09:44:04 +00:00
										 |  |  |              ".. method:: copy()\n" | 
					
						
							|  |  |  |              "\n" | 
					
						
							|  |  |  |              "   Returns a copy of this matrix.\n" | 
					
						
							| 
									
										
										
										
											2010-01-27 21:33:39 +00:00
										 |  |  |              "\n" | 
					
						
							| 
									
										
										
											
												Mathutils refactor & include in sphinx generated docs, (TODO, include getset'ers in docs)
 - Mathutils.MidpointVecs --> vector.lerp(other, fac)
 - Mathutils.AngleBetweenVecs --> vector.angle(other)
 - Mathutils.ProjectVecs --> vector.project(other)
 - Mathutils.DifferenceQuats --> quat.difference(other)
 - Mathutils.Slerp --> quat.slerp(other, fac)
 - Mathutils.Rand: removed, use pythons random module
 - Mathutils.RotationMatrix(angle, size, axis_flag, axis) --> Mathutils.RotationMatrix(angle, size, axis); merge axis & axis_flag args
 - Matrix.scalePart --> Matrix.scale_part
 - Matrix.translationPart --> Matrix.translation_part
 - Matrix.rotationPart --> Matrix.rotation_part
 - toMatrix --> to_matrix
 - toEuler --> to_euler
 - toQuat --> to_quat
 - Vector.toTrackQuat --> Vector.to_track_quat
											
										 
											2010-01-25 09:44:04 +00:00
										 |  |  |              "   :return: an instance of itself\n" | 
					
						
							| 
									
										
										
										
											2011-02-04 09:35:20 +00:00
										 |  |  |              "   :rtype: :class:`Matrix`\n"); | 
					
						
							| 
									
										
										
										
											2011-02-05 06:14:50 +00:00
										 |  |  | static PyObject *Matrix_copy(MatrixObject *self) | 
					
						
							| 
									
										
										
										
											2009-06-17 20:33:34 +00:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2019-03-30 06:12:48 +11:00
										 |  |  |   if (BaseMath_ReadCallback(self) == -1) { | 
					
						
							| 
									
										
										
										
											2009-06-23 13:34:45 +00:00
										 |  |  |     return NULL; | 
					
						
							| 
									
										
										
										
											2019-03-30 06:12:48 +11:00
										 |  |  |   } | 
					
						
							| 
									
										
										
										
											2011-02-04 03:06:23 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-04-29 20:41:28 +10:00
										 |  |  |   return Matrix_copy_notest(self, self->matrix); | 
					
						
							| 
									
										
										
										
											2009-06-17 20:33:34 +00:00
										 |  |  | } | 
					
						
							| 
									
										
										
										
											2012-03-30 11:35:58 +00:00
										 |  |  | static PyObject *Matrix_deepcopy(MatrixObject *self, PyObject *args) | 
					
						
							|  |  |  | { | 
					
						
							| 
									
										
										
										
											2018-06-26 09:26:52 +02:00
										 |  |  |   if (!PyC_CheckArgs_DeepCopy(args)) { | 
					
						
							| 
									
										
										
										
											2012-03-30 11:35:58 +00:00
										 |  |  |     return NULL; | 
					
						
							| 
									
										
										
										
											2018-06-26 09:26:52 +02:00
										 |  |  |   } | 
					
						
							| 
									
										
										
										
											2012-03-30 11:35:58 +00:00
										 |  |  |   return Matrix_copy(self); | 
					
						
							|  |  |  | } | 
					
						
							| 
									
										
										
										
											2009-06-17 20:33:34 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  | /*----------------------------print object (internal)-------------*/ | 
					
						
							| 
									
										
										
										
											2011-12-24 13:26:30 +00:00
										 |  |  | /* print the object to screen */ | 
					
						
							| 
									
										
										
										
											2011-02-04 03:06:23 +00:00
										 |  |  | static PyObject *Matrix_repr(MatrixObject *self) | 
					
						
							| 
									
										
										
										
											2009-06-17 20:33:34 +00:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2011-12-20 05:48:35 +00:00
										 |  |  |   int col, row; | 
					
						
							| 
									
										
										
										
											2011-12-24 13:26:30 +00:00
										 |  |  |   PyObject *rows[MATRIX_MAX_DIM] = {NULL}; | 
					
						
							| 
									
										
										
										
											2019-04-17 06:17:24 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-03-30 06:12:48 +11:00
										 |  |  |   if (BaseMath_ReadCallback(self) == -1) { | 
					
						
							| 
									
										
										
										
											2009-06-23 13:34:45 +00:00
										 |  |  |     return NULL; | 
					
						
							| 
									
										
										
										
											2019-03-30 06:12:48 +11:00
										 |  |  |   } | 
					
						
							| 
									
										
										
										
											2019-04-17 06:17:24 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2011-12-22 01:05:03 +00:00
										 |  |  |   for (row = 0; row < self->num_row; row++) { | 
					
						
							| 
									
										
										
										
											2011-12-24 13:26:30 +00:00
										 |  |  |     rows[row] = PyTuple_New(self->num_col); | 
					
						
							| 
									
										
										
										
											2011-12-22 01:05:03 +00:00
										 |  |  |     for (col = 0; col < self->num_col; col++) { | 
					
						
							|  |  |  |       PyTuple_SET_ITEM(rows[row], col, PyFloat_FromDouble(MATRIX_ITEM(self, row, col))); | 
					
						
							| 
									
										
										
										
											2019-04-17 06:17:24 +02:00
										 |  |  |     } | 
					
						
							| 
									
										
										
										
											2009-06-17 20:33:34 +00:00
										 |  |  |   } | 
					
						
							| 
									
										
										
										
											2011-12-22 01:05:03 +00:00
										 |  |  |   switch (self->num_row) { | 
					
						
							| 
									
										
										
										
											2012-03-26 06:55:09 +00:00
										 |  |  |     case 2: | 
					
						
							|  |  |  |       return PyUnicode_FromFormat( | 
					
						
							|  |  |  |           "Matrix((%R,\n" | 
					
						
							| 
									
										
										
										
											2019-04-17 06:17:24 +02:00
										 |  |  |           "        %R))", | 
					
						
							|  |  |  |           rows[0], | 
					
						
							| 
									
										
										
										
											2012-03-26 06:55:09 +00:00
										 |  |  |           rows[1]); | 
					
						
							| 
									
										
										
										
											2019-04-17 06:17:24 +02:00
										 |  |  | 
 | 
					
						
							|  |  |  |     case 3: | 
					
						
							| 
									
										
										
										
											2012-03-26 06:55:09 +00:00
										 |  |  |       return PyUnicode_FromFormat( | 
					
						
							|  |  |  |           "Matrix((%R,\n" | 
					
						
							|  |  |  |           "        %R,\n" | 
					
						
							|  |  |  |           "        %R))", | 
					
						
							|  |  |  |           rows[0], | 
					
						
							|  |  |  |           rows[1], | 
					
						
							|  |  |  |           rows[2]); | 
					
						
							| 
									
										
										
										
											2019-04-17 06:17:24 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-03-26 06:55:09 +00:00
										 |  |  |     case 4: | 
					
						
							|  |  |  |       return PyUnicode_FromFormat( | 
					
						
							|  |  |  |           "Matrix((%R,\n" | 
					
						
							|  |  |  |           "        %R,\n" | 
					
						
							|  |  |  |           "        %R,\n" | 
					
						
							|  |  |  |           "        %R))", | 
					
						
							|  |  |  |           rows[0], | 
					
						
							|  |  |  |           rows[1], | 
					
						
							|  |  |  |           rows[2], | 
					
						
							|  |  |  |           rows[3]); | 
					
						
							| 
									
										
										
											
												bugfix [#24665] mathutils.Matrix initialization is counter-intuitive and generates bugs
was printing transposed, also nicer printing.
>>> from mathutils import Matrix
>>> Matrix()
Matrix((1.0, 0.0, 0.0, 0.0),
       (0.0, 1.0, 0.0, 0.0),
       (0.0, 0.0, 1.0, 0.0),
       (0.0, 0.0, 0.0, 1.0))
was...
Matrix((1.000000, 0.000000, 0.000000, 0.000000), (0.000000, 1.000000, 0.000000, 0.000000), (0.000000, 0.000000, 1.000000, 0.000000), (0.000000, 0.000000, 0.000000, 1.000000))
											
										 
											2010-11-12 02:50:57 +00:00
										 |  |  |   } | 
					
						
							| 
									
										
										
										
											2019-04-17 06:17:24 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2011-07-21 02:00:29 +00:00
										 |  |  |   Py_FatalError("Matrix(): invalid row size!"); | 
					
						
							| 
									
										
										
											
												bugfix [#24665] mathutils.Matrix initialization is counter-intuitive and generates bugs
was printing transposed, also nicer printing.
>>> from mathutils import Matrix
>>> Matrix()
Matrix((1.0, 0.0, 0.0, 0.0),
       (0.0, 1.0, 0.0, 0.0),
       (0.0, 0.0, 1.0, 0.0),
       (0.0, 0.0, 0.0, 1.0))
was...
Matrix((1.000000, 0.000000, 0.000000, 0.000000), (0.000000, 1.000000, 0.000000, 0.000000), (0.000000, 0.000000, 1.000000, 0.000000), (0.000000, 0.000000, 0.000000, 1.000000))
											
										 
											2010-11-12 02:50:57 +00:00
										 |  |  |   return NULL; | 
					
						
							| 
									
										
										
										
											2009-06-17 20:33:34 +00:00
										 |  |  | } | 
					
						
							| 
									
										
										
											
												bugfix [#24665] mathutils.Matrix initialization is counter-intuitive and generates bugs
was printing transposed, also nicer printing.
>>> from mathutils import Matrix
>>> Matrix()
Matrix((1.0, 0.0, 0.0, 0.0),
       (0.0, 1.0, 0.0, 0.0),
       (0.0, 0.0, 1.0, 0.0),
       (0.0, 0.0, 0.0, 1.0))
was...
Matrix((1.000000, 0.000000, 0.000000, 0.000000), (0.000000, 1.000000, 0.000000, 0.000000), (0.000000, 0.000000, 1.000000, 0.000000), (0.000000, 0.000000, 0.000000, 1.000000))
											
										 
											2010-11-12 02:50:57 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-12-08 01:16:59 +00:00
										 |  |  | #ifndef MATH_STANDALONE
 | 
					
						
							| 
									
										
										
										
											2011-12-24 13:26:30 +00:00
										 |  |  | static PyObject *Matrix_str(MatrixObject *self) | 
					
						
							| 
									
										
										
										
											2011-12-20 02:54:25 +00:00
										 |  |  | { | 
					
						
							|  |  |  |   DynStr *ds; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2011-12-20 03:37:55 +00:00
										 |  |  |   int maxsize[MATRIX_MAX_DIM]; | 
					
						
							|  |  |  |   int row, col; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-02-01 01:42:36 +00:00
										 |  |  |   char dummy_buf[64]; | 
					
						
							| 
									
										
										
										
											2011-12-20 02:54:25 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-03-30 06:12:48 +11:00
										 |  |  |   if (BaseMath_ReadCallback(self) == -1) { | 
					
						
							| 
									
										
										
										
											2011-12-20 02:54:25 +00:00
										 |  |  |     return NULL; | 
					
						
							| 
									
										
										
										
											2019-03-30 06:12:48 +11:00
										 |  |  |   } | 
					
						
							| 
									
										
										
										
											2011-12-20 02:54:25 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2011-12-24 13:26:30 +00:00
										 |  |  |   ds = BLI_dynstr_new(); | 
					
						
							| 
									
										
										
										
											2011-12-20 02:54:25 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  |   /* First determine the maximum width for each column */ | 
					
						
							| 
									
										
										
										
											2011-12-20 04:11:23 +00:00
										 |  |  |   for (col = 0; col < self->num_col; col++) { | 
					
						
							| 
									
										
										
										
											2011-12-24 13:26:30 +00:00
										 |  |  |     maxsize[col] = 0; | 
					
						
							| 
									
										
										
										
											2011-12-20 04:11:23 +00:00
										 |  |  |     for (row = 0; row < self->num_row; row++) { | 
					
						
							| 
									
										
										
										
											2021-05-27 17:16:08 +10:00
										 |  |  |       const int size = BLI_snprintf_rlen( | 
					
						
							| 
									
										
										
										
											2020-08-20 16:10:13 +10:00
										 |  |  |           dummy_buf, sizeof(dummy_buf), "%.4f", MATRIX_ITEM(self, row, col)); | 
					
						
							| 
									
										
										
										
											2012-10-23 16:21:55 +00:00
										 |  |  |       maxsize[col] = max_ii(maxsize[col], size); | 
					
						
							| 
									
										
										
										
											2011-12-20 02:54:25 +00:00
										 |  |  |     } | 
					
						
							|  |  |  |   } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   /* Now write the unicode string to be printed */ | 
					
						
							| 
									
										
										
										
											2011-12-20 04:11:23 +00:00
										 |  |  |   BLI_dynstr_appendf(ds, "<Matrix %dx%d (", self->num_row, self->num_col); | 
					
						
							|  |  |  |   for (row = 0; row < self->num_row; row++) { | 
					
						
							|  |  |  |     for (col = 0; col < self->num_col; col++) { | 
					
						
							| 
									
										
										
										
											2011-12-20 05:48:35 +00:00
										 |  |  |       BLI_dynstr_appendf(ds, col ? ", %*.4f" : "%*.4f", maxsize[col], MATRIX_ITEM(self, row, col)); | 
					
						
							| 
									
										
										
										
											2011-12-20 02:54:25 +00:00
										 |  |  |     } | 
					
						
							| 
									
										
										
										
											2012-02-01 01:42:36 +00:00
										 |  |  |     BLI_dynstr_append(ds, row + 1 != self->num_row ? ")\n            (" : ")"); | 
					
						
							| 
									
										
										
										
											2011-12-20 02:54:25 +00:00
										 |  |  |   } | 
					
						
							| 
									
										
										
										
											2011-12-20 04:11:23 +00:00
										 |  |  |   BLI_dynstr_append(ds, ">"); | 
					
						
							| 
									
										
										
										
											2011-12-20 02:54:25 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2011-12-20 03:37:55 +00:00
										 |  |  |   return mathutils_dynstr_to_py(ds); /* frees ds */ | 
					
						
							| 
									
										
										
										
											2011-12-20 02:54:25 +00:00
										 |  |  | } | 
					
						
							| 
									
										
										
										
											2012-12-08 01:16:59 +00:00
										 |  |  | #endif
 | 
					
						
							| 
									
										
										
										
											2011-12-20 02:54:25 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2011-12-24 13:26:30 +00:00
										 |  |  | static PyObject *Matrix_richcmpr(PyObject *a, PyObject *b, int op) | 
					
						
							| 
									
										
										
										
											2009-06-17 20:33:34 +00:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2011-02-05 10:40:42 +00:00
										 |  |  |   PyObject *res; | 
					
						
							| 
									
										
										
										
											2011-12-24 13:26:30 +00:00
										 |  |  |   int ok = -1; /* zero is true */ | 
					
						
							| 
									
										
										
										
											2019-04-17 06:17:24 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2011-02-05 10:40:42 +00:00
										 |  |  |   if (MatrixObject_Check(a) && MatrixObject_Check(b)) { | 
					
						
							| 
									
										
										
										
											2011-12-24 13:26:30 +00:00
										 |  |  |     MatrixObject *matA = (MatrixObject *)a; | 
					
						
							|  |  |  |     MatrixObject *matB = (MatrixObject *)b; | 
					
						
							| 
									
										
										
										
											2019-04-17 06:17:24 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-03-30 06:12:48 +11:00
										 |  |  |     if (BaseMath_ReadCallback(matA) == -1 || BaseMath_ReadCallback(matB) == -1) { | 
					
						
							| 
									
										
										
										
											2011-02-05 10:40:42 +00:00
										 |  |  |       return NULL; | 
					
						
							| 
									
										
										
										
											2019-03-30 06:12:48 +11:00
										 |  |  |     } | 
					
						
							| 
									
										
										
										
											2019-04-17 06:17:24 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-03-16 21:39:56 +00:00
										 |  |  |     ok = ((matA->num_row == matB->num_row) && (matA->num_col == matB->num_col) && | 
					
						
							|  |  |  |           EXPP_VectorsAreEqual(matA->matrix, matB->matrix, (matA->num_col * matA->num_row), 1)) ? | 
					
						
							|  |  |  |              0 : | 
					
						
							|  |  |  |              -1; | 
					
						
							| 
									
										
										
										
											2011-02-05 10:40:42 +00:00
										 |  |  |   } | 
					
						
							| 
									
										
										
										
											2019-04-17 06:17:24 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2011-02-05 10:40:42 +00:00
										 |  |  |   switch (op) { | 
					
						
							| 
									
										
										
										
											2012-03-16 21:39:56 +00:00
										 |  |  |     case Py_NE: | 
					
						
							| 
									
										
										
										
											2013-07-21 08:16:37 +00:00
										 |  |  |       ok = !ok; | 
					
						
							| 
									
										
										
										
											2017-05-20 14:01:03 +10:00
										 |  |  |       ATTR_FALLTHROUGH; | 
					
						
							| 
									
										
										
										
											2012-03-16 21:39:56 +00:00
										 |  |  |     case Py_EQ: | 
					
						
							|  |  |  |       res = ok ? Py_False : Py_True; | 
					
						
							|  |  |  |       break; | 
					
						
							| 
									
										
										
										
											2019-04-17 06:17:24 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-03-16 21:39:56 +00:00
										 |  |  |     case Py_LT: | 
					
						
							|  |  |  |     case Py_LE: | 
					
						
							|  |  |  |     case Py_GT: | 
					
						
							|  |  |  |     case Py_GE: | 
					
						
							|  |  |  |       res = Py_NotImplemented; | 
					
						
							|  |  |  |       break; | 
					
						
							|  |  |  |     default: | 
					
						
							|  |  |  |       PyErr_BadArgument(); | 
					
						
							|  |  |  |       return NULL; | 
					
						
							| 
									
										
										
										
											2009-06-17 20:33:34 +00:00
										 |  |  |   } | 
					
						
							| 
									
										
										
										
											2019-04-17 06:17:24 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-01-06 16:42:22 +11:00
										 |  |  |   return Py_INCREF_RET(res); | 
					
						
							| 
									
										
										
										
											2009-06-17 20:33:34 +00:00
										 |  |  | } | 
					
						
							| 
									
										
										
										
											2009-06-30 00:42:17 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-02-15 10:46:14 +11:00
										 |  |  | static Py_hash_t Matrix_hash(MatrixObject *self) | 
					
						
							|  |  |  | { | 
					
						
							| 
									
										
										
										
											2015-11-22 17:12:54 +01:00
										 |  |  |   float mat[MATRIX_MAX_DIM * MATRIX_MAX_DIM]; | 
					
						
							| 
									
										
										
										
											2015-02-15 10:46:14 +11:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-03-30 06:12:48 +11:00
										 |  |  |   if (BaseMath_ReadCallback(self) == -1) { | 
					
						
							| 
									
										
										
										
											2015-02-15 10:46:14 +11:00
										 |  |  |     return -1; | 
					
						
							| 
									
										
										
										
											2019-03-30 06:12:48 +11:00
										 |  |  |   } | 
					
						
							| 
									
										
										
										
											2015-02-15 10:46:14 +11:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-03-30 06:12:48 +11:00
										 |  |  |   if (BaseMathObject_Prepare_ForHash(self) == -1) { | 
					
						
							| 
									
										
										
										
											2015-02-15 10:46:14 +11:00
										 |  |  |     return -1; | 
					
						
							| 
									
										
										
										
											2019-03-30 06:12:48 +11:00
										 |  |  |   } | 
					
						
							| 
									
										
										
										
											2015-02-15 10:46:14 +11:00
										 |  |  | 
 | 
					
						
							|  |  |  |   matrix_transpose_internal(mat, self); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   return mathutils_array_hash(mat, self->num_row * self->num_col); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2009-06-17 20:33:34 +00:00
										 |  |  | /*---------------------SEQUENCE PROTOCOLS------------------------
 | 
					
						
							| 
									
										
										
										
											2012-03-03 20:36:09 +00:00
										 |  |  |  * ----------------------------len(object)------------------------ | 
					
						
							|  |  |  |  * sequence length */ | 
					
						
							| 
									
										
										
										
											2011-02-04 03:06:23 +00:00
										 |  |  | static int Matrix_len(MatrixObject *self) | 
					
						
							| 
									
										
										
										
											2009-06-17 20:33:34 +00:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2012-07-03 21:03:39 +00:00
										 |  |  |   return self->num_row; | 
					
						
							| 
									
										
										
										
											2009-06-17 20:33:34 +00:00
										 |  |  | } | 
					
						
							|  |  |  | /*----------------------------object[]---------------------------
 | 
					
						
							| 
									
										
										
										
											2012-03-03 20:36:09 +00:00
										 |  |  |  * sequence accessor (get) | 
					
						
							|  |  |  |  * the wrapped vector gives direct access to the matrix data */ | 
					
						
							| 
									
										
										
										
											2011-12-24 07:03:19 +00:00
										 |  |  | static PyObject *Matrix_item_row(MatrixObject *self, int row) | 
					
						
							| 
									
										
										
										
											2009-06-17 20:33:34 +00:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2019-03-30 06:12:48 +11:00
										 |  |  |   if (BaseMath_ReadCallback_ForWrite(self) == -1) { | 
					
						
							| 
									
										
										
										
											2009-06-23 13:34:45 +00:00
										 |  |  |     return NULL; | 
					
						
							| 
									
										
										
										
											2019-03-30 06:12:48 +11:00
										 |  |  |   } | 
					
						
							| 
									
										
										
										
											2011-02-04 03:06:23 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2011-12-22 01:05:03 +00:00
										 |  |  |   if (row < 0 || row >= self->num_row) { | 
					
						
							| 
									
										
										
										
											2011-07-14 01:25:05 +00:00
										 |  |  |     PyErr_SetString(PyExc_IndexError, | 
					
						
							|  |  |  |                     "matrix[attribute]: " | 
					
						
							|  |  |  |                     "array index out of range"); | 
					
						
							| 
									
										
										
										
											2009-06-17 20:33:34 +00:00
										 |  |  |     return NULL; | 
					
						
							|  |  |  |   } | 
					
						
							| 
									
										
										
										
											2011-12-24 06:13:58 +00:00
										 |  |  |   return Vector_CreatePyObject_cb( | 
					
						
							|  |  |  |       (PyObject *)self, self->num_col, mathutils_matrix_row_cb_index, row); | 
					
						
							| 
									
										
										
										
											2009-06-17 20:33:34 +00:00
										 |  |  | } | 
					
						
							| 
									
										
										
										
											2011-12-24 07:03:19 +00:00
										 |  |  | /* same but column access */ | 
					
						
							|  |  |  | static PyObject *Matrix_item_col(MatrixObject *self, int col) | 
					
						
							|  |  |  | { | 
					
						
							| 
									
										
										
										
											2019-03-30 06:12:48 +11:00
										 |  |  |   if (BaseMath_ReadCallback_ForWrite(self) == -1) { | 
					
						
							| 
									
										
										
										
											2011-12-24 07:03:19 +00:00
										 |  |  |     return NULL; | 
					
						
							| 
									
										
										
										
											2019-03-30 06:12:48 +11:00
										 |  |  |   } | 
					
						
							| 
									
										
										
										
											2011-12-24 07:03:19 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  |   if (col < 0 || col >= self->num_col) { | 
					
						
							|  |  |  |     PyErr_SetString(PyExc_IndexError, | 
					
						
							|  |  |  |                     "matrix[attribute]: " | 
					
						
							|  |  |  |                     "array index out of range"); | 
					
						
							|  |  |  |     return NULL; | 
					
						
							|  |  |  |   } | 
					
						
							|  |  |  |   return Vector_CreatePyObject_cb( | 
					
						
							|  |  |  |       (PyObject *)self, self->num_row, mathutils_matrix_col_cb_index, col); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2009-06-17 20:33:34 +00:00
										 |  |  | /*----------------------------object[]-------------------------
 | 
					
						
							| 
									
										
										
										
											2012-03-03 20:36:09 +00:00
										 |  |  |  * sequence accessor (set) */ | 
					
						
							| 
									
										
										
										
											2011-01-09 12:09:54 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2011-12-24 07:03:19 +00:00
										 |  |  | static int Matrix_ass_item_row(MatrixObject *self, int row, PyObject *value) | 
					
						
							| 
									
										
										
										
											2009-06-17 20:33:34 +00:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2011-12-22 01:05:03 +00:00
										 |  |  |   int col; | 
					
						
							| 
									
										
										
										
											2014-04-29 18:12:44 +10:00
										 |  |  |   float vec[MATRIX_MAX_DIM]; | 
					
						
							| 
									
										
										
										
											2019-03-30 06:12:48 +11:00
										 |  |  |   if (BaseMath_ReadCallback_ForWrite(self) == -1) { | 
					
						
							| 
									
										
										
										
											2009-06-23 13:34:45 +00:00
										 |  |  |     return -1; | 
					
						
							| 
									
										
										
										
											2019-03-30 06:12:48 +11:00
										 |  |  |   } | 
					
						
							| 
									
										
										
										
											2011-01-09 12:09:54 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2011-12-22 01:05:03 +00:00
										 |  |  |   if (row >= self->num_row || row < 0) { | 
					
						
							|  |  |  |     PyErr_SetString(PyExc_IndexError, "matrix[attribute] = x: bad row"); | 
					
						
							| 
									
										
										
										
											2009-06-17 20:33:34 +00:00
										 |  |  |     return -1; | 
					
						
							|  |  |  |   } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-07-29 10:37:39 +10:00
										 |  |  |   if (mathutils_array_parse( | 
					
						
							|  |  |  |           vec, self->num_col, self->num_col, value, "matrix[i] = value assignment") == -1) { | 
					
						
							| 
									
										
										
										
											2009-06-17 20:33:34 +00:00
										 |  |  |     return -1; | 
					
						
							|  |  |  |   } | 
					
						
							| 
									
										
										
										
											2011-01-09 12:09:54 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2011-12-22 01:05:03 +00:00
										 |  |  |   /* Since we are assigning a row we cannot memcpy */ | 
					
						
							|  |  |  |   for (col = 0; col < self->num_col; col++) { | 
					
						
							|  |  |  |     MATRIX_ITEM(self, row, col) = vec[col]; | 
					
						
							|  |  |  |   } | 
					
						
							| 
									
										
										
										
											2011-01-09 12:09:54 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  |   (void)BaseMath_WriteCallback(self); | 
					
						
							|  |  |  |   return 0; | 
					
						
							| 
									
										
										
										
											2009-06-17 20:33:34 +00:00
										 |  |  | } | 
					
						
							| 
									
										
										
										
											2011-12-24 07:03:19 +00:00
										 |  |  | static int Matrix_ass_item_col(MatrixObject *self, int col, PyObject *value) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  |   int row; | 
					
						
							| 
									
										
										
										
											2014-04-29 18:12:44 +10:00
										 |  |  |   float vec[MATRIX_MAX_DIM]; | 
					
						
							| 
									
										
										
										
											2019-03-30 06:12:48 +11:00
										 |  |  |   if (BaseMath_ReadCallback_ForWrite(self) == -1) { | 
					
						
							| 
									
										
										
										
											2011-12-24 07:03:19 +00:00
										 |  |  |     return -1; | 
					
						
							| 
									
										
										
										
											2019-03-30 06:12:48 +11:00
										 |  |  |   } | 
					
						
							| 
									
										
										
										
											2011-12-24 07:03:19 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  |   if (col >= self->num_col || col < 0) { | 
					
						
							|  |  |  |     PyErr_SetString(PyExc_IndexError, "matrix[attribute] = x: bad col"); | 
					
						
							|  |  |  |     return -1; | 
					
						
							|  |  |  |   } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-07-29 10:37:39 +10:00
										 |  |  |   if (mathutils_array_parse( | 
					
						
							|  |  |  |           vec, self->num_row, self->num_row, value, "matrix[i] = value assignment") == -1) { | 
					
						
							| 
									
										
										
										
											2011-12-24 07:03:19 +00:00
										 |  |  |     return -1; | 
					
						
							|  |  |  |   } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   /* Since we are assigning a row we cannot memcpy */ | 
					
						
							|  |  |  |   for (row = 0; row < self->num_row; row++) { | 
					
						
							|  |  |  |     MATRIX_ITEM(self, row, col) = vec[row]; | 
					
						
							|  |  |  |   } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   (void)BaseMath_WriteCallback(self); | 
					
						
							|  |  |  |   return 0; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2009-06-17 20:33:34 +00:00
										 |  |  | /*----------------------------object[z:y]------------------------
 | 
					
						
							| 
									
										
										
										
											2021-06-26 21:35:18 +10:00
										 |  |  |  * Sequence slice (get). */ | 
					
						
							| 
									
										
										
										
											2011-02-04 03:06:23 +00:00
										 |  |  | static PyObject *Matrix_slice(MatrixObject *self, int begin, int end) | 
					
						
							| 
									
										
										
										
											2009-06-17 20:33:34 +00:00
										 |  |  | { | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2010-12-24 03:51:34 +00:00
										 |  |  |   PyObject *tuple; | 
					
						
							| 
									
										
										
										
											2009-06-17 20:33:34 +00:00
										 |  |  |   int count; | 
					
						
							| 
									
										
										
										
											2011-02-04 03:06:23 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-03-30 06:12:48 +11:00
										 |  |  |   if (BaseMath_ReadCallback(self) == -1) { | 
					
						
							| 
									
										
										
										
											2009-06-23 13:34:45 +00:00
										 |  |  |     return NULL; | 
					
						
							| 
									
										
										
										
											2019-03-30 06:12:48 +11:00
										 |  |  |   } | 
					
						
							| 
									
										
										
										
											2009-06-17 20:33:34 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2011-12-22 01:05:03 +00:00
										 |  |  |   CLAMP(begin, 0, self->num_row); | 
					
						
							|  |  |  |   CLAMP(end, 0, self->num_row); | 
					
						
							| 
									
										
										
										
											2011-12-24 13:26:30 +00:00
										 |  |  |   begin = MIN2(begin, end); | 
					
						
							| 
									
										
										
										
											2009-06-17 20:33:34 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2011-12-24 13:26:30 +00:00
										 |  |  |   tuple = PyTuple_New(end - begin); | 
					
						
							|  |  |  |   for (count = begin; count < end; count++) { | 
					
						
							| 
									
										
										
										
											2010-12-24 03:51:34 +00:00
										 |  |  |     PyTuple_SET_ITEM(tuple, | 
					
						
							|  |  |  |                      count - begin, | 
					
						
							| 
									
										
										
										
											2012-03-17 22:31:57 +00:00
										 |  |  |                      Vector_CreatePyObject_cb( | 
					
						
							|  |  |  |                          (PyObject *)self, self->num_col, mathutils_matrix_row_cb_index, count)); | 
					
						
							| 
									
										
										
										
											2009-06-17 20:33:34 +00:00
										 |  |  |   } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2010-12-24 03:51:34 +00:00
										 |  |  |   return tuple; | 
					
						
							| 
									
										
										
										
											2009-06-17 20:33:34 +00:00
										 |  |  | } | 
					
						
							|  |  |  | /*----------------------------object[z:y]------------------------
 | 
					
						
							| 
									
										
										
										
											2021-06-26 21:35:18 +10:00
										 |  |  |  * Sequence slice (set). */ | 
					
						
							| 
									
										
										
										
											2011-02-04 03:06:23 +00:00
										 |  |  | static int Matrix_ass_slice(MatrixObject *self, int begin, int end, PyObject *value) | 
					
						
							| 
									
										
										
										
											2009-06-17 20:33:34 +00:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2015-07-29 09:58:10 +10:00
										 |  |  |   PyObject *value_fast; | 
					
						
							| 
									
										
										
										
											2019-04-17 06:17:24 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-03-30 06:12:48 +11:00
										 |  |  |   if (BaseMath_ReadCallback_ForWrite(self) == -1) { | 
					
						
							| 
									
										
										
										
											2009-06-23 13:34:45 +00:00
										 |  |  |     return -1; | 
					
						
							| 
									
										
										
										
											2019-03-30 06:12:48 +11:00
										 |  |  |   } | 
					
						
							| 
									
										
										
										
											2019-04-17 06:17:24 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2011-12-22 01:05:03 +00:00
										 |  |  |   CLAMP(begin, 0, self->num_row); | 
					
						
							|  |  |  |   CLAMP(end, 0, self->num_row); | 
					
						
							| 
									
										
										
										
											2011-03-19 11:12:48 +00:00
										 |  |  |   begin = MIN2(begin, end); | 
					
						
							| 
									
										
										
										
											2019-04-17 06:17:24 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2011-01-09 12:38:22 +00:00
										 |  |  |   /* non list/tuple cases */ | 
					
						
							| 
									
										
										
										
											2011-12-24 13:26:30 +00:00
										 |  |  |   if (!(value_fast = PySequence_Fast(value, "matrix[begin:end] = value"))) { | 
					
						
							| 
									
										
										
										
											2011-01-09 12:38:22 +00:00
										 |  |  |     /* PySequence_Fast sets the error */ | 
					
						
							|  |  |  |     return -1; | 
					
						
							|  |  |  |   } | 
					
						
							| 
									
										
										
										
											2019-04-17 06:17:24 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-08-07 12:41:06 +02:00
										 |  |  |   PyObject **value_fast_items = PySequence_Fast_ITEMS(value_fast); | 
					
						
							|  |  |  |   const int size = end - begin; | 
					
						
							|  |  |  |   int row, col; | 
					
						
							|  |  |  |   float mat[MATRIX_MAX_DIM * MATRIX_MAX_DIM]; | 
					
						
							|  |  |  |   float vec[4]; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   if (PySequence_Fast_GET_SIZE(value_fast) != size) { | 
					
						
							|  |  |  |     Py_DECREF(value_fast); | 
					
						
							|  |  |  |     PyErr_SetString(PyExc_ValueError, | 
					
						
							|  |  |  |                     "matrix[begin:end] = []: " | 
					
						
							|  |  |  |                     "size mismatch in slice assignment"); | 
					
						
							|  |  |  |     return -1; | 
					
						
							|  |  |  |   } | 
					
						
							| 
									
										
										
										
											2019-04-17 06:17:24 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-08-07 12:41:06 +02:00
										 |  |  |   memcpy(mat, self->matrix, self->num_col * self->num_row * sizeof(float)); | 
					
						
							| 
									
										
										
										
											2019-04-17 06:17:24 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-08-07 12:41:06 +02:00
										 |  |  |   /* parse sub items */ | 
					
						
							|  |  |  |   for (row = begin; row < end; row++) { | 
					
						
							|  |  |  |     /* parse each sub sequence */ | 
					
						
							|  |  |  |     PyObject *item = value_fast_items[row - begin]; | 
					
						
							| 
									
										
										
										
											2019-04-17 06:17:24 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-08-07 12:41:06 +02:00
										 |  |  |     if (mathutils_array_parse( | 
					
						
							|  |  |  |             vec, self->num_col, self->num_col, item, "matrix[begin:end] = value assignment") == | 
					
						
							|  |  |  |         -1) { | 
					
						
							|  |  |  |       Py_DECREF(value_fast); | 
					
						
							|  |  |  |       return -1; | 
					
						
							|  |  |  |     } | 
					
						
							| 
									
										
										
										
											2019-04-17 06:17:24 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-08-07 12:41:06 +02:00
										 |  |  |     for (col = 0; col < self->num_col; col++) { | 
					
						
							|  |  |  |       mat[col * self->num_row + row] = vec[col]; | 
					
						
							| 
									
										
										
										
											2009-06-17 20:33:34 +00:00
										 |  |  |     } | 
					
						
							| 
									
										
										
										
											2020-08-07 12:41:06 +02:00
										 |  |  |   } | 
					
						
							| 
									
										
										
										
											2019-04-17 06:17:24 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-08-07 12:41:06 +02:00
										 |  |  |   Py_DECREF(value_fast); | 
					
						
							| 
									
										
										
										
											2019-04-17 06:17:24 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-06-26 21:35:18 +10:00
										 |  |  |   /* Parsed well - now set in matrix. */ | 
					
						
							| 
									
										
										
										
											2020-08-07 12:41:06 +02:00
										 |  |  |   memcpy(self->matrix, mat, self->num_col * self->num_row * sizeof(float)); | 
					
						
							| 
									
										
										
										
											2019-04-17 06:17:24 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-08-07 12:41:06 +02:00
										 |  |  |   (void)BaseMath_WriteCallback(self); | 
					
						
							|  |  |  |   return 0; | 
					
						
							| 
									
										
										
										
											2009-06-17 20:33:34 +00:00
										 |  |  | } | 
					
						
							|  |  |  | /*------------------------NUMERIC PROTOCOLS----------------------
 | 
					
						
							| 
									
										
										
										
											2012-03-03 20:36:09 +00:00
										 |  |  |  *------------------------obj + obj------------------------------*/ | 
					
						
							| 
									
										
										
										
											2011-02-04 03:06:23 +00:00
										 |  |  | static PyObject *Matrix_add(PyObject *m1, PyObject *m2) | 
					
						
							| 
									
										
										
										
											2009-06-17 20:33:34 +00:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2014-04-29 18:12:44 +10:00
										 |  |  |   float mat[MATRIX_MAX_DIM * MATRIX_MAX_DIM]; | 
					
						
							| 
									
										
										
										
											2009-06-17 20:33:34 +00:00
										 |  |  |   MatrixObject *mat1 = NULL, *mat2 = NULL; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2011-12-24 13:26:30 +00:00
										 |  |  |   mat1 = (MatrixObject *)m1; | 
					
						
							|  |  |  |   mat2 = (MatrixObject *)m2; | 
					
						
							| 
									
										
										
										
											2009-06-17 20:33:34 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2011-10-13 01:29:08 +00:00
										 |  |  |   if (!MatrixObject_Check(m1) || !MatrixObject_Check(m2)) { | 
					
						
							| 
									
										
										
										
											2011-11-13 09:20:04 +00:00
										 |  |  |     PyErr_Format(PyExc_TypeError, | 
					
						
							|  |  |  |                  "Matrix addition: (%s + %s) " | 
					
						
							|  |  |  |                  "invalid type for this operation", | 
					
						
							|  |  |  |                  Py_TYPE(m1)->tp_name, | 
					
						
							|  |  |  |                  Py_TYPE(m2)->tp_name); | 
					
						
							| 
									
										
										
										
											2009-06-17 20:33:34 +00:00
										 |  |  |     return NULL; | 
					
						
							|  |  |  |   } | 
					
						
							| 
									
										
										
										
											2011-02-04 03:06:23 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-03-30 06:12:48 +11:00
										 |  |  |   if (BaseMath_ReadCallback(mat1) == -1 || BaseMath_ReadCallback(mat2) == -1) { | 
					
						
							| 
									
										
										
										
											2009-06-23 13:34:45 +00:00
										 |  |  |     return NULL; | 
					
						
							| 
									
										
										
										
											2019-03-30 06:12:48 +11:00
										 |  |  |   } | 
					
						
							| 
									
										
										
										
											2011-02-04 03:06:23 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2011-12-20 04:11:23 +00:00
										 |  |  |   if (mat1->num_col != mat2->num_col || mat1->num_row != mat2->num_row) { | 
					
						
							| 
									
										
										
										
											2012-12-16 04:10:57 +00:00
										 |  |  |     PyErr_SetString(PyExc_ValueError, | 
					
						
							| 
									
										
										
										
											2011-07-14 01:25:05 +00:00
										 |  |  |                     "Matrix addition: " | 
					
						
							|  |  |  |                     "matrices must have the same dimensions for this operation"); | 
					
						
							| 
									
										
										
										
											2009-06-17 20:33:34 +00:00
										 |  |  |     return NULL; | 
					
						
							|  |  |  |   } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2011-12-20 04:11:23 +00:00
										 |  |  |   add_vn_vnvn(mat, mat1->matrix, mat2->matrix, mat1->num_col * mat1->num_row); | 
					
						
							| 
									
										
										
										
											2009-06-17 20:33:34 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-01-04 17:03:54 +11:00
										 |  |  |   return Matrix_CreatePyObject(mat, mat1->num_col, mat1->num_row, Py_TYPE(mat1)); | 
					
						
							| 
									
										
										
										
											2009-06-17 20:33:34 +00:00
										 |  |  | } | 
					
						
							|  |  |  | /*------------------------obj - obj------------------------------
 | 
					
						
							| 
									
										
										
										
											2012-03-03 20:36:09 +00:00
										 |  |  |  * subtraction */ | 
					
						
							| 
									
										
										
										
											2011-02-04 03:06:23 +00:00
										 |  |  | static PyObject *Matrix_sub(PyObject *m1, PyObject *m2) | 
					
						
							| 
									
										
										
										
											2009-06-17 20:33:34 +00:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2014-04-29 18:12:44 +10:00
										 |  |  |   float mat[MATRIX_MAX_DIM * MATRIX_MAX_DIM]; | 
					
						
							| 
									
										
										
										
											2009-06-17 20:33:34 +00:00
										 |  |  |   MatrixObject *mat1 = NULL, *mat2 = NULL; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2011-12-24 13:26:30 +00:00
										 |  |  |   mat1 = (MatrixObject *)m1; | 
					
						
							|  |  |  |   mat2 = (MatrixObject *)m2; | 
					
						
							| 
									
										
										
										
											2009-06-17 20:33:34 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2011-10-13 01:29:08 +00:00
										 |  |  |   if (!MatrixObject_Check(m1) || !MatrixObject_Check(m2)) { | 
					
						
							| 
									
										
										
										
											2011-11-13 09:20:04 +00:00
										 |  |  |     PyErr_Format(PyExc_TypeError, | 
					
						
							|  |  |  |                  "Matrix subtraction: (%s - %s) " | 
					
						
							|  |  |  |                  "invalid type for this operation", | 
					
						
							| 
									
										
										
										
											2012-03-16 21:39:56 +00:00
										 |  |  |                  Py_TYPE(m1)->tp_name, | 
					
						
							|  |  |  |                  Py_TYPE(m2)->tp_name); | 
					
						
							| 
									
										
										
										
											2009-06-17 20:33:34 +00:00
										 |  |  |     return NULL; | 
					
						
							|  |  |  |   } | 
					
						
							| 
									
										
										
										
											2011-02-04 03:06:23 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-03-30 06:12:48 +11:00
										 |  |  |   if (BaseMath_ReadCallback(mat1) == -1 || BaseMath_ReadCallback(mat2) == -1) { | 
					
						
							| 
									
										
										
										
											2009-06-23 13:34:45 +00:00
										 |  |  |     return NULL; | 
					
						
							| 
									
										
										
										
											2019-03-30 06:12:48 +11:00
										 |  |  |   } | 
					
						
							| 
									
										
										
										
											2011-02-04 03:06:23 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2011-12-20 04:11:23 +00:00
										 |  |  |   if (mat1->num_col != mat2->num_col || mat1->num_row != mat2->num_row) { | 
					
						
							| 
									
										
										
										
											2012-12-16 04:10:57 +00:00
										 |  |  |     PyErr_SetString(PyExc_ValueError, | 
					
						
							| 
									
										
										
										
											2011-07-14 01:25:05 +00:00
										 |  |  |                     "Matrix addition: " | 
					
						
							|  |  |  |                     "matrices must have the same dimensions for this operation"); | 
					
						
							| 
									
										
										
										
											2009-06-17 20:33:34 +00:00
										 |  |  |     return NULL; | 
					
						
							|  |  |  |   } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2011-12-20 04:11:23 +00:00
										 |  |  |   sub_vn_vnvn(mat, mat1->matrix, mat2->matrix, mat1->num_col * mat1->num_row); | 
					
						
							| 
									
										
										
										
											2009-06-17 20:33:34 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-01-04 17:03:54 +11:00
										 |  |  |   return Matrix_CreatePyObject(mat, mat1->num_col, mat1->num_row, Py_TYPE(mat1)); | 
					
						
							| 
									
										
										
										
											2009-06-17 20:33:34 +00:00
										 |  |  | } | 
					
						
							|  |  |  | /*------------------------obj * obj------------------------------
 | 
					
						
							| 
									
										
										
										
											2018-08-10 14:53:38 +02:00
										 |  |  |  * element-wise multiplication */ | 
					
						
							| 
									
										
										
										
											2011-01-09 09:16:04 +00:00
										 |  |  | static PyObject *matrix_mul_float(MatrixObject *mat, const float scalar) | 
					
						
							|  |  |  | { | 
					
						
							| 
									
										
										
										
											2014-04-29 18:12:44 +10:00
										 |  |  |   float tmat[MATRIX_MAX_DIM * MATRIX_MAX_DIM]; | 
					
						
							| 
									
										
										
										
											2011-12-20 04:11:23 +00:00
										 |  |  |   mul_vn_vn_fl(tmat, mat->matrix, mat->num_col * mat->num_row, scalar); | 
					
						
							| 
									
										
										
										
											2015-01-04 17:03:54 +11:00
										 |  |  |   return Matrix_CreatePyObject(tmat, mat->num_col, mat->num_row, Py_TYPE(mat)); | 
					
						
							| 
									
										
										
										
											2011-01-09 09:16:04 +00:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2011-06-02 08:29:16 +00:00
										 |  |  | static PyObject *Matrix_mul(PyObject *m1, PyObject *m2) | 
					
						
							| 
									
										
										
										
											2009-06-17 20:33:34 +00:00
										 |  |  | { | 
					
						
							|  |  |  |   float scalar; | 
					
						
							| 
									
										
										
										
											2011-01-09 09:16:04 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2009-06-17 20:33:34 +00:00
										 |  |  |   MatrixObject *mat1 = NULL, *mat2 = NULL; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2011-10-13 01:29:08 +00:00
										 |  |  |   if (MatrixObject_Check(m1)) { | 
					
						
							| 
									
										
										
										
											2011-12-24 13:26:30 +00:00
										 |  |  |     mat1 = (MatrixObject *)m1; | 
					
						
							| 
									
										
										
										
											2019-03-30 06:12:48 +11:00
										 |  |  |     if (BaseMath_ReadCallback(mat1) == -1) { | 
					
						
							| 
									
										
										
										
											2009-06-23 13:34:45 +00:00
										 |  |  |       return NULL; | 
					
						
							| 
									
										
										
										
											2019-03-30 06:12:48 +11:00
										 |  |  |     } | 
					
						
							| 
									
										
										
										
											2009-06-23 13:34:45 +00:00
										 |  |  |   } | 
					
						
							| 
									
										
										
										
											2011-10-13 01:29:08 +00:00
										 |  |  |   if (MatrixObject_Check(m2)) { | 
					
						
							| 
									
										
										
										
											2011-12-24 13:26:30 +00:00
										 |  |  |     mat2 = (MatrixObject *)m2; | 
					
						
							| 
									
										
										
										
											2019-03-30 06:12:48 +11:00
										 |  |  |     if (BaseMath_ReadCallback(mat2) == -1) { | 
					
						
							| 
									
										
										
										
											2009-06-23 13:34:45 +00:00
										 |  |  |       return NULL; | 
					
						
							| 
									
										
										
										
											2019-03-30 06:12:48 +11:00
										 |  |  |     } | 
					
						
							| 
									
										
										
										
											2009-06-23 13:34:45 +00:00
										 |  |  |   } | 
					
						
							| 
									
										
										
										
											2009-06-17 20:33:34 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2011-10-13 01:29:08 +00:00
										 |  |  |   if (mat1 && mat2) { | 
					
						
							| 
									
										
										
										
											2011-12-24 13:26:30 +00:00
										 |  |  |     /* MATRIX * MATRIX */ | 
					
						
							| 
									
										
										
										
											2014-04-29 18:12:44 +10:00
										 |  |  |     float mat[MATRIX_MAX_DIM * MATRIX_MAX_DIM]; | 
					
						
							| 
									
										
										
										
											2011-12-26 00:42:35 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-08-10 14:53:38 +02:00
										 |  |  |     if ((mat1->num_row != mat2->num_row) || (mat1->num_col != mat2->num_col)) { | 
					
						
							|  |  |  |       PyErr_SetString(PyExc_ValueError, | 
					
						
							| 
									
										
										
										
											2018-08-22 10:10:12 +10:00
										 |  |  |                       "matrix1 * matrix2: matrix1 number of rows/columns " | 
					
						
							|  |  |  |                       "and the matrix2 number of rows/columns must be the same"); | 
					
						
							| 
									
										
										
										
											2018-08-10 14:53:38 +02:00
										 |  |  |       return NULL; | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     mul_vn_vnvn(mat, mat1->matrix, mat2->matrix, mat1->num_col * mat1->num_row); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     return Matrix_CreatePyObject(mat, mat2->num_col, mat1->num_row, Py_TYPE(mat1)); | 
					
						
							|  |  |  |   } | 
					
						
							| 
									
										
										
										
											2020-08-07 12:41:06 +02:00
										 |  |  |   if (mat2) { | 
					
						
							| 
									
										
										
										
											2021-06-26 21:35:18 +10:00
										 |  |  |     /* FLOAT/INT * MATRIX */ | 
					
						
							| 
									
										
										
										
											2018-08-10 14:53:38 +02:00
										 |  |  |     if (((scalar = PyFloat_AsDouble(m1)) == -1.0f && PyErr_Occurred()) == 0) { | 
					
						
							|  |  |  |       return matrix_mul_float(mat2, scalar); | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  |   } | 
					
						
							|  |  |  |   else if (mat1) { | 
					
						
							|  |  |  |     /* MATRIX * FLOAT/INT */ | 
					
						
							|  |  |  |     if (((scalar = PyFloat_AsDouble(m2)) == -1.0f && PyErr_Occurred()) == 0) { | 
					
						
							|  |  |  |       return matrix_mul_float(mat1, scalar); | 
					
						
							| 
									
										
										
										
											2019-04-17 06:17:24 +02:00
										 |  |  |     } | 
					
						
							| 
									
										
										
										
											2018-08-10 14:53:38 +02:00
										 |  |  |   } | 
					
						
							| 
									
										
										
										
											2019-04-17 06:17:24 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-08-10 14:53:38 +02:00
										 |  |  |   PyErr_Format(PyExc_TypeError, | 
					
						
							| 
									
										
										
										
											2018-08-22 10:10:12 +10:00
										 |  |  |                "Element-wise multiplication: " | 
					
						
							|  |  |  |                "not supported between '%.200s' and '%.200s' types", | 
					
						
							|  |  |  |                Py_TYPE(m1)->tp_name, | 
					
						
							|  |  |  |                Py_TYPE(m2)->tp_name); | 
					
						
							| 
									
										
										
										
											2018-08-10 14:53:38 +02:00
										 |  |  |   return NULL; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | /*------------------------obj *= obj------------------------------
 | 
					
						
							| 
									
										
										
										
											2019-08-04 12:51:44 +10:00
										 |  |  |  * In place element-wise multiplication */ | 
					
						
							| 
									
										
										
										
											2018-08-10 14:53:38 +02:00
										 |  |  | static PyObject *Matrix_imul(PyObject *m1, PyObject *m2) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  |   float scalar; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   MatrixObject *mat1 = NULL, *mat2 = NULL; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   if (MatrixObject_Check(m1)) { | 
					
						
							|  |  |  |     mat1 = (MatrixObject *)m1; | 
					
						
							| 
									
										
										
										
											2019-03-30 06:12:48 +11:00
										 |  |  |     if (BaseMath_ReadCallback(mat1) == -1) { | 
					
						
							| 
									
										
										
										
											2018-08-10 14:53:38 +02:00
										 |  |  |       return NULL; | 
					
						
							| 
									
										
										
										
											2019-03-30 06:12:48 +11:00
										 |  |  |     } | 
					
						
							| 
									
										
										
										
											2018-08-10 14:53:38 +02:00
										 |  |  |   } | 
					
						
							|  |  |  |   if (MatrixObject_Check(m2)) { | 
					
						
							|  |  |  |     mat2 = (MatrixObject *)m2; | 
					
						
							| 
									
										
										
										
											2019-03-30 06:12:48 +11:00
										 |  |  |     if (BaseMath_ReadCallback(mat2) == -1) { | 
					
						
							| 
									
										
										
										
											2018-08-10 14:53:38 +02:00
										 |  |  |       return NULL; | 
					
						
							| 
									
										
										
										
											2019-03-30 06:12:48 +11:00
										 |  |  |     } | 
					
						
							| 
									
										
										
										
											2018-08-10 14:53:38 +02:00
										 |  |  |   } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   if (mat1 && mat2) { | 
					
						
							|  |  |  |     /* MATRIX *= MATRIX */ | 
					
						
							|  |  |  |     if ((mat1->num_row != mat2->num_row) || (mat1->num_col != mat2->num_col)) { | 
					
						
							|  |  |  |       PyErr_SetString(PyExc_ValueError, | 
					
						
							| 
									
										
										
										
											2018-08-22 10:10:12 +10:00
										 |  |  |                       "matrix1 *= matrix2: matrix1 number of rows/columns " | 
					
						
							|  |  |  |                       "and the matrix2 number of rows/columns must be the same"); | 
					
						
							| 
									
										
										
										
											2018-08-10 14:53:38 +02:00
										 |  |  |       return NULL; | 
					
						
							|  |  |  |     } | 
					
						
							| 
									
										
										
										
											2019-04-17 06:17:24 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-08-10 14:53:38 +02:00
										 |  |  |     mul_vn_vn(mat1->matrix, mat2->matrix, mat1->num_col * mat1->num_row); | 
					
						
							|  |  |  |   } | 
					
						
							|  |  |  |   else if (mat1 && (((scalar = PyFloat_AsDouble(m2)) == -1.0f && PyErr_Occurred()) == 0)) { | 
					
						
							|  |  |  |     /* MATRIX *= FLOAT/INT */ | 
					
						
							|  |  |  |     mul_vn_fl(mat1->matrix, mat1->num_row * mat1->num_col, scalar); | 
					
						
							|  |  |  |   } | 
					
						
							|  |  |  |   else { | 
					
						
							|  |  |  |     PyErr_Format(PyExc_TypeError, | 
					
						
							| 
									
										
										
										
											2019-08-04 12:51:44 +10:00
										 |  |  |                  "In place element-wise multiplication: " | 
					
						
							| 
									
										
										
										
											2018-08-22 10:10:12 +10:00
										 |  |  |                  "not supported between '%.200s' and '%.200s' types", | 
					
						
							|  |  |  |                  Py_TYPE(m1)->tp_name, | 
					
						
							|  |  |  |                  Py_TYPE(m2)->tp_name); | 
					
						
							| 
									
										
										
										
											2018-08-10 14:53:38 +02:00
										 |  |  |     return NULL; | 
					
						
							|  |  |  |   } | 
					
						
							| 
									
										
										
										
											2019-04-17 06:17:24 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-08-10 14:53:38 +02:00
										 |  |  |   (void)BaseMath_WriteCallback(mat1); | 
					
						
							|  |  |  |   Py_INCREF(m1); | 
					
						
							|  |  |  |   return m1; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | /*------------------------obj @ obj------------------------------
 | 
					
						
							|  |  |  |  * matrix multiplication */ | 
					
						
							|  |  |  | static PyObject *Matrix_matmul(PyObject *m1, PyObject *m2) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  |   int vec_size; | 
					
						
							| 
									
										
										
										
											2019-04-17 06:17:24 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-08-10 14:53:38 +02:00
										 |  |  |   MatrixObject *mat1 = NULL, *mat2 = NULL; | 
					
						
							| 
									
										
										
										
											2019-04-17 06:17:24 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-08-10 14:53:38 +02:00
										 |  |  |   if (MatrixObject_Check(m1)) { | 
					
						
							|  |  |  |     mat1 = (MatrixObject *)m1; | 
					
						
							| 
									
										
										
										
											2019-03-30 06:12:48 +11:00
										 |  |  |     if (BaseMath_ReadCallback(mat1) == -1) { | 
					
						
							| 
									
										
										
										
											2018-08-10 14:53:38 +02:00
										 |  |  |       return NULL; | 
					
						
							| 
									
										
										
										
											2019-03-30 06:12:48 +11:00
										 |  |  |     } | 
					
						
							| 
									
										
										
										
											2018-08-10 14:53:38 +02:00
										 |  |  |   } | 
					
						
							|  |  |  |   if (MatrixObject_Check(m2)) { | 
					
						
							|  |  |  |     mat2 = (MatrixObject *)m2; | 
					
						
							| 
									
										
										
										
											2019-03-30 06:12:48 +11:00
										 |  |  |     if (BaseMath_ReadCallback(mat2) == -1) { | 
					
						
							| 
									
										
										
										
											2018-08-10 14:53:38 +02:00
										 |  |  |       return NULL; | 
					
						
							| 
									
										
										
										
											2019-03-30 06:12:48 +11:00
										 |  |  |     } | 
					
						
							| 
									
										
										
										
											2018-08-10 14:53:38 +02:00
										 |  |  |   } | 
					
						
							| 
									
										
										
										
											2019-04-17 06:17:24 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-08-10 14:53:38 +02:00
										 |  |  |   if (mat1 && mat2) { | 
					
						
							|  |  |  |     /* MATRIX @ MATRIX */ | 
					
						
							|  |  |  |     float mat[MATRIX_MAX_DIM * MATRIX_MAX_DIM]; | 
					
						
							| 
									
										
										
										
											2019-04-17 06:17:24 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2011-12-20 05:48:35 +00:00
										 |  |  |     int col, row, item; | 
					
						
							| 
									
										
										
										
											2019-04-17 06:17:24 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2011-12-21 21:21:27 +00:00
										 |  |  |     if (mat1->num_col != mat2->num_row) { | 
					
						
							|  |  |  |       PyErr_SetString(PyExc_ValueError, | 
					
						
							| 
									
										
										
										
											2018-08-22 10:10:12 +10:00
										 |  |  |                       "matrix1 * matrix2: matrix1 number of columns " | 
					
						
							|  |  |  |                       "and the matrix2 number of rows must be the same"); | 
					
						
							| 
									
										
										
										
											2011-12-21 21:21:27 +00:00
										 |  |  |       return NULL; | 
					
						
							|  |  |  |     } | 
					
						
							| 
									
										
										
										
											2019-04-17 06:17:24 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2011-12-20 05:48:35 +00:00
										 |  |  |     for (col = 0; col < mat2->num_col; col++) { | 
					
						
							|  |  |  |       for (row = 0; row < mat1->num_row; row++) { | 
					
						
							| 
									
										
										
										
											2011-12-26 00:42:35 +00:00
										 |  |  |         double dot = 0.0f; | 
					
						
							| 
									
										
										
										
											2011-12-20 05:48:35 +00:00
										 |  |  |         for (item = 0; item < mat1->num_col; item++) { | 
					
						
							| 
									
										
										
										
											2012-11-04 07:18:29 +00:00
										 |  |  |           dot += (double)(MATRIX_ITEM(mat1, row, item) * MATRIX_ITEM(mat2, item, col)); | 
					
						
							| 
									
										
										
										
											2009-06-17 20:33:34 +00:00
										 |  |  |         } | 
					
						
							| 
									
										
										
										
											2011-12-21 21:21:27 +00:00
										 |  |  |         mat[(col * mat1->num_row) + row] = (float)dot; | 
					
						
							| 
									
										
										
										
											2019-04-17 06:17:24 +02:00
										 |  |  |       } | 
					
						
							| 
									
										
										
										
											2009-06-17 20:33:34 +00:00
										 |  |  |     } | 
					
						
							| 
									
										
										
										
											2019-04-17 06:17:24 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-01-04 17:03:54 +11:00
										 |  |  |     return Matrix_CreatePyObject(mat, mat2->num_col, mat1->num_row, Py_TYPE(mat1)); | 
					
						
							| 
									
										
										
										
											2009-06-18 23:12:29 +00:00
										 |  |  |   } | 
					
						
							| 
									
										
										
										
											2020-08-07 12:41:06 +02:00
										 |  |  |   if (mat1) { | 
					
						
							| 
									
										
										
										
											2018-08-10 14:53:38 +02:00
										 |  |  |     /* MATRIX @ VECTOR */ | 
					
						
							| 
									
										
										
										
											2011-10-13 01:29:08 +00:00
										 |  |  |     if (VectorObject_Check(m2)) { | 
					
						
							| 
									
										
										
										
											2011-12-24 13:26:30 +00:00
										 |  |  |       VectorObject *vec2 = (VectorObject *)m2; | 
					
						
							| 
									
										
										
										
											2014-04-29 18:12:44 +10:00
										 |  |  |       float tvec[MATRIX_MAX_DIM]; | 
					
						
							| 
									
										
										
										
											2019-03-30 06:12:48 +11:00
										 |  |  |       if (BaseMath_ReadCallback(vec2) == -1) { | 
					
						
							| 
									
										
										
										
											2011-07-25 01:44:19 +00:00
										 |  |  |         return NULL; | 
					
						
							| 
									
										
										
										
											2019-03-30 06:12:48 +11:00
										 |  |  |       } | 
					
						
							| 
									
										
										
										
											2011-10-13 01:29:08 +00:00
										 |  |  |       if (column_vector_multiplication(tvec, vec2, mat1) == -1) { | 
					
						
							| 
									
										
										
										
											2011-07-25 01:44:19 +00:00
										 |  |  |         return NULL; | 
					
						
							|  |  |  |       } | 
					
						
							| 
									
										
										
										
											2019-04-17 06:17:24 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2011-12-21 21:21:27 +00:00
										 |  |  |       if (mat1->num_col == 4 && vec2->size == 3) { | 
					
						
							|  |  |  |         vec_size = 3; | 
					
						
							|  |  |  |       } | 
					
						
							|  |  |  |       else { | 
					
						
							|  |  |  |         vec_size = mat1->num_row; | 
					
						
							|  |  |  |       } | 
					
						
							| 
									
										
										
										
											2019-04-17 06:17:24 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-01-04 17:03:54 +11:00
										 |  |  |       return Vector_CreatePyObject(tvec, vec_size, Py_TYPE(m2)); | 
					
						
							| 
									
										
										
										
											2019-04-17 06:17:24 +02:00
										 |  |  |     } | 
					
						
							| 
									
										
										
										
											2011-07-25 01:44:19 +00:00
										 |  |  |   } | 
					
						
							| 
									
										
										
										
											2019-04-17 06:17:24 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-08-10 14:53:38 +02:00
										 |  |  |   PyErr_Format(PyExc_TypeError, | 
					
						
							| 
									
										
										
										
											2018-08-22 10:10:12 +10:00
										 |  |  |                "Matrix multiplication: " | 
					
						
							|  |  |  |                "not supported between '%.200s' and '%.200s' types", | 
					
						
							|  |  |  |                Py_TYPE(m1)->tp_name, | 
					
						
							|  |  |  |                Py_TYPE(m2)->tp_name); | 
					
						
							| 
									
										
										
										
											2018-08-10 14:53:38 +02:00
										 |  |  |   return NULL; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | /*------------------------obj @= obj------------------------------
 | 
					
						
							| 
									
										
										
										
											2019-08-04 12:51:44 +10:00
										 |  |  |  * In place matrix multiplication */ | 
					
						
							| 
									
										
										
										
											2018-08-10 14:53:38 +02:00
										 |  |  | static PyObject *Matrix_imatmul(PyObject *m1, PyObject *m2) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  |   MatrixObject *mat1 = NULL, *mat2 = NULL; | 
					
						
							| 
									
										
										
										
											2019-04-17 06:17:24 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-08-10 14:53:38 +02:00
										 |  |  |   if (MatrixObject_Check(m1)) { | 
					
						
							|  |  |  |     mat1 = (MatrixObject *)m1; | 
					
						
							| 
									
										
										
										
											2019-03-30 06:12:48 +11:00
										 |  |  |     if (BaseMath_ReadCallback(mat1) == -1) { | 
					
						
							| 
									
										
										
										
											2018-08-10 14:53:38 +02:00
										 |  |  |       return NULL; | 
					
						
							| 
									
										
										
										
											2019-03-30 06:12:48 +11:00
										 |  |  |     } | 
					
						
							| 
									
										
										
										
											2018-08-10 14:53:38 +02:00
										 |  |  |   } | 
					
						
							|  |  |  |   if (MatrixObject_Check(m2)) { | 
					
						
							|  |  |  |     mat2 = (MatrixObject *)m2; | 
					
						
							| 
									
										
										
										
											2019-03-30 06:12:48 +11:00
										 |  |  |     if (BaseMath_ReadCallback(mat2) == -1) { | 
					
						
							| 
									
										
										
										
											2018-08-10 14:53:38 +02:00
										 |  |  |       return NULL; | 
					
						
							| 
									
										
										
										
											2019-03-30 06:12:48 +11:00
										 |  |  |     } | 
					
						
							| 
									
										
										
										
											2018-08-10 14:53:38 +02:00
										 |  |  |   } | 
					
						
							| 
									
										
										
										
											2019-04-17 06:17:24 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-08-10 14:53:38 +02:00
										 |  |  |   if (mat1 && mat2) { | 
					
						
							|  |  |  |     /* MATRIX @= MATRIX */ | 
					
						
							|  |  |  |     float mat[MATRIX_MAX_DIM * MATRIX_MAX_DIM]; | 
					
						
							|  |  |  |     int col, row, item; | 
					
						
							| 
									
										
										
										
											2019-04-17 06:17:24 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-08-10 14:53:38 +02:00
										 |  |  |     if (mat1->num_col != mat2->num_row) { | 
					
						
							|  |  |  |       PyErr_SetString(PyExc_ValueError, | 
					
						
							| 
									
										
										
										
											2018-08-22 10:10:12 +10:00
										 |  |  |                       "matrix1 * matrix2: matrix1 number of columns " | 
					
						
							|  |  |  |                       "and the matrix2 number of rows must be the same"); | 
					
						
							| 
									
										
										
										
											2018-08-10 14:53:38 +02:00
										 |  |  |       return NULL; | 
					
						
							| 
									
										
										
										
											2009-06-17 20:33:34 +00:00
										 |  |  |     } | 
					
						
							| 
									
										
										
										
											2019-04-17 06:17:24 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-08-10 14:53:38 +02:00
										 |  |  |     for (col = 0; col < mat2->num_col; col++) { | 
					
						
							|  |  |  |       for (row = 0; row < mat1->num_row; row++) { | 
					
						
							|  |  |  |         double dot = 0.0f; | 
					
						
							|  |  |  |         for (item = 0; item < mat1->num_col; item++) { | 
					
						
							|  |  |  |           dot += (double)(MATRIX_ITEM(mat1, row, item) * MATRIX_ITEM(mat2, item, col)); | 
					
						
							|  |  |  |         } | 
					
						
							|  |  |  |         /* store in new matrix as overwriting original at this point will cause
 | 
					
						
							|  |  |  |          * subsequent iterations to use incorrect values */ | 
					
						
							|  |  |  |         mat[(col * mat1->num_row) + row] = (float)dot; | 
					
						
							| 
									
										
										
										
											2019-04-17 06:17:24 +02:00
										 |  |  |       } | 
					
						
							| 
									
										
										
										
											2018-08-10 14:53:38 +02:00
										 |  |  |     } | 
					
						
							| 
									
										
										
										
											2019-04-17 06:17:24 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-08-10 14:53:38 +02:00
										 |  |  |     /* copy matrix back */ | 
					
						
							| 
									
										
										
										
											2018-12-16 09:46:34 +11:00
										 |  |  |     memcpy(mat1->matrix, mat, (mat1->num_row * mat1->num_col) * sizeof(float)); | 
					
						
							| 
									
										
										
										
											2011-01-09 09:16:04 +00:00
										 |  |  |   } | 
					
						
							|  |  |  |   else { | 
					
						
							| 
									
										
										
										
											2018-08-10 14:53:38 +02:00
										 |  |  |     PyErr_Format(PyExc_TypeError, | 
					
						
							| 
									
										
										
										
											2019-08-04 12:51:44 +10:00
										 |  |  |                  "In place matrix multiplication: " | 
					
						
							| 
									
										
										
										
											2018-08-22 10:10:12 +10:00
										 |  |  |                  "not supported between '%.200s' and '%.200s' types", | 
					
						
							|  |  |  |                  Py_TYPE(m1)->tp_name, | 
					
						
							|  |  |  |                  Py_TYPE(m2)->tp_name); | 
					
						
							| 
									
										
										
										
											2018-08-10 14:53:38 +02:00
										 |  |  |     return NULL; | 
					
						
							| 
									
										
										
										
											2009-06-17 20:33:34 +00:00
										 |  |  |   } | 
					
						
							| 
									
										
										
										
											2019-04-17 06:17:24 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-08-10 14:53:38 +02:00
										 |  |  |   (void)BaseMath_WriteCallback(mat1); | 
					
						
							|  |  |  |   Py_INCREF(m1); | 
					
						
							|  |  |  |   return m1; | 
					
						
							| 
									
										
										
										
											2009-06-17 20:33:34 +00:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | /*-----------------PROTOCOL DECLARATIONS--------------------------*/ | 
					
						
							|  |  |  | static PySequenceMethods Matrix_SeqMethods = { | 
					
						
							| 
									
										
										
										
											2012-03-26 06:55:09 +00:00
										 |  |  |     (lenfunc)Matrix_len,                  /* sq_length */ | 
					
						
							|  |  |  |     (binaryfunc)NULL,                     /* sq_concat */ | 
					
						
							|  |  |  |     (ssizeargfunc)NULL,                   /* sq_repeat */ | 
					
						
							|  |  |  |     (ssizeargfunc)Matrix_item_row,        /* sq_item */ | 
					
						
							|  |  |  |     (ssizessizeargfunc)NULL,              /* sq_slice, deprecated */ | 
					
						
							|  |  |  |     (ssizeobjargproc)Matrix_ass_item_row, /* sq_ass_item */ | 
					
						
							|  |  |  |     (ssizessizeobjargproc)NULL,           /* sq_ass_slice, deprecated */ | 
					
						
							|  |  |  |     (objobjproc)NULL,                     /* sq_contains */ | 
					
						
							|  |  |  |     (binaryfunc)NULL,                     /* sq_inplace_concat */ | 
					
						
							|  |  |  |     (ssizeargfunc)NULL,                   /* sq_inplace_repeat */ | 
					
						
							| 
									
										
										
										
											2009-06-17 20:33:34 +00:00
										 |  |  | }; | 
					
						
							| 
									
										
										
										
											2009-06-28 13:27:06 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2011-12-24 13:26:30 +00:00
										 |  |  | static PyObject *Matrix_subscript(MatrixObject *self, PyObject *item) | 
					
						
							| 
									
										
										
										
											2009-07-01 13:31:36 +00:00
										 |  |  | { | 
					
						
							|  |  |  |   if (PyIndex_Check(item)) { | 
					
						
							|  |  |  |     Py_ssize_t i; | 
					
						
							|  |  |  |     i = PyNumber_AsSsize_t(item, PyExc_IndexError); | 
					
						
							| 
									
										
										
										
											2019-03-30 06:12:48 +11:00
										 |  |  |     if (i == -1 && PyErr_Occurred()) { | 
					
						
							| 
									
										
										
										
											2009-07-01 13:31:36 +00:00
										 |  |  |       return NULL; | 
					
						
							| 
									
										
										
										
											2019-03-30 06:12:48 +11:00
										 |  |  |     } | 
					
						
							|  |  |  |     if (i < 0) { | 
					
						
							| 
									
										
										
										
											2011-12-24 06:13:58 +00:00
										 |  |  |       i += self->num_row; | 
					
						
							| 
									
										
										
										
											2019-03-30 06:12:48 +11:00
										 |  |  |     } | 
					
						
							| 
									
										
										
										
											2011-12-24 07:03:19 +00:00
										 |  |  |     return Matrix_item_row(self, i); | 
					
						
							| 
									
										
										
										
											2011-11-16 03:56:34 +00:00
										 |  |  |   } | 
					
						
							| 
									
										
										
										
											2020-08-07 12:41:06 +02:00
										 |  |  |   if (PySlice_Check(item)) { | 
					
						
							| 
									
										
										
										
											2009-07-01 13:31:36 +00:00
										 |  |  |     Py_ssize_t start, stop, step, slicelength; | 
					
						
							| 
									
										
										
										
											2019-04-17 06:17:24 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-03-30 06:12:48 +11:00
										 |  |  |     if (PySlice_GetIndicesEx(item, self->num_row, &start, &stop, &step, &slicelength) < 0) { | 
					
						
							| 
									
										
										
										
											2009-07-01 13:31:36 +00:00
										 |  |  |       return NULL; | 
					
						
							| 
									
										
										
										
											2019-03-30 06:12:48 +11:00
										 |  |  |     } | 
					
						
							| 
									
										
										
										
											2019-04-17 06:17:24 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2009-07-01 13:31:36 +00:00
										 |  |  |     if (slicelength <= 0) { | 
					
						
							| 
									
										
										
										
											2011-02-04 03:39:06 +00:00
										 |  |  |       return PyTuple_New(0); | 
					
						
							| 
									
										
										
										
											2009-07-01 13:31:36 +00:00
										 |  |  |     } | 
					
						
							| 
									
										
										
										
											2020-08-07 12:41:06 +02:00
										 |  |  |     if (step == 1) { | 
					
						
							| 
									
										
										
										
											2009-07-01 13:31:36 +00:00
										 |  |  |       return Matrix_slice(self, start, stop); | 
					
						
							|  |  |  |     } | 
					
						
							| 
									
										
										
										
											2020-08-07 12:41:06 +02:00
										 |  |  | 
 | 
					
						
							|  |  |  |     PyErr_SetString(PyExc_IndexError, "slice steps not supported with matrices"); | 
					
						
							| 
									
										
										
										
											2009-07-01 13:31:36 +00:00
										 |  |  |     return NULL; | 
					
						
							|  |  |  |   } | 
					
						
							| 
									
										
										
										
											2020-08-07 12:41:06 +02:00
										 |  |  | 
 | 
					
						
							|  |  |  |   PyErr_Format( | 
					
						
							|  |  |  |       PyExc_TypeError, "matrix indices must be integers, not %.200s", Py_TYPE(item)->tp_name); | 
					
						
							|  |  |  |   return NULL; | 
					
						
							| 
									
										
										
										
											2009-07-01 13:31:36 +00:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2011-12-24 13:26:30 +00:00
										 |  |  | static int Matrix_ass_subscript(MatrixObject *self, PyObject *item, PyObject *value) | 
					
						
							| 
									
										
										
										
											2009-07-01 13:31:36 +00:00
										 |  |  | { | 
					
						
							|  |  |  |   if (PyIndex_Check(item)) { | 
					
						
							|  |  |  |     Py_ssize_t i = PyNumber_AsSsize_t(item, PyExc_IndexError); | 
					
						
							| 
									
										
										
										
											2019-03-30 06:12:48 +11:00
										 |  |  |     if (i == -1 && PyErr_Occurred()) { | 
					
						
							| 
									
										
										
										
											2009-07-01 13:31:36 +00:00
										 |  |  |       return -1; | 
					
						
							| 
									
										
										
										
											2019-03-30 06:12:48 +11:00
										 |  |  |     } | 
					
						
							|  |  |  |     if (i < 0) { | 
					
						
							| 
									
										
										
										
											2011-12-24 06:13:58 +00:00
										 |  |  |       i += self->num_row; | 
					
						
							| 
									
										
										
										
											2019-03-30 06:12:48 +11:00
										 |  |  |     } | 
					
						
							| 
									
										
										
										
											2011-12-24 07:03:19 +00:00
										 |  |  |     return Matrix_ass_item_row(self, i, value); | 
					
						
							| 
									
										
										
										
											2009-07-01 13:31:36 +00:00
										 |  |  |   } | 
					
						
							| 
									
										
										
										
											2020-08-07 12:41:06 +02:00
										 |  |  |   if (PySlice_Check(item)) { | 
					
						
							| 
									
										
										
										
											2009-07-01 13:31:36 +00:00
										 |  |  |     Py_ssize_t start, stop, step, slicelength; | 
					
						
							| 
									
										
										
										
											2019-04-17 06:17:24 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-03-30 06:12:48 +11:00
										 |  |  |     if (PySlice_GetIndicesEx(item, self->num_row, &start, &stop, &step, &slicelength) < 0) { | 
					
						
							| 
									
										
										
										
											2009-07-01 13:31:36 +00:00
										 |  |  |       return -1; | 
					
						
							| 
									
										
										
										
											2019-03-30 06:12:48 +11:00
										 |  |  |     } | 
					
						
							| 
									
										
										
										
											2019-04-17 06:17:24 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-03-30 06:12:48 +11:00
										 |  |  |     if (step == 1) { | 
					
						
							| 
									
										
										
										
											2009-07-01 13:31:36 +00:00
										 |  |  |       return Matrix_ass_slice(self, start, stop, value); | 
					
						
							| 
									
										
										
										
											2019-03-30 06:12:48 +11:00
										 |  |  |     } | 
					
						
							| 
									
										
										
										
											2020-08-07 12:41:06 +02:00
										 |  |  | 
 | 
					
						
							|  |  |  |     PyErr_SetString(PyExc_IndexError, "slice steps not supported with matrices"); | 
					
						
							| 
									
										
										
										
											2009-07-01 13:31:36 +00:00
										 |  |  |     return -1; | 
					
						
							|  |  |  |   } | 
					
						
							| 
									
										
										
										
											2020-08-07 12:41:06 +02:00
										 |  |  | 
 | 
					
						
							|  |  |  |   PyErr_Format( | 
					
						
							|  |  |  |       PyExc_TypeError, "matrix indices must be integers, not %.200s", Py_TYPE(item)->tp_name); | 
					
						
							|  |  |  |   return -1; | 
					
						
							| 
									
										
										
										
											2009-07-01 13:31:36 +00:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | static PyMappingMethods Matrix_AsMapping = { | 
					
						
							|  |  |  |     (lenfunc)Matrix_len, | 
					
						
							|  |  |  |     (binaryfunc)Matrix_subscript, | 
					
						
							| 
									
										
										
										
											2019-01-19 13:21:18 +11:00
										 |  |  |     (objobjargproc)Matrix_ass_subscript, | 
					
						
							| 
									
										
										
										
											2009-07-01 13:31:36 +00:00
										 |  |  | }; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2009-06-28 13:27:06 +00:00
										 |  |  | static PyNumberMethods Matrix_NumMethods = { | 
					
						
							| 
									
										
										
										
											2012-03-26 06:55:09 +00:00
										 |  |  |     (binaryfunc)Matrix_add,            /*nb_add*/ | 
					
						
							|  |  |  |     (binaryfunc)Matrix_sub,            /*nb_subtract*/ | 
					
						
							|  |  |  |     (binaryfunc)Matrix_mul,            /*nb_multiply*/ | 
					
						
							|  |  |  |     NULL,                              /*nb_remainder*/ | 
					
						
							|  |  |  |     NULL,                              /*nb_divmod*/ | 
					
						
							|  |  |  |     NULL,                              /*nb_power*/ | 
					
						
							|  |  |  |     (unaryfunc)0,                      /*nb_negative*/ | 
					
						
							|  |  |  |     (unaryfunc)0,                      /*tp_positive*/ | 
					
						
							|  |  |  |     (unaryfunc)0,                      /*tp_absolute*/ | 
					
						
							|  |  |  |     (inquiry)0,                        /*tp_bool*/ | 
					
						
							| 
									
										
										
										
											2014-04-29 19:58:37 +10:00
										 |  |  |     (unaryfunc)Matrix_inverted_noargs, /*nb_invert*/ | 
					
						
							| 
									
										
										
										
											2012-03-26 06:55:09 +00:00
										 |  |  |     NULL,                              /*nb_lshift*/ | 
					
						
							|  |  |  |     (binaryfunc)0,                     /*nb_rshift*/ | 
					
						
							|  |  |  |     NULL,                              /*nb_and*/ | 
					
						
							|  |  |  |     NULL,                              /*nb_xor*/ | 
					
						
							|  |  |  |     NULL,                              /*nb_or*/ | 
					
						
							|  |  |  |     NULL,                              /*nb_int*/ | 
					
						
							|  |  |  |     NULL,                              /*nb_reserved*/ | 
					
						
							|  |  |  |     NULL,                              /*nb_float*/ | 
					
						
							|  |  |  |     NULL,                              /* nb_inplace_add */ | 
					
						
							|  |  |  |     NULL,                              /* nb_inplace_subtract */ | 
					
						
							| 
									
										
										
										
											2018-08-10 14:53:38 +02:00
										 |  |  |     (binaryfunc)Matrix_imul,           /* nb_inplace_multiply */ | 
					
						
							| 
									
										
										
										
											2012-03-26 06:55:09 +00:00
										 |  |  |     NULL,                              /* nb_inplace_remainder */ | 
					
						
							|  |  |  |     NULL,                              /* nb_inplace_power */ | 
					
						
							|  |  |  |     NULL,                              /* nb_inplace_lshift */ | 
					
						
							|  |  |  |     NULL,                              /* nb_inplace_rshift */ | 
					
						
							|  |  |  |     NULL,                              /* nb_inplace_and */ | 
					
						
							|  |  |  |     NULL,                              /* nb_inplace_xor */ | 
					
						
							|  |  |  |     NULL,                              /* nb_inplace_or */ | 
					
						
							|  |  |  |     NULL,                              /* nb_floor_divide */ | 
					
						
							|  |  |  |     NULL,                              /* nb_true_divide */ | 
					
						
							|  |  |  |     NULL,                              /* nb_inplace_floor_divide */ | 
					
						
							|  |  |  |     NULL,                              /* nb_inplace_true_divide */ | 
					
						
							|  |  |  |     NULL,                              /* nb_index */ | 
					
						
							| 
									
										
										
										
											2018-08-10 14:53:38 +02:00
										 |  |  |     (binaryfunc)Matrix_matmul,         /* nb_matrix_multiply */ | 
					
						
							|  |  |  |     (binaryfunc)Matrix_imatmul,        /* nb_inplace_matrix_multiply */ | 
					
						
							| 
									
										
										
										
											2009-06-28 13:27:06 +00:00
										 |  |  | }; | 
					
						
							| 
									
										
										
										
											2009-06-18 23:12:29 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2011-12-25 11:36:26 +00:00
										 |  |  | PyDoc_STRVAR(Matrix_translation_doc, "The translation component of the matrix.\n\n:type: Vector"); | 
					
						
							| 
									
										
										
										
											2011-12-21 23:12:16 +00:00
										 |  |  | static PyObject *Matrix_translation_get(MatrixObject *self, void *UNUSED(closure)) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  |   PyObject *ret; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-03-30 06:12:48 +11:00
										 |  |  |   if (BaseMath_ReadCallback(self) == -1) { | 
					
						
							| 
									
										
										
										
											2011-12-21 23:12:16 +00:00
										 |  |  |     return NULL; | 
					
						
							| 
									
										
										
										
											2019-03-30 06:12:48 +11:00
										 |  |  |   } | 
					
						
							| 
									
										
										
										
											2011-12-21 23:12:16 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-06-26 21:35:18 +10:00
										 |  |  |   /* Must be 4x4 square matrix. */ | 
					
						
							| 
									
										
										
										
											2011-12-21 23:12:16 +00:00
										 |  |  |   if (self->num_row != 4 || self->num_col != 4) { | 
					
						
							|  |  |  |     PyErr_SetString(PyExc_AttributeError, | 
					
						
							|  |  |  |                     "Matrix.translation: " | 
					
						
							|  |  |  |                     "inappropriate matrix size, must be 4x4"); | 
					
						
							|  |  |  |     return NULL; | 
					
						
							|  |  |  |   } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2011-12-26 00:05:41 +00:00
										 |  |  |   ret = (PyObject *)Vector_CreatePyObject_cb( | 
					
						
							|  |  |  |       (PyObject *)self, 3, mathutils_matrix_translation_cb_index, 3); | 
					
						
							| 
									
										
										
										
											2011-12-21 23:12:16 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  |   return ret; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | static int Matrix_translation_set(MatrixObject *self, PyObject *value, void *UNUSED(closure)) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  |   float tvec[3]; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-03-30 06:12:48 +11:00
										 |  |  |   if (BaseMath_ReadCallback_ForWrite(self) == -1) { | 
					
						
							| 
									
										
										
										
											2011-12-21 23:12:16 +00:00
										 |  |  |     return -1; | 
					
						
							| 
									
										
										
										
											2019-03-30 06:12:48 +11:00
										 |  |  |   } | 
					
						
							| 
									
										
										
										
											2011-12-21 23:12:16 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-06-26 21:35:18 +10:00
										 |  |  |   /* Must be 4x4 square matrix. */ | 
					
						
							| 
									
										
										
										
											2011-12-21 23:12:16 +00:00
										 |  |  |   if (self->num_row != 4 || self->num_col != 4) { | 
					
						
							|  |  |  |     PyErr_SetString(PyExc_AttributeError, | 
					
						
							|  |  |  |                     "Matrix.translation: " | 
					
						
							|  |  |  |                     "inappropriate matrix size, must be 4x4"); | 
					
						
							|  |  |  |     return -1; | 
					
						
							|  |  |  |   } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-07-16 11:45:52 +10:00
										 |  |  |   if (mathutils_array_parse(tvec, 3, 3, value, "Matrix.translation") == -1) { | 
					
						
							| 
									
										
										
										
											2011-12-21 23:12:16 +00:00
										 |  |  |     return -1; | 
					
						
							| 
									
										
										
										
											2011-12-26 00:42:35 +00:00
										 |  |  |   } | 
					
						
							| 
									
										
										
										
											2011-12-21 23:12:16 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  |   copy_v3_v3(((float(*)[4])self->matrix)[3], tvec); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   (void)BaseMath_WriteCallback(self); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   return 0; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2011-12-25 11:36:26 +00:00
										 |  |  | PyDoc_STRVAR(Matrix_row_doc, | 
					
						
							| 
									
										
										
										
											2018-09-03 16:49:08 +02:00
										 |  |  |              "Access the matrix by rows (default), (read-only).\n\n:type: Matrix Access"); | 
					
						
							| 
									
										
										
										
											2011-12-25 11:36:26 +00:00
										 |  |  | static PyObject *Matrix_row_get(MatrixObject *self, void *UNUSED(closure)) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  |   return MatrixAccess_CreatePyObject(self, MAT_ACCESS_ROW); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | PyDoc_STRVAR( | 
					
						
							|  |  |  |     Matrix_col_doc, | 
					
						
							| 
									
										
										
										
											2018-09-03 16:49:08 +02:00
										 |  |  |     "Access the matrix by columns, 3x3 and 4x4 only, (read-only).\n\n:type: Matrix Access"); | 
					
						
							| 
									
										
										
										
											2011-12-25 11:36:26 +00:00
										 |  |  | static PyObject *Matrix_col_get(MatrixObject *self, void *UNUSED(closure)) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  |   return MatrixAccess_CreatePyObject(self, MAT_ACCESS_COL); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | PyDoc_STRVAR(Matrix_median_scale_doc, | 
					
						
							| 
									
										
										
										
											2012-02-24 06:44:04 +00:00
										 |  |  |              "The average scale applied to each axis (read-only).\n\n:type: float"); | 
					
						
							| 
									
										
										
										
											2011-05-18 15:31:00 +00:00
										 |  |  | static PyObject *Matrix_median_scale_get(MatrixObject *self, void *UNUSED(closure)) | 
					
						
							| 
									
										
										
										
											2010-01-02 22:47:56 +00:00
										 |  |  | { | 
					
						
							|  |  |  |   float mat[3][3]; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-03-30 06:12:48 +11:00
										 |  |  |   if (BaseMath_ReadCallback(self) == -1) { | 
					
						
							| 
									
										
										
										
											2010-01-02 22:47:56 +00:00
										 |  |  |     return NULL; | 
					
						
							| 
									
										
										
										
											2019-03-30 06:12:48 +11:00
										 |  |  |   } | 
					
						
							| 
									
										
										
										
											2010-01-02 22:47:56 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-06-26 21:35:18 +10:00
										 |  |  |   /* Must be 3-4 cols, 3-4 rows, square matrix. */ | 
					
						
							| 
									
										
										
										
											2011-12-20 04:11:23 +00:00
										 |  |  |   if ((self->num_row < 3) || (self->num_col < 3)) { | 
					
						
							| 
									
										
										
										
											2011-07-14 01:25:05 +00:00
										 |  |  |     PyErr_SetString(PyExc_AttributeError, | 
					
						
							| 
									
										
										
										
											2011-09-19 14:29:21 +00:00
										 |  |  |                     "Matrix.median_scale: " | 
					
						
							| 
									
										
										
										
											2011-07-14 01:25:05 +00:00
										 |  |  |                     "inappropriate matrix size, 3x3 minimum"); | 
					
						
							| 
									
										
										
										
											2010-01-02 22:47:56 +00:00
										 |  |  |     return NULL; | 
					
						
							|  |  |  |   } | 
					
						
							| 
									
										
										
										
											2011-01-25 16:32:41 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  |   matrix_as_3x3(mat, self); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2010-01-02 22:47:56 +00:00
										 |  |  |   return PyFloat_FromDouble(mat3_to_scale(mat)); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2011-12-25 11:36:26 +00:00
										 |  |  | PyDoc_STRVAR(Matrix_is_negative_doc, | 
					
						
							| 
									
										
										
										
											2012-02-24 06:44:04 +00:00
										 |  |  |              "True if this matrix results in a negative scale, 3x3 and 4x4 only, " | 
					
						
							|  |  |  |              "(read-only).\n\n:type: bool"); | 
					
						
							| 
									
										
										
										
											2011-05-18 15:31:00 +00:00
										 |  |  | static PyObject *Matrix_is_negative_get(MatrixObject *self, void *UNUSED(closure)) | 
					
						
							| 
									
										
										
										
											2010-01-30 13:15:39 +00:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2019-03-30 06:12:48 +11:00
										 |  |  |   if (BaseMath_ReadCallback(self) == -1) { | 
					
						
							| 
									
										
										
										
											2010-01-30 13:15:39 +00:00
										 |  |  |     return NULL; | 
					
						
							| 
									
										
										
										
											2019-03-30 06:12:48 +11:00
										 |  |  |   } | 
					
						
							| 
									
										
										
										
											2019-04-17 06:17:24 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-06-26 21:35:18 +10:00
										 |  |  |   /* Must be 3-4 cols, 3-4 rows, square matrix. */ | 
					
						
							| 
									
										
										
										
											2019-03-30 06:12:48 +11:00
										 |  |  |   if (self->num_row == 4 && self->num_col == 4) { | 
					
						
							| 
									
										
										
										
											2021-05-18 14:13:20 +10:00
										 |  |  |     return PyBool_FromLong(is_negative_m4((const float(*)[4])self->matrix)); | 
					
						
							| 
									
										
										
										
											2019-03-30 06:12:48 +11:00
										 |  |  |   } | 
					
						
							| 
									
										
										
										
											2020-08-07 12:41:06 +02:00
										 |  |  |   if (self->num_row == 3 && self->num_col == 3) { | 
					
						
							| 
									
										
										
										
											2021-05-18 14:13:20 +10:00
										 |  |  |     return PyBool_FromLong(is_negative_m3((const float(*)[3])self->matrix)); | 
					
						
							| 
									
										
										
										
											2019-03-30 06:12:48 +11:00
										 |  |  |   } | 
					
						
							| 
									
										
										
										
											2020-08-07 12:41:06 +02:00
										 |  |  | 
 | 
					
						
							|  |  |  |   PyErr_SetString(PyExc_AttributeError, | 
					
						
							|  |  |  |                   "Matrix.is_negative: " | 
					
						
							|  |  |  |                   "inappropriate matrix size - expects 3x3 or 4x4 matrix"); | 
					
						
							|  |  |  |   return NULL; | 
					
						
							| 
									
										
										
										
											2010-01-30 13:15:39 +00:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2011-12-25 11:36:26 +00:00
										 |  |  | PyDoc_STRVAR(Matrix_is_orthogonal_doc, | 
					
						
							| 
									
										
										
										
											2012-02-24 06:44:04 +00:00
										 |  |  |              "True if this matrix is orthogonal, 3x3 and 4x4 only, (read-only).\n\n:type: bool"); | 
					
						
							| 
									
										
										
										
											2011-05-18 15:31:00 +00:00
										 |  |  | static PyObject *Matrix_is_orthogonal_get(MatrixObject *self, void *UNUSED(closure)) | 
					
						
							|  |  |  | { | 
					
						
							| 
									
										
										
										
											2019-03-30 06:12:48 +11:00
										 |  |  |   if (BaseMath_ReadCallback(self) == -1) { | 
					
						
							| 
									
										
										
										
											2011-05-18 15:31:00 +00:00
										 |  |  |     return NULL; | 
					
						
							| 
									
										
										
										
											2019-03-30 06:12:48 +11:00
										 |  |  |   } | 
					
						
							| 
									
										
										
										
											2019-04-17 06:17:24 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-06-26 21:35:18 +10:00
										 |  |  |   /* Must be 3-4 cols, 3-4 rows, square matrix. */ | 
					
						
							| 
									
										
										
										
											2019-03-30 06:12:48 +11:00
										 |  |  |   if (self->num_row == 4 && self->num_col == 4) { | 
					
						
							| 
									
										
										
										
											2021-05-18 14:13:20 +10:00
										 |  |  |     return PyBool_FromLong(is_orthonormal_m4((const float(*)[4])self->matrix)); | 
					
						
							| 
									
										
										
										
											2019-03-30 06:12:48 +11:00
										 |  |  |   } | 
					
						
							| 
									
										
										
										
											2020-08-07 12:41:06 +02:00
										 |  |  |   if (self->num_row == 3 && self->num_col == 3) { | 
					
						
							| 
									
										
										
										
											2021-05-18 14:13:20 +10:00
										 |  |  |     return PyBool_FromLong(is_orthonormal_m3((const float(*)[3])self->matrix)); | 
					
						
							| 
									
										
										
										
											2019-03-30 06:12:48 +11:00
										 |  |  |   } | 
					
						
							| 
									
										
										
										
											2020-08-07 12:41:06 +02:00
										 |  |  | 
 | 
					
						
							|  |  |  |   PyErr_SetString(PyExc_AttributeError, | 
					
						
							|  |  |  |                   "Matrix.is_orthogonal: " | 
					
						
							|  |  |  |                   "inappropriate matrix size - expects 3x3 or 4x4 matrix"); | 
					
						
							|  |  |  |   return NULL; | 
					
						
							| 
									
										
										
										
											2011-05-18 15:31:00 +00:00
										 |  |  | } | 
					
						
							| 
									
										
										
										
											2010-01-30 13:15:39 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-04-02 12:36:00 +00:00
										 |  |  | PyDoc_STRVAR(Matrix_is_orthogonal_axis_vectors_doc, | 
					
						
							|  |  |  |              "True if this matrix has got orthogonal axis vectors, 3x3 and 4x4 only, " | 
					
						
							|  |  |  |              "(read-only).\n\n:type: bool"); | 
					
						
							|  |  |  | static PyObject *Matrix_is_orthogonal_axis_vectors_get(MatrixObject *self, void *UNUSED(closure)) | 
					
						
							| 
									
										
										
										
											2012-04-01 00:14:41 +00:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2019-03-30 06:12:48 +11:00
										 |  |  |   if (BaseMath_ReadCallback(self) == -1) { | 
					
						
							| 
									
										
										
										
											2012-04-01 00:14:41 +00:00
										 |  |  |     return NULL; | 
					
						
							| 
									
										
										
										
											2019-03-30 06:12:48 +11:00
										 |  |  |   } | 
					
						
							| 
									
										
										
										
											2019-04-17 06:17:24 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-06-26 21:35:18 +10:00
										 |  |  |   /* Must be 3-4 cols, 3-4 rows, square matrix. */ | 
					
						
							| 
									
										
										
										
											2019-03-30 06:12:48 +11:00
										 |  |  |   if (self->num_row == 4 && self->num_col == 4) { | 
					
						
							| 
									
										
										
										
											2021-05-18 14:13:20 +10:00
										 |  |  |     return PyBool_FromLong(is_orthogonal_m4((const float(*)[4])self->matrix)); | 
					
						
							| 
									
										
										
										
											2019-03-30 06:12:48 +11:00
										 |  |  |   } | 
					
						
							| 
									
										
										
										
											2020-08-07 12:41:06 +02:00
										 |  |  |   if (self->num_row == 3 && self->num_col == 3) { | 
					
						
							| 
									
										
										
										
											2021-05-18 14:13:20 +10:00
										 |  |  |     return PyBool_FromLong(is_orthogonal_m3((const float(*)[3])self->matrix)); | 
					
						
							| 
									
										
										
										
											2019-03-30 06:12:48 +11:00
										 |  |  |   } | 
					
						
							| 
									
										
										
										
											2020-08-07 12:41:06 +02:00
										 |  |  | 
 | 
					
						
							|  |  |  |   PyErr_SetString(PyExc_AttributeError, | 
					
						
							|  |  |  |                   "Matrix.is_orthogonal_axis_vectors: " | 
					
						
							|  |  |  |                   "inappropriate matrix size - expects 3x3 or 4x4 matrix"); | 
					
						
							|  |  |  |   return NULL; | 
					
						
							| 
									
										
										
										
											2012-04-01 00:14:41 +00:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2009-06-18 23:12:29 +00:00
										 |  |  | /*****************************************************************************/ | 
					
						
							|  |  |  | /* Python attributes get/set structure:                                      */ | 
					
						
							|  |  |  | /*****************************************************************************/ | 
					
						
							|  |  |  | static PyGetSetDef Matrix_getseters[] = { | 
					
						
							| 
									
										
										
										
											2019-12-20 10:42:57 +11:00
										 |  |  |     {"median_scale", (getter)Matrix_median_scale_get, (setter)NULL, Matrix_median_scale_doc, NULL}, | 
					
						
							|  |  |  |     {"translation", | 
					
						
							| 
									
										
										
										
											2011-12-25 11:36:26 +00:00
										 |  |  |      (getter)Matrix_translation_get, | 
					
						
							|  |  |  |      (setter)Matrix_translation_set, | 
					
						
							|  |  |  |      Matrix_translation_doc, | 
					
						
							| 
									
										
										
										
											2019-04-17 06:17:24 +02:00
										 |  |  |      NULL}, | 
					
						
							| 
									
										
										
										
											2019-12-20 10:42:57 +11:00
										 |  |  |     {"row", (getter)Matrix_row_get, (setter)NULL, Matrix_row_doc, NULL}, | 
					
						
							|  |  |  |     {"col", (getter)Matrix_col_get, (setter)NULL, Matrix_col_doc, NULL}, | 
					
						
							|  |  |  |     {"is_negative", (getter)Matrix_is_negative_get, (setter)NULL, Matrix_is_negative_doc, NULL}, | 
					
						
							|  |  |  |     {"is_orthogonal", | 
					
						
							| 
									
										
										
										
											2011-12-25 11:36:26 +00:00
										 |  |  |      (getter)Matrix_is_orthogonal_get, | 
					
						
							|  |  |  |      (setter)NULL, | 
					
						
							|  |  |  |      Matrix_is_orthogonal_doc, | 
					
						
							|  |  |  |      NULL}, | 
					
						
							| 
									
										
										
										
											2019-12-20 10:42:57 +11:00
										 |  |  |     {"is_orthogonal_axis_vectors", | 
					
						
							| 
									
										
										
										
											2012-04-02 12:36:00 +00:00
										 |  |  |      (getter)Matrix_is_orthogonal_axis_vectors_get, | 
					
						
							|  |  |  |      (setter)NULL, | 
					
						
							|  |  |  |      Matrix_is_orthogonal_axis_vectors_doc, | 
					
						
							|  |  |  |      NULL}, | 
					
						
							| 
									
										
										
										
											2019-12-20 10:42:57 +11:00
										 |  |  |     {"is_wrapped", | 
					
						
							| 
									
										
										
										
											2011-12-25 11:36:26 +00:00
										 |  |  |      (getter)BaseMathObject_is_wrapped_get, | 
					
						
							|  |  |  |      (setter)NULL, | 
					
						
							|  |  |  |      BaseMathObject_is_wrapped_doc, | 
					
						
							| 
									
										
										
										
											2015-02-15 14:10:46 +11:00
										 |  |  |      NULL}, | 
					
						
							| 
									
										
										
										
											2019-12-20 10:42:57 +11:00
										 |  |  |     {"is_frozen", | 
					
						
							| 
									
										
										
										
											2015-02-15 14:10:46 +11:00
										 |  |  |      (getter)BaseMathObject_is_frozen_get, | 
					
						
							|  |  |  |      (setter)NULL, | 
					
						
							|  |  |  |      BaseMathObject_is_frozen_doc, | 
					
						
							| 
									
										
										
										
											2012-03-26 06:55:09 +00:00
										 |  |  |      NULL}, | 
					
						
							| 
									
										
										
										
											2019-12-20 10:42:57 +11:00
										 |  |  |     {"owner", (getter)BaseMathObject_owner_get, (setter)NULL, BaseMathObject_owner_doc, NULL}, | 
					
						
							| 
									
										
										
										
											2011-03-19 11:12:48 +00:00
										 |  |  |     {NULL, NULL, NULL, NULL, NULL} /* Sentinel */ | 
					
						
							| 
									
										
										
										
											2009-06-18 23:12:29 +00:00
										 |  |  | }; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
											
												Mathutils refactor & include in sphinx generated docs, (TODO, include getset'ers in docs)
 - Mathutils.MidpointVecs --> vector.lerp(other, fac)
 - Mathutils.AngleBetweenVecs --> vector.angle(other)
 - Mathutils.ProjectVecs --> vector.project(other)
 - Mathutils.DifferenceQuats --> quat.difference(other)
 - Mathutils.Slerp --> quat.slerp(other, fac)
 - Mathutils.Rand: removed, use pythons random module
 - Mathutils.RotationMatrix(angle, size, axis_flag, axis) --> Mathutils.RotationMatrix(angle, size, axis); merge axis & axis_flag args
 - Matrix.scalePart --> Matrix.scale_part
 - Matrix.translationPart --> Matrix.translation_part
 - Matrix.rotationPart --> Matrix.rotation_part
 - toMatrix --> to_matrix
 - toEuler --> to_euler
 - toQuat --> to_quat
 - Vector.toTrackQuat --> Vector.to_track_quat
											
										 
											2010-01-25 09:44:04 +00:00
										 |  |  | /*-----------------------METHOD DEFINITIONS ----------------------*/ | 
					
						
							|  |  |  | static struct PyMethodDef Matrix_methods[] = { | 
					
						
							| 
									
										
										
										
											2021-06-24 15:56:58 +10:00
										 |  |  |     /* Derived values. */ | 
					
						
							| 
									
										
										
										
											2011-02-05 06:14:50 +00:00
										 |  |  |     {"determinant", (PyCFunction)Matrix_determinant, METH_NOARGS, Matrix_determinant_doc}, | 
					
						
							|  |  |  |     {"decompose", (PyCFunction)Matrix_decompose, METH_NOARGS, Matrix_decompose_doc}, | 
					
						
							| 
									
										
										
										
											2019-04-17 06:17:24 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-06-24 15:56:58 +10:00
										 |  |  |     /* In place only. */ | 
					
						
							| 
									
										
										
										
											2011-02-04 03:06:23 +00:00
										 |  |  |     {"zero", (PyCFunction)Matrix_zero, METH_NOARGS, Matrix_zero_doc}, | 
					
						
							|  |  |  |     {"identity", (PyCFunction)Matrix_identity, METH_NOARGS, Matrix_identity_doc}, | 
					
						
							| 
									
										
										
										
											2019-04-17 06:17:24 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-06-24 15:56:58 +10:00
										 |  |  |     /* Operate on original or copy. */ | 
					
						
							| 
									
										
										
										
											2011-02-04 03:06:23 +00:00
										 |  |  |     {"transpose", (PyCFunction)Matrix_transpose, METH_NOARGS, Matrix_transpose_doc}, | 
					
						
							| 
									
										
										
										
											2011-02-05 06:14:50 +00:00
										 |  |  |     {"transposed", (PyCFunction)Matrix_transposed, METH_NOARGS, Matrix_transposed_doc}, | 
					
						
							| 
									
										
										
										
											2012-12-16 04:05:16 +00:00
										 |  |  |     {"normalize", (PyCFunction)Matrix_normalize, METH_NOARGS, Matrix_normalize_doc}, | 
					
						
							|  |  |  |     {"normalized", (PyCFunction)Matrix_normalized, METH_NOARGS, Matrix_normalized_doc}, | 
					
						
							| 
									
										
										
										
											2014-04-29 19:58:37 +10:00
										 |  |  |     {"invert", (PyCFunction)Matrix_invert, METH_VARARGS, Matrix_invert_doc}, | 
					
						
							|  |  |  |     {"inverted", (PyCFunction)Matrix_inverted, METH_VARARGS, Matrix_inverted_doc}, | 
					
						
							| 
									
										
										
										
											2014-09-06 14:54:08 +02:00
										 |  |  |     {"invert_safe", (PyCFunction)Matrix_invert_safe, METH_NOARGS, Matrix_invert_safe_doc}, | 
					
						
							|  |  |  |     {"inverted_safe", (PyCFunction)Matrix_inverted_safe, METH_NOARGS, Matrix_inverted_safe_doc}, | 
					
						
							| 
									
										
										
										
											2012-10-29 03:36:55 +00:00
										 |  |  |     {"adjugate", (PyCFunction)Matrix_adjugate, METH_NOARGS, Matrix_adjugate_doc}, | 
					
						
							|  |  |  |     {"adjugated", (PyCFunction)Matrix_adjugated, METH_NOARGS, Matrix_adjugated_doc}, | 
					
						
							| 
									
										
										
										
											2020-02-20 15:09:44 +11:00
										 |  |  |     {"to_2x2", (PyCFunction)Matrix_to_2x2, METH_NOARGS, Matrix_to_2x2_doc}, | 
					
						
							| 
									
										
										
										
											2010-02-23 09:39:47 +00:00
										 |  |  |     {"to_3x3", (PyCFunction)Matrix_to_3x3, METH_NOARGS, Matrix_to_3x3_doc}, | 
					
						
							| 
									
										
										
										
											2011-02-05 06:14:50 +00:00
										 |  |  |     {"to_4x4", (PyCFunction)Matrix_to_4x4, METH_NOARGS, Matrix_to_4x4_doc}, | 
					
						
							| 
									
										
										
										
											2021-06-24 15:56:58 +10:00
										 |  |  |     /* TODO: {"resize_3x3", (PyCFunction) Matrix_resize3x3, METH_NOARGS, Matrix_resize3x3_doc}, */ | 
					
						
							| 
									
										
										
										
											2011-02-05 06:14:50 +00:00
										 |  |  |     {"resize_4x4", (PyCFunction)Matrix_resize_4x4, METH_NOARGS, Matrix_resize_4x4_doc}, | 
					
						
							| 
									
										
										
										
											2011-02-05 09:57:02 +00:00
										 |  |  |     {"rotate", (PyCFunction)Matrix_rotate, METH_O, Matrix_rotate_doc}, | 
					
						
							| 
									
										
										
										
											2019-04-17 06:17:24 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-06-24 15:56:58 +10:00
										 |  |  |     /* Return converted representation. */ | 
					
						
							| 
									
										
										
										
											2011-02-04 03:06:23 +00:00
										 |  |  |     {"to_euler", (PyCFunction)Matrix_to_euler, METH_VARARGS, Matrix_to_euler_doc}, | 
					
						
							| 
									
										
										
										
											2011-02-05 06:14:50 +00:00
										 |  |  |     {"to_quaternion", (PyCFunction)Matrix_to_quaternion, METH_NOARGS, Matrix_to_quaternion_doc}, | 
					
						
							|  |  |  |     {"to_scale", (PyCFunction)Matrix_to_scale, METH_NOARGS, Matrix_to_scale_doc}, | 
					
						
							|  |  |  |     {"to_translation", (PyCFunction)Matrix_to_translation, METH_NOARGS, Matrix_to_translation_doc}, | 
					
						
							| 
									
										
										
										
											2019-04-17 06:17:24 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-06-24 15:56:58 +10:00
										 |  |  |     /* Operation between 2 or more types. */ | 
					
						
							| 
									
										
										
										
											2011-02-05 06:14:50 +00:00
										 |  |  |     {"lerp", (PyCFunction)Matrix_lerp, METH_VARARGS, Matrix_lerp_doc}, | 
					
						
							| 
									
										
										
											
												Mathutils refactor & include in sphinx generated docs, (TODO, include getset'ers in docs)
 - Mathutils.MidpointVecs --> vector.lerp(other, fac)
 - Mathutils.AngleBetweenVecs --> vector.angle(other)
 - Mathutils.ProjectVecs --> vector.project(other)
 - Mathutils.DifferenceQuats --> quat.difference(other)
 - Mathutils.Slerp --> quat.slerp(other, fac)
 - Mathutils.Rand: removed, use pythons random module
 - Mathutils.RotationMatrix(angle, size, axis_flag, axis) --> Mathutils.RotationMatrix(angle, size, axis); merge axis & axis_flag args
 - Matrix.scalePart --> Matrix.scale_part
 - Matrix.translationPart --> Matrix.translation_part
 - Matrix.rotationPart --> Matrix.rotation_part
 - toMatrix --> to_matrix
 - toEuler --> to_euler
 - toQuat --> to_quat
 - Vector.toTrackQuat --> Vector.to_track_quat
											
										 
											2010-01-25 09:44:04 +00:00
										 |  |  |     {"copy", (PyCFunction)Matrix_copy, METH_NOARGS, Matrix_copy_doc}, | 
					
						
							|  |  |  |     {"__copy__", (PyCFunction)Matrix_copy, METH_NOARGS, Matrix_copy_doc}, | 
					
						
							| 
									
										
										
										
											2012-03-30 11:35:58 +00:00
										 |  |  |     {"__deepcopy__", (PyCFunction)Matrix_deepcopy, METH_VARARGS, Matrix_copy_doc}, | 
					
						
							| 
									
										
										
										
											2019-04-17 06:17:24 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-06-24 15:56:58 +10:00
										 |  |  |     /* Base-math methods. */ | 
					
						
							| 
									
										
										
										
											2015-02-15 11:26:31 +11:00
										 |  |  |     {"freeze", (PyCFunction)BaseMathObject_freeze, METH_NOARGS, BaseMathObject_freeze_doc}, | 
					
						
							| 
									
										
										
										
											2019-04-17 06:17:24 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-06-24 15:56:58 +10:00
										 |  |  |     /* Class methods. */ | 
					
						
							| 
									
										
										
										
											2012-01-24 01:56:44 +00:00
										 |  |  |     {"Identity", (PyCFunction)C_Matrix_Identity, METH_VARARGS | METH_CLASS, C_Matrix_Identity_doc}, | 
					
						
							| 
									
										
										
										
											2010-08-11 16:40:36 +00:00
										 |  |  |     {"Rotation", (PyCFunction)C_Matrix_Rotation, METH_VARARGS | METH_CLASS, C_Matrix_Rotation_doc}, | 
					
						
							|  |  |  |     {"Scale", (PyCFunction)C_Matrix_Scale, METH_VARARGS | METH_CLASS, C_Matrix_Scale_doc}, | 
					
						
							|  |  |  |     {"Shear", (PyCFunction)C_Matrix_Shear, METH_VARARGS | METH_CLASS, C_Matrix_Shear_doc}, | 
					
						
							| 
									
										
										
										
											2019-05-19 14:52:11 +03:00
										 |  |  |     {"Diagonal", (PyCFunction)C_Matrix_Diagonal, METH_O | METH_CLASS, C_Matrix_Diagonal_doc}, | 
					
						
							| 
									
										
										
										
											2010-08-11 16:40:36 +00:00
										 |  |  |     {"Translation", | 
					
						
							|  |  |  |      (PyCFunction)C_Matrix_Translation, | 
					
						
							|  |  |  |      METH_O | METH_CLASS, | 
					
						
							|  |  |  |      C_Matrix_Translation_doc}, | 
					
						
							|  |  |  |     {"OrthoProjection", | 
					
						
							|  |  |  |      (PyCFunction)C_Matrix_OrthoProjection, | 
					
						
							|  |  |  |      METH_VARARGS | METH_CLASS, | 
					
						
							|  |  |  |      C_Matrix_OrthoProjection_doc}, | 
					
						
							| 
									
										
										
										
											2021-05-14 19:46:19 +03:00
										 |  |  |     {"LocRotScale", | 
					
						
							|  |  |  |      (PyCFunction)C_Matrix_LocRotScale, | 
					
						
							|  |  |  |      METH_VARARGS | METH_CLASS, | 
					
						
							|  |  |  |      C_Matrix_LocRotScale_doc}, | 
					
						
							| 
									
										
										
										
											2019-02-03 14:01:45 +11:00
										 |  |  |     {NULL, NULL, 0, NULL}, | 
					
						
							| 
									
										
										
											
												Mathutils refactor & include in sphinx generated docs, (TODO, include getset'ers in docs)
 - Mathutils.MidpointVecs --> vector.lerp(other, fac)
 - Mathutils.AngleBetweenVecs --> vector.angle(other)
 - Mathutils.ProjectVecs --> vector.project(other)
 - Mathutils.DifferenceQuats --> quat.difference(other)
 - Mathutils.Slerp --> quat.slerp(other, fac)
 - Mathutils.Rand: removed, use pythons random module
 - Mathutils.RotationMatrix(angle, size, axis_flag, axis) --> Mathutils.RotationMatrix(angle, size, axis); merge axis & axis_flag args
 - Matrix.scalePart --> Matrix.scale_part
 - Matrix.translationPart --> Matrix.translation_part
 - Matrix.rotationPart --> Matrix.rotation_part
 - toMatrix --> to_matrix
 - toEuler --> to_euler
 - toQuat --> to_quat
 - Vector.toTrackQuat --> Vector.to_track_quat
											
										 
											2010-01-25 09:44:04 +00:00
										 |  |  | }; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2009-06-17 20:33:34 +00:00
										 |  |  | /*------------------PY_OBECT DEFINITION--------------------------*/ | 
					
						
							| 
									
										
										
										
											2011-05-24 16:05:51 +00:00
										 |  |  | PyDoc_STRVAR( | 
					
						
							|  |  |  |     matrix_doc, | 
					
						
							| 
									
										
										
										
											2015-02-01 16:06:32 +01:00
										 |  |  |     ".. class:: Matrix([rows])\n" | 
					
						
							|  |  |  |     "\n" | 
					
						
							|  |  |  |     "   This object gives access to Matrices in Blender, supporting square and rectangular\n" | 
					
						
							|  |  |  |     "   matrices from 2x2 up to 4x4.\n" | 
					
						
							|  |  |  |     "\n" | 
					
						
							|  |  |  |     "   :param rows: Sequence of rows.\n" | 
					
						
							| 
									
										
										
										
											2018-09-03 16:49:08 +02:00
										 |  |  |     "      When omitted, a 4x4 identity matrix is constructed.\n" | 
					
						
							| 
									
										
										
										
											2015-02-01 16:06:32 +01:00
										 |  |  |     "   :type rows: 2d number sequence\n"); | 
					
						
							| 
									
										
										
										
											2009-06-17 20:33:34 +00:00
										 |  |  | PyTypeObject matrix_Type = { | 
					
						
							|  |  |  |     PyVarObject_HEAD_INIT(NULL, 0) "Matrix", /*tp_name*/ | 
					
						
							| 
									
										
										
										
											2012-03-26 06:55:09 +00:00
										 |  |  |     sizeof(MatrixObject),                    /*tp_basicsize*/ | 
					
						
							|  |  |  |     0,                                       /*tp_itemsize*/ | 
					
						
							|  |  |  |     (destructor)BaseMathObject_dealloc,      /*tp_dealloc*/ | 
					
						
							| 
									
										
										
										
											2019-10-16 14:44:36 +11:00
										 |  |  |     (printfunc)NULL,                         /*tp_print*/ | 
					
						
							| 
									
										
										
										
											2012-03-26 06:55:09 +00:00
										 |  |  |     NULL,                                    /*tp_getattr*/ | 
					
						
							|  |  |  |     NULL,                                    /*tp_setattr*/ | 
					
						
							|  |  |  |     NULL,                                    /*tp_compare*/ | 
					
						
							|  |  |  |     (reprfunc)Matrix_repr,                   /*tp_repr*/ | 
					
						
							|  |  |  |     &Matrix_NumMethods,                      /*tp_as_number*/ | 
					
						
							|  |  |  |     &Matrix_SeqMethods,                      /*tp_as_sequence*/ | 
					
						
							|  |  |  |     &Matrix_AsMapping,                       /*tp_as_mapping*/ | 
					
						
							| 
									
										
										
										
											2015-02-15 10:46:14 +11:00
										 |  |  |     (hashfunc)Matrix_hash,                   /*tp_hash*/ | 
					
						
							| 
									
										
										
										
											2012-03-26 06:55:09 +00:00
										 |  |  |     NULL,                                    /*tp_call*/ | 
					
						
							| 
									
										
										
										
											2012-12-08 01:16:59 +00:00
										 |  |  | #ifndef MATH_STANDALONE
 | 
					
						
							| 
									
										
										
										
											2012-03-26 06:55:09 +00:00
										 |  |  |     (reprfunc)Matrix_str, /*tp_str*/ | 
					
						
							| 
									
										
										
										
											2012-12-08 01:16:59 +00:00
										 |  |  | #else
 | 
					
						
							|  |  |  |     NULL, /*tp_str*/ | 
					
						
							|  |  |  | #endif
 | 
					
						
							| 
									
										
										
										
											2012-03-26 06:55:09 +00:00
										 |  |  |     NULL,                                                          /*tp_getattro*/ | 
					
						
							|  |  |  |     NULL,                                                          /*tp_setattro*/ | 
					
						
							|  |  |  |     NULL,                                                          /*tp_as_buffer*/ | 
					
						
							| 
									
										
										
										
											2011-02-24 04:58:51 +00:00
										 |  |  |     Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE | Py_TPFLAGS_HAVE_GC, /*tp_flags*/ | 
					
						
							| 
									
										
										
										
											2012-03-26 06:55:09 +00:00
										 |  |  |     matrix_doc,                                                    /*tp_doc*/ | 
					
						
							| 
									
										
										
										
											2012-10-20 20:20:02 +00:00
										 |  |  |     (traverseproc)BaseMathObject_traverse,                         /* tp_traverse */ | 
					
						
							|  |  |  |     (inquiry)BaseMathObject_clear,                                 /*tp_clear*/ | 
					
						
							| 
									
										
										
										
											2012-03-26 06:55:09 +00:00
										 |  |  |     (richcmpfunc)Matrix_richcmpr,                                  /*tp_richcompare*/ | 
					
						
							|  |  |  |     0,                                                             /*tp_weaklistoffset*/ | 
					
						
							|  |  |  |     NULL,                                                          /*tp_iter*/ | 
					
						
							|  |  |  |     NULL,                                                          /*tp_iternext*/ | 
					
						
							|  |  |  |     Matrix_methods,                                                /*tp_methods*/ | 
					
						
							|  |  |  |     NULL,                                                          /*tp_members*/ | 
					
						
							|  |  |  |     Matrix_getseters,                                              /*tp_getset*/ | 
					
						
							|  |  |  |     NULL,                                                          /*tp_base*/ | 
					
						
							|  |  |  |     NULL,                                                          /*tp_dict*/ | 
					
						
							|  |  |  |     NULL,                                                          /*tp_descr_get*/ | 
					
						
							|  |  |  |     NULL,                                                          /*tp_descr_set*/ | 
					
						
							|  |  |  |     0,                                                             /*tp_dictoffset*/ | 
					
						
							|  |  |  |     NULL,                                                          /*tp_init*/ | 
					
						
							|  |  |  |     NULL,                                                          /*tp_alloc*/ | 
					
						
							|  |  |  |     Matrix_new,                                                    /*tp_new*/ | 
					
						
							|  |  |  |     NULL,                                                          /*tp_free*/ | 
					
						
							|  |  |  |     NULL,                                                          /*tp_is_gc*/ | 
					
						
							|  |  |  |     NULL,                                                          /*tp_bases*/ | 
					
						
							|  |  |  |     NULL,                                                          /*tp_mro*/ | 
					
						
							|  |  |  |     NULL,                                                          /*tp_cache*/ | 
					
						
							|  |  |  |     NULL,                                                          /*tp_subclasses*/ | 
					
						
							|  |  |  |     NULL,                                                          /*tp_weaklist*/ | 
					
						
							| 
									
										
										
										
											2019-04-16 16:40:47 +02:00
										 |  |  |     NULL,                                                          /*tp_del*/ | 
					
						
							| 
									
										
										
										
											2009-06-17 20:33:34 +00:00
										 |  |  | }; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-01-04 17:03:54 +11:00
										 |  |  | PyObject *Matrix_CreatePyObject(const float *mat, | 
					
						
							| 
									
										
										
										
											2020-02-20 15:38:58 +11:00
										 |  |  |                                 const ushort num_col, | 
					
						
							|  |  |  |                                 const ushort num_row, | 
					
						
							| 
									
										
										
										
											2015-01-04 17:03:54 +11:00
										 |  |  |                                 PyTypeObject *base_type) | 
					
						
							| 
									
										
										
										
											2009-06-17 20:33:34 +00:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2011-02-24 05:46:57 +00:00
										 |  |  |   MatrixObject *self; | 
					
						
							| 
									
										
										
										
											2015-01-04 17:03:54 +11:00
										 |  |  |   float *mat_alloc; | 
					
						
							| 
									
										
										
										
											2019-04-17 06:17:24 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2011-12-19 05:14:09 +00:00
										 |  |  |   /* matrix objects can be any 2-4row x 2-4col matrix */ | 
					
						
							| 
									
										
										
										
											2011-12-20 04:11:23 +00:00
										 |  |  |   if (num_col < 2 || num_col > 4 || num_row < 2 || num_row > 4) { | 
					
						
							| 
									
										
										
										
											2011-07-14 01:25:05 +00:00
										 |  |  |     PyErr_SetString(PyExc_RuntimeError, | 
					
						
							|  |  |  |                     "Matrix(): " | 
					
						
							|  |  |  |                     "row and column sizes must be between 2 and 4"); | 
					
						
							| 
									
										
										
										
											2011-02-24 05:46:57 +00:00
										 |  |  |     return NULL; | 
					
						
							| 
									
										
										
										
											2009-06-17 20:33:34 +00:00
										 |  |  |   } | 
					
						
							| 
									
										
										
										
											2019-04-17 06:17:24 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-01-04 17:03:54 +11:00
										 |  |  |   mat_alloc = PyMem_Malloc(num_col * num_row * sizeof(float)); | 
					
						
							|  |  |  |   if (UNLIKELY(mat_alloc == NULL)) { | 
					
						
							|  |  |  |     PyErr_SetString(PyExc_MemoryError, | 
					
						
							|  |  |  |                     "Matrix(): " | 
					
						
							|  |  |  |                     "problem allocating data"); | 
					
						
							|  |  |  |     return NULL; | 
					
						
							|  |  |  |   } | 
					
						
							| 
									
										
										
										
											2019-04-17 06:17:24 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-01-04 17:03:54 +11:00
										 |  |  |   self = BASE_MATH_NEW(MatrixObject, matrix_Type, base_type); | 
					
						
							| 
									
										
										
										
											2011-10-13 01:29:08 +00:00
										 |  |  |   if (self) { | 
					
						
							| 
									
										
										
										
											2015-01-04 17:03:54 +11:00
										 |  |  |     self->matrix = mat_alloc; | 
					
						
							| 
									
										
										
										
											2011-12-20 04:11:23 +00:00
										 |  |  |     self->num_col = num_col; | 
					
						
							|  |  |  |     self->num_row = num_row; | 
					
						
							| 
									
										
										
										
											2019-04-17 06:17:24 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2011-02-24 05:46:57 +00:00
										 |  |  |     /* init callbacks as NULL */ | 
					
						
							| 
									
										
										
										
											2011-12-24 13:26:30 +00:00
										 |  |  |     self->cb_user = NULL; | 
					
						
							|  |  |  |     self->cb_type = self->cb_subtype = 0; | 
					
						
							| 
									
										
										
										
											2019-04-17 06:17:24 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-06-26 21:35:18 +10:00
										 |  |  |     if (mat) { /* If a float array passed. */ | 
					
						
							| 
									
										
										
										
											2015-01-04 17:03:54 +11:00
										 |  |  |       memcpy(self->matrix, mat, num_col * num_row * sizeof(float)); | 
					
						
							| 
									
										
										
										
											2009-06-17 20:33:34 +00:00
										 |  |  |     } | 
					
						
							| 
									
										
										
										
											2015-01-04 17:03:54 +11:00
										 |  |  |     else if (num_col == num_row) { | 
					
						
							|  |  |  |       /* or if no arguments are passed return identity matrix for square matrices */ | 
					
						
							|  |  |  |       matrix_identity_internal(self); | 
					
						
							| 
									
										
										
										
											2011-02-24 04:58:51 +00:00
										 |  |  |     } | 
					
						
							| 
									
										
										
										
											2011-02-24 05:46:57 +00:00
										 |  |  |     else { | 
					
						
							| 
									
										
										
										
											2015-01-04 17:03:54 +11:00
										 |  |  |       /* otherwise zero everything */ | 
					
						
							|  |  |  |       memset(self->matrix, 0, num_col * num_row * sizeof(float)); | 
					
						
							| 
									
										
										
										
											2009-06-17 20:33:34 +00:00
										 |  |  |     } | 
					
						
							| 
									
										
										
										
											2015-01-04 17:03:54 +11:00
										 |  |  |     self->flag = BASE_MATH_FLAG_DEFAULT; | 
					
						
							|  |  |  |   } | 
					
						
							|  |  |  |   else { | 
					
						
							|  |  |  |     PyMem_Free(mat_alloc); | 
					
						
							|  |  |  |   } | 
					
						
							| 
									
										
										
										
											2019-04-17 06:17:24 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-01-04 17:03:54 +11:00
										 |  |  |   return (PyObject *)self; | 
					
						
							|  |  |  | } | 
					
						
							| 
									
										
										
										
											2019-04-17 06:17:24 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-01-04 17:03:54 +11:00
										 |  |  | PyObject *Matrix_CreatePyObject_wrap(float *mat, | 
					
						
							| 
									
										
										
										
											2020-02-20 15:38:58 +11:00
										 |  |  |                                      const ushort num_col, | 
					
						
							|  |  |  |                                      const ushort num_row, | 
					
						
							| 
									
										
										
										
											2015-01-04 17:03:54 +11:00
										 |  |  |                                      PyTypeObject *base_type) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  |   MatrixObject *self; | 
					
						
							| 
									
										
										
										
											2019-04-17 06:17:24 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-01-04 17:03:54 +11:00
										 |  |  |   /* matrix objects can be any 2-4row x 2-4col matrix */ | 
					
						
							|  |  |  |   if (num_col < 2 || num_col > 4 || num_row < 2 || num_row > 4) { | 
					
						
							|  |  |  |     PyErr_SetString(PyExc_RuntimeError, | 
					
						
							|  |  |  |                     "Matrix(): " | 
					
						
							|  |  |  |                     "row and column sizes must be between 2 and 4"); | 
					
						
							|  |  |  |     return NULL; | 
					
						
							|  |  |  |   } | 
					
						
							| 
									
										
										
										
											2019-04-17 06:17:24 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-01-04 17:03:54 +11:00
										 |  |  |   self = BASE_MATH_NEW(MatrixObject, matrix_Type, base_type); | 
					
						
							|  |  |  |   if (self) { | 
					
						
							|  |  |  |     self->num_col = num_col; | 
					
						
							|  |  |  |     self->num_row = num_row; | 
					
						
							| 
									
										
										
										
											2019-04-17 06:17:24 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-01-04 17:03:54 +11:00
										 |  |  |     /* init callbacks as NULL */ | 
					
						
							|  |  |  |     self->cb_user = NULL; | 
					
						
							|  |  |  |     self->cb_type = self->cb_subtype = 0; | 
					
						
							| 
									
										
										
										
											2019-04-17 06:17:24 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-01-04 17:03:54 +11:00
										 |  |  |     self->matrix = mat; | 
					
						
							|  |  |  |     self->flag = BASE_MATH_FLAG_DEFAULT | BASE_MATH_FLAG_IS_WRAP; | 
					
						
							| 
									
										
										
										
											2011-02-24 04:58:51 +00:00
										 |  |  |   } | 
					
						
							| 
									
										
										
										
											2011-02-24 05:46:57 +00:00
										 |  |  |   return (PyObject *)self; | 
					
						
							| 
									
										
										
										
											2009-06-17 20:33:34 +00:00
										 |  |  | } | 
					
						
							| 
									
										
										
										
											2009-06-22 04:26:48 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-02-20 15:38:58 +11:00
										 |  |  | PyObject *Matrix_CreatePyObject_cb( | 
					
						
							|  |  |  |     PyObject *cb_user, const ushort num_col, const ushort num_row, uchar cb_type, uchar cb_subtype) | 
					
						
							| 
									
										
										
										
											2009-06-23 13:34:45 +00:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2015-01-04 17:03:54 +11:00
										 |  |  |   MatrixObject *self = (MatrixObject *)Matrix_CreatePyObject(NULL, num_col, num_row, NULL); | 
					
						
							| 
									
										
										
										
											2011-10-13 01:29:08 +00:00
										 |  |  |   if (self) { | 
					
						
							| 
									
										
										
										
											2011-02-24 05:46:57 +00:00
										 |  |  |     Py_INCREF(cb_user); | 
					
						
							| 
									
										
										
										
											2012-03-17 22:31:57 +00:00
										 |  |  |     self->cb_user = cb_user; | 
					
						
							|  |  |  |     self->cb_type = cb_type; | 
					
						
							|  |  |  |     self->cb_subtype = cb_subtype; | 
					
						
							| 
									
										
										
										
											2011-03-03 06:01:31 +00:00
										 |  |  |     PyObject_GC_Track(self); | 
					
						
							| 
									
										
										
										
											2009-06-23 13:34:45 +00:00
										 |  |  |   } | 
					
						
							|  |  |  |   return (PyObject *)self; | 
					
						
							|  |  |  | } | 
					
						
							| 
									
										
										
										
											2011-12-24 07:03:19 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-02-20 15:09:44 +11:00
										 |  |  | /**
 | 
					
						
							|  |  |  |  * \param mat: Initialized matrix value to use in-place, allocated with #PyMem_Malloc | 
					
						
							|  |  |  |  */ | 
					
						
							|  |  |  | PyObject *Matrix_CreatePyObject_alloc(float *mat, | 
					
						
							| 
									
										
										
										
											2020-02-20 15:38:58 +11:00
										 |  |  |                                       const ushort num_col, | 
					
						
							|  |  |  |                                       const ushort num_row, | 
					
						
							| 
									
										
										
										
											2020-02-20 15:09:44 +11:00
										 |  |  |                                       PyTypeObject *base_type) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  |   MatrixObject *self; | 
					
						
							|  |  |  |   self = (MatrixObject *)Matrix_CreatePyObject_wrap(mat, num_col, num_row, base_type); | 
					
						
							|  |  |  |   if (self) { | 
					
						
							|  |  |  |     self->flag &= ~BASE_MATH_FLAG_IS_WRAP; | 
					
						
							|  |  |  |   } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   return (PyObject *)self; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-08-19 21:36:50 +10:00
										 |  |  | /**
 | 
					
						
							|  |  |  |  * Use with PyArg_ParseTuple's "O&" formatting. | 
					
						
							|  |  |  |  */ | 
					
						
							|  |  |  | static bool Matrix_ParseCheck(MatrixObject *pymat) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  |   if (!MatrixObject_Check(pymat)) { | 
					
						
							|  |  |  |     PyErr_Format( | 
					
						
							|  |  |  |         PyExc_TypeError, "expected a mathutils.Matrix, not a %.200s", Py_TYPE(pymat)->tp_name); | 
					
						
							| 
									
										
										
										
											2020-09-02 19:10:18 +02:00
										 |  |  |     return false; | 
					
						
							| 
									
										
										
										
											2017-08-19 21:36:50 +10:00
										 |  |  |   } | 
					
						
							|  |  |  |   /* sets error */ | 
					
						
							|  |  |  |   if (BaseMath_ReadCallback(pymat) == -1) { | 
					
						
							| 
									
										
										
										
											2020-09-02 19:10:18 +02:00
										 |  |  |     return false; | 
					
						
							| 
									
										
										
										
											2017-08-19 21:36:50 +10:00
										 |  |  |   } | 
					
						
							| 
									
										
										
										
											2020-09-02 19:10:18 +02:00
										 |  |  |   return true; | 
					
						
							| 
									
										
										
										
											2017-08-19 21:36:50 +10:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | int Matrix_ParseAny(PyObject *o, void *p) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  |   MatrixObject **pymat_p = p; | 
					
						
							|  |  |  |   MatrixObject *pymat = (MatrixObject *)o; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   if (!Matrix_ParseCheck(pymat)) { | 
					
						
							|  |  |  |     return 0; | 
					
						
							|  |  |  |   } | 
					
						
							|  |  |  |   *pymat_p = pymat; | 
					
						
							|  |  |  |   return 1; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-02-20 13:57:32 +11:00
										 |  |  | int Matrix_Parse2x2(PyObject *o, void *p) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  |   MatrixObject **pymat_p = p; | 
					
						
							|  |  |  |   MatrixObject *pymat = (MatrixObject *)o; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   if (!Matrix_ParseCheck(pymat)) { | 
					
						
							|  |  |  |     return 0; | 
					
						
							|  |  |  |   } | 
					
						
							|  |  |  |   if ((pymat->num_col != 2) || (pymat->num_row != 2)) { | 
					
						
							|  |  |  |     PyErr_SetString(PyExc_ValueError, "matrix must be 2x2"); | 
					
						
							|  |  |  |     return 0; | 
					
						
							|  |  |  |   } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   *pymat_p = pymat; | 
					
						
							|  |  |  |   return 1; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-08-19 21:36:50 +10:00
										 |  |  | int Matrix_Parse3x3(PyObject *o, void *p) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  |   MatrixObject **pymat_p = p; | 
					
						
							|  |  |  |   MatrixObject *pymat = (MatrixObject *)o; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   if (!Matrix_ParseCheck(pymat)) { | 
					
						
							|  |  |  |     return 0; | 
					
						
							|  |  |  |   } | 
					
						
							|  |  |  |   if ((pymat->num_col != 3) || (pymat->num_row != 3)) { | 
					
						
							|  |  |  |     PyErr_SetString(PyExc_ValueError, "matrix must be 3x3"); | 
					
						
							|  |  |  |     return 0; | 
					
						
							|  |  |  |   } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   *pymat_p = pymat; | 
					
						
							|  |  |  |   return 1; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | int Matrix_Parse4x4(PyObject *o, void *p) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  |   MatrixObject **pymat_p = p; | 
					
						
							|  |  |  |   MatrixObject *pymat = (MatrixObject *)o; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   if (!Matrix_ParseCheck(pymat)) { | 
					
						
							|  |  |  |     return 0; | 
					
						
							|  |  |  |   } | 
					
						
							|  |  |  |   if ((pymat->num_col != 4) || (pymat->num_row != 4)) { | 
					
						
							|  |  |  |     PyErr_SetString(PyExc_ValueError, "matrix must be 4x4"); | 
					
						
							|  |  |  |     return 0; | 
					
						
							|  |  |  |   } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   *pymat_p = pymat; | 
					
						
							|  |  |  |   return 1; | 
					
						
							|  |  |  | } | 
					
						
							| 
									
										
										
										
											2011-12-24 07:03:19 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  | /* ----------------------------------------------------------------------------
 | 
					
						
							| 
									
										
										
										
											2012-07-16 23:23:33 +00:00
										 |  |  |  * special type for alternate access */ | 
					
						
							| 
									
										
										
										
											2011-12-24 07:03:19 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  | typedef struct { | 
					
						
							| 
									
										
										
										
											2021-06-24 15:56:58 +10:00
										 |  |  |   PyObject_HEAD /* Required Python macro. */ | 
					
						
							| 
									
										
										
										
											2021-06-24 17:10:22 +10:00
										 |  |  |   MatrixObject *matrix_user; | 
					
						
							| 
									
										
										
										
											2011-12-24 07:03:19 +00:00
										 |  |  |   eMatrixAccess_t type; | 
					
						
							|  |  |  | } MatrixAccessObject; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | static int MatrixAccess_traverse(MatrixAccessObject *self, visitproc visit, void *arg) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  |   Py_VISIT(self->matrix_user); | 
					
						
							|  |  |  |   return 0; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-01-02 09:04:37 +00:00
										 |  |  | static int MatrixAccess_clear(MatrixAccessObject *self) | 
					
						
							| 
									
										
										
										
											2011-12-24 07:03:19 +00:00
										 |  |  | { | 
					
						
							|  |  |  |   Py_CLEAR(self->matrix_user); | 
					
						
							|  |  |  |   return 0; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-01-02 09:04:37 +00:00
										 |  |  | static void MatrixAccess_dealloc(MatrixAccessObject *self) | 
					
						
							| 
									
										
										
										
											2011-12-24 07:03:19 +00:00
										 |  |  | { | 
					
						
							|  |  |  |   if (self->matrix_user) { | 
					
						
							|  |  |  |     PyObject_GC_UnTrack(self); | 
					
						
							|  |  |  |     MatrixAccess_clear(self); | 
					
						
							|  |  |  |   } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   Py_TYPE(self)->tp_free(self); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | /* sequence access */ | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | static int MatrixAccess_len(MatrixAccessObject *self) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  |   return (self->type == MAT_ACCESS_ROW) ? self->matrix_user->num_row : self->matrix_user->num_col; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-01-02 09:04:37 +00:00
										 |  |  | static PyObject *MatrixAccess_slice(MatrixAccessObject *self, int begin, int end) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  |   PyObject *tuple; | 
					
						
							|  |  |  |   int count; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   /* row/col access */ | 
					
						
							|  |  |  |   MatrixObject *matrix_user = self->matrix_user; | 
					
						
							|  |  |  |   int matrix_access_len; | 
					
						
							|  |  |  |   PyObject *(*Matrix_item_new)(MatrixObject *, int); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   if (self->type == MAT_ACCESS_ROW) { | 
					
						
							|  |  |  |     matrix_access_len = matrix_user->num_row; | 
					
						
							|  |  |  |     Matrix_item_new = Matrix_item_row; | 
					
						
							|  |  |  |   } | 
					
						
							|  |  |  |   else { /* MAT_ACCESS_ROW */ | 
					
						
							|  |  |  |     matrix_access_len = matrix_user->num_col; | 
					
						
							|  |  |  |     Matrix_item_new = Matrix_item_col; | 
					
						
							|  |  |  |   } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   CLAMP(begin, 0, matrix_access_len); | 
					
						
							| 
									
										
										
										
											2019-03-30 06:12:48 +11:00
										 |  |  |   if (end < 0) { | 
					
						
							|  |  |  |     end = (matrix_access_len + 1) + end; | 
					
						
							|  |  |  |   } | 
					
						
							| 
									
										
										
										
											2012-01-02 09:04:37 +00:00
										 |  |  |   CLAMP(end, 0, matrix_access_len); | 
					
						
							|  |  |  |   begin = MIN2(begin, end); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   tuple = PyTuple_New(end - begin); | 
					
						
							|  |  |  |   for (count = begin; count < end; count++) { | 
					
						
							|  |  |  |     PyTuple_SET_ITEM(tuple, count - begin, Matrix_item_new(matrix_user, count)); | 
					
						
							|  |  |  |   } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   return tuple; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2011-12-24 13:26:30 +00:00
										 |  |  | static PyObject *MatrixAccess_subscript(MatrixAccessObject *self, PyObject *item) | 
					
						
							| 
									
										
										
										
											2011-12-24 07:03:19 +00:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2011-12-24 13:26:30 +00:00
										 |  |  |   MatrixObject *matrix_user = self->matrix_user; | 
					
						
							| 
									
										
										
										
											2019-04-17 06:17:24 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2011-12-24 07:03:19 +00:00
										 |  |  |   if (PyIndex_Check(item)) { | 
					
						
							|  |  |  |     Py_ssize_t i; | 
					
						
							|  |  |  |     i = PyNumber_AsSsize_t(item, PyExc_IndexError); | 
					
						
							| 
									
										
										
										
											2019-03-30 06:12:48 +11:00
										 |  |  |     if (i == -1 && PyErr_Occurred()) { | 
					
						
							| 
									
										
										
										
											2011-12-24 07:03:19 +00:00
										 |  |  |       return NULL; | 
					
						
							| 
									
										
										
										
											2019-03-30 06:12:48 +11:00
										 |  |  |     } | 
					
						
							| 
									
										
										
										
											2011-12-24 07:03:19 +00:00
										 |  |  |     if (self->type == MAT_ACCESS_ROW) { | 
					
						
							| 
									
										
										
										
											2019-03-30 06:12:48 +11:00
										 |  |  |       if (i < 0) { | 
					
						
							| 
									
										
										
										
											2011-12-24 07:03:19 +00:00
										 |  |  |         i += matrix_user->num_row; | 
					
						
							| 
									
										
										
										
											2019-03-30 06:12:48 +11:00
										 |  |  |       } | 
					
						
							| 
									
										
										
										
											2011-12-24 07:03:19 +00:00
										 |  |  |       return Matrix_item_row(matrix_user, i); | 
					
						
							|  |  |  |     } | 
					
						
							| 
									
										
										
										
											2020-08-07 12:41:06 +02:00
										 |  |  |     /* MAT_ACCESS_ROW */ | 
					
						
							|  |  |  |     if (i < 0) { | 
					
						
							|  |  |  |       i += matrix_user->num_col; | 
					
						
							| 
									
										
										
										
											2011-12-24 07:03:19 +00:00
										 |  |  |     } | 
					
						
							| 
									
										
										
										
											2020-08-07 12:41:06 +02:00
										 |  |  |     return Matrix_item_col(matrix_user, i); | 
					
						
							| 
									
										
										
										
											2011-12-24 07:03:19 +00:00
										 |  |  |   } | 
					
						
							| 
									
										
										
										
											2020-08-07 12:41:06 +02:00
										 |  |  |   if (PySlice_Check(item)) { | 
					
						
							| 
									
										
										
										
											2012-01-02 09:04:37 +00:00
										 |  |  |     Py_ssize_t start, stop, step, slicelength; | 
					
						
							| 
									
										
										
										
											2019-04-17 06:17:24 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-03-30 06:12:48 +11:00
										 |  |  |     if (PySlice_GetIndicesEx(item, MatrixAccess_len(self), &start, &stop, &step, &slicelength) < | 
					
						
							|  |  |  |         0) { | 
					
						
							| 
									
										
										
										
											2012-01-02 09:04:37 +00:00
										 |  |  |       return NULL; | 
					
						
							| 
									
										
										
										
											2019-03-30 06:12:48 +11:00
										 |  |  |     } | 
					
						
							| 
									
										
										
										
											2019-04-17 06:17:24 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-01-02 09:04:37 +00:00
										 |  |  |     if (slicelength <= 0) { | 
					
						
							|  |  |  |       return PyTuple_New(0); | 
					
						
							|  |  |  |     } | 
					
						
							| 
									
										
										
										
											2020-08-07 12:41:06 +02:00
										 |  |  |     if (step == 1) { | 
					
						
							| 
									
										
										
										
											2012-01-02 09:04:37 +00:00
										 |  |  |       return MatrixAccess_slice(self, start, stop); | 
					
						
							|  |  |  |     } | 
					
						
							| 
									
										
										
										
											2020-08-07 12:41:06 +02:00
										 |  |  | 
 | 
					
						
							|  |  |  |     PyErr_SetString(PyExc_IndexError, "slice steps not supported with matrix accessors"); | 
					
						
							| 
									
										
										
										
											2011-12-24 07:03:19 +00:00
										 |  |  |     return NULL; | 
					
						
							|  |  |  |   } | 
					
						
							| 
									
										
										
										
											2020-08-07 12:41:06 +02:00
										 |  |  | 
 | 
					
						
							|  |  |  |   PyErr_Format( | 
					
						
							|  |  |  |       PyExc_TypeError, "matrix indices must be integers, not %.200s", Py_TYPE(item)->tp_name); | 
					
						
							|  |  |  |   return NULL; | 
					
						
							| 
									
										
										
										
											2011-12-24 07:03:19 +00:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2011-12-24 13:26:30 +00:00
										 |  |  | static int MatrixAccess_ass_subscript(MatrixAccessObject *self, PyObject *item, PyObject *value) | 
					
						
							| 
									
										
										
										
											2011-12-24 07:03:19 +00:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2011-12-24 13:26:30 +00:00
										 |  |  |   MatrixObject *matrix_user = self->matrix_user; | 
					
						
							| 
									
										
										
										
											2019-04-17 06:17:24 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2011-12-24 07:03:19 +00:00
										 |  |  |   if (PyIndex_Check(item)) { | 
					
						
							|  |  |  |     Py_ssize_t i = PyNumber_AsSsize_t(item, PyExc_IndexError); | 
					
						
							| 
									
										
										
										
											2019-03-30 06:12:48 +11:00
										 |  |  |     if (i == -1 && PyErr_Occurred()) { | 
					
						
							| 
									
										
										
										
											2011-12-24 07:03:19 +00:00
										 |  |  |       return -1; | 
					
						
							| 
									
										
										
										
											2019-03-30 06:12:48 +11:00
										 |  |  |     } | 
					
						
							| 
									
										
										
										
											2019-04-17 06:17:24 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2011-12-24 07:03:19 +00:00
										 |  |  |     if (self->type == MAT_ACCESS_ROW) { | 
					
						
							| 
									
										
										
										
											2019-03-30 06:12:48 +11:00
										 |  |  |       if (i < 0) { | 
					
						
							| 
									
										
										
										
											2011-12-24 07:03:19 +00:00
										 |  |  |         i += matrix_user->num_row; | 
					
						
							| 
									
										
										
										
											2019-03-30 06:12:48 +11:00
										 |  |  |       } | 
					
						
							| 
									
										
										
										
											2011-12-24 07:03:19 +00:00
										 |  |  |       return Matrix_ass_item_row(matrix_user, i, value); | 
					
						
							|  |  |  |     } | 
					
						
							| 
									
										
										
										
											2020-08-07 12:41:06 +02:00
										 |  |  |     /* MAT_ACCESS_ROW */ | 
					
						
							|  |  |  |     if (i < 0) { | 
					
						
							|  |  |  |       i += matrix_user->num_col; | 
					
						
							| 
									
										
										
										
											2011-12-24 07:03:19 +00:00
										 |  |  |     } | 
					
						
							| 
									
										
										
										
											2020-08-07 12:41:06 +02:00
										 |  |  |     return Matrix_ass_item_col(matrix_user, i, value); | 
					
						
							| 
									
										
										
										
											2011-12-24 07:03:19 +00:00
										 |  |  |   } | 
					
						
							| 
									
										
										
										
											2021-07-03 23:08:40 +10:00
										 |  |  |   /* TODO: slice. */ | 
					
						
							| 
									
										
										
										
											2020-08-07 12:41:06 +02:00
										 |  |  | 
 | 
					
						
							|  |  |  |   PyErr_Format( | 
					
						
							|  |  |  |       PyExc_TypeError, "matrix indices must be integers, not %.200s", Py_TYPE(item)->tp_name); | 
					
						
							|  |  |  |   return -1; | 
					
						
							| 
									
										
										
										
											2011-12-24 07:03:19 +00:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-01-02 09:04:37 +00:00
										 |  |  | static PyObject *MatrixAccess_iter(MatrixAccessObject *self) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  |   /* Try get values from a collection */ | 
					
						
							|  |  |  |   PyObject *ret; | 
					
						
							|  |  |  |   PyObject *iter = NULL; | 
					
						
							|  |  |  |   ret = MatrixAccess_slice(self, 0, MATRIX_MAX_DIM); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   /* we know this is a tuple so no need to PyIter_Check
 | 
					
						
							|  |  |  |    * otherwise it could be NULL (unlikely) if conversion failed */ | 
					
						
							|  |  |  |   if (ret) { | 
					
						
							|  |  |  |     iter = PyObject_GetIter(ret); | 
					
						
							|  |  |  |     Py_DECREF(ret); | 
					
						
							|  |  |  |   } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   return iter; | 
					
						
							|  |  |  | } | 
					
						
							| 
									
										
										
										
											2011-12-24 07:03:19 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  | static PyMappingMethods MatrixAccess_AsMapping = { | 
					
						
							|  |  |  |     (lenfunc)MatrixAccess_len, | 
					
						
							|  |  |  |     (binaryfunc)MatrixAccess_subscript, | 
					
						
							| 
									
										
										
										
											2019-01-19 13:21:18 +11:00
										 |  |  |     (objobjargproc)MatrixAccess_ass_subscript, | 
					
						
							| 
									
										
										
										
											2011-12-24 07:03:19 +00:00
										 |  |  | }; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | PyTypeObject matrix_access_Type = { | 
					
						
							|  |  |  |     PyVarObject_HEAD_INIT(NULL, 0) "MatrixAccess",           /*tp_name*/ | 
					
						
							| 
									
										
										
										
											2012-03-26 06:55:09 +00:00
										 |  |  |     sizeof(MatrixAccessObject),                              /*tp_basicsize*/ | 
					
						
							|  |  |  |     0,                                                       /*tp_itemsize*/ | 
					
						
							|  |  |  |     (destructor)MatrixAccess_dealloc,                        /*tp_dealloc*/ | 
					
						
							| 
									
										
										
										
											2019-10-16 14:44:36 +11:00
										 |  |  |     (printfunc)NULL,                                         /*tp_print*/ | 
					
						
							| 
									
										
										
										
											2012-03-26 06:55:09 +00:00
										 |  |  |     NULL,                                                    /*tp_getattr*/ | 
					
						
							|  |  |  |     NULL,                                                    /*tp_setattr*/ | 
					
						
							|  |  |  |     NULL,                                                    /*tp_compare*/ | 
					
						
							|  |  |  |     NULL,                                                    /*tp_repr*/ | 
					
						
							|  |  |  |     NULL,                                                    /*tp_as_number*/ | 
					
						
							| 
									
										
										
										
											2021-06-26 21:35:18 +10:00
										 |  |  |     NULL /* &MatrixAccess_SeqMethods */ /* TODO */,          /*tp_as_sequence*/ | 
					
						
							| 
									
										
										
										
											2012-03-26 06:55:09 +00:00
										 |  |  |     &MatrixAccess_AsMapping,                                 /*tp_as_mapping*/ | 
					
						
							|  |  |  |     NULL,                                                    /*tp_hash*/ | 
					
						
							|  |  |  |     NULL,                                                    /*tp_call*/ | 
					
						
							|  |  |  |     NULL,                                                    /*tp_str*/ | 
					
						
							|  |  |  |     NULL,                                                    /*tp_getattro*/ | 
					
						
							|  |  |  |     NULL,                                                    /*tp_setattro*/ | 
					
						
							|  |  |  |     NULL,                                                    /*tp_as_buffer*/ | 
					
						
							| 
									
										
										
										
											2011-12-24 07:03:19 +00:00
										 |  |  |     Py_TPFLAGS_DEFAULT | Py_TPFLAGS_HAVE_GC,                 /*tp_flags*/ | 
					
						
							| 
									
										
										
										
											2012-03-26 06:55:09 +00:00
										 |  |  |     NULL,                                                    /*tp_doc*/ | 
					
						
							| 
									
										
										
										
											2012-10-20 20:20:02 +00:00
										 |  |  |     (traverseproc)MatrixAccess_traverse,                     /*tp_traverse*/ | 
					
						
							|  |  |  |     (inquiry)MatrixAccess_clear,                             /*tp_clear*/ | 
					
						
							| 
									
										
										
										
											2011-12-24 07:03:19 +00:00
										 |  |  |     NULL /* (richcmpfunc)MatrixAccess_richcmpr */ /* TODO*/, /*tp_richcompare*/ | 
					
						
							| 
									
										
										
										
											2012-03-26 06:55:09 +00:00
										 |  |  |     0,                                                       /*tp_weaklistoffset*/ | 
					
						
							| 
									
										
										
										
											2012-01-02 09:04:37 +00:00
										 |  |  |     (getiterfunc)MatrixAccess_iter,                          /* getiterfunc tp_iter; */ | 
					
						
							| 
									
										
										
										
											2011-12-24 07:03:19 +00:00
										 |  |  | }; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | static PyObject *MatrixAccess_CreatePyObject(MatrixObject *matrix, const eMatrixAccess_t type) | 
					
						
							|  |  |  | { | 
					
						
							| 
									
										
										
										
											2011-12-24 13:26:30 +00:00
										 |  |  |   MatrixAccessObject *matrix_access = (MatrixAccessObject *)PyObject_GC_New(MatrixObject, | 
					
						
							|  |  |  |                                                                             &matrix_access_Type); | 
					
						
							| 
									
										
										
										
											2011-12-24 07:03:19 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2011-12-24 13:26:30 +00:00
										 |  |  |   matrix_access->matrix_user = matrix; | 
					
						
							| 
									
										
										
										
											2011-12-24 07:03:19 +00:00
										 |  |  |   Py_INCREF(matrix); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2011-12-24 13:26:30 +00:00
										 |  |  |   matrix_access->type = type; | 
					
						
							| 
									
										
										
										
											2011-12-24 07:03:19 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  |   return (PyObject *)matrix_access; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | /* end special access
 | 
					
						
							|  |  |  |  * -------------------------------------------------------------------------- */ |