Cleanup: use "num" as a suffix in: source/blender/python

See T85728
This commit is contained in:
Campbell Barton
2022-03-28 11:06:01 +11:00
parent 77155ae1c0
commit 83c274ccfc
15 changed files with 547 additions and 540 deletions

View File

@@ -34,7 +34,7 @@ static PyObject *MatrixAccess_CreatePyObject(MatrixObject *matrix, const eMatrix
static int matrix_row_vector_check(MatrixObject *mat, VectorObject *vec, int row)
{
if ((vec->size != mat->num_col) || (row >= mat->num_row)) {
if ((vec->vec_num != mat->col_num) || (row >= mat->row_num)) {
PyErr_SetString(PyExc_AttributeError,
"Matrix(): "
"owner matrix has been resized since this row vector was created");
@@ -46,7 +46,7 @@ static int matrix_row_vector_check(MatrixObject *mat, VectorObject *vec, int row
static int matrix_col_vector_check(MatrixObject *mat, VectorObject *vec, int col)
{
if ((vec->size != mat->num_row) || (col >= mat->num_col)) {
if ((vec->vec_num != mat->row_num) || (col >= mat->col_num)) {
PyErr_SetString(PyExc_AttributeError,
"Matrix(): "
"owner matrix has been resized since this column vector was created");
@@ -80,7 +80,7 @@ static int mathutils_matrix_row_get(BaseMathObject *bmo, int row)
return -1;
}
for (col = 0; col < self->num_col; col++) {
for (col = 0; col < self->col_num; col++) {
bmo->data[col] = MATRIX_ITEM(self, row, col);
}
@@ -99,7 +99,7 @@ static int mathutils_matrix_row_set(BaseMathObject *bmo, int row)
return -1;
}
for (col = 0; col < self->num_col; col++) {
for (col = 0; col < self->col_num; col++) {
MATRIX_ITEM(self, row, col) = bmo->data[col];
}
@@ -162,7 +162,7 @@ static int mathutils_matrix_col_check(BaseMathObject *bmo)
static int mathutils_matrix_col_get(BaseMathObject *bmo, int col)
{
MatrixObject *self = (MatrixObject *)bmo->cb_user;
int num_row;
int row_num;
int row;
if (BaseMath_ReadCallback(self) == -1) {
@@ -172,10 +172,10 @@ static int mathutils_matrix_col_get(BaseMathObject *bmo, int col)
return -1;
}
/* for 'translation' size will always be '3' even on 4x4 vec */
num_row = min_ii(self->num_row, ((const VectorObject *)bmo)->size);
/* for 'translation' `vec_num` will always be '3' even on 4x4 vec */
row_num = min_ii(self->row_num, ((const VectorObject *)bmo)->vec_num);
for (row = 0; row < num_row; row++) {
for (row = 0; row < row_num; row++) {
bmo->data[row] = MATRIX_ITEM(self, row, col);
}
@@ -185,7 +185,7 @@ static int mathutils_matrix_col_get(BaseMathObject *bmo, int col)
static int mathutils_matrix_col_set(BaseMathObject *bmo, int col)
{
MatrixObject *self = (MatrixObject *)bmo->cb_user;
int num_row;
int row_num;
int row;
if (BaseMath_ReadCallback_ForWrite(self) == -1) {
@@ -195,10 +195,10 @@ static int mathutils_matrix_col_set(BaseMathObject *bmo, int col)
return -1;
}
/* for 'translation' size will always be '3' even on 4x4 vec */
num_row = min_ii(self->num_row, ((const VectorObject *)bmo)->size);
/* for 'translation' `vec_num` will always be '3' even on 4x4 vec */
row_num = min_ii(self->row_num, ((const VectorObject *)bmo)->vec_num);
for (row = 0; row < num_row; row++) {
for (row = 0; row < row_num; row++) {
MATRIX_ITEM(self, row, col) = bmo->data[row];
}
@@ -349,18 +349,18 @@ static PyObject *Matrix_new(PyTypeObject *type, PyObject *args, PyObject *kwds)
/* Input is now as a sequence of rows so length of sequence
* is the number of rows */
/* -1 is an error, size checks will account for this */
const ushort num_row = PySequence_Size(arg);
const ushort row_num = PySequence_Size(arg);
if (num_row >= 2 && num_row <= 4) {
if (row_num >= 2 && row_num <= 4) {
PyObject *item = PySequence_GetItem(arg, 0);
/* Since each item is a row, number of items is the
* same as the number of columns */
const ushort num_col = PySequence_Size(item);
const ushort col_num = PySequence_Size(item);
Py_XDECREF(item);
if (num_col >= 2 && num_col <= 4) {
if (col_num >= 2 && col_num <= 4) {
/* Sane row & col size, new matrix and assign as slice. */
PyObject *matrix = Matrix_CreatePyObject(NULL, num_col, num_row, type);
PyObject *matrix = Matrix_CreatePyObject(NULL, col_num, row_num, type);
if (Matrix_ass_slice((MatrixObject *)matrix, 0, INT_MAX, arg) == 0) {
return matrix;
}
@@ -613,7 +613,7 @@ PyDoc_STRVAR(C_Matrix_Scale_doc,
static PyObject *C_Matrix_Scale(PyObject *cls, PyObject *args)
{
PyObject *vec = NULL;
int vec_size;
int vec_num;
float tvec[3];
float factor;
int matSize;
@@ -646,12 +646,10 @@ static PyObject *C_Matrix_Scale(PyObject *cls, PyObject *args)
return NULL;
}
if (vec) {
vec_size = (matSize == 2 ? 2 : 3);
if (mathutils_array_parse(tvec,
vec_size,
vec_size,
vec,
"Matrix.Scale(factor, size, axis), invalid 'axis' arg") == -1) {
vec_num = (matSize == 2 ? 2 : 3);
if (mathutils_array_parse(
tvec, vec_num, vec_num, vec, "Matrix.Scale(factor, size, axis), invalid 'axis' arg") ==
-1) {
return NULL;
}
}
@@ -671,11 +669,11 @@ static PyObject *C_Matrix_Scale(PyObject *cls, PyObject *args)
* normalize arbitrary axis */
float norm = 0.0f;
int x;
for (x = 0; x < vec_size; x++) {
for (x = 0; x < vec_num; x++) {
norm += tvec[x] * tvec[x];
}
norm = sqrtf(norm);
for (x = 0; x < vec_size; x++) {
for (x = 0; x < vec_num; x++) {
tvec[x] /= norm;
}
if (matSize == 2) {
@@ -795,23 +793,23 @@ static PyObject *C_Matrix_OrthoProjection(PyObject *cls, PyObject *args)
else {
/* arbitrary plane */
const int vec_size = (matSize == 2 ? 2 : 3);
const int vec_num = (matSize == 2 ? 2 : 3);
float tvec[4];
if (mathutils_array_parse(tvec,
vec_size,
vec_size,
vec_num,
vec_num,
axis,
"Matrix.OrthoProjection(axis, size), invalid 'axis' arg") == -1) {
return NULL;
}
/* normalize arbitrary axis */
for (x = 0; x < vec_size; x++) {
for (x = 0; x < vec_num; x++) {
norm += tvec[x] * tvec[x];
}
norm = sqrtf(norm);
for (x = 0; x < vec_size; x++) {
for (x = 0; x < vec_num; x++) {
tvec[x] /= norm;
}
if (matSize == 2) {
@@ -1019,7 +1017,7 @@ static PyObject *C_Matrix_LocRotScale(PyObject *cls, PyObject *args)
return NULL;
}
if (mat_obj->num_col == 3 && mat_obj->num_row == 3) {
if (mat_obj->col_num == 3 && mat_obj->row_num == 3) {
copy_m4_m3(mat, (const float(*)[3])mat_obj->matrix);
}
else {
@@ -1062,20 +1060,20 @@ void matrix_as_3x3(float mat[3][3], MatrixObject *self)
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->col_num == mat_src->col_num) && (mat_dst->row_num == mat_src->row_num));
BLI_assert(mat_dst != mat_src);
memcpy(mat_dst->matrix, mat_src->matrix, sizeof(float) * (mat_dst->num_col * mat_dst->num_row));
memcpy(mat_dst->matrix, mat_src->matrix, sizeof(float) * (mat_dst->col_num * mat_dst->row_num));
}
static void matrix_unit_internal(MatrixObject *self)
{
const int mat_size = sizeof(float) * (self->num_col * self->num_row);
const int mat_size = sizeof(float) * (self->col_num * self->row_num);
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;
const int col_row_max = min_ii(self->col_num, self->row_num);
const int row_num = self->row_num;
for (int col = 0; col < col_row_max; col++) {
self->matrix[(col * num_row) + col] = 1.0f;
self->matrix[(col * row_num) + col] = 1.0f;
}
}
@@ -1085,8 +1083,8 @@ static void matrix_transpose_internal(float mat_dst_fl[], const MatrixObject *ma
ushort col, row;
uint i = 0;
for (row = 0; row < mat_src->num_row; row++) {
for (col = 0; col < mat_src->num_col; col++) {
for (row = 0; row < mat_src->row_num; row++) {
for (col = 0; col < mat_src->col_num; col++) {
mat_dst_fl[i++] = MATRIX_ITEM(mat_src, row, col);
}
}
@@ -1095,13 +1093,13 @@ static void matrix_transpose_internal(float mat_dst_fl[], const MatrixObject *ma
/* assumes rowsize == colsize is checked and the read callback has run */
static float matrix_determinant_internal(const MatrixObject *self)
{
if (self->num_col == 2) {
if (self->col_num == 2) {
return determinant_m2(MATRIX_ITEM(self, 0, 0),
MATRIX_ITEM(self, 0, 1),
MATRIX_ITEM(self, 1, 0),
MATRIX_ITEM(self, 1, 1));
}
if (self->num_col == 3) {
if (self->col_num == 3) {
return determinant_m3(MATRIX_ITEM(self, 0, 0),
MATRIX_ITEM(self, 0, 1),
MATRIX_ITEM(self, 0, 2),
@@ -1152,8 +1150,8 @@ static void matrix_invert_with_det_n_internal(float *mat_dst,
/* divide by determinant & set values */
k = 0;
for (i = 0; i < dim; i++) { /* num_col */
for (j = 0; j < dim; j++) { /* num_row */
for (i = 0; i < dim; i++) { /* col_num */
for (j = 0; j < dim; j++) { /* row_num */
mat_dst[MATRIX_ITEM_INDEX_NUMROW(dim, j, i)] = mat[k++] / det;
}
}
@@ -1165,11 +1163,11 @@ static void matrix_invert_with_det_n_internal(float *mat_dst,
static bool matrix_invert_internal(const MatrixObject *self, float *r_mat)
{
float det;
BLI_assert(self->num_col == self->num_row);
BLI_assert(self->col_num == self->row_num);
det = matrix_determinant_internal(self);
if (det != 0.0f) {
matrix_invert_with_det_n_internal(r_mat, self->matrix, det, self->num_col);
matrix_invert_with_det_n_internal(r_mat, self->matrix, det, self->col_num);
return true;
}
@@ -1184,7 +1182,7 @@ 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);
BLI_assert(self->col_num == self->row_num);
det = matrix_determinant_internal(self);
if (det == 0.0f) {
@@ -1194,7 +1192,7 @@ static void matrix_invert_safe_internal(const MatrixObject *self, float *r_mat)
* and modify it in place to add diagonal epsilon. */
in_mat = r_mat;
switch (self->num_col) {
switch (self->col_num) {
case 2: {
float(*mat)[2] = (float(*)[2])in_mat;
@@ -1248,7 +1246,7 @@ static void matrix_invert_safe_internal(const MatrixObject *self, float *r_mat)
}
}
matrix_invert_with_det_n_internal(r_mat, in_mat, det, self->num_col);
matrix_invert_with_det_n_internal(r_mat, in_mat, det, self->col_num);
}
/*-----------------------------METHODS----------------------------*/
@@ -1268,13 +1266,13 @@ static PyObject *Matrix_to_quaternion(MatrixObject *self)
}
/* must be 3-4 cols, 3-4 rows, square matrix */
if ((self->num_row < 3) || (self->num_col < 3) || (self->num_row != self->num_col)) {
if ((self->row_num < 3) || (self->col_num < 3) || (self->row_num != self->col_num)) {
PyErr_SetString(PyExc_ValueError,
"Matrix.to_quat(): "
"inappropriate matrix size - expects 3x3 or 4x4 matrix");
return NULL;
}
if (self->num_row == 3) {
if (self->row_num == 3) {
mat3_to_quat(quat, (float(*)[3])self->matrix);
}
else {
@@ -1326,10 +1324,10 @@ static PyObject *Matrix_to_euler(MatrixObject *self, PyObject *args)
}
/* Must be 3-4 cols, 3-4 rows, square matrix. */
if (self->num_row == 3 && self->num_col == 3) {
if (self->row_num == 3 && self->col_num == 3) {
copy_m3_m3(mat, (const float(*)[3])self->matrix);
}
else if (self->num_row == 4 && self->num_col == 4) {
else if (self->row_num == 4 && self->col_num == 4) {
copy_m3_m4(mat, (const float(*)[4])self->matrix);
}
else {
@@ -1401,36 +1399,36 @@ static PyObject *Matrix_resize_4x4(MatrixObject *self)
unit_m4(mat);
for (col = 0; col < self->num_col; col++) {
memcpy(mat[col], MATRIX_COL_PTR(self, col), self->num_row * sizeof(float));
for (col = 0; col < self->col_num; col++) {
memcpy(mat[col], MATRIX_COL_PTR(self, col), self->row_num * sizeof(float));
}
copy_m4_m4((float(*)[4])self->matrix, (const float(*)[4])mat);
self->num_col = 4;
self->num_row = 4;
self->col_num = 4;
self->row_num = 4;
Py_RETURN_NONE;
}
static PyObject *Matrix_to_NxN(MatrixObject *self, const int num_col, const int num_row)
static PyObject *Matrix_to_NxN(MatrixObject *self, const int col_num, const int row_num)
{
const int mat_size = sizeof(float) * (num_col * num_row);
const int mat_size = sizeof(float) * (col_num * row_num);
MatrixObject *pymat = (MatrixObject *)Matrix_CreatePyObject_alloc(
PyMem_Malloc(mat_size), num_col, num_row, Py_TYPE(self));
PyMem_Malloc(mat_size), col_num, row_num, Py_TYPE(self));
if ((self->num_row == num_row) && (self->num_col == num_col)) {
if ((self->row_num == row_num) && (self->col_num == col_num)) {
memcpy(pymat->matrix, self->matrix, mat_size);
}
else {
if ((self->num_col < num_col) || (self->num_row < num_row)) {
if ((self->col_num < col_num) || (self->row_num < row_num)) {
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);
const int col_len_src = min_ii(col_num, self->col_num);
const int row_len_src = min_ii(row_num, self->row_num);
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);
&pymat->matrix[col * row_num], MATRIX_COL_PTR(self, col), sizeof(float) * row_len_src);
}
}
return (PyObject *)pymat;
@@ -1495,7 +1493,7 @@ static PyObject *Matrix_to_translation(MatrixObject *self)
return NULL;
}
if ((self->num_row < 3) || self->num_col < 4) {
if ((self->row_num < 3) || self->col_num < 4) {
PyErr_SetString(PyExc_ValueError,
"Matrix.to_translation(): "
"inappropriate matrix size");
@@ -1526,7 +1524,7 @@ static PyObject *Matrix_to_scale(MatrixObject *self)
}
/* Must be 3-4 cols, 3-4 rows, square matrix. */
if ((self->num_row < 3) || (self->num_col < 3)) {
if ((self->row_num < 3) || (self->col_num < 3)) {
PyErr_SetString(PyExc_ValueError,
"Matrix.to_scale(): "
"inappropriate matrix size, 3x3 minimum size");
@@ -1546,7 +1544,7 @@ static PyObject *Matrix_to_scale(MatrixObject *self)
/* re-usable checks for invert */
static bool matrix_invert_is_compat(const MatrixObject *self)
{
if (self->num_col != self->num_row) {
if (self->col_num != self->row_num) {
PyErr_SetString(PyExc_ValueError,
"Matrix.invert(ed): "
"only square matrices are supported");
@@ -1571,7 +1569,7 @@ static bool matrix_invert_args_check(const MatrixObject *self, PyObject *args, b
return false;
}
if ((self->num_col != fallback->num_col) || (self->num_row != fallback->num_row)) {
if ((self->col_num != fallback->col_num) || (self->row_num != fallback->row_num)) {
PyErr_SetString(PyExc_TypeError,
"Matrix.invert: "
"matrix argument has different dimensions");
@@ -1782,7 +1780,7 @@ static PyObject *Matrix_adjugate(MatrixObject *self)
return NULL;
}
if (self->num_col != self->num_row) {
if (self->col_num != self->row_num) {
PyErr_SetString(PyExc_ValueError,
"Matrix.adjugate(d): "
"only square matrices are supported");
@@ -1790,12 +1788,12 @@ static PyObject *Matrix_adjugate(MatrixObject *self)
}
/* calculate the classical adjoint */
if (self->num_col <= 4) {
adjoint_matrix_n(self->matrix, self->matrix, self->num_col);
if (self->col_num <= 4) {
adjoint_matrix_n(self->matrix, self->matrix, self->col_num);
}
else {
PyErr_Format(
PyExc_ValueError, "Matrix adjugate(d): size (%d) unsupported", (int)self->num_col);
PyExc_ValueError, "Matrix adjugate(d): size (%d) unsupported", (int)self->col_num);
return NULL;
}
@@ -1838,7 +1836,7 @@ static PyObject *Matrix_rotate(MatrixObject *self, PyObject *value)
return NULL;
}
if (self->num_row != 3 || self->num_col != 3) {
if (self->row_num != 3 || self->col_num != 3) {
PyErr_SetString(PyExc_ValueError,
"Matrix.rotate(): "
"must have 3x3 dimensions");
@@ -1870,7 +1868,7 @@ static PyObject *Matrix_decompose(MatrixObject *self)
float quat[4];
float size[3];
if (self->num_row != 4 || self->num_col != 4) {
if (self->row_num != 4 || self->col_num != 4) {
PyErr_SetString(PyExc_ValueError,
"Matrix.decompose(): "
"inappropriate matrix size - expects 4x4 matrix");
@@ -1913,7 +1911,7 @@ static PyObject *Matrix_lerp(MatrixObject *self, PyObject *args)
return NULL;
}
if (self->num_col != mat2->num_col || self->num_row != mat2->num_row) {
if (self->col_num != mat2->col_num || self->row_num != mat2->row_num) {
PyErr_SetString(PyExc_ValueError,
"Matrix.lerp(): "
"expects both matrix objects of the same dimensions");
@@ -1925,14 +1923,14 @@ static PyObject *Matrix_lerp(MatrixObject *self, PyObject *args)
}
/* TODO: different sized matrix. */
if (self->num_col == 4 && self->num_row == 4) {
if (self->col_num == 4 && self->row_num == 4) {
#ifdef MATH_STANDALONE
blend_m4_m4m4((float(*)[4])mat, (float(*)[4])self->matrix, (float(*)[4])mat2->matrix, fac);
#else
interp_m4_m4m4((float(*)[4])mat, (float(*)[4])self->matrix, (float(*)[4])mat2->matrix, fac);
#endif
}
else if (self->num_col == 3 && self->num_row == 3) {
else if (self->col_num == 3 && self->row_num == 3) {
#ifdef MATH_STANDALONE
blend_m3_m3m3((float(*)[3])mat, (float(*)[3])self->matrix, (float(*)[3])mat2->matrix, fac);
#else
@@ -1946,7 +1944,7 @@ static PyObject *Matrix_lerp(MatrixObject *self, PyObject *args)
return NULL;
}
return Matrix_CreatePyObject(mat, self->num_col, self->num_row, Py_TYPE(self));
return Matrix_CreatePyObject(mat, self->col_num, self->row_num, Py_TYPE(self));
}
/*---------------------------matrix.determinant() ----------------*/
@@ -1966,7 +1964,7 @@ static PyObject *Matrix_determinant(MatrixObject *self)
return NULL;
}
if (self->num_col != self->num_row) {
if (self->col_num != self->row_num) {
PyErr_SetString(PyExc_ValueError,
"Matrix.determinant(): "
"only square matrices are supported");
@@ -1989,19 +1987,19 @@ static PyObject *Matrix_transpose(MatrixObject *self)
return NULL;
}
if (self->num_col != self->num_row) {
if (self->col_num != self->row_num) {
PyErr_SetString(PyExc_ValueError,
"Matrix.transpose(d): "
"only square matrices are supported");
return NULL;
}
if (self->num_col == 2) {
if (self->col_num == 2) {
const float t = MATRIX_ITEM(self, 1, 0);
MATRIX_ITEM(self, 1, 0) = MATRIX_ITEM(self, 0, 1);
MATRIX_ITEM(self, 0, 1) = t;
}
else if (self->num_col == 3) {
else if (self->col_num == 3) {
transpose_m3((float(*)[3])self->matrix);
}
else {
@@ -2035,17 +2033,17 @@ static PyObject *Matrix_normalize(MatrixObject *self)
return NULL;
}
if (self->num_col != self->num_row) {
if (self->col_num != self->row_num) {
PyErr_SetString(PyExc_ValueError,
"Matrix.normalize(): "
"only square matrices are supported");
return NULL;
}
if (self->num_col == 3) {
if (self->col_num == 3) {
normalize_m3((float(*)[3])self->matrix);
}
else if (self->num_col == 4) {
else if (self->col_num == 4) {
normalize_m4((float(*)[4])self->matrix);
}
else {
@@ -2083,7 +2081,7 @@ static PyObject *Matrix_zero(MatrixObject *self)
return NULL;
}
copy_vn_fl(self->matrix, self->num_col * self->num_row, 0.0f);
copy_vn_fl(self->matrix, self->col_num * self->row_num, 0.0f);
if (BaseMath_WriteCallback(self) == -1) {
return NULL;
@@ -2094,12 +2092,12 @@ static PyObject *Matrix_zero(MatrixObject *self)
/*---------------------------matrix.identity(() ------------------*/
static void matrix_identity_internal(MatrixObject *self)
{
BLI_assert((self->num_col == self->num_row) && (self->num_row <= 4));
BLI_assert((self->col_num == self->row_num) && (self->row_num <= 4));
if (self->num_col == 2) {
if (self->col_num == 2) {
unit_m2((float(*)[2])self->matrix);
}
else if (self->num_col == 3) {
else if (self->col_num == 3) {
unit_m3((float(*)[3])self->matrix);
}
else {
@@ -2123,7 +2121,7 @@ static PyObject *Matrix_identity(MatrixObject *self)
return NULL;
}
if (self->num_col != self->num_row) {
if (self->col_num != self->row_num) {
PyErr_SetString(PyExc_ValueError,
"Matrix.identity(): "
"only square matrices are supported");
@@ -2143,7 +2141,7 @@ static PyObject *Matrix_identity(MatrixObject *self)
static PyObject *Matrix_copy_notest(MatrixObject *self, const float *matrix)
{
return Matrix_CreatePyObject((const float *)matrix, self->num_col, self->num_row, Py_TYPE(self));
return Matrix_CreatePyObject((const float *)matrix, self->col_num, self->row_num, Py_TYPE(self));
}
PyDoc_STRVAR(Matrix_copy_doc,
@@ -2180,13 +2178,13 @@ static PyObject *Matrix_repr(MatrixObject *self)
return NULL;
}
for (row = 0; row < self->num_row; row++) {
rows[row] = PyTuple_New(self->num_col);
for (col = 0; col < self->num_col; col++) {
for (row = 0; row < self->row_num; row++) {
rows[row] = PyTuple_New(self->col_num);
for (col = 0; col < self->col_num; col++) {
PyTuple_SET_ITEM(rows[row], col, PyFloat_FromDouble(MATRIX_ITEM(self, row, col)));
}
}
switch (self->num_row) {
switch (self->row_num) {
case 2:
return PyUnicode_FromFormat(
"Matrix((%R,\n"
@@ -2236,9 +2234,9 @@ static PyObject *Matrix_str(MatrixObject *self)
ds = BLI_dynstr_new();
/* First determine the maximum width for each column */
for (col = 0; col < self->num_col; col++) {
for (col = 0; col < self->col_num; col++) {
maxsize[col] = 0;
for (row = 0; row < self->num_row; row++) {
for (row = 0; row < self->row_num; row++) {
const int size = BLI_snprintf_rlen(
dummy_buf, sizeof(dummy_buf), "%.4f", MATRIX_ITEM(self, row, col));
maxsize[col] = max_ii(maxsize[col], size);
@@ -2246,12 +2244,12 @@ static PyObject *Matrix_str(MatrixObject *self)
}
/* Now write the unicode string to be printed */
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++) {
BLI_dynstr_appendf(ds, "<Matrix %dx%d (", self->row_num, self->col_num);
for (row = 0; row < self->row_num; row++) {
for (col = 0; col < self->col_num; col++) {
BLI_dynstr_appendf(ds, col ? ", %*.4f" : "%*.4f", maxsize[col], MATRIX_ITEM(self, row, col));
}
BLI_dynstr_append(ds, row + 1 != self->num_row ? ")\n (" : ")");
BLI_dynstr_append(ds, row + 1 != self->row_num ? ")\n (" : ")");
}
BLI_dynstr_append(ds, ">");
@@ -2272,8 +2270,8 @@ static PyObject *Matrix_richcmpr(PyObject *a, PyObject *b, int op)
return NULL;
}
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)) ?
ok = ((matA->row_num == matB->row_num) && (matA->col_num == matB->col_num) &&
EXPP_VectorsAreEqual(matA->matrix, matB->matrix, (matA->col_num * matA->row_num), 1)) ?
0 :
-1;
}
@@ -2314,7 +2312,7 @@ static Py_hash_t Matrix_hash(MatrixObject *self)
matrix_transpose_internal(mat, self);
return mathutils_array_hash(mat, self->num_row * self->num_col);
return mathutils_array_hash(mat, self->row_num * self->col_num);
}
/*---------------------SEQUENCE PROTOCOLS------------------------
@@ -2322,7 +2320,7 @@ static Py_hash_t Matrix_hash(MatrixObject *self)
* sequence length */
static int Matrix_len(MatrixObject *self)
{
return self->num_row;
return self->row_num;
}
/*----------------------------object[]---------------------------
* sequence accessor (get)
@@ -2333,14 +2331,14 @@ static PyObject *Matrix_item_row(MatrixObject *self, int row)
return NULL;
}
if (row < 0 || row >= self->num_row) {
if (row < 0 || row >= self->row_num) {
PyErr_SetString(PyExc_IndexError,
"matrix[attribute]: "
"array index out of range");
return NULL;
}
return Vector_CreatePyObject_cb(
(PyObject *)self, self->num_col, mathutils_matrix_row_cb_index, row);
(PyObject *)self, self->col_num, mathutils_matrix_row_cb_index, row);
}
/* same but column access */
static PyObject *Matrix_item_col(MatrixObject *self, int col)
@@ -2349,14 +2347,14 @@ static PyObject *Matrix_item_col(MatrixObject *self, int col)
return NULL;
}
if (col < 0 || col >= self->num_col) {
if (col < 0 || col >= self->col_num) {
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);
(PyObject *)self, self->row_num, mathutils_matrix_col_cb_index, col);
}
/*----------------------------object[]-------------------------
@@ -2370,18 +2368,18 @@ static int Matrix_ass_item_row(MatrixObject *self, int row, PyObject *value)
return -1;
}
if (row >= self->num_row || row < 0) {
if (row >= self->row_num || row < 0) {
PyErr_SetString(PyExc_IndexError, "matrix[attribute] = x: bad row");
return -1;
}
if (mathutils_array_parse(
vec, self->num_col, self->num_col, value, "matrix[i] = value assignment") == -1) {
vec, self->col_num, self->col_num, value, "matrix[i] = value assignment") == -1) {
return -1;
}
/* Since we are assigning a row we cannot memcpy */
for (col = 0; col < self->num_col; col++) {
for (col = 0; col < self->col_num; col++) {
MATRIX_ITEM(self, row, col) = vec[col];
}
@@ -2396,18 +2394,18 @@ static int Matrix_ass_item_col(MatrixObject *self, int col, PyObject *value)
return -1;
}
if (col >= self->num_col || col < 0) {
if (col >= self->col_num || col < 0) {
PyErr_SetString(PyExc_IndexError, "matrix[attribute] = x: bad col");
return -1;
}
if (mathutils_array_parse(
vec, self->num_row, self->num_row, value, "matrix[i] = value assignment") == -1) {
vec, self->row_num, self->row_num, value, "matrix[i] = value assignment") == -1) {
return -1;
}
/* Since we are assigning a row we cannot memcpy */
for (row = 0; row < self->num_row; row++) {
for (row = 0; row < self->row_num; row++) {
MATRIX_ITEM(self, row, col) = vec[row];
}
@@ -2427,8 +2425,8 @@ static PyObject *Matrix_slice(MatrixObject *self, int begin, int end)
return NULL;
}
CLAMP(begin, 0, self->num_row);
CLAMP(end, 0, self->num_row);
CLAMP(begin, 0, self->row_num);
CLAMP(end, 0, self->row_num);
begin = MIN2(begin, end);
tuple = PyTuple_New(end - begin);
@@ -2436,7 +2434,7 @@ static PyObject *Matrix_slice(MatrixObject *self, int begin, int end)
PyTuple_SET_ITEM(tuple,
count - begin,
Vector_CreatePyObject_cb(
(PyObject *)self, self->num_col, mathutils_matrix_row_cb_index, count));
(PyObject *)self, self->col_num, mathutils_matrix_row_cb_index, count));
}
return tuple;
@@ -2451,8 +2449,8 @@ static int Matrix_ass_slice(MatrixObject *self, int begin, int end, PyObject *va
return -1;
}
CLAMP(begin, 0, self->num_row);
CLAMP(end, 0, self->num_row);
CLAMP(begin, 0, self->row_num);
CLAMP(end, 0, self->row_num);
begin = MIN2(begin, end);
/* non list/tuple cases */
@@ -2475,7 +2473,7 @@ static int Matrix_ass_slice(MatrixObject *self, int begin, int end, PyObject *va
return -1;
}
memcpy(mat, self->matrix, self->num_col * self->num_row * sizeof(float));
memcpy(mat, self->matrix, self->col_num * self->row_num * sizeof(float));
/* parse sub items */
for (row = begin; row < end; row++) {
@@ -2483,21 +2481,21 @@ static int Matrix_ass_slice(MatrixObject *self, int begin, int end, PyObject *va
PyObject *item = value_fast_items[row - begin];
if (mathutils_array_parse(
vec, self->num_col, self->num_col, item, "matrix[begin:end] = value assignment") ==
vec, self->col_num, self->col_num, item, "matrix[begin:end] = value assignment") ==
-1) {
Py_DECREF(value_fast);
return -1;
}
for (col = 0; col < self->num_col; col++) {
mat[col * self->num_row + row] = vec[col];
for (col = 0; col < self->col_num; col++) {
mat[col * self->row_num + row] = vec[col];
}
}
Py_DECREF(value_fast);
/* Parsed well - now set in matrix. */
memcpy(self->matrix, mat, self->num_col * self->num_row * sizeof(float));
memcpy(self->matrix, mat, self->col_num * self->row_num * sizeof(float));
(void)BaseMath_WriteCallback(self);
return 0;
@@ -2525,16 +2523,16 @@ static PyObject *Matrix_add(PyObject *m1, PyObject *m2)
return NULL;
}
if (mat1->num_col != mat2->num_col || mat1->num_row != mat2->num_row) {
if (mat1->col_num != mat2->col_num || mat1->row_num != mat2->row_num) {
PyErr_SetString(PyExc_ValueError,
"Matrix addition: "
"matrices must have the same dimensions for this operation");
return NULL;
}
add_vn_vnvn(mat, mat1->matrix, mat2->matrix, mat1->num_col * mat1->num_row);
add_vn_vnvn(mat, mat1->matrix, mat2->matrix, mat1->col_num * mat1->row_num);
return Matrix_CreatePyObject(mat, mat1->num_col, mat1->num_row, Py_TYPE(mat1));
return Matrix_CreatePyObject(mat, mat1->col_num, mat1->row_num, Py_TYPE(mat1));
}
/*------------------------obj - obj------------------------------
* subtraction */
@@ -2559,24 +2557,24 @@ static PyObject *Matrix_sub(PyObject *m1, PyObject *m2)
return NULL;
}
if (mat1->num_col != mat2->num_col || mat1->num_row != mat2->num_row) {
if (mat1->col_num != mat2->col_num || mat1->row_num != mat2->row_num) {
PyErr_SetString(PyExc_ValueError,
"Matrix addition: "
"matrices must have the same dimensions for this operation");
return NULL;
}
sub_vn_vnvn(mat, mat1->matrix, mat2->matrix, mat1->num_col * mat1->num_row);
sub_vn_vnvn(mat, mat1->matrix, mat2->matrix, mat1->col_num * mat1->row_num);
return Matrix_CreatePyObject(mat, mat1->num_col, mat1->num_row, Py_TYPE(mat1));
return Matrix_CreatePyObject(mat, mat1->col_num, mat1->row_num, Py_TYPE(mat1));
}
/*------------------------obj * obj------------------------------
* element-wise multiplication */
static PyObject *matrix_mul_float(MatrixObject *mat, const float scalar)
{
float tmat[MATRIX_MAX_DIM * MATRIX_MAX_DIM];
mul_vn_vn_fl(tmat, mat->matrix, mat->num_col * mat->num_row, scalar);
return Matrix_CreatePyObject(tmat, mat->num_col, mat->num_row, Py_TYPE(mat));
mul_vn_vn_fl(tmat, mat->matrix, mat->col_num * mat->row_num, scalar);
return Matrix_CreatePyObject(tmat, mat->col_num, mat->row_num, Py_TYPE(mat));
}
static PyObject *Matrix_mul(PyObject *m1, PyObject *m2)
@@ -2602,16 +2600,16 @@ static PyObject *Matrix_mul(PyObject *m1, PyObject *m2)
/* MATRIX * MATRIX */
float mat[MATRIX_MAX_DIM * MATRIX_MAX_DIM];
if ((mat1->num_row != mat2->num_row) || (mat1->num_col != mat2->num_col)) {
if ((mat1->row_num != mat2->row_num) || (mat1->col_num != mat2->col_num)) {
PyErr_SetString(PyExc_ValueError,
"matrix1 * matrix2: matrix1 number of rows/columns "
"and the matrix2 number of rows/columns must be the same");
return NULL;
}
mul_vn_vnvn(mat, mat1->matrix, mat2->matrix, mat1->num_col * mat1->num_row);
mul_vn_vnvn(mat, mat1->matrix, mat2->matrix, mat1->col_num * mat1->row_num);
return Matrix_CreatePyObject(mat, mat2->num_col, mat1->num_row, Py_TYPE(mat1));
return Matrix_CreatePyObject(mat, mat2->col_num, mat1->row_num, Py_TYPE(mat1));
}
if (mat2) {
/* FLOAT/INT * MATRIX */
@@ -2656,18 +2654,18 @@ static PyObject *Matrix_imul(PyObject *m1, PyObject *m2)
if (mat1 && mat2) {
/* MATRIX *= MATRIX */
if ((mat1->num_row != mat2->num_row) || (mat1->num_col != mat2->num_col)) {
if ((mat1->row_num != mat2->row_num) || (mat1->col_num != mat2->col_num)) {
PyErr_SetString(PyExc_ValueError,
"matrix1 *= matrix2: matrix1 number of rows/columns "
"and the matrix2 number of rows/columns must be the same");
return NULL;
}
mul_vn_vn(mat1->matrix, mat2->matrix, mat1->num_col * mat1->num_row);
mul_vn_vn(mat1->matrix, mat2->matrix, mat1->col_num * mat1->row_num);
}
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);
mul_vn_fl(mat1->matrix, mat1->row_num * mat1->col_num, scalar);
}
else {
PyErr_Format(PyExc_TypeError,
@@ -2686,7 +2684,7 @@ static PyObject *Matrix_imul(PyObject *m1, PyObject *m2)
* matrix multiplication */
static PyObject *Matrix_matmul(PyObject *m1, PyObject *m2)
{
int vec_size;
int vec_num;
MatrixObject *mat1 = NULL, *mat2 = NULL;
@@ -2709,24 +2707,24 @@ static PyObject *Matrix_matmul(PyObject *m1, PyObject *m2)
int col, row, item;
if (mat1->num_col != mat2->num_row) {
if (mat1->col_num != mat2->row_num) {
PyErr_SetString(PyExc_ValueError,
"matrix1 * matrix2: matrix1 number of columns "
"and the matrix2 number of rows must be the same");
return NULL;
}
for (col = 0; col < mat2->num_col; col++) {
for (row = 0; row < mat1->num_row; row++) {
for (col = 0; col < mat2->col_num; col++) {
for (row = 0; row < mat1->row_num; row++) {
double dot = 0.0f;
for (item = 0; item < mat1->num_col; item++) {
for (item = 0; item < mat1->col_num; item++) {
dot += (double)(MATRIX_ITEM(mat1, row, item) * MATRIX_ITEM(mat2, item, col));
}
mat[(col * mat1->num_row) + row] = (float)dot;
mat[(col * mat1->row_num) + row] = (float)dot;
}
}
return Matrix_CreatePyObject(mat, mat2->num_col, mat1->num_row, Py_TYPE(mat1));
return Matrix_CreatePyObject(mat, mat2->col_num, mat1->row_num, Py_TYPE(mat1));
}
if (mat1) {
/* MATRIX @ VECTOR */
@@ -2740,14 +2738,14 @@ static PyObject *Matrix_matmul(PyObject *m1, PyObject *m2)
return NULL;
}
if (mat1->num_col == 4 && vec2->size == 3) {
vec_size = 3;
if (mat1->col_num == 4 && vec2->vec_num == 3) {
vec_num = 3;
}
else {
vec_size = mat1->num_row;
vec_num = mat1->row_num;
}
return Vector_CreatePyObject(tvec, vec_size, Py_TYPE(m2));
return Vector_CreatePyObject(tvec, vec_num, Py_TYPE(m2));
}
}
@@ -2782,27 +2780,27 @@ static PyObject *Matrix_imatmul(PyObject *m1, PyObject *m2)
float mat[MATRIX_MAX_DIM * MATRIX_MAX_DIM];
int col, row, item;
if (mat1->num_col != mat2->num_row) {
if (mat1->col_num != mat2->row_num) {
PyErr_SetString(PyExc_ValueError,
"matrix1 * matrix2: matrix1 number of columns "
"and the matrix2 number of rows must be the same");
return NULL;
}
for (col = 0; col < mat2->num_col; col++) {
for (row = 0; row < mat1->num_row; row++) {
for (col = 0; col < mat2->col_num; col++) {
for (row = 0; row < mat1->row_num; row++) {
double dot = 0.0f;
for (item = 0; item < mat1->num_col; item++) {
for (item = 0; item < mat1->col_num; 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;
mat[(col * mat1->row_num) + row] = (float)dot;
}
}
/* copy matrix back */
memcpy(mat1->matrix, mat, (mat1->num_row * mat1->num_col) * sizeof(float));
memcpy(mat1->matrix, mat, (mat1->row_num * mat1->col_num) * sizeof(float));
}
else {
PyErr_Format(PyExc_TypeError,
@@ -2841,14 +2839,14 @@ static PyObject *Matrix_subscript(MatrixObject *self, PyObject *item)
return NULL;
}
if (i < 0) {
i += self->num_row;
i += self->row_num;
}
return Matrix_item_row(self, i);
}
if (PySlice_Check(item)) {
Py_ssize_t start, stop, step, slicelength;
if (PySlice_GetIndicesEx(item, self->num_row, &start, &stop, &step, &slicelength) < 0) {
if (PySlice_GetIndicesEx(item, self->row_num, &start, &stop, &step, &slicelength) < 0) {
return NULL;
}
@@ -2876,14 +2874,14 @@ static int Matrix_ass_subscript(MatrixObject *self, PyObject *item, PyObject *va
return -1;
}
if (i < 0) {
i += self->num_row;
i += self->row_num;
}
return Matrix_ass_item_row(self, i, value);
}
if (PySlice_Check(item)) {
Py_ssize_t start, stop, step, slicelength;
if (PySlice_GetIndicesEx(item, self->num_row, &start, &stop, &step, &slicelength) < 0) {
if (PySlice_GetIndicesEx(item, self->row_num, &start, &stop, &step, &slicelength) < 0) {
return -1;
}
@@ -2955,7 +2953,7 @@ static PyObject *Matrix_translation_get(MatrixObject *self, void *UNUSED(closure
}
/* Must be 4x4 square matrix. */
if (self->num_row != 4 || self->num_col != 4) {
if (self->row_num != 4 || self->col_num != 4) {
PyErr_SetString(PyExc_AttributeError,
"Matrix.translation: "
"inappropriate matrix size, must be 4x4");
@@ -2977,7 +2975,7 @@ static int Matrix_translation_set(MatrixObject *self, PyObject *value, void *UNU
}
/* Must be 4x4 square matrix. */
if (self->num_row != 4 || self->num_col != 4) {
if (self->row_num != 4 || self->col_num != 4) {
PyErr_SetString(PyExc_AttributeError,
"Matrix.translation: "
"inappropriate matrix size, must be 4x4");
@@ -3021,7 +3019,7 @@ static PyObject *Matrix_median_scale_get(MatrixObject *self, void *UNUSED(closur
}
/* Must be 3-4 cols, 3-4 rows, square matrix. */
if ((self->num_row < 3) || (self->num_col < 3)) {
if ((self->row_num < 3) || (self->col_num < 3)) {
PyErr_SetString(PyExc_AttributeError,
"Matrix.median_scale: "
"inappropriate matrix size, 3x3 minimum");
@@ -3043,10 +3041,10 @@ static PyObject *Matrix_is_negative_get(MatrixObject *self, void *UNUSED(closure
}
/* Must be 3-4 cols, 3-4 rows, square matrix. */
if (self->num_row == 4 && self->num_col == 4) {
if (self->row_num == 4 && self->col_num == 4) {
return PyBool_FromLong(is_negative_m4((const float(*)[4])self->matrix));
}
if (self->num_row == 3 && self->num_col == 3) {
if (self->row_num == 3 && self->col_num == 3) {
return PyBool_FromLong(is_negative_m3((const float(*)[3])self->matrix));
}
@@ -3065,10 +3063,10 @@ static PyObject *Matrix_is_orthogonal_get(MatrixObject *self, void *UNUSED(closu
}
/* Must be 3-4 cols, 3-4 rows, square matrix. */
if (self->num_row == 4 && self->num_col == 4) {
if (self->row_num == 4 && self->col_num == 4) {
return PyBool_FromLong(is_orthonormal_m4((const float(*)[4])self->matrix));
}
if (self->num_row == 3 && self->num_col == 3) {
if (self->row_num == 3 && self->col_num == 3) {
return PyBool_FromLong(is_orthonormal_m3((const float(*)[3])self->matrix));
}
@@ -3088,10 +3086,10 @@ static PyObject *Matrix_is_orthogonal_axis_vectors_get(MatrixObject *self, void
}
/* Must be 3-4 cols, 3-4 rows, square matrix. */
if (self->num_row == 4 && self->num_col == 4) {
if (self->row_num == 4 && self->col_num == 4) {
return PyBool_FromLong(is_orthogonal_m4((const float(*)[4])self->matrix));
}
if (self->num_row == 3 && self->num_col == 3) {
if (self->row_num == 3 && self->col_num == 3) {
return PyBool_FromLong(is_orthogonal_m3((const float(*)[3])self->matrix));
}
@@ -3271,22 +3269,22 @@ PyTypeObject matrix_Type = {
};
PyObject *Matrix_CreatePyObject(const float *mat,
const ushort num_col,
const ushort num_row,
const ushort col_num,
const ushort row_num,
PyTypeObject *base_type)
{
MatrixObject *self;
float *mat_alloc;
/* matrix objects can be any 2-4row x 2-4col matrix */
if (num_col < 2 || num_col > 4 || num_row < 2 || num_row > 4) {
if (col_num < 2 || col_num > 4 || row_num < 2 || row_num > 4) {
PyErr_SetString(PyExc_RuntimeError,
"Matrix(): "
"row and column sizes must be between 2 and 4");
return NULL;
}
mat_alloc = PyMem_Malloc(num_col * num_row * sizeof(float));
mat_alloc = PyMem_Malloc(col_num * row_num * sizeof(float));
if (UNLIKELY(mat_alloc == NULL)) {
PyErr_SetString(PyExc_MemoryError,
"Matrix(): "
@@ -3297,23 +3295,23 @@ PyObject *Matrix_CreatePyObject(const float *mat,
self = BASE_MATH_NEW(MatrixObject, matrix_Type, base_type);
if (self) {
self->matrix = mat_alloc;
self->num_col = num_col;
self->num_row = num_row;
self->col_num = col_num;
self->row_num = row_num;
/* init callbacks as NULL */
self->cb_user = NULL;
self->cb_type = self->cb_subtype = 0;
if (mat) { /* If a float array passed. */
memcpy(self->matrix, mat, num_col * num_row * sizeof(float));
memcpy(self->matrix, mat, col_num * row_num * sizeof(float));
}
else if (num_col == num_row) {
else if (col_num == row_num) {
/* or if no arguments are passed return identity matrix for square matrices */
matrix_identity_internal(self);
}
else {
/* otherwise zero everything */
memset(self->matrix, 0, num_col * num_row * sizeof(float));
memset(self->matrix, 0, col_num * row_num * sizeof(float));
}
self->flag = BASE_MATH_FLAG_DEFAULT;
}
@@ -3325,14 +3323,14 @@ PyObject *Matrix_CreatePyObject(const float *mat,
}
PyObject *Matrix_CreatePyObject_wrap(float *mat,
const ushort num_col,
const ushort num_row,
const ushort col_num,
const ushort row_num,
PyTypeObject *base_type)
{
MatrixObject *self;
/* matrix objects can be any 2-4row x 2-4col matrix */
if (num_col < 2 || num_col > 4 || num_row < 2 || num_row > 4) {
if (col_num < 2 || col_num > 4 || row_num < 2 || row_num > 4) {
PyErr_SetString(PyExc_RuntimeError,
"Matrix(): "
"row and column sizes must be between 2 and 4");
@@ -3341,8 +3339,8 @@ PyObject *Matrix_CreatePyObject_wrap(float *mat,
self = BASE_MATH_NEW(MatrixObject, matrix_Type, base_type);
if (self) {
self->num_col = num_col;
self->num_row = num_row;
self->col_num = col_num;
self->row_num = row_num;
/* init callbacks as NULL */
self->cb_user = NULL;
@@ -3355,9 +3353,9 @@ PyObject *Matrix_CreatePyObject_wrap(float *mat,
}
PyObject *Matrix_CreatePyObject_cb(
PyObject *cb_user, const ushort num_col, const ushort num_row, uchar cb_type, uchar cb_subtype)
PyObject *cb_user, const ushort col_num, const ushort row_num, uchar cb_type, uchar cb_subtype)
{
MatrixObject *self = (MatrixObject *)Matrix_CreatePyObject(NULL, num_col, num_row, NULL);
MatrixObject *self = (MatrixObject *)Matrix_CreatePyObject(NULL, col_num, row_num, NULL);
if (self) {
Py_INCREF(cb_user);
self->cb_user = cb_user;
@@ -3369,12 +3367,12 @@ PyObject *Matrix_CreatePyObject_cb(
}
PyObject *Matrix_CreatePyObject_alloc(float *mat,
const ushort num_col,
const ushort num_row,
const ushort col_num,
const ushort row_num,
PyTypeObject *base_type)
{
MatrixObject *self;
self = (MatrixObject *)Matrix_CreatePyObject_wrap(mat, num_col, num_row, base_type);
self = (MatrixObject *)Matrix_CreatePyObject_wrap(mat, col_num, row_num, base_type);
if (self) {
self->flag &= ~BASE_MATH_FLAG_IS_WRAP;
}
@@ -3419,7 +3417,7 @@ int Matrix_Parse2x2(PyObject *o, void *p)
if (!Matrix_ParseCheck(pymat)) {
return 0;
}
if ((pymat->num_col != 2) || (pymat->num_row != 2)) {
if ((pymat->col_num != 2) || (pymat->row_num != 2)) {
PyErr_SetString(PyExc_ValueError, "matrix must be 2x2");
return 0;
}
@@ -3436,7 +3434,7 @@ int Matrix_Parse3x3(PyObject *o, void *p)
if (!Matrix_ParseCheck(pymat)) {
return 0;
}
if ((pymat->num_col != 3) || (pymat->num_row != 3)) {
if ((pymat->col_num != 3) || (pymat->row_num != 3)) {
PyErr_SetString(PyExc_ValueError, "matrix must be 3x3");
return 0;
}
@@ -3453,7 +3451,7 @@ int Matrix_Parse4x4(PyObject *o, void *p)
if (!Matrix_ParseCheck(pymat)) {
return 0;
}
if ((pymat->num_col != 4) || (pymat->num_row != 4)) {
if ((pymat->col_num != 4) || (pymat->row_num != 4)) {
PyErr_SetString(PyExc_ValueError, "matrix must be 4x4");
return 0;
}
@@ -3497,7 +3495,7 @@ static void MatrixAccess_dealloc(MatrixAccessObject *self)
static int MatrixAccess_len(MatrixAccessObject *self)
{
return (self->type == MAT_ACCESS_ROW) ? self->matrix_user->num_row : self->matrix_user->num_col;
return (self->type == MAT_ACCESS_ROW) ? self->matrix_user->row_num : self->matrix_user->col_num;
}
static PyObject *MatrixAccess_slice(MatrixAccessObject *self, int begin, int end)
@@ -3511,11 +3509,11 @@ static PyObject *MatrixAccess_slice(MatrixAccessObject *self, int begin, int end
PyObject *(*Matrix_item_new)(MatrixObject *, int);
if (self->type == MAT_ACCESS_ROW) {
matrix_access_len = matrix_user->num_row;
matrix_access_len = matrix_user->row_num;
Matrix_item_new = Matrix_item_row;
}
else { /* MAT_ACCESS_ROW */
matrix_access_len = matrix_user->num_col;
matrix_access_len = matrix_user->col_num;
Matrix_item_new = Matrix_item_col;
}
@@ -3546,13 +3544,13 @@ static PyObject *MatrixAccess_subscript(MatrixAccessObject *self, PyObject *item
}
if (self->type == MAT_ACCESS_ROW) {
if (i < 0) {
i += matrix_user->num_row;
i += matrix_user->row_num;
}
return Matrix_item_row(matrix_user, i);
}
/* MAT_ACCESS_ROW */
if (i < 0) {
i += matrix_user->num_col;
i += matrix_user->col_num;
}
return Matrix_item_col(matrix_user, i);
}
@@ -3592,13 +3590,13 @@ static int MatrixAccess_ass_subscript(MatrixAccessObject *self, PyObject *item,
if (self->type == MAT_ACCESS_ROW) {
if (i < 0) {
i += matrix_user->num_row;
i += matrix_user->row_num;
}
return Matrix_ass_item_row(matrix_user, i, value);
}
/* MAT_ACCESS_ROW */
if (i < 0) {
i += matrix_user->num_col;
i += matrix_user->col_num;
}
return Matrix_ass_item_col(matrix_user, i, value);
}