23#ifndef MATH_STANDALONE
41 Py_ssize_t slice_length,
54 PyErr_SetString(PyExc_AttributeError,
56 "owner matrix has been resized since this row vector was created");
66 PyErr_SetString(PyExc_AttributeError,
68 "owner matrix has been resized since this column vector was created");
100 memcpy(mat_dst->matrix, mat_src->matrix,
sizeof(
float) * (mat_dst->
col_num * mat_dst->
row_num));
106 memset(self->matrix, 0x0, mat_size);
108 const int row_num = self->
row_num;
109 for (
int col = 0; col < col_row_max; col++) {
110 self->matrix[(col * row_num) + col] = 1.0f;
120 for (row = 0; row < mat_src->
row_num; row++) {
121 for (col = 0; col < mat_src->
col_num; col++) {
148 return determinant_m4(
reinterpret_cast<const float (*)[4]
>(self->matrix));
157 reinterpret_cast<const float (*)[2]
>(mat_src));
162 reinterpret_cast<const float (*)[3]
>(mat_src));
167 reinterpret_cast<const float (*)[4]
>(mat_src));
177 const float *mat_src,
190 for (i = 0; i < dim; i++) {
191 for (j = 0; j < dim; j++) {
221 float *in_mat = self->matrix;
234 float (*mat)[2] =
reinterpret_cast<float (*)[2]
>(in_mat);
236 if (in_mat != self->matrix) {
237 copy_m2_m2(mat, reinterpret_cast<const float (*)[2]>(self->matrix));
242 if ((det =
determinant_m2(mat[0][0], mat[0][1], mat[1][0], mat[1][1])) == 0.0f)
251 float (*mat)[3] =
reinterpret_cast<float (*)[3]
>(in_mat);
253 if (in_mat != self->matrix) {
254 copy_m3_m3(mat, reinterpret_cast<const float (*)[3]>(self->matrix));
267 float (*mat)[4] =
reinterpret_cast<float (*)[4]
>(in_mat);
269 if (in_mat != self->matrix) {
270 copy_m4_m4(mat, reinterpret_cast<const float (*)[4]>(self->matrix));
296 PyObject *ret_dummy = matrix_func(
reinterpret_cast<MatrixObject *
>(
ret));
298 Py_DECREF(ret_dummy);
312 for (
int row = 0; row < self->
row_num; row++) {
313 for (
int col = 0; col < self->
col_num; col++) {
314 if (
MATRIX_ITEM(self, row, col) != ((row != col) ? 0.0f : 1.0f)) {
349 for (col = 0; col < self->
col_num; col++) {
368 for (col = 0; col < self->
col_num; col++) {
447 for (row = 0; row < row_num; row++) {
470 for (row = 0; row < row_num; row++) {
544 for (row = 0; row < 3; row++) {
560 for (row = 0; row < 3; row++) {
609 PyObject *
const *args,
613 if (kwnames && PyTuple_GET_SIZE(kwnames)) [[unlikely]] {
614 PyErr_SetString(PyExc_TypeError,
616 "takes no keyword args");
620 switch (PyVectorcall_NARGS(nargsf)) {
625 PyObject *arg = args[0];
630 const ushort row_num = PySequence_Size(arg);
632 if (row_num >= 2 && row_num <= 4) {
633 PyObject *item = PySequence_GetItem(arg, 0);
636 const ushort col_num = PySequence_Size(item);
639 if (col_num >= 2 && col_num <= 4) {
642 nullptr, col_num, row_num,
reinterpret_cast<PyTypeObject *
>(type));
656 PyErr_SetString(PyExc_TypeError,
657 "mathutils.Matrix(): "
658 "expects no args or a single arg containing 2-4 numeric sequences");
662static PyObject *
Matrix_new(PyTypeObject *type, PyObject *args, PyObject *kwds)
665 if (kwds && PyDict_GET_SIZE(kwds)) [[unlikely]] {
666 PyErr_SetString(PyExc_TypeError,
667 "mathutils.Matrix(): "
668 "takes no keyword args");
671 PyObject *
const *args_array = &PyTuple_GET_ITEM(args, 0);
672 const size_t args_array_num = PyTuple_GET_SIZE(args);
674 reinterpret_cast<PyObject *
>(type), args_array, args_array_num,
nullptr);
686 C_Matrix_Identity_doc,
687 ".. classmethod:: Identity(size, /)\n"
689 " Create an identity matrix.\n"
691 " :param size: The size of the identity matrix to construct [2, 4].\n"
693 " :return: A new identity matrix.\n"
694 " :rtype: :class:`Matrix`\n");
699 if (!PyArg_ParseTuple(args,
707 if (matSize < 2 || matSize > 4) {
708 PyErr_SetString(PyExc_RuntimeError,
709 "Matrix.Identity(): "
710 "size must be between 2 and 4");
720 C_Matrix_Rotation_doc,
721 ".. classmethod:: Rotation(angle, size, axis=None, /)\n"
723 " Create a matrix representing a rotation.\n"
725 " :param angle: The angle of rotation desired, in radians.\n"
726 " :type angle: float\n"
727 " :param size: The size of the rotation matrix to construct [2, 4].\n"
729 " :param axis: Axis of rotation: a single-character string ('X', 'Y' or 'Z')\n"
730 " or a 3D vector. Required for ``size`` 3 or 4. Must be None (or omitted)\n"
731 " when ``size`` is 2 - 2D rotation has no axis.\n"
732 " :type axis: Literal['X', 'Y', 'Z'] | Sequence[float] | None\n"
733 " :return: A new rotation matrix.\n"
734 " :rtype: :class:`Matrix`\n");
737 PyObject *vec = Py_None;
738 const char *axis =
nullptr;
741 float mat[16] = {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1};
743 if (!PyArg_ParseTuple(args,
756 if (vec != Py_None && PyUnicode_Check(vec)) {
757 axis = PyUnicode_AsUTF8(vec);
758 if (axis ==
nullptr || axis[0] ==
'\0' || axis[1] !=
'\0' || axis[0] <
'X' || axis[0] >
'Z') {
759 PyErr_SetString(PyExc_ValueError,
760 "Matrix.Rotation(): "
761 "3rd argument axis value must be a 3D vector "
762 "or a string in 'X', 'Y', 'Z'");
772 if (!
ELEM(matSize, 2, 3, 4)) {
773 PyErr_SetString(PyExc_ValueError,
774 "Matrix.Rotation(): "
775 "can only return a 2x2 3x3 or 4x4 matrix");
778 if (matSize == 2 && (vec != Py_None)) {
779 PyErr_SetString(PyExc_ValueError,
780 "Matrix.Rotation(): "
781 "cannot create a 2x2 rotation matrix around arbitrary axis");
784 if (
ELEM(matSize, 3, 4) && (axis ==
nullptr) && (vec == Py_None)) {
785 PyErr_SetString(PyExc_ValueError,
786 "Matrix.Rotation(): "
787 "axis of rotation for 3d and 4d matrices is required");
792 if (vec != Py_None) {
796 tvec, 3, 3, vec,
"Matrix.Rotation(angle, size, axis), invalid 'axis' arg") == -1)
803 else if (matSize == 2) {
821 C_Matrix_Translation_doc,
822 ".. classmethod:: Translation(vector, /)\n"
824 " Create a matrix representing a translation.\n"
826 " :param vector: The translation vector.\n"
827 " :type vector: Sequence[float]\n"
828 " :return: An identity matrix with a translation.\n"
829 " :rtype: :class:`Matrix`\n");
837 mat[3], 3, 4, value,
"mathutils.Matrix.Translation(vector), invalid vector arg") == -1)
847 C_Matrix_Diagonal_doc,
848 ".. classmethod:: Diagonal(vector, /)\n"
850 " Create a diagonal (scaling) matrix using the values from the vector.\n"
852 " :param vector: The vector of values for the diagonal.\n"
853 " :type vector: Sequence[float]\n"
854 " :return: A diagonal matrix.\n"
855 " :rtype: :class:`Matrix`\n");
859 float mat[16] = {0.0f};
863 vec, 2, 4, value,
"mathutils.Matrix.Diagonal(vector), invalid vector arg");
869 for (
int i = 0; i < size; i++) {
870 mat[size * i + i] = vec[i];
880 ".. classmethod:: Scale(factor, size, axis=None, /)\n"
882 " Create a matrix representing a scaling.\n"
884 " :param factor: The factor of scaling to apply.\n"
885 " :type factor: float\n"
886 " :param size: The size of the scale matrix to construct [2, 4].\n"
888 " :param axis: Direction along which to scale. When None (or omitted),\n"
889 " ``factor`` is applied uniformly along all axes.\n"
890 " :type axis: Sequence[float] | None\n"
891 " :return: A new scale matrix.\n"
892 " :rtype: :class:`Matrix`\n");
895 PyObject *vec = Py_None;
900 float mat[16] = {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1};
902 if (!PyArg_ParseTuple(args,
914 if (!
ELEM(matSize, 2, 3, 4)) {
915 PyErr_SetString(PyExc_ValueError,
917 "can only return a 2x2 3x3 or 4x4 matrix");
920 if (vec != Py_None) {
921 vec_num = (matSize == 2 ? 2 : 3);
923 tvec, vec_num, vec_num, vec,
"Matrix.Scale(factor, size, axis), invalid 'axis' arg") ==
929 if (vec == Py_None) {
945 for (
x = 0;
x < vec_num;
x++) {
946 norm += tvec[
x] * tvec[
x];
949 for (
x = 0;
x < vec_num;
x++) {
953 mat[0] = 1 + ((factor - 1) * (tvec[0] * tvec[0]));
954 mat[1] = ((factor - 1) * (tvec[0] * tvec[1]));
955 mat[2] = ((factor - 1) * (tvec[0] * tvec[1]));
956 mat[3] = 1 + ((factor - 1) * (tvec[1] * tvec[1]));
959 mat[0] = 1 + ((factor - 1) * (tvec[0] * tvec[0]));
960 mat[1] = ((factor - 1) * (tvec[0] * tvec[1]));
961 mat[2] = ((factor - 1) * (tvec[0] * tvec[2]));
962 mat[3] = ((factor - 1) * (tvec[0] * tvec[1]));
963 mat[4] = 1 + ((factor - 1) * (tvec[1] * tvec[1]));
964 mat[5] = ((factor - 1) * (tvec[1] * tvec[2]));
965 mat[6] = ((factor - 1) * (tvec[0] * tvec[2]));
966 mat[7] = ((factor - 1) * (tvec[1] * tvec[2]));
967 mat[8] = 1 + ((factor - 1) * (tvec[2] * tvec[2]));
979 C_Matrix_OrthoProjection_doc,
980 ".. classmethod:: OrthoProjection(axis, size, /)\n"
982 " Create a matrix to represent an orthographic projection.\n"
984 " :param axis: An axis string,\n"
985 " where a single axis is for a 2D matrix.\n"
986 " Or a vector for an arbitrary axis\n"
987 " :type axis: Literal['X', 'Y', 'XY', 'XZ', 'YZ'] | Sequence[float]\n"
988 " :param size: The size of the projection matrix to construct [2, 4].\n"
990 " :return: A new projection matrix.\n"
991 " :rtype: :class:`Matrix`\n");
998 float mat[16] = {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1};
1000 if (!PyArg_ParseTuple(args,
1003 ":Matrix.OrthoProjection",
1009 if (!
ELEM(matSize, 2, 3, 4)) {
1010 PyErr_SetString(PyExc_ValueError,
1011 "Matrix.OrthoProjection(): "
1012 "can only return a 2x2 3x3 or 4x4 matrix");
1016 if (PyUnicode_Check(axis)) {
1017 Py_ssize_t plane_len;
1018 const char *plane = PyUnicode_AsUTF8AndSize(axis, &plane_len);
1020 if (plane_len == 1 && plane[0] ==
'X') {
1023 else if (plane_len == 1 && plane[0] ==
'Y') {
1027 PyErr_Format(PyExc_ValueError,
1028 "Matrix.OrthoProjection(): "
1029 "unknown plane, expected: X, Y, not '%.200s'",
1035 if (plane_len == 2 && plane[0] ==
'X' && plane[1] ==
'Y') {
1039 else if (plane_len == 2 && plane[0] ==
'X' && plane[1] ==
'Z') {
1043 else if (plane_len == 2 && plane[0] ==
'Y' && plane[1] ==
'Z') {
1048 PyErr_Format(PyExc_ValueError,
1049 "Matrix.OrthoProjection(): "
1050 "unknown plane, expected: XY, XZ, YZ, not '%.200s'",
1059 const int vec_num = (matSize == 2 ? 2 : 3);
1066 "Matrix.OrthoProjection(axis, size), invalid 'axis' arg") == -1)
1072 for (
x = 0;
x < vec_num;
x++) {
1073 norm += tvec[
x] * tvec[
x];
1076 for (
x = 0;
x < vec_num;
x++) {
1080 mat[0] = 1 - (tvec[0] * tvec[0]);
1081 mat[1] = -(tvec[0] * tvec[1]);
1082 mat[2] = -(tvec[0] * tvec[1]);
1083 mat[3] = 1 - (tvec[1] * tvec[1]);
1085 else if (matSize > 2) {
1086 mat[0] = 1 - (tvec[0] * tvec[0]);
1087 mat[1] = -(tvec[0] * tvec[1]);
1088 mat[2] = -(tvec[0] * tvec[2]);
1089 mat[3] = -(tvec[0] * tvec[1]);
1090 mat[4] = 1 - (tvec[1] * tvec[1]);
1091 mat[5] = -(tvec[1] * tvec[2]);
1092 mat[6] = -(tvec[0] * tvec[2]);
1093 mat[7] = -(tvec[1] * tvec[2]);
1094 mat[8] = 1 - (tvec[2] * tvec[2]);
1108 ".. classmethod:: Shear(plane, size, factor, /)\n"
1110 " Create a matrix to represent a shear transformation.\n"
1112 " :param plane: An axis string,\n"
1113 " where a single axis is for a 2D matrix only.\n"
1114 " :type plane: Literal['X', 'Y', 'XY', 'XZ', 'YZ']\n"
1115 " :param size: The size of the shear matrix to construct [2, 4].\n"
1116 " :type size: int\n"
1117 " :param factor: The factor of shear to apply. "
1118 "For a 2 *size* matrix use a single float. "
1119 "For a 3 or 4 *size* matrix pass a pair of floats corresponding with the *plane* axis.\n"
1120 " :type factor: float | Sequence[float]\n"
1121 " :return: A new shear matrix.\n"
1122 " :rtype: :class:`Matrix`\n");
1128 float mat[16] = {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1};
1130 if (!PyArg_ParseTuple(args,
1141 if (!
ELEM(matSize, 2, 3, 4)) {
1142 PyErr_SetString(PyExc_ValueError,
1144 "can only return a 2x2 3x3 or 4x4 matrix");
1149 float const factor = PyFloat_AsDouble(fac);
1151 if (factor == -1.0f && PyErr_Occurred()) {
1152 PyErr_SetString(PyExc_TypeError,
1154 "the factor to be a float");
1162 if (
STREQ(plane,
"X")) {
1165 else if (
STREQ(plane,
"Y")) {
1169 PyErr_SetString(PyExc_ValueError,
1171 "expected: X, Y or wrong matrix size for shearing plane");
1188 if (
STREQ(plane,
"XY")) {
1192 else if (
STREQ(plane,
"XZ")) {
1196 else if (
STREQ(plane,
"YZ")) {
1201 PyErr_SetString(PyExc_ValueError,
1203 "expected: X, Y, XY, XZ, YZ");
1217 C_Matrix_LocRotScale_doc,
1218 ".. classmethod:: LocRotScale(location, rotation, scale, /)\n"
1220 " Create a matrix combining translation, rotation and scale,\n"
1221 " acting as the inverse of the decompose() method.\n"
1223 " Any of the inputs may be replaced with None if not needed.\n"
1225 " :param location: The translation component.\n"
1226 " :type location: Sequence[float] | None\n"
1227 " :param rotation: The rotation component as a "
1228 "3x3 matrix, quaternion, euler or None for no rotation.\n"
1229 " :type rotation: :class:`Matrix` | :class:`Quaternion` | :class:`Euler` | None\n"
1230 " :param scale: The scale component.\n"
1231 " :type scale: Sequence[float] | None\n"
1232 " :return: Combined transformation as a 4x4 matrix. \n"
1233 " :rtype: :class:`Matrix`\n");
1236 PyObject *loc_obj, *rot_obj, *scale_obj;
1237 float mat[4][4], loc[3];
1239 if (!PyArg_ParseTuple(args,
1243 ":Matrix.LocRotScale",
1252 if (loc_obj == Py_None) {
1256 loc, 3, 3, loc_obj,
"Matrix.LocRotScale(), invalid location argument") == -1)
1262 if (rot_obj == Py_None) {
1291 copy_m4_m3(mat,
reinterpret_cast<const float (*)[3]
>(mat_obj->matrix));
1294 PyErr_SetString(PyExc_ValueError,
1295 "Matrix.LocRotScale(): "
1296 "inappropriate rotation matrix size - expects 3x3 matrix");
1301 PyErr_SetString(PyExc_ValueError,
1302 "Matrix.LocRotScale(): "
1303 "rotation argument must be Matrix, Quaternion, Euler or None");
1308 if (scale_obj != Py_None) {
1312 scale, 3, 3, scale_obj,
"Matrix.LocRotScale(), invalid scale argument") == -1)
1333 Matrix_to_quaternion_doc,
1334 ".. method:: to_quaternion()\n"
1336 " Return a quaternion representation of the rotation matrix.\n"
1338 " :return: Quaternion representation of the rotation matrix.\n"
1339 " :rtype: :class:`Quaternion`\n");
1350 PyErr_SetString(PyExc_ValueError,
1351 "Matrix.to_quat(): "
1352 "inappropriate matrix size - expects 3x3 or 4x4 matrix");
1356 mat3_to_quat(quat,
reinterpret_cast<const float (*)[3]
>(self->matrix));
1359 mat4_to_quat(quat,
reinterpret_cast<const float (*)[4]
>(self->matrix));
1372 Matrix_to_euler_doc,
1373 ".. method:: to_euler(order='XYZ', euler_compat=None, /)\n"
1375 " Return an Euler representation of the rotation matrix\n"
1376 " (3x3 or 4x4 matrix only).\n"
1378 " :param order: A rotation order string.\n"
1379 " :type order: Literal['XYZ', 'XZY', 'YXZ', 'YZX', 'ZXY', 'ZYX']\n"
1380 " :param euler_compat: Optional euler argument the new euler will be made\n"
1381 " compatible with (no axis flipping between them).\n"
1382 " Useful for converting a series of matrices to animation curves.\n"
1383 " :type euler_compat: :class:`Euler` | None\n"
1384 " :return: Euler representation of the matrix.\n"
1385 " :rtype: :class:`Euler`\n");
1388 const char *order_str =
nullptr;
1390 float eul[3], eul_compatf[3];
1400 static const char *_keywords[] = {
"",
"",
nullptr};
1401 static _PyArg_Parser _parser = {
1409 if (!_PyArg_ParseTupleAndKeywordsFast(
1425 copy_m3_m3(mat,
reinterpret_cast<const float (*)[3]
>(self->matrix));
1428 copy_m3_m4(mat,
reinterpret_cast<const float (*)[4]
>(self->matrix));
1431 PyErr_SetString(PyExc_ValueError,
1432 "Matrix.to_euler(): "
1433 "inappropriate matrix size - expects 3x3 or 4x4 matrix");
1475 Matrix_resize_4x4_doc,
1476 ".. method:: resize_4x4()\n"
1478 " Resize the matrix to 4x4.\n");
1489 self->matrix =
static_cast<float *
>(
1491 if (self->matrix ==
nullptr) {
1492 PyErr_SetString(PyExc_MemoryError,
1493 "Matrix.resize_4x4(): "
1494 "problem allocating pointer space");
1500 for (col = 0; col < self->
col_num; col++) {
1504 copy_m4_m4(
reinterpret_cast<float (*)[4]
>(self->matrix),
const_cast<const float (*)[4]
>(mat));
1520 const int mat_size =
sizeof(
float) * (col_num * row_num);
1522 static_cast<float *
>(PyMem_Malloc(mat_size)), col_num, row_num, Py_TYPE(self)));
1525 memcpy(pymat->matrix, self->matrix, mat_size);
1533 for (
int col = 0; col < col_len_src; col++) {
1535 &pymat->matrix[col * row_num],
MATRIX_COL_PTR(self, col),
sizeof(
float) * row_len_src);
1538 return reinterpret_cast<PyObject *
>(pymat);
1544 ".. method:: to_2x2()\n"
1546 " Return a 2x2 copy of this matrix.\n"
1548 " :return: a new matrix.\n"
1549 " :rtype: :class:`Matrix`\n");
1561 ".. method:: to_3x3()\n"
1563 " Return a 3x3 copy of this matrix.\n"
1565 " :return: a new matrix.\n"
1566 " :rtype: :class:`Matrix`\n");
1578 ".. method:: to_4x4()\n"
1580 " Return a 4x4 copy of this matrix.\n"
1582 " :return: a new matrix.\n"
1583 " :rtype: :class:`Matrix`\n");
1601 Matrix_to_translation_doc,
1602 ".. method:: to_translation()\n"
1604 " Return the translation part of a 4x4 matrix.\n"
1606 " :return: Return the translation of a matrix.\n"
1607 " :rtype: :class:`Vector`\n");
1615 PyErr_SetString(PyExc_ValueError,
1616 "Matrix.to_translation(): "
1617 "inappropriate matrix size");
1626 Matrix_to_scale_doc,
1627 ".. method:: to_scale()\n"
1629 " Return the scale part of a 3x3 or 4x4 matrix.\n"
1631 " :return: Return the scale of a matrix.\n"
1632 " :rtype: :class:`Vector`\n"
1634 " .. note:: This method does not return a negative scale on any axis because it is "
1635 "not possible to obtain this data from the matrix alone.\n");
1648 PyErr_SetString(PyExc_ValueError,
1649 "Matrix.to_scale(): "
1650 "inappropriate matrix size, 3x3 minimum size");
1672 PyErr_SetString(PyExc_ValueError,
1673 "Matrix.invert(ed): "
1674 "only square matrices are supported");
1683 switch (PyTuple_GET_SIZE(args)) {
1688 PyObject *arg = PyTuple_GET_ITEM(args, 0);
1689 if (arg == Py_None) {
1695 PyErr_SetString(PyExc_TypeError,
1697 "expects a matrix argument or nothing");
1702 PyErr_SetString(PyExc_TypeError,
1704 "matrix argument has different dimensions");
1712 PyErr_SetString(PyExc_ValueError,
1713 "Matrix.invert(ed): "
1714 "takes at most one argument");
1722 PyErr_SetString(PyExc_ValueError,
1723 "Matrix.invert(ed): "
1724 "matrix does not have an inverse");
1730 ".. method:: invert(fallback=None, /)\n"
1732 " Set the matrix to its inverse.\n"
1734 " :param fallback: Set the matrix to this value when the inverse cannot be calculated\n"
1735 " (instead of raising a :exc:`ValueError` exception).\n"
1736 " :type fallback: :class:`Matrix` | None\n"
1738 " .. seealso:: `Inverse matrix <https://en.wikipedia.org/wiki/Inverse_matrix>`__ on "
1756 if (PyTuple_GET_SIZE(args) == 1 && ((arg = PyTuple_GET_ITEM(args, 0)) != Py_None)) {
1763 if (self != fallback) {
1779 Matrix_inverted_doc,
1780 ".. method:: inverted(fallback=None, /)\n"
1782 " Return an inverted copy of the matrix.\n"
1784 " :param fallback: return this when the inverse can't be calculated\n"
1785 " (instead of raising a :exc:`ValueError`).\n"
1786 " :type fallback: Any\n"
1787 " :return: The inverted matrix or fallback when given.\n"
1788 " :rtype: :class:`Matrix` | Any\n");
1810 if (PyTuple_GET_SIZE(args) == 1 && ((arg = PyTuple_GET_ITEM(args, 0)) != Py_None)) {
1846 Matrix_invert_safe_doc,
1847 ".. method:: invert_safe()\n"
1849 " Set the matrix to its inverse, will never error.\n"
1850 " If degenerated (e.g. zero scale on an axis), add some epsilon to its diagonal, "
1851 "to get an invertible one.\n"
1852 " If tweaked matrix is still degenerated, set to the identity matrix instead.\n"
1854 " .. seealso:: `Inverse Matrix <https://en.wikipedia.org/wiki/Inverse_matrix>`__ on "
1874 Matrix_inverted_safe_doc,
1875 ".. method:: inverted_safe()\n"
1877 " Return an inverted copy of the matrix, will never error.\n"
1878 " If degenerated (e.g. zero scale on an axis), add some epsilon to its diagonal, "
1879 "to get an invertible one.\n"
1880 " If tweaked matrix is still degenerated, return the identity matrix instead.\n"
1882 " :return: the inverted matrix.\n"
1883 " :rtype: :class:`Matrix`\n");
1909 Matrix_adjugate_doc,
1910 ".. method:: adjugate()\n"
1912 " Set the matrix to its adjugate.\n"
1914 " :raises ValueError: if the matrix cannot be adjugated.\n"
1916 " .. seealso:: `Adjugate matrix <https://en.wikipedia.org/wiki/Adjugate_matrix>`__ on "
1925 PyErr_SetString(PyExc_ValueError,
1926 "Matrix.adjugate(d): "
1927 "only square matrices are supported");
1937 PyExc_ValueError,
"Matrix adjugate(d): size (%d) unsupported",
int(self->
col_num));
1947 Matrix_adjugated_doc,
1948 ".. method:: adjugated()\n"
1950 " Return an adjugated copy of the matrix.\n"
1952 " :return: the adjugated matrix.\n"
1953 " :rtype: :class:`Matrix`\n"
1954 " :raises ValueError: if the matrix cannot be adjugated\n");
1963 ".. method:: rotate(other, /)\n"
1965 " Rotates the matrix by another mathutils value.\n"
1967 " .. note:: The matrix must be 3x3.\n"
1969 " .. note:: If any of the columns are not unit length this may not have desired results.\n"
1971 " :param other: rotation component of mathutils value\n"
1972 " :type other: :class:`Euler` | :class:`Quaternion` | :class:`Matrix`\n");
1975 float self_rmat[3][3], other_rmat[3][3], rmat[3][3];
1986 PyErr_SetString(PyExc_ValueError,
1988 "must have 3x3 dimensions");
1995 copy_m3_m3(
reinterpret_cast<float (*)[3]
>(self->matrix), rmat);
2009 Matrix_decompose_doc,
2010 ".. method:: decompose()\n"
2012 " Return the translation, rotation, and scale components of this 4x4 matrix.\n"
2014 " :return: Tuple of translation, rotation, and scale.\n"
2015 " :rtype: tuple[:class:`Vector`, :class:`Quaternion`, :class:`Vector`]\n");
2025 PyErr_SetString(PyExc_ValueError,
2026 "Matrix.decompose(): "
2027 "inappropriate matrix size - expects 4x4 matrix");
2038 ret = PyTuple_New(3);
2055 ".. method:: lerp(other, factor, /)\n"
2057 " Returns the interpolation of two matrices. Uses polar decomposition, see "
2058 "\"Matrix Animation and Polar Decomposition\", Shoemake and Duff, 1992.\n"
2060 " :param other: value to interpolate with.\n"
2061 " :type other: :class:`Matrix`\n"
2062 " :param factor: The interpolation value in [0.0, 1.0].\n"
2063 " :type factor: float\n"
2064 " :return: The interpolated matrix.\n"
2065 " :rtype: :class:`Matrix`\n");
2071 if (!PyArg_ParseTuple(args,
2083 PyErr_SetString(PyExc_ValueError,
2085 "expects both matrix objects of the same dimensions");
2095#ifdef MATH_STANDALONE
2096 blend_m4_m4m4((
float (*)[4])mat, (
float (*)[4])self->matrix, (
float (*)[4])mat2->matrix, fac);
2099 reinterpret_cast<float (*)[4]
>(self->matrix),
2100 reinterpret_cast<float (*)[4]
>(mat2->matrix),
2105#ifdef MATH_STANDALONE
2106 blend_m3_m3m3((
float (*)[3])mat, (
float (*)[3])self->matrix, (
float (*)[3])mat2->matrix, fac);
2109 reinterpret_cast<float (*)[3]
>(self->matrix),
2110 reinterpret_cast<float (*)[3]
>(mat2->matrix),
2115 PyErr_SetString(PyExc_ValueError,
2117 "only 3x3 and 4x4 matrices supported");
2126 Matrix_determinant_doc,
2127 ".. method:: determinant()\n"
2129 " Return the determinant of a matrix.\n"
2131 " :return: Return the determinant of a matrix.\n"
2134 " .. seealso:: `Determinant <https://en.wikipedia.org/wiki/Determinant>`__ on Wikipedia.\n");
2142 PyErr_SetString(PyExc_ValueError,
2143 "Matrix.determinant(): "
2144 "only square matrices are supported");
2159 Matrix_transpose_doc,
2160 ".. method:: transpose()\n"
2162 " Set the matrix to its transpose.\n"
2164 " .. seealso:: `Transpose <https://en.wikipedia.org/wiki/Transpose>`__ on Wikipedia.\n");
2172 PyErr_SetString(PyExc_ValueError,
2173 "Matrix.transpose(d): "
2174 "only square matrices are supported");
2183 else if (self->
col_num == 3) {
2184 transpose_m3(
reinterpret_cast<float (*)[3]
>(self->matrix));
2187 transpose_m4(
reinterpret_cast<float (*)[4]
>(self->matrix));
2196 Matrix_transposed_doc,
2197 ".. method:: transposed()\n"
2199 " Return a new, transposed matrix.\n"
2201 " :return: a transposed matrix\n"
2202 " :rtype: :class:`Matrix`\n");
2216 Matrix_normalize_doc,
2217 ".. method:: normalize()\n"
2219 " Normalize each of the matrix columns (3x3 and 4x4 only).\n"
2221 " .. note:: for 4x4 matrices, the 4th column (translation) is left untouched.\n");
2229 PyErr_SetString(PyExc_ValueError,
2230 "Matrix.normalize(): "
2231 "only square matrices are supported");
2236 normalize_m3(
reinterpret_cast<float (*)[3]
>(self->matrix));
2238 else if (self->
col_num == 4) {
2239 normalize_m4(
reinterpret_cast<float (*)[4]
>(self->matrix));
2242 PyErr_SetString(PyExc_ValueError,
2243 "Matrix.normalize(): "
2244 "can only use a 3x3 or 4x4 matrix");
2253 Matrix_normalized_doc,
2254 ".. method:: normalized()\n"
2256 " Return a column normalized matrix (3x3 and 4x4 only).\n"
2258 " :return: a column normalized matrix\n"
2259 " :rtype: :class:`Matrix`\n"
2261 " .. note:: for 4x4 matrices, the 4th column (translation) is left untouched.\n");
2276 ".. method:: zero()\n"
2278 " Set all the matrix values to zero.\n");
2305 unit_m2(
reinterpret_cast<float (*)[2]
>(self->matrix));
2307 else if (self->
col_num == 3) {
2308 unit_m3(
reinterpret_cast<float (*)[3]
>(self->matrix));
2311 unit_m4(
reinterpret_cast<float (*)[4]
>(self->matrix));
2317 Matrix_identity_doc,
2318 ".. method:: identity()\n"
2320 " Set the matrix to the identity matrix.\n"
2322 " .. note:: An object with a location and rotation of zero, and a scale of one\n"
2323 " will have an identity matrix.\n"
2325 " .. seealso:: `Identity matrix <https://en.wikipedia.org/wiki/Identity_matrix>`__ "
2334 PyErr_SetString(PyExc_ValueError,
2335 "Matrix.identity(): "
2336 "only square matrices are supported");
2364 ".. method:: copy()\n"
2366 " Returns a copy of this matrix.\n"
2368 " :return: A copy of the matrix.\n"
2369 " :rtype: :class:`Matrix`\n");
2403 for (row = 0; row < self->
row_num; row++) {
2404 rows[row] = PyTuple_New(self->
col_num);
2405 for (col = 0; col < self->
col_num; col++) {
2406 PyTuple_SET_ITEM(rows[row], col, PyFloat_FromDouble(
MATRIX_ITEM(self, row, col)));
2410 PyObject *
result =
nullptr;
2413 result = PyUnicode_FromFormat(
2421 result = PyUnicode_FromFormat(
2431 result = PyUnicode_FromFormat(
2443 Py_FatalError(
"Matrix(): invalid row size!");
2448 for (row = 0; row < self->
row_num; row++) {
2449 Py_DECREF(rows[row]);
2455#ifndef MATH_STANDALONE
2472 for (col = 0; col < self->
col_num; col++) {
2474 for (row = 0; row < self->
row_num; row++) {
2476 maxsize[col] =
max_ii(maxsize[col], size);
2482 for (row = 0; row < self->
row_num; row++) {
2483 for (col = 0; col < self->
col_num; col++) {
2510 memset(view, 0,
sizeof(*view));
2512 view->obj =
reinterpret_cast<PyObject *
>(self);
2513 view->buf =
static_cast<void *
>(self->matrix);
2514 view->len = Py_ssize_t(self->
row_num * self->
col_num *
sizeof(
float));
2515 view->itemsize =
sizeof(
float);
2516 if ((flags & PyBUF_WRITABLE) == 0) {
2519 if (flags & PyBUF_FORMAT) {
2520 view->format =
const_cast<char *
>(
"f");
2522 if (flags & PyBUF_ND) {
2525 view->shape[0] = self->
row_num;
2526 view->shape[1] = self->
col_num;
2528 if (flags & PyBUF_STRIDES) {
2530 view->strides[0] =
sizeof(
float);
2531 view->strides[1] = Py_ssize_t(self->
row_num) *
sizeof(
float);
2545 if (view->readonly == 0) {
2550 MEM_SAFE_DELETE(view->shape);
2551 MEM_SAFE_DELETE(view->strides);
2590 res = ok ? Py_False : Py_True;
2597 res = Py_NotImplemented;
2601 PyErr_BadArgument();
2606 return Py_NewRef(res);
2655 if (row < 0 || row >= self->
row_num) {
2656 PyErr_SetString(PyExc_IndexError,
2657 "matrix[attribute]: "
2658 "array index out of range");
2675 if (col < 0 || col >= self->
col_num) {
2676 PyErr_SetString(PyExc_IndexError,
2677 "matrix[attribute]: "
2678 "array index out of range");
2694 if (row >= self->
row_num || row < 0) {
2695 PyErr_SetString(PyExc_IndexError,
"matrix[attribute] = x: bad row");
2700 vec, self->
col_num, self->
col_num, value,
"matrix[i] = value assignment") == -1)
2706 for (col = 0; col < self->
col_num; col++) {
2723 if (col >= self->
col_num || col < 0) {
2724 PyErr_SetString(PyExc_IndexError,
"matrix[attribute] = x: bad col");
2729 vec, self->
row_num, self->
row_num, value,
"matrix[i] = value assignment") == -1)
2735 for (row = 0; row < self->
row_num; row++) {
2750 Py_ssize_t slice_length)
2756 PyObject *tuple = PyTuple_New(slice_length);
2757 Py_ssize_t
index = start;
2758 for (Py_ssize_t i = 0; i < slice_length; i++,
index +=
step) {
2760 PyTuple_SET_ITEM(tuple,
2776 Py_ssize_t slice_length,
2791 PyObject *value_fast = PySequence_Fast(value,
"matrix[slice] = value");
2792 if (value_fast ==
nullptr) {
2796 const Py_ssize_t value_num = PySequence_Fast_GET_SIZE(value_fast);
2797 if (value_num != slice_length) {
2798 Py_DECREF(value_fast);
2799 PyErr_Format(PyExc_ValueError,
2800 "matrix[slice] = value: sequence size is %zd, expected %zd",
2811 PyObject **value_fast_items = PySequence_Fast_ITEMS(value_fast);
2813 for (Py_ssize_t i = 0; i < slice_length; i++) {
2817 value_fast_items[i],
2818 "matrix[slice] = value") == -1)
2820 Py_DECREF(value_fast);
2825 Py_DECREF(value_fast);
2828 Py_ssize_t
index = start;
2829 for (Py_ssize_t i = 0; i < slice_length; i++,
index +=
step) {
2831 for (
int col = 0; col < self->
col_num; col++) {
2843 if (PyIndex_Check(item)) {
2845 i = PyNumber_AsSsize_t(item, PyExc_IndexError);
2846 if (i == -1 && PyErr_Occurred()) {
2854 if (PySlice_Check(item)) {
2855 Py_ssize_t start, stop,
step, slice_length;
2857 if (PySlice_GetIndicesEx(item, self->
row_num, &start, &stop, &
step, &slice_length) < 0) {
2865 PyExc_TypeError,
"matrix indices must be integers, not %.200s", Py_TYPE(item)->tp_name);
2872 if (PyIndex_Check(item)) {
2873 Py_ssize_t i = PyNumber_AsSsize_t(item, PyExc_IndexError);
2874 if (i == -1 && PyErr_Occurred()) {
2882 if (PySlice_Check(item)) {
2883 Py_ssize_t start, stop,
step, slice_length;
2885 if (PySlice_GetIndicesEx(item, self->
row_num, &start, &stop, &
step, &slice_length) < 0) {
2893 PyExc_TypeError,
"matrix indices must be integers, not %.200s", Py_TYPE(item)->tp_name);
2913 PyErr_Format(PyExc_TypeError,
2914 "Matrix addition: (%s + %s) "
2915 "invalid type for this operation",
2916 Py_TYPE(m1)->tp_name,
2917 Py_TYPE(m2)->tp_name);
2925 if (mat1->
col_num != mat2->col_num || mat1->
row_num != mat2->row_num) {
2926 PyErr_SetString(PyExc_ValueError,
2928 "matrices must have the same dimensions for this operation");
2947 PyErr_Format(PyExc_TypeError,
2948 "Matrix subtraction: (%s - %s) "
2949 "invalid type for this operation",
2950 Py_TYPE(m1)->tp_name,
2951 Py_TYPE(m2)->tp_name);
2959 if (mat1->
col_num != mat2->col_num || mat1->
row_num != mat2->row_num) {
2960 PyErr_SetString(PyExc_ValueError,
2962 "matrices must have the same dimensions for this operation");
3002 if ((mat1->
row_num != mat2->row_num) || (mat1->
col_num != mat2->col_num)) {
3003 PyErr_SetString(PyExc_ValueError,
3004 "matrix1 * matrix2: matrix1 number of rows/columns "
3005 "and the matrix2 number of rows/columns must be the same");
3015 if (((scalar = PyFloat_AsDouble(m1)) == -1.0f && PyErr_Occurred()) == 0) {
3021 if (((scalar = PyFloat_AsDouble(m2)) == -1.0f && PyErr_Occurred()) == 0) {
3026 PyErr_Format(PyExc_TypeError,
3027 "Element-wise multiplication: "
3028 "not supported between '%.200s' and '%.200s' types",
3029 Py_TYPE(m1)->tp_name,
3030 Py_TYPE(m2)->tp_name);
3056 if ((mat1->
row_num != mat2->row_num) || (mat1->
col_num != mat2->col_num)) {
3057 PyErr_SetString(PyExc_ValueError,
3058 "matrix1 *= matrix2: matrix1 number of rows/columns "
3059 "and the matrix2 number of rows/columns must be the same");
3065 else if (mat1 && (((scalar = PyFloat_AsDouble(m2)) == -1.0f && PyErr_Occurred()) == 0)) {
3070 PyErr_Format(PyExc_TypeError,
3071 "In place element-wise multiplication: "
3072 "not supported between '%.200s' and '%.200s' types",
3073 Py_TYPE(m1)->tp_name,
3074 Py_TYPE(m2)->tp_name);
3109 if (mat1->
col_num != mat2->row_num) {
3110 PyErr_SetString(PyExc_ValueError,
3111 "matrix1 * matrix2: matrix1 number of columns "
3112 "and the matrix2 number of rows must be the same");
3116 for (col = 0; col < mat2->col_num; col++) {
3117 for (row = 0; row < mat1->
row_num; row++) {
3119 for (item = 0; item < mat1->
col_num; item++) {
3122 mat[(col * mat1->
row_num) + row] =
float(
dot);
3151 PyErr_Format(PyExc_TypeError,
3152 "Matrix multiplication: "
3153 "not supported between '%.200s' and '%.200s' types",
3154 Py_TYPE(m1)->tp_name,
3155 Py_TYPE(m2)->tp_name);
3182 if (mat1->
col_num != mat2->row_num) {
3183 PyErr_SetString(PyExc_ValueError,
3184 "matrix1 * matrix2: matrix1 number of columns "
3185 "and the matrix2 number of rows must be the same");
3189 for (col = 0; col < mat2->col_num; col++) {
3190 for (row = 0; row < mat1->
row_num; row++) {
3192 for (item = 0; item < mat1->
col_num; item++) {
3197 mat[(col * mat1->
row_num) + row] =
float(
dot);
3202 memcpy(mat1->matrix, mat, (mat1->
row_num * mat1->
col_num) *
sizeof(
float));
3205 PyErr_Format(PyExc_TypeError,
3206 "In place matrix multiplication: "
3207 "not supported between '%.200s' and '%.200s' types",
3208 Py_TYPE(m1)->tp_name,
3209 Py_TYPE(m2)->tp_name);
3290 Matrix_translation_doc,
3291 "The translation component of the matrix.\n"
3293 ":type: :class:`Vector`\n");
3304 PyErr_SetString(PyExc_AttributeError,
3305 "Matrix.translation: "
3306 "inappropriate matrix size, must be 4x4");
3326 PyErr_SetString(PyExc_AttributeError,
3327 "Matrix.translation: "
3328 "inappropriate matrix size, must be 4x4");
3336 copy_v3_v3((
reinterpret_cast<float (*)[4]
>(self->matrix))[3], tvec);
3346 "Access the matrix by rows (default), (read-only).\n"
3348 ":type: :class:`MatrixAccess`\n");
3357 "Access the matrix by columns (read-only).\n"
3359 ":type: :class:`MatrixAccess`\n");
3367 Matrix_median_scale_doc,
3368 "The average scale applied to each axis (read-only).\n"
3381 PyErr_SetString(PyExc_AttributeError,
3382 "Matrix.median_scale: "
3383 "inappropriate matrix size, 3x3 minimum");
3394 Matrix_is_identity_doc,
3395 "True if this is an identity matrix (read-only).\n"
3408 Matrix_is_negative_doc,
3409 "True if this matrix results in a negative scale, 3x3 and 4x4 only, "
3421 return PyBool_FromLong(
is_negative_m4(
reinterpret_cast<const float (*)[4]
>(self->matrix)));
3424 return PyBool_FromLong(
is_negative_m3(
reinterpret_cast<const float (*)[3]
>(self->matrix)));
3427 PyErr_SetString(PyExc_AttributeError,
3428 "Matrix.is_negative: "
3429 "inappropriate matrix size - expects 3x3 or 4x4 matrix");
3435 Matrix_is_orthogonal_doc,
3436 "True if this matrix is orthogonal, 3x3 and 4x4 only, (read-only).\n"
3447 return PyBool_FromLong(
is_orthonormal_m4(
reinterpret_cast<const float (*)[4]
>(self->matrix)));
3450 return PyBool_FromLong(
is_orthonormal_m3(
reinterpret_cast<const float (*)[3]
>(self->matrix)));
3453 PyErr_SetString(PyExc_AttributeError,
3454 "Matrix.is_orthogonal: "
3455 "inappropriate matrix size - expects 3x3 or 4x4 matrix");
3461 Matrix_is_orthogonal_axis_vectors_doc,
3462 "True if this matrix has orthogonal axis vectors, 3x3 and 4x4 only, "
3474 return PyBool_FromLong(
is_orthogonal_m4(
reinterpret_cast<const float (*)[4]
>(self->matrix)));
3477 return PyBool_FromLong(
is_orthogonal_m3(
reinterpret_cast<const float (*)[3]
>(self->matrix)));
3480 PyErr_SetString(PyExc_AttributeError,
3481 "Matrix.is_orthogonal_axis_vectors: "
3482 "inappropriate matrix size - expects 3x3 or 4x4 matrix");
3495 static_cast<setter
>(
nullptr),
3496 Matrix_median_scale_doc,
3501 Matrix_translation_doc,
3505 static_cast<setter
>(
nullptr),
3510 static_cast<setter
>(
nullptr),
3515 static_cast<setter
>(
nullptr),
3516 Matrix_is_identity_doc,
3520 static_cast<setter
>(
nullptr),
3521 Matrix_is_negative_doc,
3525 static_cast<setter
>(
nullptr),
3526 Matrix_is_orthogonal_doc,
3528 {
"is_orthogonal_axis_vectors",
3530 static_cast<setter
>(
nullptr),
3531 Matrix_is_orthogonal_axis_vectors_doc,
3535 static_cast<setter
>(
nullptr),
3540 static_cast<setter
>(
nullptr),
3545 static_cast<setter
>(
nullptr),
3550 static_cast<setter
>(
nullptr),
3553 {
nullptr,
nullptr,
nullptr,
nullptr,
nullptr}
3564# pragma clang diagnostic push
3565# pragma clang diagnostic ignored "-Wcast-function-type"
3567# pragma GCC diagnostic push
3568# pragma GCC diagnostic ignored "-Wcast-function-type"
3577 Matrix_determinant_doc},
3581 Matrix_decompose_doc},
3584 {
"zero",
reinterpret_cast<PyCFunction
>(
Matrix_zero), METH_NOARGS, Matrix_zero_doc},
3585 {
"identity",
reinterpret_cast<PyCFunction
>(
Matrix_identity), METH_NOARGS, Matrix_identity_doc},
3591 Matrix_transpose_doc},
3595 Matrix_transposed_doc},
3599 Matrix_normalize_doc},
3603 Matrix_normalized_doc},
3604 {
"invert",
reinterpret_cast<PyCFunction
>(
Matrix_invert), METH_VARARGS, Matrix_invert_doc},
3608 Matrix_inverted_doc},
3612 Matrix_invert_safe_doc},
3616 Matrix_inverted_safe_doc},
3617 {
"adjugate",
reinterpret_cast<PyCFunction
>(
Matrix_adjugate), METH_NOARGS, Matrix_adjugate_doc},
3621 Matrix_adjugated_doc},
3622 {
"to_2x2",
reinterpret_cast<PyCFunction
>(
Matrix_to_2x2), METH_NOARGS, Matrix_to_2x2_doc},
3623 {
"to_3x3",
reinterpret_cast<PyCFunction
>(
Matrix_to_3x3), METH_NOARGS, Matrix_to_3x3_doc},
3624 {
"to_4x4",
reinterpret_cast<PyCFunction
>(
Matrix_to_4x4), METH_NOARGS, Matrix_to_4x4_doc},
3629 Matrix_resize_4x4_doc},
3630 {
"rotate",
reinterpret_cast<PyCFunction
>(
Matrix_rotate), METH_O, Matrix_rotate_doc},
3636 Matrix_to_euler_doc},
3640 Matrix_to_quaternion_doc},
3641 {
"to_scale",
reinterpret_cast<PyCFunction
>(
Matrix_to_scale), METH_NOARGS, Matrix_to_scale_doc},
3645 Matrix_to_translation_doc},
3648 {
"lerp",
reinterpret_cast<PyCFunction
>(
Matrix_lerp), METH_VARARGS, Matrix_lerp_doc},
3649 {
"copy",
reinterpret_cast<PyCFunction
>(
Matrix_copy), METH_NOARGS, Matrix_copy_doc},
3650 {
"__copy__",
reinterpret_cast<PyCFunction
>(
Matrix_copy), METH_NOARGS, Matrix_copy_doc},
3665 METH_VARARGS | METH_CLASS,
3666 C_Matrix_Identity_doc},
3669 METH_VARARGS | METH_CLASS,
3670 C_Matrix_Rotation_doc},
3673 METH_VARARGS | METH_CLASS,
3674 C_Matrix_Scale_doc},
3677 METH_VARARGS | METH_CLASS,
3678 C_Matrix_Shear_doc},
3681 METH_O | METH_CLASS,
3682 C_Matrix_Diagonal_doc},
3685 METH_O | METH_CLASS,
3686 C_Matrix_Translation_doc},
3689 METH_VARARGS | METH_CLASS,
3690 C_Matrix_OrthoProjection_doc},
3693 METH_VARARGS | METH_CLASS,
3694 C_Matrix_LocRotScale_doc},
3695 {
nullptr,
nullptr, 0,
nullptr},
3700# pragma clang diagnostic pop
3702# pragma GCC diagnostic pop
3712#ifdef MATH_STANDALONE
3713# define Matrix_str nullptr
3719 ".. class:: Matrix(rows=((1, 0, 0, 0), (0, 1, 0, 0), (0, 0, 1, 0), (0, 0, 0, 1)), /)\n"
3721 " This object gives access to Matrices in Blender, supporting square and rectangular\n"
3722 " matrices from 2x2 up to 4x4.\n"
3724 " :param rows: Sequence of rows.\n"
3725 " :type rows: Sequence[Sequence[float]]\n");
3727 PyVarObject_HEAD_INIT(
nullptr, 0)
3746 Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE | Py_TPFLAGS_HAVE_GC,
3778#ifdef MATH_STANDALONE
3791 PyTypeObject *base_type)
3797 if (col_num < 2 || col_num > 4 || row_num < 2 || row_num > 4) {
3798 PyErr_SetString(PyExc_RuntimeError,
3800 "row and column sizes must be between 2 and 4");
3804 mat_alloc =
static_cast<float *
>(PyMem_Malloc(col_num * row_num *
sizeof(
float)));
3805 if (mat_alloc ==
nullptr) [[unlikely]] {
3806 PyErr_SetString(PyExc_MemoryError,
3808 "problem allocating data");
3814 self->matrix = mat_alloc;
3819 self->cb_user =
nullptr;
3820 self->cb_type = self->cb_subtype = 0;
3823 memcpy(self->matrix, mat, col_num * row_num *
sizeof(
float));
3825 else if (col_num == row_num) {
3831 memset(self->matrix, 0, col_num * row_num *
sizeof(
float));
3836 PyMem_Free(mat_alloc);
3839 return reinterpret_cast<PyObject *
>(self);
3845 PyTypeObject *base_type)
3850 if (col_num < 2 || col_num > 4 || row_num < 2 || row_num > 4) {
3851 PyErr_SetString(PyExc_RuntimeError,
3853 "row and column sizes must be between 2 and 4");
3863 self->cb_user =
nullptr;
3864 self->cb_type = self->cb_subtype = 0;
3869 return reinterpret_cast<PyObject *
>(self);
3879 self->cb_user = cb_user;
3880 self->cb_type = cb_type;
3881 self->cb_subtype = cb_subtype;
3882 BLI_assert(!PyObject_GC_IsTracked((PyObject *)self));
3883 PyObject_GC_Track(self);
3885 return reinterpret_cast<PyObject *
>(self);
3891 PyTypeObject *base_type)
3900 return reinterpret_cast<PyObject *
>(self);
3916 PyExc_TypeError,
"expected a mathutils.Matrix, not a %.200s", Py_TYPE(pymat)->tp_name);
3947 PyErr_SetString(PyExc_ValueError,
"matrix must be 2x2");
3964 PyErr_SetString(PyExc_ValueError,
"matrix must be 3x3");
3981 PyErr_SetString(PyExc_ValueError,
"matrix must be 4x4");
4016 PyObject_GC_UnTrack(self);
4020 Py_TYPE(self)->tp_free(self);
4041 Py_ssize_t slice_length)
4044 int matrix_access_len;
4045 PyObject *(*Matrix_item_new)(
MatrixObject *, Py_ssize_t);
4048 matrix_access_len = matrix_user->
row_num;
4052 matrix_access_len = matrix_user->
col_num;
4056 PyObject *tuple = PyTuple_New(slice_length);
4057 Py_ssize_t
index = start;
4058 for (Py_ssize_t i = 0; i < slice_length; i++,
index +=
step) {
4061 PyTuple_SET_ITEM(tuple, i, Matrix_item_new(matrix_user,
index));
4074 Py_ssize_t slice_length,
4078 int matrix_access_len;
4082 matrix_access_len = matrix_user->
row_num;
4083 axis_size = matrix_user->
col_num;
4086 matrix_access_len = matrix_user->
col_num;
4087 axis_size = matrix_user->
row_num;
4102 PyObject *value_fast = PySequence_Fast(value,
"matrix.row/col[slice] = value");
4103 if (value_fast ==
nullptr) {
4107 const Py_ssize_t value_num = PySequence_Fast_GET_SIZE(value_fast);
4108 if (value_num != slice_length) {
4109 Py_DECREF(value_fast);
4110 PyErr_Format(PyExc_ValueError,
4111 "matrix.%s[slice] = value: sequence size is %zd, expected %zd",
4123 PyObject **value_fast_items = PySequence_Fast_ITEMS(value_fast);
4125 for (Py_ssize_t i = 0; i < slice_length; i++) {
4129 value_fast_items[i],
4130 "matrix.row/col[slice] = value") == -1)
4132 Py_DECREF(value_fast);
4137 Py_DECREF(value_fast);
4140 Py_ssize_t
index = start;
4142 for (Py_ssize_t i = 0; i < slice_length; i++,
index +=
step) {
4144 for (
int col = 0; col < axis_size; col++) {
4150 for (Py_ssize_t i = 0; i < slice_length; i++,
index +=
step) {
4152 for (
int row = 0; row < axis_size; row++) {
4166 if (PyIndex_Check(item)) {
4168 i = PyNumber_AsSsize_t(item, PyExc_IndexError);
4169 if (i == -1 && PyErr_Occurred()) {
4184 if (PySlice_Check(item)) {
4185 Py_ssize_t start, stop,
step, slice_length;
4197 PyExc_TypeError,
"matrix indices must be integers, not %.200s", Py_TYPE(item)->tp_name);
4205 if (PyIndex_Check(item)) {
4206 Py_ssize_t i = PyNumber_AsSsize_t(item, PyExc_IndexError);
4207 if (i == -1 && PyErr_Occurred()) {
4223 if (PySlice_Check(item)) {
4224 Py_ssize_t start, stop,
step, slice_length;
4236 PyExc_TypeError,
"matrix indices must be integers, not %.200s", Py_TYPE(item)->tp_name);
4244 PyObject *iter =
nullptr;
4250 iter = PyObject_GetIter(
ret);
4272 "An indexable type for accessing matrix rows or columns as :class:`Vector` types.\n");
4275 PyVarObject_HEAD_INIT(
nullptr, 0)
4294 Py_TPFLAGS_DEFAULT | Py_TPFLAGS_HAVE_GC,
4340 matrix_access->
type = type;
4342 return reinterpret_cast<PyObject *
>(matrix_access);
A dynamically sized string ADT.
#define PSEUDOINVERSE_EPSILON
#define SNPRINTF_UTF8_RLEN(dst, format,...)
#define BLI_assert_unreachable()
#define UNUSED_VARS_NDEBUG(...)
SIMD_FORCE_INLINE btScalar norm() const
Return the norm (length) of the vector.
SIMD_FORCE_INLINE btScalar angle(const btVector3 &v) const
Return the angle between this and another vector.
float dot(VecOp< float, D >, VecOp< float, D >) RET
VecBase< float, D > step(VecOp< float, D >, VecOp< float, D >) RET
float3x3 scale(float3x3 mat, float2 scale)
#define BaseMathObject_Prepare_ForResize(_self, error_prefix)
#define BaseMath_ReadCallback_ForWrite(_self)
#define BaseMath_Prepare_ForBufferAccess(_self, _view, _flags)
#define BaseMath_WriteCallback(_self)
#define BASE_MATH_NEW(struct_name, root_type, base_type)
#define BaseMathObject_Prepare_ForHash(_self)
#define BASE_MATH_FLAG_DEFAULT
#define BaseMath_Prepare_ForWrite(_self)
#define BaseMath_ReadCallback(_self)
#define EulerObject_Check(v)
#define MATRIX_COL_PTR(_mat, _col)
#define MatrixObject_Check(v)
#define MATRIX_ITEM_INDEX_NUMROW(_totrow, _row, _col)
#define MATRIX_ITEM(_mat, _row, _col)
#define QuaternionObject_Check(v)
#define VectorObject_Check(v)
char BaseMathObject_owner_doc[]
static void MatrixAccess_dealloc(MatrixAccessObject *self)
BLI_assert(slot->slot_subtype.map==BMO_OP_SLOT_SUBTYPE_MAP_FLT)
void mul_vn_fl(float *array_tar, int size, float f)
char BaseMathObject_freeze_doc[]
static PyObject * C_Matrix_Translation(PyObject *cls, PyObject *value)
static int Matrix_ass_subscript(MatrixObject *self, PyObject *item, PyObject *value)
static PyMethodDef Matrix_methods[]
int EXPP_VectorsAreEqual(const float *vecA, const float *vecB, int size, int floatSteps)
static PyObject * Matrix_zero(MatrixObject *self)
static PyObject * Matrix_to_NxN(MatrixObject *self, const int col_num, const int row_num)
static int mathutils_matrix_row_check(BaseMathObject *bmo)
void BLI_dynstr_appendf(DynStr *__restrict ds, const char *__restrict format,...) ATTR_PRINTF_FORMAT(2
static void adjoint_matrix_n(float *mat_dst, const float *mat_src, const ushort dim)
static bool matrix_invert_args_check(const MatrixObject *self, PyObject *args, bool check_type)
static PyObject * Matrix_imul(PyObject *m1, PyObject *m2)
void mat4_to_loc_rot_size(float loc[3], float rot[3][3], float size[3], const float wmat[4][4])
static Py_ssize_t MatrixAccess_len(MatrixAccessObject *self)
static PyObject * Matrix_matmul(PyObject *m1, PyObject *m2)
bool mathutils_slice_is_subset(Py_ssize_t start, Py_ssize_t step, Py_ssize_t slice_length, Py_ssize_t array_num)
static PyObject * Matrix_normalized(MatrixObject *self)
static int mathutils_matrix_translation_set(BaseMathObject *bmo, int col)
static PyObject * Matrix_str(MatrixObject *self)
void BaseMathObject_dealloc(BaseMathObject *self)
static PyObject * C_Matrix_OrthoProjection(PyObject *cls, PyObject *args)
MINLINE void copy_v3_v3(float r[3], const float a[3])
void mat4_to_quat(float q[4], const float mat[4][4])
static PyObject * C_Matrix_Rotation(PyObject *cls, PyObject *args)
int PyC_CheckArgs_DeepCopy(PyObject *args)
void * MEM_new_array_uninitialized(size_t len, size_t size, const char *str) ATTR_WARN_UNUSED_RESULT ATTR_ALLOC_SIZE(1
static PyObject * Matrix_transpose(MatrixObject *self)
void sub_vn_vnvn(float *array_tar, const float *array_src_a, const float *array_src_b, int size)
void copy_m3_m4(float m1[3][3], const float m2[4][4])
Py_hash_t mathutils_array_hash(const float *array, size_t array_len)
void copy_m3_m3(float m1[3][3], const float m2[3][3])
PyObject * mathutils_dynstr_to_py(DynStr *ds)
static int matrix_row_vector_check(MatrixObject *mat, VectorObject *vec, int row)
static PyObject * Matrix_to_3x3(MatrixObject *self)
void mul_vn_vn_fl(float *array_tar, const float *array_src, int size, float f)
void copy_m4_m3(float m1[4][4], const float m2[3][3])
static PyObject * Matrix_mul(PyObject *m1, PyObject *m2)
static PyObject * Matrix_transposed(MatrixObject *self)
static PyObject * Matrix_rotate(MatrixObject *self, PyObject *value)
static void matrix_transpose_internal(float mat_dst_fl[], const MatrixObject *mat_src)
uchar mathutils_matrix_col_cb_index
uchar mathutils_matrix_row_cb_index
void normalize_m3(float R[3][3]) ATTR_NONNULL()
static Py_hash_t Matrix_hash(MatrixObject *self)
PyDoc_STRVAR(bpy_bm_new_doc, ".. function:: new(*, use_operators=True)\n" "\n" " :param use_operators: Support calling operators in :mod:`bmesh.ops` (uses some " "extra memory per vert/edge/face).\n" " :type use_operators: bool\n" " :return: Return a new, empty BMesh.\n" " :rtype: :class:`bmesh.types.BMesh`\n")
PyObject * BaseMathObject_owner_get(BaseMathObject *self, void *)
static PyObject * Matrix_repr(MatrixObject *self)
int Matrix_Parse2x2(PyObject *o, void *p)
PyObject * Euler_CreatePyObject(const float eul[3], const short order, PyTypeObject *base_type)
static int mathutils_matrix_row_get_index(BaseMathObject *bmo, int row, int col)
void interp_m4_m4m4(float R[4][4], const float A[4][4], const float B[4][4], float t)
static PyObject * Matrix_richcmpr(PyObject *a, PyObject *b, int op)
float determinant_m2(float a, float b, float c, float d)
void axis_angle_to_mat3(float R[3][3], const float axis[3], float angle)
void blend_m4_m4m4(float out[4][4], const float dst[4][4], const float src[4][4], float srcweight)
static void Matrix_releasebuffer(PyObject *, Py_buffer *view)
PyTypeObject matrix_access_Type
bool is_negative_m4(const float mat[4][4])
static PyObject * Matrix_to_scale(MatrixObject *self)
static PyObject * matrix__apply_to_copy(PyObject *(*matrix_func)(MatrixObject *), MatrixObject *self)
int BaseMathObject_clear(BaseMathObject *self)
MINLINE int max_ii(int a, int b)
PyObject * BaseMathObject_freeze(BaseMathObject *self)
void unit_m2(float m[2][2])
int Matrix_ParseAny(PyObject *o, void *p)
void mat3_normalized_to_compatible_eulO(float eul[3], const float oldrot[3], short order, const float mat[3][3])
static int mathutils_matrix_translation_get(BaseMathObject *bmo, int col)
static PyObject * Matrix_to_translation(MatrixObject *self)
static int mathutils_matrix_col_get(BaseMathObject *bmo, int col)
void mat3_normalized_to_eul(float eul[3], const float mat[3][3])
float determinant_m3_array(const float m[3][3])
static int Matrix_ass_item_col(MatrixObject *self, int col, PyObject *value)
static void matrix_invert_raise_degenerate()
PyObject * Matrix_CreatePyObject_cb(PyObject *cb_user, const ushort col_num, const ushort row_num, uchar cb_type, uchar cb_subtype)
static PyObject * Matrix_to_2x2(MatrixObject *self)
Mathutils_Callback mathutils_matrix_col_cb
void mat3_to_rot_size(float rot[3][3], float size[3], const float mat3[3][3])
int BaseMathObject_is_gc(BaseMathObject *self)
void normalize_m4(float R[4][4]) ATTR_NONNULL()
static bool matrix_invert_is_compat(const MatrixObject *self)
static void matrix_identity_internal(MatrixObject *self)
static int MatrixAccess_clear(MatrixAccessObject *self)
static PyObject * Matrix_lerp(MatrixObject *self, PyObject *args)
static PyObject * MatrixAccess_iter(MatrixAccessObject *self)
static PyObject * Matrix_is_orthogonal_get(MatrixObject *self, void *)
PyObject * BaseMathObject_is_frozen_get(BaseMathObject *self, void *)
static PyObject * Matrix_is_negative_get(MatrixObject *self, void *)
bool is_orthogonal_m3(const float m[3][3])
static PyObject * Matrix_inverted(MatrixObject *self, PyObject *args)
void BLI_dynstr_append(DynStr *__restrict ds, const char *cstr) ATTR_NONNULL()
PyObject * Vector_CreatePyObject(const float *vec, const int vec_num, PyTypeObject *base_type)
PyObject * BaseMathObject_is_valid_get(BaseMathObject *self, void *)
void matrix_as_3x3(float mat[3][3], MatrixObject *self)
static int MatrixAccess_traverse(MatrixAccessObject *self, visitproc visit, void *arg)
void adjoint_m3_m3(float R[3][3], const float M[3][3])
PyObject * Matrix_CreatePyObject(const float *mat, const ushort col_num, const ushort row_num, PyTypeObject *base_type)
void transpose_m3(float R[3][3])
void mat3_normalized_to_quat_fast(float q[4], const float mat[3][3])
static PyObject * Matrix_translation_get(MatrixObject *self, void *)
static int mathutils_matrix_col_set_index(BaseMathObject *bmo, int col, int row)
static PyObject * Matrix_to_euler(MatrixObject *self, PyObject *args)
PyObject * Quaternion_CreatePyObject(const float quat[4], PyTypeObject *base_type)
Mathutils_Callback mathutils_matrix_row_cb
int Matrix_Parse3x3(PyObject *o, void *p)
static PyObject * Matrix_add(PyObject *m1, PyObject *m2)
static PyObject * MatrixAccess_CreatePyObject(MatrixObject *matrix, const eMatrixAccess_t type)
static PyObject * Matrix_deepcopy(MatrixObject *self, PyObject *args)
static int mathutils_matrix_col_get_index(BaseMathObject *bmo, int col, int row)
static void matrix_3x3_as_4x4(float mat[16])
static int Matrix_ass_item_row(MatrixObject *self, Py_ssize_t row, PyObject *value)
bool is_orthonormal_m3(const float m[3][3])
static PyObject * C_Matrix_Scale(PyObject *cls, PyObject *args)
void adjoint_m2_m2(float R[2][2], const float M[2][2])
static PyObject * Matrix_slice(MatrixObject *self, Py_ssize_t start, Py_ssize_t step, Py_ssize_t slice_length)
PyObject * Vector_CreatePyObject_cb(PyObject *cb_user, int vec_num, uchar cb_type, uchar cb_subtype)
static bool Matrix_ParseCheck(MatrixObject *pymat)
static PyNumberMethods Matrix_NumMethods
static int Matrix_getbuffer(PyObject *obj, Py_buffer *view, int flags)
static int MatrixAccess_ass_slice(MatrixAccessObject *self, Py_ssize_t start, Py_ssize_t step, Py_ssize_t slice_length, PyObject *value)
static bool matrix_invert_internal(const MatrixObject *self, float *r_mat)
@ BASE_MATH_FLAG_HAS_BUFFER_VIEW
PyObject * Matrix_CreatePyObject_wrap(float *mat, const ushort col_num, const ushort row_num, PyTypeObject *base_type)
void blend_m3_m3m3(float out[3][3], const float dst[3][3], const float src[3][3], float srcweight)
static PyObject * Matrix_to_quaternion(MatrixObject *self)
int mathutils_array_parse(float *array, int array_num_min, int array_num_max, PyObject *value, const char *error_prefix)
static PyObject * MatrixAccess_subscript(MatrixAccessObject *self, PyObject *item)
static PyObject * Matrix_adjugate(MatrixObject *self)
int column_vector_multiplication(float r_vec[4], VectorObject *vec, MatrixObject *mat)
static PyObject * Matrix_item_row(MatrixObject *self, Py_ssize_t row)
static Py_ssize_t Matrix_len(MatrixObject *self)
static PyObject * Matrix_normalize(MatrixObject *self)
void unit_m4(float m[4][4])
void mul_vn_vn(float *array_tar, const float *array_src, int size)
static PyBufferProcs Matrix_as_buffer
static int MatrixAccess_ass_subscript(MatrixAccessObject *self, PyObject *item, PyObject *value)
static PyObject * Matrix_is_orthogonal_axis_vectors_get(MatrixObject *self, void *)
static int matrix_col_vector_check(MatrixObject *mat, VectorObject *vec, int col)
static int mathutils_matrix_translation_check(BaseMathObject *bmo)
static PyObject * Matrix_inverted_noargs(MatrixObject *self)
void angle_to_mat2(float R[2][2], float angle)
MINLINE void zero_v3(float r[3])
short euler_order_from_string(const char *str, const char *error_prefix)
void mat3_normalized_to_compatible_eul(float eul[3], const float oldrot[3], float mat[3][3])
static PyObject * Matrix_sub(PyObject *m1, PyObject *m2)
static PyObject * Matrix_determinant(MatrixObject *self)
void add_vn_vnvn(float *array_tar, const float *array_src_a, const float *array_src_b, int size)
static PyObject * C_Matrix_Identity(PyObject *cls, PyObject *args)
static PyObject * Matrix_imatmul(PyObject *m1, PyObject *m2)
static int mathutils_matrix_row_set(BaseMathObject *bmo, int row)
static PyMappingMethods Matrix_AsMapping
static PyObject * Matrix_median_scale_get(MatrixObject *self, void *)
static PyObject * Matrix_row_get(MatrixObject *self, void *)
static PyMappingMethods MatrixAccess_AsMapping
PyObject * BaseMathObject_is_wrapped_get(BaseMathObject *self, void *)
char BaseMathObject_is_valid_doc[]
void transpose_m4(float R[4][4])
static PyObject * Matrix_to_4x4(MatrixObject *self)
void interp_m3_m3m3(float R[3][3], const float A[3][3], const float B[3][3], float t)
void unit_m3(float m[3][3])
Mathutils_Callback mathutils_matrix_translation_cb
bool is_orthonormal_m4(const float m[4][4])
static PyObject * Matrix_col_get(MatrixObject *self, void *)
int BaseMathObject_traverse(BaseMathObject *self, visitproc visit, void *arg)
static PyObject * Matrix_resize_4x4(MatrixObject *self)
int Matrix_Parse4x4(PyObject *o, void *p)
static bool matrix_is_identity(MatrixObject *self)
static PyObject * C_Matrix_LocRotScale(PyObject *cls, PyObject *args)
int mathutils_any_to_rotmat(float rmat[3][3], PyObject *value, const char *error_prefix)
static PyObject * Matrix_is_identity_get(MatrixObject *self, void *)
void eulO_to_mat4(float mat[4][4], const float e[3], short order)
uchar mathutils_matrix_translation_cb_index
static int Matrix_ass_slice(MatrixObject *self, Py_ssize_t start, Py_ssize_t step, Py_ssize_t slice_length, PyObject *value)
bool is_orthogonal_m4(const float m[4][4])
void rescale_m4(float mat[4][4], const float scale[3])
static PyObject * C_Matrix_Shear(PyObject *cls, PyObject *args)
static PyGetSetDef Matrix_getseters[]
static PyObject * matrix_mul_float(MatrixObject *mat, const float scalar)
static int mathutils_matrix_translation_set_index(BaseMathObject *bmo, int col, int row)
char BaseMathObject_is_frozen_doc[]
static PyObject * MatrixAccess_slice(MatrixAccessObject *self, Py_ssize_t start, Py_ssize_t step, Py_ssize_t slice_length)
static int Matrix_translation_set(MatrixObject *self, PyObject *value, void *)
static PyObject * Matrix_invert_safe(MatrixObject *self)
static PyObject * Matrix_invert(MatrixObject *self, PyObject *args)
void mul_vn_vnvn(float *array_tar, const float *array_src_a, const float *array_src_b, int size)
void mul_m3_m3m3(float R[3][3], const float A[3][3], const float B[3][3])
void copy_m4_m4(float m1[4][4], const float m2[4][4])
static void matrix_unit_internal(MatrixObject *self)
static PyObject * C_Matrix_Diagonal(PyObject *cls, PyObject *value)
static PyObject * Matrix_copy_notest(MatrixObject *self, const float *matrix)
static PyObject * Matrix_copy(MatrixObject *self)
bool is_negative_m3(const float mat[3][3])
static float matrix_determinant_internal(const MatrixObject *self)
static int mathutils_matrix_row_get(BaseMathObject *bmo, int row)
MINLINE int min_ii(int a, int b)
DynStr * BLI_dynstr_new() ATTR_MALLOC ATTR_WARN_UNUSED_RESULT
int PyC_ParseTypeOrNone(PyObject *o, void *p)
static PyObject * Matrix_vectorcall(PyObject *type, PyObject *const *args, const size_t nargsf, PyObject *kwnames)
static PyObject * Matrix_subscript(MatrixObject *self, PyObject *item)
PyObject * Matrix_CreatePyObject_alloc(float *mat, const ushort col_num, const ushort row_num, PyTypeObject *base_type)
static void matrix_invert_safe_internal(const MatrixObject *self, float *r_mat)
float determinant_m3(float a1, float a2, float a3, float b1, float b2, float b3, float c1, float c2, float c3)
float mat3_to_scale(const float mat[3][3])
void mat3_to_quat(float q[4], const float mat[3][3])
static void matrix_invert_with_det_n_internal(float *mat_dst, const float *mat_src, const float det, const ushort dim)
static int mathutils_matrix_col_set(BaseMathObject *bmo, int col)
static PyObject * Matrix_item_col(MatrixObject *self, Py_ssize_t col)
static int mathutils_matrix_col_check(BaseMathObject *bmo)
static void matrix_copy(MatrixObject *mat_dst, const MatrixObject *mat_src)
void mat3_normalized_to_eulO(float eul[3], short order, const float m[3][3])
void axis_angle_to_mat3_single(float R[3][3], char axis, float angle)
void quat_to_mat4(float m[4][4], const float q[4])
static PyObject * Matrix_inverted_safe(MatrixObject *self)
static int mathutils_matrix_translation_get_index(BaseMathObject *bmo, int col, int row)
static PyObject * Matrix_identity(MatrixObject *self)
static int mathutils_matrix_row_set_index(BaseMathObject *bmo, int row, int col)
void adjoint_m4_m4(float R[4][4], const float M[4][4])
static PyObject * Matrix_adjugated(MatrixObject *self)
static PyObject * Matrix_decompose(MatrixObject *self)
static PyObject * Matrix_new(PyTypeObject *type, PyObject *args, PyObject *kwds)
char BaseMathObject_is_wrapped_doc[]
float determinant_m4(const float m[4][4])
static PySequenceMethods Matrix_SeqMethods
float angle_wrap_rad(float angle)
#define PyC_TYPE_OR_NONE_INIT(py_type, value_p)
#define PyTuple_SET_ITEMS(op_arg,...)
KERNEL_FEATURE_LIGHT_PASSES KERNEL_FEATURE_PATH_GUIDING float
PyObject_HEAD MatrixObject * matrix_user