diff options
author | Campbell Barton <campbell@blender.org> | 2022-03-28 03:06:01 +0300 |
---|---|---|
committer | Campbell Barton <campbell@blender.org> | 2022-03-28 06:14:31 +0300 |
commit | 83c274ccfc86c168657af9de9939cd96b0fc3f41 (patch) | |
tree | 6bd70f43b81d6352aba7d08a4ee93d2a1bbbcb44 | |
parent | 77155ae1c03e6bd430c4a3a1b9a09bd6d245a156 (diff) |
Cleanup: use "num" as a suffix in: source/blender/python
See T85728
-rw-r--r-- | source/blender/freestyle/intern/python/BPy_Convert.cpp | 8 | ||||
-rw-r--r-- | source/blender/python/bmesh/bmesh_py_ops_call.c | 4 | ||||
-rw-r--r-- | source/blender/python/bmesh/bmesh_py_types.c | 2 | ||||
-rw-r--r-- | source/blender/python/gpu/gpu_py_shader.c | 4 | ||||
-rw-r--r-- | source/blender/python/intern/bpy_app_handlers.c | 10 | ||||
-rw-r--r-- | source/blender/python/intern/bpy_rna_array.c | 8 | ||||
-rw-r--r-- | source/blender/python/mathutils/mathutils.c | 122 | ||||
-rw-r--r-- | source/blender/python/mathutils/mathutils.h | 4 | ||||
-rw-r--r-- | source/blender/python/mathutils/mathutils_Matrix.c | 396 | ||||
-rw-r--r-- | source/blender/python/mathutils/mathutils_Matrix.h | 24 | ||||
-rw-r--r-- | source/blender/python/mathutils/mathutils_Quaternion.c | 2 | ||||
-rw-r--r-- | source/blender/python/mathutils/mathutils_Vector.c | 428 | ||||
-rw-r--r-- | source/blender/python/mathutils/mathutils_Vector.h | 11 | ||||
-rw-r--r-- | source/blender/python/mathutils/mathutils_geometry.c | 39 | ||||
-rw-r--r-- | source/blender/python/mathutils/mathutils_noise.c | 25 |
15 files changed, 547 insertions, 540 deletions
diff --git a/source/blender/freestyle/intern/python/BPy_Convert.cpp b/source/blender/freestyle/intern/python/BPy_Convert.cpp index 55a33720465..02ed3f463c7 100644 --- a/source/blender/freestyle/intern/python/BPy_Convert.cpp +++ b/source/blender/freestyle/intern/python/BPy_Convert.cpp @@ -569,7 +569,7 @@ bool Vec3r_ptr_from_PyObject(PyObject *obj, Vec3r &vec) bool Vec2f_ptr_from_Vector(PyObject *obj, Vec2f &vec) { - if (!VectorObject_Check(obj) || ((VectorObject *)obj)->size != 2) { + if (!VectorObject_Check(obj) || ((VectorObject *)obj)->vec_num != 2) { return false; } if (BaseMath_ReadCallback((BaseMathObject *)obj) == -1) { @@ -582,7 +582,7 @@ bool Vec2f_ptr_from_Vector(PyObject *obj, Vec2f &vec) bool Vec3f_ptr_from_Vector(PyObject *obj, Vec3f &vec) { - if (!VectorObject_Check(obj) || ((VectorObject *)obj)->size != 3) { + if (!VectorObject_Check(obj) || ((VectorObject *)obj)->vec_num != 3) { return false; } if (BaseMath_ReadCallback((BaseMathObject *)obj) == -1) { @@ -596,7 +596,7 @@ bool Vec3f_ptr_from_Vector(PyObject *obj, Vec3f &vec) bool Vec3r_ptr_from_Vector(PyObject *obj, Vec3r &vec) { - if (!VectorObject_Check(obj) || ((VectorObject *)obj)->size != 3) { + if (!VectorObject_Check(obj) || ((VectorObject *)obj)->vec_num != 3) { return false; } if (BaseMath_ReadCallback((BaseMathObject *)obj) == -1) { @@ -758,7 +758,7 @@ bool Vec3r_ptr_from_PyTuple(PyObject *obj, Vec3r &vec) bool float_array_from_PyObject(PyObject *obj, float *v, int n) { - if (VectorObject_Check(obj) && ((VectorObject *)obj)->size == n) { + if (VectorObject_Check(obj) && ((VectorObject *)obj)->vec_num == n) { if (BaseMath_ReadCallback((BaseMathObject *)obj) == -1) { return false; } diff --git a/source/blender/python/bmesh/bmesh_py_ops_call.c b/source/blender/python/bmesh/bmesh_py_ops_call.c index 6492f528a5e..35d5cb6a994 100644 --- a/source/blender/python/bmesh/bmesh_py_ops_call.c +++ b/source/blender/python/bmesh/bmesh_py_ops_call.c @@ -233,8 +233,8 @@ static int bpy_slot_from_py(BMesh *bm, if (!Matrix_ParseAny(value, &pymat)) { return -1; } - const ushort size = pymat->num_col; - if ((size != pymat->num_row) || (!ELEM(size, 3, 4))) { + const ushort size = pymat->col_num; + if ((size != pymat->row_num) || (!ELEM(size, 3, 4))) { PyErr_Format(PyExc_TypeError, "%.200s: keyword \"%.200s\" expected a 3x3 or 4x4 matrix", opname, diff --git a/source/blender/python/bmesh/bmesh_py_types.c b/source/blender/python/bmesh/bmesh_py_types.c index 9ceff9b84b6..46f89dd4103 100644 --- a/source/blender/python/bmesh/bmesh_py_types.c +++ b/source/blender/python/bmesh/bmesh_py_types.c @@ -1309,7 +1309,7 @@ static PyObject *bpy_bmesh_transform(BPy_BMElem *self, PyObject *args, PyObject if (BaseMath_ReadCallback(mat) == -1) { return NULL; } - if (mat->num_col != 4 || mat->num_row != 4) { + if (mat->col_num != 4 || mat->row_num != 4) { PyErr_SetString(PyExc_ValueError, "expected a 4x4 matrix"); return NULL; } diff --git a/source/blender/python/gpu/gpu_py_shader.c b/source/blender/python/gpu/gpu_py_shader.c index 1a53ccd6686..43b26e05327 100644 --- a/source/blender/python/gpu/gpu_py_shader.c +++ b/source/blender/python/gpu/gpu_py_shader.c @@ -381,11 +381,11 @@ static PyObject *pygpu_shader_uniform_float(BPyGPUShader *self, PyObject *args) if (BaseMath_ReadCallback(mat) == -1) { return NULL; } - if ((mat->num_row != mat->num_col) || !ELEM(mat->num_row, 3, 4)) { + if ((mat->row_num != mat->col_num) || !ELEM(mat->row_num, 3, 4)) { PyErr_SetString(PyExc_ValueError, "Expected 3x3 or 4x4 matrix"); return NULL; } - length = mat->num_row * mat->num_col; + length = mat->row_num * mat->col_num; memcpy(values, mat->matrix, sizeof(float) * length); } else { diff --git a/source/blender/python/intern/bpy_app_handlers.c b/source/blender/python/intern/bpy_app_handlers.c index ba3e6a3d74b..34ffef03e66 100644 --- a/source/blender/python/intern/bpy_app_handlers.c +++ b/source/blender/python/intern/bpy_app_handlers.c @@ -24,7 +24,7 @@ void bpy_app_generic_callback(struct Main *main, struct PointerRNA **pointers, - const int num_pointers, + const int pointers_num, void *arg); static PyTypeObject BlenderAppCbType; @@ -305,7 +305,7 @@ static PyObject *choose_arguments(PyObject *func, PyObject *args_all, PyObject * /* the actual callback - not necessarily called from py */ void bpy_app_generic_callback(struct Main *UNUSED(main), struct PointerRNA **pointers, - const int num_pointers, + const int pointers_num, void *arg) { PyObject *cb_list = py_cb_array[POINTER_AS_INT(arg)]; @@ -320,14 +320,14 @@ void bpy_app_generic_callback(struct Main *UNUSED(main), Py_ssize_t pos; /* setup arguments */ - for (int i = 0; i < num_pointers; ++i) { + for (int i = 0; i < pointers_num; ++i) { PyTuple_SET_ITEM(args_all, i, pyrna_struct_CreatePyObject(pointers[i])); } - for (int i = num_pointers; i < num_arguments; ++i) { + for (int i = pointers_num; i < num_arguments; ++i) { PyTuple_SET_ITEM(args_all, i, Py_INCREF_RET(Py_None)); } - if (num_pointers == 0) { + if (pointers_num == 0) { PyTuple_SET_ITEM(args_single, 0, Py_INCREF_RET(Py_None)); } else { diff --git a/source/blender/python/intern/bpy_rna_array.c b/source/blender/python/intern/bpy_rna_array.c index f5bec247250..8506ec97bc3 100644 --- a/source/blender/python/intern/bpy_rna_array.c +++ b/source/blender/python/intern/bpy_rna_array.c @@ -377,15 +377,15 @@ static int validate_array(PyObject *rvalue, totdim); return -1; } - if (pymat->num_col != dimsize[0] || pymat->num_row != dimsize[1]) { + if (pymat->col_num != dimsize[0] || pymat->row_num != dimsize[1]) { PyErr_Format(PyExc_ValueError, "%s %.200s.%.200s, matrix assign dimension size mismatch, " "is %dx%d, expected be %dx%d", error_prefix, RNA_struct_identifier(ptr->type), RNA_property_identifier(prop), - pymat->num_col, - pymat->num_row, + pymat->col_num, + pymat->row_num, dimsize[0], dimsize[1]); return -1; @@ -473,7 +473,7 @@ static char *copy_values(PyObject *seq, if (dim == 0) { if (MatrixObject_Check(seq)) { MatrixObject *pymat = (MatrixObject *)seq; - const size_t allocsize = pymat->num_col * pymat->num_row * sizeof(float); + const size_t allocsize = pymat->col_num * pymat->row_num * sizeof(float); /* read callback already done by validate */ /* since this is the first iteration we can assume data is allocated */ diff --git a/source/blender/python/mathutils/mathutils.c b/source/blender/python/mathutils/mathutils.c index 8ed156a7e55..1aa2cec861c 100644 --- a/source/blender/python/mathutils/mathutils.c +++ b/source/blender/python/mathutils/mathutils.c @@ -92,47 +92,46 @@ Py_hash_t mathutils_array_hash(const float *array, size_t array_len) } int mathutils_array_parse( - float *array, int array_min, int array_max, PyObject *value, const char *error_prefix) + float *array, int array_num_min, int array_num_max, PyObject *value, const char *error_prefix) { - const uint flag = array_max; - int size; + const uint flag = array_num_max; + int num; - array_max &= ~MU_ARRAY_FLAGS; + array_num_max &= ~MU_ARRAY_FLAGS; #if 1 /* approx 6x speedup for mathutils types */ - if ((size = VectorObject_Check(value) ? ((VectorObject *)value)->size : 0) || - (size = EulerObject_Check(value) ? 3 : 0) || - (size = QuaternionObject_Check(value) ? 4 : 0) || - (size = ColorObject_Check(value) ? 3 : 0)) { + if ((num = VectorObject_Check(value) ? ((VectorObject *)value)->vec_num : 0) || + (num = EulerObject_Check(value) ? 3 : 0) || (num = QuaternionObject_Check(value) ? 4 : 0) || + (num = ColorObject_Check(value) ? 3 : 0)) { if (BaseMath_ReadCallback((BaseMathObject *)value) == -1) { return -1; } if (flag & MU_ARRAY_SPILL) { - CLAMP_MAX(size, array_max); + CLAMP_MAX(num, array_num_max); } - if (size > array_max || size < array_min) { - if (array_max == array_min) { + if (num > array_num_max || num < array_num_min) { + if (array_num_max == array_num_min) { PyErr_Format(PyExc_ValueError, - "%.200s: sequence size is %d, expected %d", + "%.200s: sequence length is %d, expected %d", error_prefix, - size, - array_max); + num, + array_num_max); } else { PyErr_Format(PyExc_ValueError, - "%.200s: sequence size is %d, expected [%d - %d]", + "%.200s: sequence length is %d, expected [%d - %d]", error_prefix, - size, - array_min, - array_max); + num, + array_num_min, + array_num_max); } return -1; } - memcpy(array, ((const BaseMathObject *)value)->data, size * sizeof(float)); + memcpy(array, ((const BaseMathObject *)value)->data, num * sizeof(float)); } else #endif @@ -145,77 +144,76 @@ int mathutils_array_parse( return -1; } - size = PySequence_Fast_GET_SIZE(value_fast); + num = PySequence_Fast_GET_SIZE(value_fast); if (flag & MU_ARRAY_SPILL) { - CLAMP_MAX(size, array_max); + CLAMP_MAX(num, array_num_max); } - if (size > array_max || size < array_min) { - if (array_max == array_min) { + if (num > array_num_max || num < array_num_min) { + if (array_num_max == array_num_min) { PyErr_Format(PyExc_ValueError, - "%.200s: sequence size is %d, expected %d", + "%.200s: sequence length is %d, expected %d", error_prefix, - size, - array_max); + num, + array_num_max); } else { PyErr_Format(PyExc_ValueError, - "%.200s: sequence size is %d, expected [%d - %d]", + "%.200s: sequence length is %d, expected [%d - %d]", error_prefix, - size, - array_min, - array_max); + num, + array_num_min, + array_num_max); } Py_DECREF(value_fast); return -1; } - size = mathutils_array_parse_fast(array, size, value_fast, error_prefix); + num = mathutils_array_parse_fast(array, num, value_fast, error_prefix); Py_DECREF(value_fast); } - if (size != -1) { + if (num != -1) { if (flag & MU_ARRAY_ZERO) { - const int size_left = array_max - size; - if (size_left) { - memset(&array[size], 0, sizeof(float) * size_left); + const int array_num_left = array_num_max - num; + if (array_num_left) { + memset(&array[num], 0, sizeof(float) * array_num_left); } } } - return size; + return num; } int mathutils_array_parse_alloc(float **array, - int array_min, + int array_num, PyObject *value, const char *error_prefix) { - int size; + int num; #if 1 /* approx 6x speedup for mathutils types */ - if ((size = VectorObject_Check(value) ? ((VectorObject *)value)->size : 0) || - (size = EulerObject_Check(value) ? 3 : 0) || - (size = QuaternionObject_Check(value) ? 4 : 0) || - (size = ColorObject_Check(value) ? 3 : 0)) { + if ((num = VectorObject_Check(value) ? ((VectorObject *)value)->vec_num : 0) || + (num = EulerObject_Check(value) ? 3 : 0) || (num = QuaternionObject_Check(value) ? 4 : 0) || + (num = ColorObject_Check(value) ? 3 : 0)) { if (BaseMath_ReadCallback((BaseMathObject *)value) == -1) { return -1; } - if (size < array_min) { + if (num < array_num) { PyErr_Format(PyExc_ValueError, "%.200s: sequence size is %d, expected > %d", error_prefix, - size, - array_min); + num, + array_num); return -1; } - *array = PyMem_Malloc(size * sizeof(float)); - memcpy(*array, ((const BaseMathObject *)value)->data, size * sizeof(float)); - return size; + *array = PyMem_Malloc(num * sizeof(float)); + memcpy(*array, ((const BaseMathObject *)value)->data, num * sizeof(float)); + return num; } #endif @@ -230,21 +228,21 @@ int mathutils_array_parse_alloc(float **array, return -1; } - size = PySequence_Fast_GET_SIZE(value_fast); + num = PySequence_Fast_GET_SIZE(value_fast); - if (size < array_min) { + if (num < array_num) { Py_DECREF(value_fast); PyErr_Format(PyExc_ValueError, "%.200s: sequence size is %d, expected > %d", error_prefix, - size, - array_min); + num, + array_num); return -1; } - *array = PyMem_Malloc(size * sizeof(float)); + *array = PyMem_Malloc(num * sizeof(float)); - ret = mathutils_array_parse_fast(*array, size, value_fast, error_prefix); + ret = mathutils_array_parse_fast(*array, num, value_fast, error_prefix); Py_DECREF(value_fast); if (ret == -1) { @@ -261,7 +259,7 @@ int mathutils_array_parse_alloc_v(float **array, { PyObject *value_fast; const int array_dim_flag = array_dim; - int i, size; + int i, num; /* non list/tuple cases */ if (!(value_fast = PySequence_Fast(value, error_prefix))) { @@ -269,30 +267,30 @@ int mathutils_array_parse_alloc_v(float **array, return -1; } - size = PySequence_Fast_GET_SIZE(value_fast); + num = PySequence_Fast_GET_SIZE(value_fast); - if (size != 0) { + if (num != 0) { PyObject **value_fast_items = PySequence_Fast_ITEMS(value_fast); float *fp; array_dim &= ~MU_ARRAY_FLAGS; - fp = *array = PyMem_Malloc(size * array_dim * sizeof(float)); + fp = *array = PyMem_Malloc(num * array_dim * sizeof(float)); - for (i = 0; i < size; i++, fp += array_dim) { + for (i = 0; i < num; i++, fp += array_dim) { PyObject *item = value_fast_items[i]; if (mathutils_array_parse(fp, array_dim, array_dim_flag, item, error_prefix) == -1) { PyMem_Free(*array); *array = NULL; - size = -1; + num = -1; break; } } } Py_DECREF(value_fast); - return size; + return num; } int mathutils_int_array_parse(int *array, int array_dim, PyObject *value, const char *error_prefix) @@ -458,7 +456,7 @@ int mathutils_any_to_rotmat(float rmat[3][3], PyObject *value, const char *error if (BaseMath_ReadCallback((BaseMathObject *)value) == -1) { return -1; } - if (((MatrixObject *)value)->num_row < 3 || ((MatrixObject *)value)->num_col < 3) { + if (((MatrixObject *)value)->row_num < 3 || ((MatrixObject *)value)->col_num < 3) { PyErr_Format( PyExc_ValueError, "%.200s: matrix must have minimum 3x3 dimensions", error_prefix); return -1; diff --git a/source/blender/python/mathutils/mathutils.h b/source/blender/python/mathutils/mathutils.h index 5831489ef5b..84386e99d18 100644 --- a/source/blender/python/mathutils/mathutils.h +++ b/source/blender/python/mathutils/mathutils.h @@ -153,12 +153,12 @@ void _BaseMathObject_RaiseNotFrozenExc(const BaseMathObject *self); * \return length of `value`, -1 on error. */ int mathutils_array_parse( - float *array, int array_min, int array_max, PyObject *value, const char *error_prefix); + float *array, int array_num_min, int array_num_max, PyObject *value, const char *error_prefix); /** * \return -1 is returned on error and no allocation is made. */ int mathutils_array_parse_alloc(float **array, - int array_min, + int array_num_min, PyObject *value, const char *error_prefix); /** diff --git a/source/blender/python/mathutils/mathutils_Matrix.c b/source/blender/python/mathutils/mathutils_Matrix.c index b8eaf1486ab..76b5424711f 100644 --- a/source/blender/python/mathutils/mathutils_Matrix.c +++ b/source/blender/python/mathutils/mathutils_Matrix.c @@ -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); } diff --git a/source/blender/python/mathutils/mathutils_Matrix.h b/source/blender/python/mathutils/mathutils_Matrix.h index 6dd1640b3bf..bc596ce6ac8 100644 --- a/source/blender/python/mathutils/mathutils_Matrix.h +++ b/source/blender/python/mathutils/mathutils_Matrix.h @@ -20,14 +20,14 @@ typedef unsigned short ushort; #ifdef DEBUG # define MATRIX_ITEM_ASSERT(_mat, _row, _col) \ - (BLI_assert(_row < (_mat)->num_row && _col < (_mat)->num_col)) + (BLI_assert(_row < (_mat)->row_num && _col < (_mat)->col_num)) #else # define MATRIX_ITEM_ASSERT(_mat, _row, _col) (void)0 #endif #define MATRIX_ITEM_INDEX_NUMROW(_totrow, _row, _col) (((_totrow) * (_col)) + (_row)) #define MATRIX_ITEM_INDEX(_mat, _row, _col) \ - (MATRIX_ITEM_ASSERT(_mat, _row, _col), (((_mat)->num_row * (_col)) + (_row))) + (MATRIX_ITEM_ASSERT(_mat, _row, _col), (((_mat)->row_num * (_col)) + (_row))) #define MATRIX_ITEM_PTR(_mat, _row, _col) ((_mat)->matrix + MATRIX_ITEM_INDEX(_mat, _row, _col)) #define MATRIX_ITEM(_mat, _row, _col) ((_mat)->matrix[MATRIX_ITEM_INDEX(_mat, _row, _col)]) @@ -36,8 +36,8 @@ typedef unsigned short ushort; typedef struct { BASE_MATH_MEMBERS(matrix); - ushort num_col; - ushort num_row; + ushort col_num; + ushort row_num; } MatrixObject; /* struct data contains a pointer to the actual data that the @@ -47,17 +47,17 @@ typedef struct { /* prototypes */ PyObject *Matrix_CreatePyObject(const float *mat, - ushort num_col, - ushort num_row, + ushort col_num, + ushort row_num, PyTypeObject *base_type) ATTR_WARN_UNUSED_RESULT; PyObject *Matrix_CreatePyObject_wrap(float *mat, - ushort num_col, - ushort num_row, + ushort col_num, + ushort row_num, PyTypeObject *base_type) ATTR_WARN_UNUSED_RESULT ATTR_NONNULL(1); PyObject *Matrix_CreatePyObject_cb(PyObject *user, - unsigned short num_col, - unsigned short num_row, + unsigned short col_num, + unsigned short row_num, unsigned char cb_type, unsigned char cb_subtype) ATTR_WARN_UNUSED_RESULT; @@ -65,8 +65,8 @@ PyObject *Matrix_CreatePyObject_cb(PyObject *user, * \param mat: Initialized matrix value to use in-place, allocated with #PyMem_Malloc */ PyObject *Matrix_CreatePyObject_alloc(float *mat, - ushort num_col, - ushort num_row, + ushort col_num, + ushort row_num, PyTypeObject *base_type) ATTR_WARN_UNUSED_RESULT; /* PyArg_ParseTuple's "O&" formatting helpers. */ diff --git a/source/blender/python/mathutils/mathutils_Quaternion.c b/source/blender/python/mathutils/mathutils_Quaternion.c index f0ba125e768..7b51154f0d0 100644 --- a/source/blender/python/mathutils/mathutils_Quaternion.c +++ b/source/blender/python/mathutils/mathutils_Quaternion.c @@ -1035,7 +1035,7 @@ static PyObject *Quaternion_matmul(PyObject *q1, PyObject *q2) VectorObject *vec2 = (VectorObject *)q2; float tvec[3]; - if (vec2->size != 3) { + if (vec2->vec_num != 3) { PyErr_SetString(PyExc_ValueError, "Vector multiplication: " "only 3D vector rotations (with quats) " diff --git a/source/blender/python/mathutils/mathutils_Vector.c b/source/blender/python/mathutils/mathutils_Vector.c index 080a1e7fbdd..ffeb121b3d1 100644 --- a/source/blender/python/mathutils/mathutils_Vector.c +++ b/source/blender/python/mathutils/mathutils_Vector.c @@ -45,7 +45,7 @@ static int row_vector_multiplication(float r_vec[MAX_DIMENSIONS], static PyObject *Vector_new(PyTypeObject *type, PyObject *args, PyObject *kwds) { float *vec = NULL; - int size = 3; /* default to a 3D vector */ + int vec_num = 3; /* default to a 3D vector */ if (kwds && PyDict_Size(kwds)) { PyErr_SetString(PyExc_TypeError, @@ -56,7 +56,7 @@ static PyObject *Vector_new(PyTypeObject *type, PyObject *args, PyObject *kwds) switch (PyTuple_GET_SIZE(args)) { case 0: - vec = PyMem_Malloc(size * sizeof(float)); + vec = PyMem_Malloc(vec_num * sizeof(float)); if (vec == NULL) { PyErr_SetString(PyExc_MemoryError, @@ -65,10 +65,10 @@ static PyObject *Vector_new(PyTypeObject *type, PyObject *args, PyObject *kwds) return NULL; } - copy_vn_fl(vec, size, 0.0f); + copy_vn_fl(vec, vec_num, 0.0f); break; case 1: - if ((size = mathutils_array_parse_alloc( + if ((vec_num = mathutils_array_parse_alloc( &vec, 2, PyTuple_GET_ITEM(args, 0), "mathutils.Vector()")) == -1) { return NULL; } @@ -79,7 +79,7 @@ static PyObject *Vector_new(PyTypeObject *type, PyObject *args, PyObject *kwds) "more than a single arg given"); return NULL; } - return Vector_CreatePyObject_alloc(vec, size, type); + return Vector_CreatePyObject_alloc(vec, vec_num, type); } static PyObject *vec__apply_to_copy(PyObject *(*vec_func)(VectorObject *), VectorObject *self) @@ -108,19 +108,19 @@ PyDoc_STRVAR(C_Vector_Fill_doc, static PyObject *C_Vector_Fill(PyObject *cls, PyObject *args) { float *vec; - int size; + int vec_num; float fill = 0.0f; - if (!PyArg_ParseTuple(args, "i|f:Vector.Fill", &size, &fill)) { + if (!PyArg_ParseTuple(args, "i|f:Vector.Fill", &vec_num, &fill)) { return NULL; } - if (size < 2) { + if (vec_num < 2) { PyErr_SetString(PyExc_RuntimeError, "Vector(): invalid size"); return NULL; } - vec = PyMem_Malloc(size * sizeof(float)); + vec = PyMem_Malloc(vec_num * sizeof(float)); if (vec == NULL) { PyErr_SetString(PyExc_MemoryError, @@ -129,9 +129,9 @@ static PyObject *C_Vector_Fill(PyObject *cls, PyObject *args) return NULL; } - copy_vn_fl(vec, size, fill); + copy_vn_fl(vec, vec_num, fill); - return Vector_CreatePyObject_alloc(vec, size, (PyTypeObject *)cls); + return Vector_CreatePyObject_alloc(vec, vec_num, (PyTypeObject *)cls); } PyDoc_STRVAR(C_Vector_Range_doc, @@ -148,7 +148,7 @@ PyDoc_STRVAR(C_Vector_Range_doc, static PyObject *C_Vector_Range(PyObject *cls, PyObject *args) { float *vec; - int stop, size; + int stop, vec_num; int start = 0; int step = 1; @@ -158,7 +158,7 @@ static PyObject *C_Vector_Range(PyObject *cls, PyObject *args) switch (PyTuple_GET_SIZE(args)) { case 1: - size = start; + vec_num = start; start = 0; break; case 2: @@ -169,7 +169,7 @@ static PyObject *C_Vector_Range(PyObject *cls, PyObject *args) return NULL; } - size = stop - start; + vec_num = stop - start; break; default: if (start >= stop) { @@ -179,23 +179,23 @@ static PyObject *C_Vector_Range(PyObject *cls, PyObject *args) return NULL; } - size = (stop - start); + vec_num = (stop - start); - if ((size % step) != 0) { - size += step; + if ((vec_num % step) != 0) { + vec_num += step; } - size /= step; + vec_num /= step; break; } - if (size < 2) { + if (vec_num < 2) { PyErr_SetString(PyExc_RuntimeError, "Vector(): invalid size"); return NULL; } - vec = PyMem_Malloc(size * sizeof(float)); + vec = PyMem_Malloc(vec_num * sizeof(float)); if (vec == NULL) { PyErr_SetString(PyExc_MemoryError, @@ -204,9 +204,9 @@ static PyObject *C_Vector_Range(PyObject *cls, PyObject *args) return NULL; } - range_vn_fl(vec, size, (float)start, (float)step); + range_vn_fl(vec, vec_num, (float)start, (float)step); - return Vector_CreatePyObject_alloc(vec, size, (PyTypeObject *)cls); + return Vector_CreatePyObject_alloc(vec, vec_num, (PyTypeObject *)cls); } PyDoc_STRVAR(C_Vector_Linspace_doc, @@ -224,21 +224,21 @@ PyDoc_STRVAR(C_Vector_Linspace_doc, static PyObject *C_Vector_Linspace(PyObject *cls, PyObject *args) { float *vec; - int size; + int vec_num; float start, end, step; - if (!PyArg_ParseTuple(args, "ffi:Vector.Linspace", &start, &end, &size)) { + if (!PyArg_ParseTuple(args, "ffi:Vector.Linspace", &start, &end, &vec_num)) { return NULL; } - if (size < 2) { + if (vec_num < 2) { PyErr_SetString(PyExc_RuntimeError, "Vector.Linspace(): invalid size"); return NULL; } - step = (end - start) / (float)(size - 1); + step = (end - start) / (float)(vec_num - 1); - vec = PyMem_Malloc(size * sizeof(float)); + vec = PyMem_Malloc(vec_num * sizeof(float)); if (vec == NULL) { PyErr_SetString(PyExc_MemoryError, @@ -247,9 +247,9 @@ static PyObject *C_Vector_Linspace(PyObject *cls, PyObject *args) return NULL; } - range_vn_fl(vec, size, start, step); + range_vn_fl(vec, vec_num, start, step); - return Vector_CreatePyObject_alloc(vec, size, (PyTypeObject *)cls); + return Vector_CreatePyObject_alloc(vec, vec_num, (PyTypeObject *)cls); } PyDoc_STRVAR( @@ -266,20 +266,20 @@ static PyObject *C_Vector_Repeat(PyObject *cls, PyObject *args) { float *vec; float *iter_vec = NULL; - int i, size, value_size; + int i, vec_num, value_num; PyObject *value; - if (!PyArg_ParseTuple(args, "Oi:Vector.Repeat", &value, &size)) { + if (!PyArg_ParseTuple(args, "Oi:Vector.Repeat", &value, &vec_num)) { return NULL; } - if (size < 2) { - PyErr_SetString(PyExc_RuntimeError, "Vector.Repeat(): invalid size"); + if (vec_num < 2) { + PyErr_SetString(PyExc_RuntimeError, "Vector.Repeat(): invalid vec_num"); return NULL; } - if ((value_size = mathutils_array_parse_alloc( - &iter_vec, 2, value, "Vector.Repeat(vector, size), invalid 'vector' arg")) == -1) { + if ((value_num = mathutils_array_parse_alloc( + &iter_vec, 2, value, "Vector.Repeat(vector, vec_num), invalid 'vector' arg")) == -1) { return NULL; } @@ -290,7 +290,7 @@ static PyObject *C_Vector_Repeat(PyObject *cls, PyObject *args) return NULL; } - vec = PyMem_Malloc(size * sizeof(float)); + vec = PyMem_Malloc(vec_num * sizeof(float)); if (vec == NULL) { PyMem_Free(iter_vec); @@ -301,14 +301,14 @@ static PyObject *C_Vector_Repeat(PyObject *cls, PyObject *args) } i = 0; - while (i < size) { - vec[i] = iter_vec[i % value_size]; + while (i < vec_num) { + vec[i] = iter_vec[i % value_num]; i++; } PyMem_Free(iter_vec); - return Vector_CreatePyObject_alloc(vec, size, (PyTypeObject *)cls); + return Vector_CreatePyObject_alloc(vec, vec_num, (PyTypeObject *)cls); } /*-----------------------------METHODS---------------------------- */ @@ -322,7 +322,7 @@ static PyObject *Vector_zero(VectorObject *self) return NULL; } - copy_vn_fl(self->vec, self->size, 0.0f); + copy_vn_fl(self->vec, self->vec_num, 0.0f); if (BaseMath_WriteCallback(self) == -1) { return NULL; @@ -342,12 +342,12 @@ PyDoc_STRVAR(Vector_normalize_doc, " however 4D Vectors w axis is left untouched.\n"); static PyObject *Vector_normalize(VectorObject *self) { - const int size = (self->size == 4 ? 3 : self->size); + const int vec_num = (self->vec_num == 4 ? 3 : self->vec_num); if (BaseMath_ReadCallback_ForWrite(self) == -1) { return NULL; } - normalize_vn(self->vec, size); + normalize_vn(self->vec, vec_num); (void)BaseMath_WriteCallback(self); Py_RETURN_NONE; @@ -370,7 +370,7 @@ PyDoc_STRVAR(Vector_resize_doc, " Resize the vector to have size number of elements.\n"); static PyObject *Vector_resize(VectorObject *self, PyObject *value) { - int size; + int vec_num; if (self->flag & BASE_MATH_FLAG_IS_WRAP) { PyErr_SetString(PyExc_TypeError, @@ -385,19 +385,19 @@ static PyObject *Vector_resize(VectorObject *self, PyObject *value) return NULL; } - if ((size = PyC_Long_AsI32(value)) == -1) { + if ((vec_num = PyC_Long_AsI32(value)) == -1) { PyErr_SetString(PyExc_TypeError, "Vector.resize(size): " "expected size argument to be an integer"); return NULL; } - if (size < 2) { + if (vec_num < 2) { PyErr_SetString(PyExc_RuntimeError, "Vector.resize(): invalid size"); return NULL; } - self->vec = PyMem_Realloc(self->vec, (size * sizeof(float))); + self->vec = PyMem_Realloc(self->vec, (vec_num * sizeof(float))); if (self->vec == NULL) { PyErr_SetString(PyExc_MemoryError, "Vector.resize(): " @@ -406,11 +406,11 @@ static PyObject *Vector_resize(VectorObject *self, PyObject *value) } /* If the vector has increased in length, set all new elements to 0.0f */ - if (size > self->size) { - copy_vn_fl(self->vec + self->size, size - self->size, 0.0f); + if (vec_num > self->vec_num) { + copy_vn_fl(self->vec + self->vec_num, vec_num - self->vec_num, 0.0f); } - self->size = size; + self->vec_num = vec_num; Py_RETURN_NONE; } @@ -423,19 +423,19 @@ PyDoc_STRVAR(Vector_resized_doc, " :rtype: :class:`Vector`\n"); static PyObject *Vector_resized(VectorObject *self, PyObject *value) { - int size; + int vec_num; float *vec; - if ((size = PyLong_AsLong(value)) == -1) { + if ((vec_num = PyLong_AsLong(value)) == -1) { return NULL; } - if (size < 2) { + if (vec_num < 2) { PyErr_SetString(PyExc_RuntimeError, "Vector.resized(): invalid size"); return NULL; } - vec = PyMem_Malloc(size * sizeof(float)); + vec = PyMem_Malloc(vec_num * sizeof(float)); if (vec == NULL) { PyErr_SetString(PyExc_MemoryError, @@ -444,10 +444,10 @@ static PyObject *Vector_resized(VectorObject *self, PyObject *value) return NULL; } - copy_vn_fl(vec, size, 0.0f); - memcpy(vec, self->vec, self->size * sizeof(float)); + copy_vn_fl(vec, vec_num, 0.0f); + memcpy(vec, self->vec, self->vec_num * sizeof(float)); - return Vector_CreatePyObject_alloc(vec, size, NULL); + return Vector_CreatePyObject_alloc(vec, vec_num, NULL); } PyDoc_STRVAR(Vector_resize_2d_doc, @@ -477,7 +477,7 @@ static PyObject *Vector_resize_2d(VectorObject *self) return NULL; } - self->size = 2; + self->vec_num = 2; Py_RETURN_NONE; } @@ -508,11 +508,11 @@ static PyObject *Vector_resize_3d(VectorObject *self) return NULL; } - if (self->size == 2) { + if (self->vec_num == 2) { self->vec[2] = 0.0f; } - self->size = 3; + self->vec_num = 3; Py_RETURN_NONE; } @@ -543,14 +543,14 @@ static PyObject *Vector_resize_4d(VectorObject *self) return NULL; } - if (self->size == 2) { + if (self->vec_num == 2) { self->vec[2] = 0.0f; self->vec[3] = 1.0f; } - else if (self->size == 3) { + else if (self->vec_num == 3) { self->vec[3] = 1.0f; } - self->size = 4; + self->vec_num = 4; Py_RETURN_NONE; } PyDoc_STRVAR(Vector_to_2d_doc, @@ -583,7 +583,7 @@ static PyObject *Vector_to_3d(VectorObject *self) return NULL; } - memcpy(tvec, self->vec, sizeof(float) * MIN2(self->size, 3)); + memcpy(tvec, self->vec, sizeof(float) * MIN2(self->vec_num, 3)); return Vector_CreatePyObject(tvec, 3, Py_TYPE(self)); } PyDoc_STRVAR(Vector_to_4d_doc, @@ -601,7 +601,7 @@ static PyObject *Vector_to_4d(VectorObject *self) return NULL; } - memcpy(tvec, self->vec, sizeof(float) * MIN2(self->size, 4)); + memcpy(tvec, self->vec, sizeof(float) * MIN2(self->vec_num, 4)); return Vector_CreatePyObject(tvec, 4, Py_TYPE(self)); } @@ -620,15 +620,15 @@ static PyObject *Vector_to_tuple_ex(VectorObject *self, int ndigits) PyObject *ret; int i; - ret = PyTuple_New(self->size); + ret = PyTuple_New(self->vec_num); if (ndigits >= 0) { - for (i = 0; i < self->size; i++) { + for (i = 0; i < self->vec_num; i++) { PyTuple_SET_ITEM(ret, i, PyFloat_FromDouble(double_round((double)self->vec[i], ndigits))); } } else { - for (i = 0; i < self->size; i++) { + for (i = 0; i < self->vec_num; i++) { PyTuple_SET_ITEM(ret, i, PyFloat_FromDouble(self->vec[i])); } } @@ -684,7 +684,7 @@ static PyObject *Vector_to_track_quat(VectorObject *self, PyObject *args) return NULL; } - if (self->size != 3) { + if (self->vec_num != 3) { PyErr_SetString(PyExc_TypeError, "Vector.to_track_quat(): " "only for 3D vectors"); @@ -795,7 +795,7 @@ static PyObject *Vector_orthogonal(VectorObject *self) { float vec[3]; - if (self->size > 3) { + if (self->vec_num > 3) { PyErr_SetString(PyExc_TypeError, "Vector.orthogonal(): " "Vector must be 3D or 2D"); @@ -806,14 +806,14 @@ static PyObject *Vector_orthogonal(VectorObject *self) return NULL; } - if (self->size == 3) { + if (self->vec_num == 3) { ortho_v3_v3(vec, self->vec); } else { ortho_v2_v2(vec, self->vec); } - return Vector_CreatePyObject(vec, self->size, Py_TYPE(self)); + return Vector_CreatePyObject(vec, self->vec_num, Py_TYPE(self)); } /** @@ -833,7 +833,7 @@ PyDoc_STRVAR(Vector_reflect_doc, " :rtype: :class:`Vector`\n"); static PyObject *Vector_reflect(VectorObject *self, PyObject *value) { - int value_size; + int value_num; float mirror[3], vec[3]; float reflect[3] = {0.0f}; float tvec[MAX_DIMENSIONS]; @@ -842,28 +842,28 @@ static PyObject *Vector_reflect(VectorObject *self, PyObject *value) return NULL; } - if ((value_size = mathutils_array_parse( + if ((value_num = mathutils_array_parse( tvec, 2, 4, value, "Vector.reflect(other), invalid 'other' arg")) == -1) { return NULL; } - if (self->size < 2 || self->size > 4) { + if (self->vec_num < 2 || self->vec_num > 4) { PyErr_SetString(PyExc_ValueError, "Vector must be 2D, 3D or 4D"); return NULL; } mirror[0] = tvec[0]; mirror[1] = tvec[1]; - mirror[2] = (value_size > 2) ? tvec[2] : 0.0f; + mirror[2] = (value_num > 2) ? tvec[2] : 0.0f; vec[0] = self->vec[0]; vec[1] = self->vec[1]; - vec[2] = (value_size > 2) ? self->vec[2] : 0.0f; + vec[2] = (value_num > 2) ? self->vec[2] : 0.0f; normalize_v3(mirror); reflect_v3_v3v3(reflect, vec, mirror); - return Vector_CreatePyObject(reflect, self->size, Py_TYPE(self)); + return Vector_CreatePyObject(reflect, self->vec_num, Py_TYPE(self)); } PyDoc_STRVAR(Vector_cross_doc, @@ -886,17 +886,18 @@ static PyObject *Vector_cross(VectorObject *self, PyObject *value) return NULL; } - if (self->size > 3) { + if (self->vec_num > 3) { PyErr_SetString(PyExc_ValueError, "Vector must be 2D or 3D"); return NULL; } if (mathutils_array_parse( - tvec, self->size, self->size, value, "Vector.cross(other), invalid 'other' arg") == -1) { + tvec, self->vec_num, self->vec_num, value, "Vector.cross(other), invalid 'other' arg") == + -1) { return NULL; } - if (self->size == 3) { + if (self->vec_num == 3) { ret = Vector_CreatePyObject(NULL, 3, Py_TYPE(self)); cross_v3_v3v3(((VectorObject *)ret)->vec, self->vec, tvec); } @@ -926,11 +927,11 @@ static PyObject *Vector_dot(VectorObject *self, PyObject *value) } if (mathutils_array_parse_alloc( - &tvec, self->size, value, "Vector.dot(other), invalid 'other' arg") == -1) { + &tvec, self->vec_num, value, "Vector.dot(other), invalid 'other' arg") == -1) { return NULL; } - ret = PyFloat_FromDouble(dot_vn_vn(self->vec, tvec, self->size)); + ret = PyFloat_FromDouble(dot_vn_vn(self->vec, tvec, self->vec_num)); PyMem_Free(tvec); return ret; } @@ -950,7 +951,7 @@ PyDoc_STRVAR( " :rtype: float\n"); static PyObject *Vector_angle(VectorObject *self, PyObject *args) { - const int size = MIN2(self->size, 3); /* 4D angle makes no sense */ + const int vec_num = MIN2(self->vec_num, 3); /* 4D angle makes no sense */ float tvec[MAX_DIMENSIONS]; PyObject *value; double dot = 0.0f, dot_self = 0.0f, dot_other = 0.0f; @@ -968,16 +969,17 @@ static PyObject *Vector_angle(VectorObject *self, PyObject *args) /* don't use clamped size, rule of thumb is vector sizes must match, * even though n this case 'w' is ignored */ if (mathutils_array_parse( - tvec, self->size, self->size, value, "Vector.angle(other), invalid 'other' arg") == -1) { + tvec, self->vec_num, self->vec_num, value, "Vector.angle(other), invalid 'other' arg") == + -1) { return NULL; } - if (self->size > 4) { + if (self->vec_num > 4) { PyErr_SetString(PyExc_ValueError, "Vector must be 2D, 3D or 4D"); return NULL; } - for (x = 0; x < size; x++) { + for (x = 0; x < vec_num; x++) { dot_self += (double)self->vec[x] * (double)self->vec[x]; dot_other += (double)tvec[x] * (double)tvec[x]; dot += (double)self->vec[x] * (double)tvec[x]; @@ -1032,7 +1034,7 @@ static PyObject *Vector_angle_signed(VectorObject *self, PyObject *args) return NULL; } - if (self->size != 2) { + if (self->vec_num != 2) { PyErr_SetString(PyExc_ValueError, "Vector must be 2D"); return NULL; } @@ -1069,7 +1071,7 @@ static PyObject *Vector_rotation_difference(VectorObject *self, PyObject *value) { float quat[4], vec_a[3], vec_b[3]; - if (self->size < 3 || self->size > 4) { + if (self->vec_num < 3 || self->vec_num > 4) { PyErr_SetString(PyExc_ValueError, "vec.difference(value): " "expects both vectors to be size 3 or 4"); @@ -1105,7 +1107,7 @@ PyDoc_STRVAR(Vector_project_doc, " :rtype: :class:`Vector`\n"); static PyObject *Vector_project(VectorObject *self, PyObject *value) { - const int size = self->size; + const int vec_num = self->vec_num; float *tvec; double dot = 0.0f, dot2 = 0.0f; int x; @@ -1115,21 +1117,21 @@ static PyObject *Vector_project(VectorObject *self, PyObject *value) } if (mathutils_array_parse_alloc( - &tvec, size, value, "Vector.project(other), invalid 'other' arg") == -1) { + &tvec, vec_num, value, "Vector.project(other), invalid 'other' arg") == -1) { return NULL; } /* get dot products */ - for (x = 0; x < size; x++) { + for (x = 0; x < vec_num; x++) { dot += (double)(self->vec[x] * tvec[x]); dot2 += (double)(tvec[x] * tvec[x]); } /* projection */ dot /= dot2; - for (x = 0; x < size; x++) { + for (x = 0; x < vec_num; x++) { tvec[x] *= (float)dot; } - return Vector_CreatePyObject_alloc(tvec, size, Py_TYPE(self)); + return Vector_CreatePyObject_alloc(tvec, vec_num, Py_TYPE(self)); } PyDoc_STRVAR(Vector_lerp_doc, @@ -1145,7 +1147,7 @@ PyDoc_STRVAR(Vector_lerp_doc, " :rtype: :class:`Vector`\n"); static PyObject *Vector_lerp(VectorObject *self, PyObject *args) { - const int size = self->size; + const int vec_num = self->vec_num; PyObject *value = NULL; float fac; float *tvec; @@ -1158,14 +1160,14 @@ static PyObject *Vector_lerp(VectorObject *self, PyObject *args) return NULL; } - if (mathutils_array_parse_alloc(&tvec, size, value, "Vector.lerp(other), invalid 'other' arg") == - -1) { + if (mathutils_array_parse_alloc( + &tvec, vec_num, value, "Vector.lerp(other), invalid 'other' arg") == -1) { return NULL; } - interp_vn_vn(tvec, self->vec, 1.0f - fac, size); + interp_vn_vn(tvec, self->vec, 1.0f - fac, vec_num); - return Vector_CreatePyObject_alloc(tvec, size, Py_TYPE(self)); + return Vector_CreatePyObject_alloc(tvec, vec_num, Py_TYPE(self)); } PyDoc_STRVAR(Vector_slerp_doc, @@ -1185,7 +1187,7 @@ PyDoc_STRVAR(Vector_slerp_doc, " :rtype: :class:`Vector`\n"); static PyObject *Vector_slerp(VectorObject *self, PyObject *args) { - const int size = self->size; + const int vec_num = self->vec_num; PyObject *value = NULL; float fac, cosom, w[2]; float self_vec[3], other_vec[3], ret_vec[3]; @@ -1201,18 +1203,18 @@ static PyObject *Vector_slerp(VectorObject *self, PyObject *args) return NULL; } - if (self->size > 3) { + if (self->vec_num > 3) { PyErr_SetString(PyExc_ValueError, "Vector must be 2D or 3D"); return NULL; } if (mathutils_array_parse( - other_vec, size, size, value, "Vector.slerp(other), invalid 'other' arg") == -1) { + other_vec, vec_num, vec_num, value, "Vector.slerp(other), invalid 'other' arg") == -1) { return NULL; } - self_len_sq = normalize_vn_vn(self_vec, self->vec, size); - other_len_sq = normalize_vn(other_vec, size); + self_len_sq = normalize_vn_vn(self_vec, self->vec, vec_num); + other_len_sq = normalize_vn(other_vec, vec_num); /* use fallbacks for zero length vectors */ if (UNLIKELY((self_len_sq < FLT_EPSILON) || (other_len_sq < FLT_EPSILON))) { @@ -1229,7 +1231,7 @@ static PyObject *Vector_slerp(VectorObject *self, PyObject *args) } /* We have sane state, execute slerp */ - cosom = (float)dot_vn_vn(self_vec, other_vec, size); + cosom = (float)dot_vn_vn(self_vec, other_vec, vec_num); /* direct opposite, can't slerp */ if (UNLIKELY(cosom < (-1.0f + FLT_EPSILON))) { @@ -1247,11 +1249,11 @@ static PyObject *Vector_slerp(VectorObject *self, PyObject *args) interp_dot_slerp(fac, cosom, w); - for (x = 0; x < size; x++) { + for (x = 0; x < vec_num; x++) { ret_vec[x] = (w[0] * self_vec[x]) + (w[1] * other_vec[x]); } - return Vector_CreatePyObject(ret_vec, size, Py_TYPE(self)); + return Vector_CreatePyObject(ret_vec, vec_num, Py_TYPE(self)); } PyDoc_STRVAR( @@ -1270,7 +1272,7 @@ static PyObject *Vector_rotate(VectorObject *self, PyObject *value) return NULL; } - if (self->size == 2) { + if (self->vec_num == 2) { /* Special case for 2D Vector with 2x2 matrix, so we avoid resizing it to a 3x3. */ float other_rmat[2][2]; MatrixObject *pymat; @@ -1311,7 +1313,7 @@ static PyObject *Vector_copy(VectorObject *self) return NULL; } - return Vector_CreatePyObject(self->vec, self->size, Py_TYPE(self)); + return Vector_CreatePyObject(self->vec, self->vec_num, Py_TYPE(self)); } static PyObject *Vector_deepcopy(VectorObject *self, PyObject *args) { @@ -1350,7 +1352,7 @@ static PyObject *Vector_str(VectorObject *self) BLI_dynstr_append(ds, "<Vector ("); - for (i = 0; i < self->size; i++) { + for (i = 0; i < self->vec_num; i++) { BLI_dynstr_appendf(ds, i ? ", %.4f" : "%.4f", self->vec[i]); } @@ -1364,21 +1366,21 @@ static PyObject *Vector_str(VectorObject *self) /* sequence length len(vector) */ static int Vector_len(VectorObject *self) { - return self->size; + return self->vec_num; } /* sequence accessor (get): vector[index] */ static PyObject *vector_item_internal(VectorObject *self, int i, const bool is_attr) { if (i < 0) { - i = self->size - i; + i = self->vec_num - i; } - if (i < 0 || i >= self->size) { + if (i < 0 || i >= self->vec_num) { if (is_attr) { PyErr_Format(PyExc_AttributeError, "Vector.%c: unavailable on %dd vector", *(((const char *)"xyzw") + i), - self->size); + self->vec_num); } else { PyErr_SetString(PyExc_IndexError, "vector[index]: out of range"); @@ -1415,15 +1417,15 @@ static int vector_ass_item_internal(VectorObject *self, int i, PyObject *value, } if (i < 0) { - i = self->size - i; + i = self->vec_num - i; } - if (i < 0 || i >= self->size) { + if (i < 0 || i >= self->vec_num) { if (is_attr) { PyErr_Format(PyExc_AttributeError, "Vector.%c = x: unavailable on %dd vector", *(((const char *)"xyzw") + i), - self->size); + self->vec_num); } else { PyErr_SetString(PyExc_IndexError, @@ -1455,11 +1457,11 @@ static PyObject *Vector_slice(VectorObject *self, int begin, int end) return NULL; } - CLAMP(begin, 0, self->size); + CLAMP(begin, 0, self->vec_num); if (end < 0) { - end = self->size + end + 1; + end = self->vec_num + end + 1; } - CLAMP(end, 0, self->size); + CLAMP(end, 0, self->vec_num); begin = MIN2(begin, end); tuple = PyTuple_New(end - begin); @@ -1472,19 +1474,19 @@ static PyObject *Vector_slice(VectorObject *self, int begin, int end) /* sequence slice (set): vector[a:b] = value */ static int Vector_ass_slice(VectorObject *self, int begin, int end, PyObject *seq) { - int size = 0; + int vec_num = 0; float *vec = NULL; if (BaseMath_ReadCallback_ForWrite(self) == -1) { return -1; } - CLAMP(begin, 0, self->size); - CLAMP(end, 0, self->size); + CLAMP(begin, 0, self->vec_num); + CLAMP(end, 0, self->vec_num); begin = MIN2(begin, end); - size = (end - begin); - if (mathutils_array_parse_alloc(&vec, size, seq, "vector[begin:end] = [...]") == -1) { + vec_num = (end - begin); + if (mathutils_array_parse_alloc(&vec, vec_num, seq, "vector[begin:end] = [...]") == -1) { return -1; } @@ -1496,7 +1498,7 @@ static int Vector_ass_slice(VectorObject *self, int begin, int end, PyObject *se } /* Parsed well - now set in vector. */ - memcpy(self->vec + begin, vec, size * sizeof(float)); + memcpy(self->vec + begin, vec, vec_num * sizeof(float)); PyMem_Free(vec); @@ -1530,14 +1532,14 @@ static PyObject *Vector_add(PyObject *v1, PyObject *v2) } /* VECTOR + VECTOR. */ - if (vec1->size != vec2->size) { + if (vec1->vec_num != vec2->vec_num) { PyErr_SetString(PyExc_AttributeError, "Vector addition: " "vectors must have the same dimensions for this operation"); return NULL; } - vec = PyMem_Malloc(vec1->size * sizeof(float)); + vec = PyMem_Malloc(vec1->vec_num * sizeof(float)); if (vec == NULL) { PyErr_SetString(PyExc_MemoryError, "Vector(): " @@ -1545,9 +1547,9 @@ static PyObject *Vector_add(PyObject *v1, PyObject *v2) return NULL; } - add_vn_vnvn(vec, vec1->vec, vec2->vec, vec1->size); + add_vn_vnvn(vec, vec1->vec, vec2->vec, vec1->vec_num); - return Vector_CreatePyObject_alloc(vec, vec1->size, Py_TYPE(v1)); + return Vector_CreatePyObject_alloc(vec, vec1->vec_num, Py_TYPE(v1)); } /* addition in-place: obj += obj */ @@ -1566,7 +1568,7 @@ static PyObject *Vector_iadd(PyObject *v1, PyObject *v2) vec1 = (VectorObject *)v1; vec2 = (VectorObject *)v2; - if (vec1->size != vec2->size) { + if (vec1->vec_num != vec2->vec_num) { PyErr_SetString(PyExc_AttributeError, "Vector addition: " "vectors must have the same dimensions for this operation"); @@ -1577,7 +1579,7 @@ static PyObject *Vector_iadd(PyObject *v1, PyObject *v2) return NULL; } - add_vn_vn(vec1->vec, vec2->vec, vec1->size); + add_vn_vn(vec1->vec, vec2->vec, vec1->vec_num); (void)BaseMath_WriteCallback(vec1); Py_INCREF(v1); @@ -1605,14 +1607,14 @@ static PyObject *Vector_sub(PyObject *v1, PyObject *v2) return NULL; } - if (vec1->size != vec2->size) { + if (vec1->vec_num != vec2->vec_num) { PyErr_SetString(PyExc_AttributeError, "Vector subtraction: " "vectors must have the same dimensions for this operation"); return NULL; } - vec = PyMem_Malloc(vec1->size * sizeof(float)); + vec = PyMem_Malloc(vec1->vec_num * sizeof(float)); if (vec == NULL) { PyErr_SetString(PyExc_MemoryError, "Vector(): " @@ -1620,9 +1622,9 @@ static PyObject *Vector_sub(PyObject *v1, PyObject *v2) return NULL; } - sub_vn_vnvn(vec, vec1->vec, vec2->vec, vec1->size); + sub_vn_vnvn(vec, vec1->vec, vec2->vec, vec1->vec_num); - return Vector_CreatePyObject_alloc(vec, vec1->size, Py_TYPE(v1)); + return Vector_CreatePyObject_alloc(vec, vec1->vec_num, Py_TYPE(v1)); } /* subtraction in-place: obj -= obj */ @@ -1641,7 +1643,7 @@ static PyObject *Vector_isub(PyObject *v1, PyObject *v2) vec1 = (VectorObject *)v1; vec2 = (VectorObject *)v2; - if (vec1->size != vec2->size) { + if (vec1->vec_num != vec2->vec_num) { PyErr_SetString(PyExc_AttributeError, "Vector subtraction: " "vectors must have the same dimensions for this operation"); @@ -1652,7 +1654,7 @@ static PyObject *Vector_isub(PyObject *v1, PyObject *v2) return NULL; } - sub_vn_vn(vec1->vec, vec2->vec, vec1->size); + sub_vn_vn(vec1->vec, vec2->vec, vec1->vec_num); (void)BaseMath_WriteCallback(vec1); Py_INCREF(v1); @@ -1667,8 +1669,8 @@ int column_vector_multiplication(float r_vec[MAX_DIMENSIONS], VectorObject *vec, float vec_cpy[MAX_DIMENSIONS]; int row, col, z = 0; - if (mat->num_col != vec->size) { - if (mat->num_col == 4 && vec->size == 3) { + if (mat->col_num != vec->vec_num) { + if (mat->col_num == 4 && vec->vec_num == 3) { vec_cpy[3] = 1.0f; } else { @@ -1680,13 +1682,13 @@ int column_vector_multiplication(float r_vec[MAX_DIMENSIONS], VectorObject *vec, } } - memcpy(vec_cpy, vec->vec, vec->size * sizeof(float)); + memcpy(vec_cpy, vec->vec, vec->vec_num * sizeof(float)); r_vec[3] = 1.0f; - for (row = 0; row < mat->num_row; row++) { + for (row = 0; row < mat->row_num; row++) { double dot = 0.0f; - for (col = 0; col < mat->num_col; col++) { + for (col = 0; col < mat->col_num; col++) { dot += (double)(MATRIX_ITEM(mat, row, col) * vec_cpy[col]); } r_vec[z++] = (float)dot; @@ -1697,7 +1699,7 @@ int column_vector_multiplication(float r_vec[MAX_DIMENSIONS], VectorObject *vec, static PyObject *vector_mul_float(VectorObject *vec, const float scalar) { - float *tvec = PyMem_Malloc(vec->size * sizeof(float)); + float *tvec = PyMem_Malloc(vec->vec_num * sizeof(float)); if (tvec == NULL) { PyErr_SetString(PyExc_MemoryError, "vec * float: " @@ -1705,13 +1707,13 @@ static PyObject *vector_mul_float(VectorObject *vec, const float scalar) return NULL; } - mul_vn_vn_fl(tvec, vec->vec, vec->size, scalar); - return Vector_CreatePyObject_alloc(tvec, vec->size, Py_TYPE(vec)); + mul_vn_vn_fl(tvec, vec->vec, vec->vec_num, scalar); + return Vector_CreatePyObject_alloc(tvec, vec->vec_num, Py_TYPE(vec)); } static PyObject *vector_mul_vec(VectorObject *vec1, VectorObject *vec2) { - float *tvec = PyMem_Malloc(vec1->size * sizeof(float)); + float *tvec = PyMem_Malloc(vec1->vec_num * sizeof(float)); if (tvec == NULL) { PyErr_SetString(PyExc_MemoryError, "vec * vec: " @@ -1719,8 +1721,8 @@ static PyObject *vector_mul_vec(VectorObject *vec1, VectorObject *vec2) return NULL; } - mul_vn_vnvn(tvec, vec1->vec, vec2->vec, vec1->size); - return Vector_CreatePyObject_alloc(tvec, vec1->size, Py_TYPE(vec1)); + mul_vn_vnvn(tvec, vec1->vec, vec2->vec, vec1->vec_num); + return Vector_CreatePyObject_alloc(tvec, vec1->vec_num, Py_TYPE(vec1)); } static PyObject *Vector_mul(PyObject *v1, PyObject *v2) @@ -1745,7 +1747,7 @@ static PyObject *Vector_mul(PyObject *v1, PyObject *v2) /* make sure v1 is always the vector */ if (vec1 && vec2) { - if (vec1->size != vec2->size) { + if (vec1->vec_num != vec2->vec_num) { PyErr_SetString(PyExc_ValueError, "Vector multiplication: " "vectors must have the same dimensions for this operation"); @@ -1800,7 +1802,7 @@ static PyObject *Vector_imul(PyObject *v1, PyObject *v2) /* Intentionally don't support (Quaternion, Matrix) here, uses reverse order instead. */ if (vec1 && vec2) { - if (vec1->size != vec2->size) { + if (vec1->vec_num != vec2->vec_num) { PyErr_SetString(PyExc_ValueError, "Vector multiplication: " "vectors must have the same dimensions for this operation"); @@ -1808,11 +1810,11 @@ static PyObject *Vector_imul(PyObject *v1, PyObject *v2) } /* Element-wise product in-place. */ - mul_vn_vn(vec1->vec, vec2->vec, vec1->size); + mul_vn_vn(vec1->vec, vec2->vec, vec1->vec_num); } else if (vec1 && (((scalar = PyFloat_AsDouble(v2)) == -1.0f && PyErr_Occurred()) == 0)) { /* VEC *= FLOAT */ - mul_vn_fl(vec1->vec, vec1->size, scalar); + mul_vn_fl(vec1->vec, vec1->vec_num, scalar); } else { PyErr_Format(PyExc_TypeError, @@ -1831,7 +1833,7 @@ static PyObject *Vector_imul(PyObject *v1, PyObject *v2) static PyObject *Vector_matmul(PyObject *v1, PyObject *v2) { VectorObject *vec1 = NULL, *vec2 = NULL; - int vec_size; + int vec_num; if (VectorObject_Check(v1)) { vec1 = (VectorObject *)v1; @@ -1850,7 +1852,7 @@ static PyObject *Vector_matmul(PyObject *v1, PyObject *v2) /* make sure v1 is always the vector */ if (vec1 && vec2) { - if (vec1->size != vec2->size) { + if (vec1->vec_num != vec2->vec_num) { PyErr_SetString(PyExc_ValueError, "Vector multiplication: " "vectors must have the same dimensions for this operation"); @@ -1858,7 +1860,7 @@ static PyObject *Vector_matmul(PyObject *v1, PyObject *v2) } /* Dot product. */ - return PyFloat_FromDouble(dot_vn_vn(vec1->vec, vec2->vec, vec1->size)); + return PyFloat_FromDouble(dot_vn_vn(vec1->vec, vec2->vec, vec1->vec_num)); } if (vec1) { if (MatrixObject_Check(v2)) { @@ -1872,14 +1874,14 @@ static PyObject *Vector_matmul(PyObject *v1, PyObject *v2) return NULL; } - if (((MatrixObject *)v2)->num_row == 4 && vec1->size == 3) { - vec_size = 3; + if (((MatrixObject *)v2)->row_num == 4 && vec1->vec_num == 3) { + vec_num = 3; } else { - vec_size = ((MatrixObject *)v2)->num_col; + vec_num = ((MatrixObject *)v2)->col_num; } - return Vector_CreatePyObject(tvec, vec_size, Py_TYPE(vec1)); + return Vector_CreatePyObject(tvec, vec_num, Py_TYPE(vec1)); } } @@ -1934,7 +1936,7 @@ static PyObject *Vector_div(PyObject *v1, PyObject *v2) return NULL; } - vec = PyMem_Malloc(vec1->size * sizeof(float)); + vec = PyMem_Malloc(vec1->vec_num * sizeof(float)); if (vec == NULL) { PyErr_SetString(PyExc_MemoryError, @@ -1943,9 +1945,9 @@ static PyObject *Vector_div(PyObject *v1, PyObject *v2) return NULL; } - mul_vn_vn_fl(vec, vec1->vec, vec1->size, 1.0f / scalar); + mul_vn_vn_fl(vec, vec1->vec, vec1->vec_num, 1.0f / scalar); - return Vector_CreatePyObject_alloc(vec, vec1->size, Py_TYPE(v1)); + return Vector_CreatePyObject_alloc(vec, vec1->vec_num, Py_TYPE(v1)); } /* divide in-place: obj /= obj */ @@ -1973,7 +1975,7 @@ static PyObject *Vector_idiv(PyObject *v1, PyObject *v2) return NULL; } - mul_vn_fl(vec1->vec, vec1->size, 1.0f / scalar); + mul_vn_fl(vec1->vec, vec1->vec_num, 1.0f / scalar); (void)BaseMath_WriteCallback(vec1); @@ -1991,9 +1993,9 @@ static PyObject *Vector_neg(VectorObject *self) return NULL; } - tvec = PyMem_Malloc(self->size * sizeof(float)); - negate_vn_vn(tvec, self->vec, self->size); - return Vector_CreatePyObject_alloc(tvec, self->size, Py_TYPE(self)); + tvec = PyMem_Malloc(self->vec_num * sizeof(float)); + negate_vn_vn(tvec, self->vec, self->vec_num); + return Vector_CreatePyObject_alloc(tvec, self->vec_num, Py_TYPE(self)); } /*------------------------tp_richcmpr @@ -2019,7 +2021,7 @@ static PyObject *Vector_richcmpr(PyObject *objectA, PyObject *objectB, int compa return NULL; } - if (vecA->size != vecB->size) { + if (vecA->vec_num != vecB->vec_num) { if (comparison_type == Py_NE) { Py_RETURN_TRUE; } @@ -2029,15 +2031,15 @@ static PyObject *Vector_richcmpr(PyObject *objectA, PyObject *objectB, int compa switch (comparison_type) { case Py_LT: - lenA = len_squared_vn(vecA->vec, vecA->size); - lenB = len_squared_vn(vecB->vec, vecB->size); + lenA = len_squared_vn(vecA->vec, vecA->vec_num); + lenB = len_squared_vn(vecB->vec, vecB->vec_num); if (lenA < lenB) { result = 1; } break; case Py_LE: - lenA = len_squared_vn(vecA->vec, vecA->size); - lenB = len_squared_vn(vecB->vec, vecB->size); + lenA = len_squared_vn(vecA->vec, vecA->vec_num); + lenB = len_squared_vn(vecB->vec, vecB->vec_num); if (lenA < lenB) { result = 1; } @@ -2046,21 +2048,21 @@ static PyObject *Vector_richcmpr(PyObject *objectA, PyObject *objectB, int compa } break; case Py_EQ: - result = EXPP_VectorsAreEqual(vecA->vec, vecB->vec, vecA->size, 1); + result = EXPP_VectorsAreEqual(vecA->vec, vecB->vec, vecA->vec_num, 1); break; case Py_NE: - result = !EXPP_VectorsAreEqual(vecA->vec, vecB->vec, vecA->size, 1); + result = !EXPP_VectorsAreEqual(vecA->vec, vecB->vec, vecA->vec_num, 1); break; case Py_GT: - lenA = len_squared_vn(vecA->vec, vecA->size); - lenB = len_squared_vn(vecB->vec, vecB->size); + lenA = len_squared_vn(vecA->vec, vecA->vec_num); + lenB = len_squared_vn(vecB->vec, vecB->vec_num); if (lenA > lenB) { result = 1; } break; case Py_GE: - lenA = len_squared_vn(vecA->vec, vecA->size); - lenB = len_squared_vn(vecB->vec, vecB->size); + lenA = len_squared_vn(vecA->vec, vecA->vec_num); + lenB = len_squared_vn(vecB->vec, vecB->vec_num); if (lenA > lenB) { result = 1; } @@ -2089,7 +2091,7 @@ static Py_hash_t Vector_hash(VectorObject *self) return -1; } - return mathutils_array_hash(self->vec, self->size); + return mathutils_array_hash(self->vec, self->vec_num); } /*-----------------PROTCOL DECLARATIONS--------------------------*/ @@ -2115,14 +2117,14 @@ static PyObject *Vector_subscript(VectorObject *self, PyObject *item) return NULL; } if (i < 0) { - i += self->size; + i += self->vec_num; } return Vector_item(self, i); } if (PySlice_Check(item)) { Py_ssize_t start, stop, step, slicelength; - if (PySlice_GetIndicesEx(item, self->size, &start, &stop, &step, &slicelength) < 0) { + if (PySlice_GetIndicesEx(item, self->vec_num, &start, &stop, &step, &slicelength) < 0) { return NULL; } @@ -2150,14 +2152,14 @@ static int Vector_ass_subscript(VectorObject *self, PyObject *item, PyObject *va return -1; } if (i < 0) { - i += self->size; + i += self->vec_num; } return Vector_ass_item(self, i, value); } if (PySlice_Check(item)) { Py_ssize_t start, stop, step, slicelength; - if (PySlice_GetIndicesEx(item, self->size, &start, &stop, &step, &slicelength) < 0) { + if (PySlice_GetIndicesEx(item, self->vec_num, &start, &stop, &step, &slicelength) < 0) { return -1; } @@ -2247,7 +2249,7 @@ static PyObject *Vector_length_get(VectorObject *self, void *UNUSED(closure)) return NULL; } - return PyFloat_FromDouble(sqrt(dot_vn_vn(self->vec, self->vec, self->size))); + return PyFloat_FromDouble(sqrt(dot_vn_vn(self->vec, self->vec, self->vec_num))); } static int Vector_length_set(VectorObject *self, PyObject *value) @@ -2268,11 +2270,11 @@ static int Vector_length_set(VectorObject *self, PyObject *value) return -1; } if (param == 0.0) { - copy_vn_fl(self->vec, self->size, 0.0f); + copy_vn_fl(self->vec, self->vec_num, 0.0f); return 0; } - dot = dot_vn_vn(self->vec, self->vec, self->size); + dot = dot_vn_vn(self->vec, self->vec, self->vec_num); if (!dot) { /* can't sqrt zero */ @@ -2287,7 +2289,7 @@ static int Vector_length_set(VectorObject *self, PyObject *value) dot = dot / param; - mul_vn_fl(self->vec, self->size, 1.0 / dot); + mul_vn_fl(self->vec, self->vec_num, 1.0 / dot); (void)BaseMath_WriteCallback(self); /* checked already */ @@ -2302,7 +2304,7 @@ static PyObject *Vector_length_squared_get(VectorObject *self, void *UNUSED(clos return NULL; } - return PyFloat_FromDouble(dot_vn_vn(self->vec, self->vec, self->size)); + return PyFloat_FromDouble(dot_vn_vn(self->vec, self->vec, self->vec_num)); } /** @@ -2382,7 +2384,7 @@ static PyObject *Vector_swizzle_get(VectorObject *self, void *closure) swizzleClosure = POINTER_AS_INT(closure); while (swizzleClosure & SWIZZLE_VALID_AXIS) { axis_from = swizzleClosure & SWIZZLE_AXIS; - if (axis_from >= self->size) { + if (axis_from >= self->vec_num) { PyErr_SetString(PyExc_AttributeError, "Vector swizzle: " "specified axis not present"); @@ -2432,7 +2434,7 @@ static int Vector_swizzle_set(VectorObject *self, PyObject *value, void *closure while (swizzleClosure & SWIZZLE_VALID_AXIS) { axis_to = swizzleClosure & SWIZZLE_AXIS; - if (axis_to >= self->size) { + if (axis_to >= self->vec_num) { PyErr_SetString(PyExc_AttributeError, "Vector swizzle: " "specified axis not present"); @@ -2468,8 +2470,8 @@ static int Vector_swizzle_set(VectorObject *self, PyObject *value, void *closure /* We must first copy current vec into tvec, else some org values may be lost. * See T31760. - * Assuming self->size can't be higher than MAX_DIMENSIONS! */ - memcpy(tvec, self->vec, self->size * sizeof(float)); + * Assuming self->vec_num can't be higher than MAX_DIMENSIONS! */ + memcpy(tvec, self->vec, self->vec_num * sizeof(float)); while (swizzleClosure & SWIZZLE_VALID_AXIS) { axis_to = swizzleClosure & SWIZZLE_AXIS; @@ -2480,7 +2482,7 @@ static int Vector_swizzle_set(VectorObject *self, PyObject *value, void *closure /* We must copy back the whole tvec into vec, else some changes may be lost (e.g. xz...). * See T31760. */ - memcpy(self->vec, tvec, self->size * sizeof(float)); + memcpy(self->vec, tvec, self->vec_num * sizeof(float)); /* continue with BaseMathObject_WriteCallback at the end */ if (BaseMath_WriteCallback(self) == -1) { @@ -2898,10 +2900,10 @@ static int row_vector_multiplication(float r_vec[MAX_DIMENSIONS], MatrixObject *mat) { float vec_cpy[MAX_DIMENSIONS]; - int row, col, z = 0, vec_size = vec->size; + int row, col, z = 0, vec_num = vec->vec_num; - if (mat->num_row != vec_size) { - if (mat->num_row == 4 && vec_size == 3) { + if (mat->row_num != vec_num) { + if (mat->row_num == 4 && vec_num == 3) { vec_cpy[3] = 1.0f; } else { @@ -2916,13 +2918,13 @@ static int row_vector_multiplication(float r_vec[MAX_DIMENSIONS], return -1; } - memcpy(vec_cpy, vec->vec, vec_size * sizeof(float)); + memcpy(vec_cpy, vec->vec, vec_num * sizeof(float)); r_vec[3] = 1.0f; /* Multiplication. */ - for (col = 0; col < mat->num_col; col++) { + for (col = 0; col < mat->col_num; col++) { double dot = 0.0; - for (row = 0; row < mat->num_row; row++) { + for (row = 0; row < mat->row_num; row++) { dot += (double)(MATRIX_ITEM(mat, row, col) * vec_cpy[row]); } r_vec[z++] = (float)dot; @@ -2941,7 +2943,7 @@ static PyObject *Vector_negate(VectorObject *self) return NULL; } - negate_vn(self->vec, self->size); + negate_vn(self->vec, self->vec_num); (void)BaseMath_WriteCallback(self); /* already checked for error */ Py_RETURN_NONE; @@ -3096,17 +3098,17 @@ PyTypeObject vector_Type = { NULL, }; -PyObject *Vector_CreatePyObject(const float *vec, const int size, PyTypeObject *base_type) +PyObject *Vector_CreatePyObject(const float *vec, const int vec_num, PyTypeObject *base_type) { VectorObject *self; float *vec_alloc; - if (size < 2) { + if (vec_num < 2) { PyErr_SetString(PyExc_RuntimeError, "Vector(): invalid size"); return NULL; } - vec_alloc = PyMem_Malloc(size * sizeof(float)); + vec_alloc = PyMem_Malloc(vec_num * sizeof(float)); if (UNLIKELY(vec_alloc == NULL)) { PyErr_SetString(PyExc_MemoryError, "Vector(): " @@ -3117,18 +3119,18 @@ PyObject *Vector_CreatePyObject(const float *vec, const int size, PyTypeObject * self = BASE_MATH_NEW(VectorObject, vector_Type, base_type); if (self) { self->vec = vec_alloc; - self->size = size; + self->vec_num = vec_num; /* init callbacks as NULL */ self->cb_user = NULL; self->cb_type = self->cb_subtype = 0; if (vec) { - memcpy(self->vec, vec, size * sizeof(float)); + memcpy(self->vec, vec, vec_num * sizeof(float)); } else { /* new empty */ - copy_vn_fl(self->vec, size, 0.0f); - if (size == 4) { /* do the homogeneous thing */ + copy_vn_fl(self->vec, vec_num, 0.0f); + if (vec_num == 4) { /* do the homogeneous thing */ self->vec[3] = 1.0f; } } @@ -3141,18 +3143,18 @@ PyObject *Vector_CreatePyObject(const float *vec, const int size, PyTypeObject * return (PyObject *)self; } -PyObject *Vector_CreatePyObject_wrap(float *vec, const int size, PyTypeObject *base_type) +PyObject *Vector_CreatePyObject_wrap(float *vec, const int vec_num, PyTypeObject *base_type) { VectorObject *self; - if (size < 2) { + if (vec_num < 2) { PyErr_SetString(PyExc_RuntimeError, "Vector(): invalid size"); return NULL; } self = BASE_MATH_NEW(VectorObject, vector_Type, base_type); if (self) { - self->size = size; + self->vec_num = vec_num; /* init callbacks as NULL */ self->cb_user = NULL; @@ -3164,9 +3166,9 @@ PyObject *Vector_CreatePyObject_wrap(float *vec, const int size, PyTypeObject *b return (PyObject *)self; } -PyObject *Vector_CreatePyObject_cb(PyObject *cb_user, int size, uchar cb_type, uchar cb_subtype) +PyObject *Vector_CreatePyObject_cb(PyObject *cb_user, int vec_num, uchar cb_type, uchar cb_subtype) { - VectorObject *self = (VectorObject *)Vector_CreatePyObject(NULL, size, NULL); + VectorObject *self = (VectorObject *)Vector_CreatePyObject(NULL, vec_num, NULL); if (self) { Py_INCREF(cb_user); self->cb_user = cb_user; @@ -3178,10 +3180,10 @@ PyObject *Vector_CreatePyObject_cb(PyObject *cb_user, int size, uchar cb_type, u return (PyObject *)self; } -PyObject *Vector_CreatePyObject_alloc(float *vec, const int size, PyTypeObject *base_type) +PyObject *Vector_CreatePyObject_alloc(float *vec, const int vec_num, PyTypeObject *base_type) { VectorObject *self; - self = (VectorObject *)Vector_CreatePyObject_wrap(vec, size, base_type); + self = (VectorObject *)Vector_CreatePyObject_wrap(vec, vec_num, base_type); if (self) { self->flag &= ~BASE_MATH_FLAG_IS_WRAP; } diff --git a/source/blender/python/mathutils/mathutils_Vector.h b/source/blender/python/mathutils/mathutils_Vector.h index 422050c8742..3bc4e9d6b6f 100644 --- a/source/blender/python/mathutils/mathutils_Vector.h +++ b/source/blender/python/mathutils/mathutils_Vector.h @@ -14,12 +14,13 @@ extern PyTypeObject vector_Type; typedef struct { BASE_MATH_MEMBERS(vec); - int size; /* vec size 2 or more */ + /** Number of items in this vector (2 or more). */ + int vec_num; } VectorObject; /*prototypes*/ PyObject *Vector_CreatePyObject(const float *vec, - int size, + int vec_num, PyTypeObject *base_type) ATTR_WARN_UNUSED_RESULT; /** * Create a vector that wraps existing memory. @@ -27,7 +28,7 @@ PyObject *Vector_CreatePyObject(const float *vec, * \param vec: Use this vector in-place. */ PyObject *Vector_CreatePyObject_wrap(float *vec, - int size, + int vec_num, PyTypeObject *base_type) ATTR_WARN_UNUSED_RESULT ATTR_NONNULL(1); /** @@ -35,13 +36,13 @@ PyObject *Vector_CreatePyObject_wrap(float *vec, * see: #Mathutils_RegisterCallback */ PyObject *Vector_CreatePyObject_cb(PyObject *user, - int size, + int vec_num, unsigned char cb_type, unsigned char subtype) ATTR_WARN_UNUSED_RESULT; /** * \param vec: Initialized vector value to use in-place, allocated with #PyMem_Malloc */ PyObject *Vector_CreatePyObject_alloc(float *vec, - int size, + int vec_num, PyTypeObject *base_type) ATTR_WARN_UNUSED_RESULT ATTR_NONNULL(1); diff --git a/source/blender/python/mathutils/mathutils_geometry.c b/source/blender/python/mathutils/mathutils_geometry.c index 84ba2ce4031..1e492574903 100644 --- a/source/blender/python/mathutils/mathutils_geometry.c +++ b/source/blender/python/mathutils/mathutils_geometry.c @@ -158,24 +158,30 @@ static PyObject *M_Geometry_intersect_line_line(PyObject *UNUSED(self), PyObject PyObject *tuple; PyObject *py_lines[4]; float lines[4][3], i1[3], i2[3]; - int len; + int ix_vec_num; int result; if (!PyArg_ParseTuple(args, "OOOO:intersect_line_line", UNPACK4_EX(&, py_lines, ))) { return NULL; } - if ((((len = mathutils_array_parse( + if ((((ix_vec_num = mathutils_array_parse( lines[0], 2, 3 | MU_ARRAY_SPILL | MU_ARRAY_ZERO, py_lines[0], error_prefix)) != -1) && - (mathutils_array_parse( - lines[1], len, len | MU_ARRAY_SPILL | MU_ARRAY_ZERO, py_lines[1], error_prefix) != - -1) && - (mathutils_array_parse( - lines[2], len, len | MU_ARRAY_SPILL | MU_ARRAY_ZERO, py_lines[2], error_prefix) != - -1) && - (mathutils_array_parse( - lines[3], len, len | MU_ARRAY_SPILL | MU_ARRAY_ZERO, py_lines[3], error_prefix) != - -1)) == 0) { + (mathutils_array_parse(lines[1], + ix_vec_num, + ix_vec_num | MU_ARRAY_SPILL | MU_ARRAY_ZERO, + py_lines[1], + error_prefix) != -1) && + (mathutils_array_parse(lines[2], + ix_vec_num, + ix_vec_num | MU_ARRAY_SPILL | MU_ARRAY_ZERO, + py_lines[2], + error_prefix) != -1) && + (mathutils_array_parse(lines[3], + ix_vec_num, + ix_vec_num | MU_ARRAY_SPILL | MU_ARRAY_ZERO, + py_lines[3], + error_prefix) != -1)) == 0) { return NULL; } @@ -192,8 +198,9 @@ static PyObject *M_Geometry_intersect_line_line(PyObject *UNUSED(self), PyObject } tuple = PyTuple_New(2); - PyTuple_SET_ITEMS( - tuple, Vector_CreatePyObject(i1, len, NULL), Vector_CreatePyObject(i2, len, NULL)); + PyTuple_SET_ITEMS(tuple, + Vector_CreatePyObject(i1, ix_vec_num, NULL), + Vector_CreatePyObject(i2, ix_vec_num, NULL)); return tuple; } @@ -764,14 +771,14 @@ static PyObject *M_Geometry_intersect_point_line(PyObject *UNUSED(self), PyObjec float pt[3], pt_out[3], line_a[3], line_b[3]; float lambda; PyObject *ret; - int size = 2; + int pt_num = 2; if (!PyArg_ParseTuple(args, "OOO:intersect_point_line", &py_pt, &py_line_a, &py_line_b)) { return NULL; } /* accept 2d verts */ - if ((((size = mathutils_array_parse( + if ((((pt_num = mathutils_array_parse( pt, 2, 3 | MU_ARRAY_SPILL | MU_ARRAY_ZERO, py_pt, error_prefix)) != -1) && (mathutils_array_parse( line_a, 2, 3 | MU_ARRAY_SPILL | MU_ARRAY_ZERO, py_line_a, error_prefix) != -1) && @@ -784,7 +791,7 @@ static PyObject *M_Geometry_intersect_point_line(PyObject *UNUSED(self), PyObjec lambda = closest_to_line_v3(pt_out, pt, line_a, line_b); ret = PyTuple_New(2); - PyTuple_SET_ITEMS(ret, Vector_CreatePyObject(pt_out, size, NULL), PyFloat_FromDouble(lambda)); + PyTuple_SET_ITEMS(ret, Vector_CreatePyObject(pt_out, pt_num, NULL), PyFloat_FromDouble(lambda)); return ret; } diff --git a/source/blender/python/mathutils/mathutils_noise.c b/source/blender/python/mathutils/mathutils_noise.c index 0853c5dd3ea..e1282e90c48 100644 --- a/source/blender/python/mathutils/mathutils_noise.c +++ b/source/blender/python/mathutils/mathutils_noise.c @@ -305,23 +305,24 @@ static PyObject *M_Noise_random_unit_vector(PyObject *UNUSED(self), PyObject *ar static const char *kwlist[] = {"size", NULL}; float vec[4] = {0.0f, 0.0f, 0.0f, 0.0f}; float norm = 2.0f; - int size = 3; + int vec_num = 3; - if (!PyArg_ParseTupleAndKeywords(args, kw, "|$i:random_unit_vector", (char **)kwlist, &size)) { + if (!PyArg_ParseTupleAndKeywords( + args, kw, "|$i:random_unit_vector", (char **)kwlist, &vec_num)) { return NULL; } - if (size > 4 || size < 2) { + if (vec_num > 4 || vec_num < 2) { PyErr_SetString(PyExc_ValueError, "Vector(): invalid size"); return NULL; } while (norm == 0.0f || norm > 1.0f) { - rand_vn(vec, size); - norm = normalize_vn(vec, size); + rand_vn(vec, vec_num); + norm = normalize_vn(vec, vec_num); } - return Vector_CreatePyObject(vec, size, NULL); + return Vector_CreatePyObject(vec, vec_num, NULL); } PyDoc_STRVAR(M_Noise_random_vector_doc, @@ -337,22 +338,22 @@ static PyObject *M_Noise_random_vector(PyObject *UNUSED(self), PyObject *args, P { static const char *kwlist[] = {"size", NULL}; float *vec = NULL; - int size = 3; + int vec_num = 3; - if (!PyArg_ParseTupleAndKeywords(args, kw, "|$i:random_vector", (char **)kwlist, &size)) { + if (!PyArg_ParseTupleAndKeywords(args, kw, "|$i:random_vector", (char **)kwlist, &vec_num)) { return NULL; } - if (size < 2) { + if (vec_num < 2) { PyErr_SetString(PyExc_ValueError, "Vector(): invalid size"); return NULL; } - vec = PyMem_New(float, size); + vec = PyMem_New(float, vec_num); - rand_vn(vec, size); + rand_vn(vec, vec_num); - return Vector_CreatePyObject_alloc(vec, size, NULL); + return Vector_CreatePyObject_alloc(vec, vec_num, NULL); } PyDoc_STRVAR(M_Noise_seed_set_doc, |