diff options
author | Campbell Barton <ideasman42@gmail.com> | 2019-03-29 22:12:48 +0300 |
---|---|---|
committer | Campbell Barton <ideasman42@gmail.com> | 2019-03-29 23:14:28 +0300 |
commit | 25ec4b437fe927205a810470cdc23efd7282c85b (patch) | |
tree | 6d7ba2fe73703915b4b94d3f2dab03fb731e9544 /source/blender/python/mathutils | |
parent | 18d06e8d21ed8c9a19df4205abcd7ed17eb9af00 (diff) |
Cleanup: style, use braces for the Python API
Diffstat (limited to 'source/blender/python/mathutils')
-rw-r--r-- | source/blender/python/mathutils/mathutils.c | 31 | ||||
-rw-r--r-- | source/blender/python/mathutils/mathutils_Color.c | 136 | ||||
-rw-r--r-- | source/blender/python/mathutils/mathutils_Euler.c | 116 | ||||
-rw-r--r-- | source/blender/python/mathutils/mathutils_Matrix.c | 317 | ||||
-rw-r--r-- | source/blender/python/mathutils/mathutils_Quaternion.c | 209 | ||||
-rw-r--r-- | source/blender/python/mathutils/mathutils_Vector.c | 250 | ||||
-rw-r--r-- | source/blender/python/mathutils/mathutils_bvhtree.c | 6 | ||||
-rw-r--r-- | source/blender/python/mathutils/mathutils_geometry.c | 24 | ||||
-rw-r--r-- | source/blender/python/mathutils/mathutils_interpolate.c | 12 | ||||
-rw-r--r-- | source/blender/python/mathutils/mathutils_kdtree.c | 12 | ||||
-rw-r--r-- | source/blender/python/mathutils/mathutils_noise.c | 72 |
11 files changed, 797 insertions, 388 deletions
diff --git a/source/blender/python/mathutils/mathutils.c b/source/blender/python/mathutils/mathutils.c index f577ef3b441..41738ced41a 100644 --- a/source/blender/python/mathutils/mathutils.c +++ b/source/blender/python/mathutils/mathutils.c @@ -105,15 +105,17 @@ Py_hash_t mathutils_array_hash(const float *array, size_t array_len) i = 0; while (--len >= 0) { y = _Py_HashDouble((double)(array[i++])); - if (y == -1) + if (y == -1) { return -1; + } x = (x ^ y) * mult; /* the cast might truncate len; that doesn't change hash stability */ mult += (Py_hash_t)(82520UL + len + len); } x += 97531UL; - if (x == (Py_uhash_t)-1) + if (x == (Py_uhash_t)-1) { x = -2; + } return x; } @@ -392,8 +394,9 @@ int EXPP_VectorsAreEqual(const float *vecA, const float *vecB, int size, int flo { int x; for (x = 0; x < size; x++) { - if (EXPP_FloatsAreEqual(vecA[x], vecB[x], floatSteps) == 0) + if (EXPP_FloatsAreEqual(vecA[x], vecB[x], floatSteps) == 0) { return 0; + } } return 1; } @@ -425,8 +428,10 @@ unsigned char Mathutils_RegisterCallback(Mathutils_Callback *cb) /* find the first free slot */ for (i = 0; mathutils_callbacks[i]; i++) { - if (mathutils_callbacks[i] == cb) /* already registered? */ + if (mathutils_callbacks[i] == cb) { + /* already registered? */ return i; + } } BLI_assert(i + 1 < MATHUTILS_TOT_CB); @@ -611,18 +616,24 @@ PyMODINIT_FUNC PyInit_mathutils(void) PyObject *submodule; PyObject *sys_modules = PyImport_GetModuleDict(); - if (PyType_Ready(&vector_Type) < 0) + if (PyType_Ready(&vector_Type) < 0) { return NULL; - if (PyType_Ready(&matrix_Type) < 0) + } + if (PyType_Ready(&matrix_Type) < 0) { return NULL; - if (PyType_Ready(&matrix_access_Type) < 0) + } + if (PyType_Ready(&matrix_access_Type) < 0) { return NULL; - if (PyType_Ready(&euler_Type) < 0) + } + if (PyType_Ready(&euler_Type) < 0) { return NULL; - if (PyType_Ready(&quaternion_Type) < 0) + } + if (PyType_Ready(&quaternion_Type) < 0) { return NULL; - if (PyType_Ready(&color_Type) < 0) + } + if (PyType_Ready(&color_Type) < 0) { return NULL; + } mod = PyModule_Create(&M_Mathutils_module_def); diff --git a/source/blender/python/mathutils/mathutils_Color.c b/source/blender/python/mathutils/mathutils_Color.c index b05b8c81cf9..c97d2720720 100644 --- a/source/blender/python/mathutils/mathutils_Color.c +++ b/source/blender/python/mathutils/mathutils_Color.c @@ -52,8 +52,9 @@ static PyObject *Color_new(PyTypeObject *type, PyObject *args, PyObject *kwds) case 0: break; case 1: - if ((mathutils_array_parse(col, COLOR_SIZE, COLOR_SIZE, PyTuple_GET_ITEM(args, 0), "mathutils.Color()")) == -1) + if ((mathutils_array_parse(col, COLOR_SIZE, COLOR_SIZE, PyTuple_GET_ITEM(args, 0), "mathutils.Color()")) == -1) { return NULL; + } break; default: PyErr_SetString(PyExc_TypeError, @@ -101,8 +102,9 @@ PyDoc_STRVAR(Color_copy_doc, ); static PyObject *Color_copy(ColorObject *self) { - if (BaseMath_ReadCallback(self) == -1) + if (BaseMath_ReadCallback(self) == -1) { return NULL; + } return Color_CreatePyObject(self->col, Py_TYPE(self)); } @@ -121,8 +123,9 @@ static PyObject *Color_repr(ColorObject *self) { PyObject *ret, *tuple; - if (BaseMath_ReadCallback(self) == -1) + if (BaseMath_ReadCallback(self) == -1) { return NULL; + } tuple = Color_ToTupleExt(self, -1); @@ -137,8 +140,9 @@ static PyObject *Color_str(ColorObject *self) { DynStr *ds; - if (BaseMath_ReadCallback(self) == -1) + if (BaseMath_ReadCallback(self) == -1) { return NULL; + } ds = BLI_dynstr_new(); @@ -160,8 +164,9 @@ static PyObject *Color_richcmpr(PyObject *a, PyObject *b, int op) ColorObject *colA = (ColorObject *)a; ColorObject *colB = (ColorObject *)b; - if (BaseMath_ReadCallback(colA) == -1 || BaseMath_ReadCallback(colB) == -1) + if (BaseMath_ReadCallback(colA) == -1 || BaseMath_ReadCallback(colB) == -1) { return NULL; + } ok = EXPP_VectorsAreEqual(colA->col, colB->col, COLOR_SIZE, 1) ? 0 : -1; } @@ -190,11 +195,13 @@ static PyObject *Color_richcmpr(PyObject *a, PyObject *b, int op) static Py_hash_t Color_hash(ColorObject *self) { - if (BaseMath_ReadCallback(self) == -1) + if (BaseMath_ReadCallback(self) == -1) { return -1; + } - if (BaseMathObject_Prepare_ForHash(self) == -1) + if (BaseMathObject_Prepare_ForHash(self) == -1) { return -1; + } return mathutils_array_hash(self->col, COLOR_SIZE); } @@ -210,7 +217,9 @@ static int Color_len(ColorObject *UNUSED(self)) /* sequence accessor (get) */ static PyObject *Color_item(ColorObject *self, int i) { - if (i < 0) i = COLOR_SIZE - i; + if (i < 0) { + i = COLOR_SIZE - i; + } if (i < 0 || i >= COLOR_SIZE) { PyErr_SetString(PyExc_IndexError, @@ -219,8 +228,9 @@ static PyObject *Color_item(ColorObject *self, int i) return NULL; } - if (BaseMath_ReadIndexCallback(self, i) == -1) + if (BaseMath_ReadIndexCallback(self, i) == -1) { return NULL; + } return PyFloat_FromDouble(self->col[i]); @@ -231,8 +241,9 @@ static int Color_ass_item(ColorObject *self, int i, PyObject *value) { float f; - if (BaseMath_Prepare_ForWrite(self) == -1) + if (BaseMath_Prepare_ForWrite(self) == -1) { return -1; + } f = PyFloat_AsDouble(value); if (f == -1 && PyErr_Occurred()) { /* parsed item not a number */ @@ -242,7 +253,9 @@ static int Color_ass_item(ColorObject *self, int i, PyObject *value) return -1; } - if (i < 0) i = COLOR_SIZE - i; + if (i < 0) { + i = COLOR_SIZE - i; + } if (i < 0 || i >= COLOR_SIZE) { PyErr_SetString(PyExc_IndexError, "color[item] = x: " @@ -252,8 +265,9 @@ static int Color_ass_item(ColorObject *self, int i, PyObject *value) self->col[i] = f; - if (BaseMath_WriteIndexCallback(self, i) == -1) + if (BaseMath_WriteIndexCallback(self, i) == -1) { return -1; + } return 0; } @@ -264,11 +278,14 @@ static PyObject *Color_slice(ColorObject *self, int begin, int end) PyObject *tuple; int count; - if (BaseMath_ReadCallback(self) == -1) + if (BaseMath_ReadCallback(self) == -1) { return NULL; + } CLAMP(begin, 0, COLOR_SIZE); - if (end < 0) end = (COLOR_SIZE + 1) + end; + if (end < 0) { + end = (COLOR_SIZE + 1) + end; + } CLAMP(end, 0, COLOR_SIZE); begin = MIN2(begin, end); @@ -286,16 +303,20 @@ static int Color_ass_slice(ColorObject *self, int begin, int end, PyObject *seq) int i, size; float col[COLOR_SIZE]; - if (BaseMath_ReadCallback_ForWrite(self) == -1) + if (BaseMath_ReadCallback_ForWrite(self) == -1) { return -1; + } CLAMP(begin, 0, COLOR_SIZE); - if (end < 0) end = (COLOR_SIZE + 1) + end; + if (end < 0) { + end = (COLOR_SIZE + 1) + end; + } CLAMP(end, 0, COLOR_SIZE); begin = MIN2(begin, end); - if ((size = mathutils_array_parse(col, 0, COLOR_SIZE, seq, "mathutils.Color[begin:end] = []")) == -1) + if ((size = mathutils_array_parse(col, 0, COLOR_SIZE, seq, "mathutils.Color[begin:end] = []")) == -1) { return -1; + } if (size != (end - begin)) { PyErr_SetString(PyExc_ValueError, @@ -304,8 +325,9 @@ static int Color_ass_slice(ColorObject *self, int begin, int end, PyObject *seq) return -1; } - for (i = 0; i < COLOR_SIZE; i++) + for (i = 0; i < COLOR_SIZE; i++) { self->col[begin + i] = col[i]; + } (void)BaseMath_WriteCallback(self); return 0; @@ -316,17 +338,20 @@ static PyObject *Color_subscript(ColorObject *self, PyObject *item) if (PyIndex_Check(item)) { Py_ssize_t i; i = PyNumber_AsSsize_t(item, PyExc_IndexError); - if (i == -1 && PyErr_Occurred()) + if (i == -1 && PyErr_Occurred()) { return NULL; - if (i < 0) + } + if (i < 0) { i += COLOR_SIZE; + } return Color_item(self, i); } else if (PySlice_Check(item)) { Py_ssize_t start, stop, step, slicelength; - if (PySlice_GetIndicesEx(item, COLOR_SIZE, &start, &stop, &step, &slicelength) < 0) + if (PySlice_GetIndicesEx(item, COLOR_SIZE, &start, &stop, &step, &slicelength) < 0) { return NULL; + } if (slicelength <= 0) { return PyTuple_New(0); @@ -352,20 +377,24 @@ static int Color_ass_subscript(ColorObject *self, PyObject *item, PyObject *valu { if (PyIndex_Check(item)) { Py_ssize_t i = PyNumber_AsSsize_t(item, PyExc_IndexError); - if (i == -1 && PyErr_Occurred()) + if (i == -1 && PyErr_Occurred()) { return -1; - if (i < 0) + } + if (i < 0) { i += COLOR_SIZE; + } return Color_ass_item(self, i, value); } else if (PySlice_Check(item)) { Py_ssize_t start, stop, step, slicelength; - if (PySlice_GetIndicesEx(item, COLOR_SIZE, &start, &stop, &step, &slicelength) < 0) + if (PySlice_GetIndicesEx(item, COLOR_SIZE, &start, &stop, &step, &slicelength) < 0) { return -1; + } - if (step == 1) + if (step == 1) { return Color_ass_slice(self, start, stop, value); + } else { PyErr_SetString(PyExc_IndexError, "slice steps not supported with color"); @@ -419,8 +448,9 @@ static PyObject *Color_add(PyObject *v1, PyObject *v2) color1 = (ColorObject *)v1; color2 = (ColorObject *)v2; - if (BaseMath_ReadCallback(color1) == -1 || BaseMath_ReadCallback(color2) == -1) + if (BaseMath_ReadCallback(color1) == -1 || BaseMath_ReadCallback(color2) == -1) { return NULL; + } add_vn_vnvn(col, color1->col, color2->col, COLOR_SIZE); @@ -442,8 +472,9 @@ static PyObject *Color_iadd(PyObject *v1, PyObject *v2) color1 = (ColorObject *)v1; color2 = (ColorObject *)v2; - if (BaseMath_ReadCallback_ForWrite(color1) == -1 || BaseMath_ReadCallback(color2) == -1) + if (BaseMath_ReadCallback_ForWrite(color1) == -1 || BaseMath_ReadCallback(color2) == -1) { return NULL; + } add_vn_vn(color1->col, color2->col, COLOR_SIZE); @@ -468,8 +499,9 @@ static PyObject *Color_sub(PyObject *v1, PyObject *v2) color1 = (ColorObject *)v1; color2 = (ColorObject *)v2; - if (BaseMath_ReadCallback(color1) == -1 || BaseMath_ReadCallback(color2) == -1) + if (BaseMath_ReadCallback(color1) == -1 || BaseMath_ReadCallback(color2) == -1) { return NULL; + } sub_vn_vnvn(col, color1->col, color2->col, COLOR_SIZE); @@ -491,8 +523,9 @@ static PyObject *Color_isub(PyObject *v1, PyObject *v2) color1 = (ColorObject *)v1; color2 = (ColorObject *)v2; - if (BaseMath_ReadCallback_ForWrite(color1) == -1 || BaseMath_ReadCallback(color2) == -1) + if (BaseMath_ReadCallback_ForWrite(color1) == -1 || BaseMath_ReadCallback(color2) == -1) { return NULL; + } sub_vn_vn(color1->col, color2->col, COLOR_SIZE); @@ -516,13 +549,15 @@ static PyObject *Color_mul(PyObject *v1, PyObject *v2) if (ColorObject_Check(v1)) { color1 = (ColorObject *)v1; - if (BaseMath_ReadCallback(color1) == -1) + if (BaseMath_ReadCallback(color1) == -1) { return NULL; + } } if (ColorObject_Check(v2)) { color2 = (ColorObject *)v2; - if (BaseMath_ReadCallback(color2) == -1) + if (BaseMath_ReadCallback(color2) == -1) { return NULL; + } } @@ -558,8 +593,9 @@ static PyObject *Color_div(PyObject *v1, PyObject *v2) if (ColorObject_Check(v1)) { color1 = (ColorObject *)v1; - if (BaseMath_ReadCallback(color1) == -1) + if (BaseMath_ReadCallback(color1) == -1) { return NULL; + } } else { PyErr_SetString(PyExc_TypeError, @@ -590,8 +626,9 @@ static PyObject *Color_imul(PyObject *v1, PyObject *v2) ColorObject *color = (ColorObject *)v1; float scalar; - if (BaseMath_ReadCallback_ForWrite(color) == -1) + if (BaseMath_ReadCallback_ForWrite(color) == -1) { return NULL; + } /* only support color *= float */ if (((scalar = PyFloat_AsDouble(v2)) == -1.0f && PyErr_Occurred()) == 0) { /* COLOR *= FLOAT */ @@ -616,8 +653,9 @@ static PyObject *Color_idiv(PyObject *v1, PyObject *v2) ColorObject *color = (ColorObject *)v1; float scalar; - if (BaseMath_ReadCallback_ForWrite(color) == -1) + if (BaseMath_ReadCallback_ForWrite(color) == -1) { return NULL; + } /* only support color /= float */ if (((scalar = PyFloat_AsDouble(v2)) == -1.0f && PyErr_Occurred()) == 0) { /* COLOR /= FLOAT */ @@ -648,8 +686,9 @@ static PyObject *Color_neg(ColorObject *self) { float tcol[COLOR_SIZE]; - if (BaseMath_ReadCallback(self) == -1) + if (BaseMath_ReadCallback(self) == -1) { return NULL; + } negate_vn_vn(tcol, self->col, COLOR_SIZE); return Color_CreatePyObject(tcol, Py_TYPE(self)); @@ -718,8 +757,9 @@ static PyObject *Color_channel_hsv_get(ColorObject *self, void *type) float hsv[3]; int i = POINTER_AS_INT(type); - if (BaseMath_ReadCallback(self) == -1) + if (BaseMath_ReadCallback(self) == -1) { return NULL; + } rgb_to_hsv(self->col[0], self->col[1], self->col[2], &(hsv[0]), &(hsv[1]), &(hsv[2])); @@ -739,16 +779,18 @@ static int Color_channel_hsv_set(ColorObject *self, PyObject *value, void *type) return -1; } - if (BaseMath_ReadCallback_ForWrite(self) == -1) + if (BaseMath_ReadCallback_ForWrite(self) == -1) { return -1; + } rgb_to_hsv_v(self->col, hsv); CLAMP(f, 0.0f, 1.0f); hsv[i] = f; hsv_to_rgb_v(hsv, self->col); - if (BaseMath_WriteCallback(self) == -1) + if (BaseMath_WriteCallback(self) == -1) { return -1; + } return 0; } @@ -760,8 +802,9 @@ static PyObject *Color_hsv_get(ColorObject *self, void *UNUSED(closure)) float hsv[3]; PyObject *ret; - if (BaseMath_ReadCallback(self) == -1) + if (BaseMath_ReadCallback(self) == -1) { return NULL; + } rgb_to_hsv(self->col[0], self->col[1], self->col[2], &(hsv[0]), &(hsv[1]), &(hsv[2])); @@ -777,11 +820,13 @@ static int Color_hsv_set(ColorObject *self, PyObject *value, void *UNUSED(closur { float hsv[3]; - if (mathutils_array_parse(hsv, 3, 3, value, "mathutils.Color.hsv = value") == -1) + if (mathutils_array_parse(hsv, 3, 3, value, "mathutils.Color.hsv = value") == -1) { return -1; + } - if (BaseMath_Prepare_ForWrite(self) == -1) + if (BaseMath_Prepare_ForWrite(self) == -1) { return -1; + } CLAMP(hsv[0], 0.0f, 1.0f); CLAMP(hsv[1], 0.0f, 1.0f); @@ -789,8 +834,9 @@ static int Color_hsv_set(ColorObject *self, PyObject *value, void *UNUSED(closur hsv_to_rgb_v(hsv, self->col); - if (BaseMath_WriteCallback(self) == -1) + if (BaseMath_WriteCallback(self) == -1) { return -1; + } return 0; } @@ -913,10 +959,12 @@ PyObject *Color_CreatePyObject( self->cb_type = self->cb_subtype = 0; /* NEW */ - if (col) + if (col) { copy_v3_v3(self->col, col); - else + } + else { zero_v3(self->col); + } self->flag = BASE_MATH_FLAG_DEFAULT; } diff --git a/source/blender/python/mathutils/mathutils_Euler.c b/source/blender/python/mathutils/mathutils_Euler.c index a3336309574..e928049644b 100644 --- a/source/blender/python/mathutils/mathutils_Euler.c +++ b/source/blender/python/mathutils/mathutils_Euler.c @@ -51,19 +51,22 @@ static PyObject *Euler_new(PyTypeObject *type, PyObject *args, PyObject *kwds) return NULL; } - if (!PyArg_ParseTuple(args, "|Os:mathutils.Euler", &seq, &order_str)) + if (!PyArg_ParseTuple(args, "|Os:mathutils.Euler", &seq, &order_str)) { return NULL; + } switch (PyTuple_GET_SIZE(args)) { case 0: break; case 2: - if ((order = euler_order_from_string(order_str, "mathutils.Euler()")) == -1) + if ((order = euler_order_from_string(order_str, "mathutils.Euler()")) == -1) { return NULL; + } ATTR_FALLTHROUGH; case 1: - if (mathutils_array_parse(eul, EULER_SIZE, EULER_SIZE, seq, "mathutils.Euler()") == -1) + if (mathutils_array_parse(eul, EULER_SIZE, EULER_SIZE, seq, "mathutils.Euler()") == -1) { return NULL; + } break; } return Euler_CreatePyObject(eul, order, type); @@ -141,8 +144,9 @@ static PyObject *Euler_to_quaternion(EulerObject *self) { float quat[4]; - if (BaseMath_ReadCallback(self) == -1) + if (BaseMath_ReadCallback(self) == -1) { return NULL; + } eulO_to_quat(quat, self->eul, self->order); @@ -162,8 +166,9 @@ static PyObject *Euler_to_matrix(EulerObject *self) { float mat[9]; - if (BaseMath_ReadCallback(self) == -1) + if (BaseMath_ReadCallback(self) == -1) { return NULL; + } eulO_to_mat3((float (*)[3])mat, self->eul, self->order); @@ -177,13 +182,15 @@ PyDoc_STRVAR(Euler_zero_doc, ); static PyObject *Euler_zero(EulerObject *self) { - if (BaseMath_Prepare_ForWrite(self) == -1) + if (BaseMath_Prepare_ForWrite(self) == -1) { return NULL; + } zero_v3(self->eul); - if (BaseMath_WriteCallback(self) == -1) + if (BaseMath_WriteCallback(self) == -1) { return NULL; + } Py_RETURN_NONE; } @@ -218,8 +225,9 @@ static PyObject *Euler_rotate_axis(EulerObject *self, PyObject *args) return NULL; } - if (BaseMath_ReadCallback_ForWrite(self) == -1) + if (BaseMath_ReadCallback_ForWrite(self) == -1) { return NULL; + } rotate_eulO(self->eul, self->order, (char)axis, angle); @@ -241,11 +249,13 @@ static PyObject *Euler_rotate(EulerObject *self, PyObject *value) { float self_rmat[3][3], other_rmat[3][3], rmat[3][3]; - if (BaseMath_ReadCallback_ForWrite(self) == -1) + if (BaseMath_ReadCallback_ForWrite(self) == -1) { return NULL; + } - if (mathutils_any_to_rotmat(other_rmat, value, "euler.rotate(value)") == -1) + if (mathutils_any_to_rotmat(other_rmat, value, "euler.rotate(value)") == -1) { return NULL; + } eulO_to_mat3(self_rmat, self->eul, self->order); mul_m3_m3m3(rmat, other_rmat, self_rmat); @@ -268,8 +278,9 @@ static PyObject *Euler_make_compatible(EulerObject *self, PyObject *value) { float teul[EULER_SIZE]; - if (BaseMath_ReadCallback_ForWrite(self) == -1) + if (BaseMath_ReadCallback_ForWrite(self) == -1) { return NULL; + } if (mathutils_array_parse(teul, EULER_SIZE, EULER_SIZE, value, "euler.make_compatible(other), invalid 'other' arg") == -1) @@ -300,8 +311,9 @@ PyDoc_STRVAR(Euler_copy_doc, ); static PyObject *Euler_copy(EulerObject *self) { - if (BaseMath_ReadCallback(self) == -1) + if (BaseMath_ReadCallback(self) == -1) { return NULL; + } return Euler_CreatePyObject(self->eul, self->order, Py_TYPE(self)); } @@ -320,8 +332,9 @@ static PyObject *Euler_repr(EulerObject *self) { PyObject *ret, *tuple; - if (BaseMath_ReadCallback(self) == -1) + if (BaseMath_ReadCallback(self) == -1) { return NULL; + } tuple = Euler_ToTupleExt(self, -1); @@ -336,8 +349,9 @@ static PyObject *Euler_str(EulerObject *self) { DynStr *ds; - if (BaseMath_ReadCallback(self) == -1) + if (BaseMath_ReadCallback(self) == -1) { return NULL; + } ds = BLI_dynstr_new(); @@ -357,8 +371,9 @@ static PyObject *Euler_richcmpr(PyObject *a, PyObject *b, int op) EulerObject *eulA = (EulerObject *)a; EulerObject *eulB = (EulerObject *)b; - if (BaseMath_ReadCallback(eulA) == -1 || BaseMath_ReadCallback(eulB) == -1) + if (BaseMath_ReadCallback(eulA) == -1 || BaseMath_ReadCallback(eulB) == -1) { return NULL; + } ok = ((eulA->order == eulB->order) && EXPP_VectorsAreEqual(eulA->eul, eulB->eul, EULER_SIZE, 1)) ? 0 : -1; } @@ -387,11 +402,13 @@ static PyObject *Euler_richcmpr(PyObject *a, PyObject *b, int op) static Py_hash_t Euler_hash(EulerObject *self) { - if (BaseMath_ReadCallback(self) == -1) + if (BaseMath_ReadCallback(self) == -1) { return -1; + } - if (BaseMathObject_Prepare_ForHash(self) == -1) + if (BaseMathObject_Prepare_ForHash(self) == -1) { return -1; + } return mathutils_array_hash(self->eul, EULER_SIZE); } @@ -407,7 +424,9 @@ static int Euler_len(EulerObject *UNUSED(self)) /* sequence accessor (get) */ static PyObject *Euler_item(EulerObject *self, int i) { - if (i < 0) i = EULER_SIZE - i; + if (i < 0) { + i = EULER_SIZE - i; + } if (i < 0 || i >= EULER_SIZE) { PyErr_SetString(PyExc_IndexError, @@ -416,8 +435,9 @@ static PyObject *Euler_item(EulerObject *self, int i) return NULL; } - if (BaseMath_ReadIndexCallback(self, i) == -1) + if (BaseMath_ReadIndexCallback(self, i) == -1) { return NULL; + } return PyFloat_FromDouble(self->eul[i]); @@ -428,8 +448,9 @@ static int Euler_ass_item(EulerObject *self, int i, PyObject *value) { float f; - if (BaseMath_Prepare_ForWrite(self) == -1) + if (BaseMath_Prepare_ForWrite(self) == -1) { return -1; + } f = PyFloat_AsDouble(value); if (f == -1 && PyErr_Occurred()) { /* parsed item not a number */ @@ -439,7 +460,9 @@ static int Euler_ass_item(EulerObject *self, int i, PyObject *value) return -1; } - if (i < 0) i = EULER_SIZE - i; + if (i < 0) { + i = EULER_SIZE - i; + } if (i < 0 || i >= EULER_SIZE) { PyErr_SetString(PyExc_IndexError, @@ -450,8 +473,9 @@ static int Euler_ass_item(EulerObject *self, int i, PyObject *value) self->eul[i] = f; - if (BaseMath_WriteIndexCallback(self, i) == -1) + if (BaseMath_WriteIndexCallback(self, i) == -1) { return -1; + } return 0; } @@ -462,11 +486,14 @@ static PyObject *Euler_slice(EulerObject *self, int begin, int end) PyObject *tuple; int count; - if (BaseMath_ReadCallback(self) == -1) + if (BaseMath_ReadCallback(self) == -1) { return NULL; + } CLAMP(begin, 0, EULER_SIZE); - if (end < 0) end = (EULER_SIZE + 1) + end; + if (end < 0) { + end = (EULER_SIZE + 1) + end; + } CLAMP(end, 0, EULER_SIZE); begin = MIN2(begin, end); @@ -484,16 +511,20 @@ static int Euler_ass_slice(EulerObject *self, int begin, int end, PyObject *seq) int i, size; float eul[EULER_SIZE]; - if (BaseMath_ReadCallback_ForWrite(self) == -1) + if (BaseMath_ReadCallback_ForWrite(self) == -1) { return -1; + } CLAMP(begin, 0, EULER_SIZE); - if (end < 0) end = (EULER_SIZE + 1) + end; + if (end < 0) { + end = (EULER_SIZE + 1) + end; + } CLAMP(end, 0, EULER_SIZE); begin = MIN2(begin, end); - if ((size = mathutils_array_parse(eul, 0, EULER_SIZE, seq, "mathutils.Euler[begin:end] = []")) == -1) + if ((size = mathutils_array_parse(eul, 0, EULER_SIZE, seq, "mathutils.Euler[begin:end] = []")) == -1) { return -1; + } if (size != (end - begin)) { PyErr_SetString(PyExc_ValueError, @@ -502,8 +533,9 @@ static int Euler_ass_slice(EulerObject *self, int begin, int end, PyObject *seq) return -1; } - for (i = 0; i < EULER_SIZE; i++) + for (i = 0; i < EULER_SIZE; i++) { self->eul[begin + i] = eul[i]; + } (void)BaseMath_WriteCallback(self); return 0; @@ -514,17 +546,20 @@ static PyObject *Euler_subscript(EulerObject *self, PyObject *item) if (PyIndex_Check(item)) { Py_ssize_t i; i = PyNumber_AsSsize_t(item, PyExc_IndexError); - if (i == -1 && PyErr_Occurred()) + if (i == -1 && PyErr_Occurred()) { return NULL; - if (i < 0) + } + if (i < 0) { i += EULER_SIZE; + } return Euler_item(self, i); } else if (PySlice_Check(item)) { Py_ssize_t start, stop, step, slicelength; - if (PySlice_GetIndicesEx(item, EULER_SIZE, &start, &stop, &step, &slicelength) < 0) + if (PySlice_GetIndicesEx(item, EULER_SIZE, &start, &stop, &step, &slicelength) < 0) { return NULL; + } if (slicelength <= 0) { return PyTuple_New(0); @@ -551,20 +586,24 @@ static int Euler_ass_subscript(EulerObject *self, PyObject *item, PyObject *valu { if (PyIndex_Check(item)) { Py_ssize_t i = PyNumber_AsSsize_t(item, PyExc_IndexError); - if (i == -1 && PyErr_Occurred()) + if (i == -1 && PyErr_Occurred()) { return -1; - if (i < 0) + } + if (i < 0) { i += EULER_SIZE; + } return Euler_ass_item(self, i, value); } else if (PySlice_Check(item)) { Py_ssize_t start, stop, step, slicelength; - if (PySlice_GetIndicesEx(item, EULER_SIZE, &start, &stop, &step, &slicelength) < 0) + if (PySlice_GetIndicesEx(item, EULER_SIZE, &start, &stop, &step, &slicelength) < 0) { return -1; + } - if (step == 1) + if (step == 1) { return Euler_ass_slice(self, start, stop, value); + } else { PyErr_SetString(PyExc_IndexError, "slice steps not supported with euler"); @@ -621,8 +660,10 @@ PyDoc_STRVAR(Euler_order_doc, ); static PyObject *Euler_order_get(EulerObject *self, void *UNUSED(closure)) { - if (BaseMath_ReadCallback(self) == -1) /* can read order too */ + if (BaseMath_ReadCallback(self) == -1) { + /* can read order too */ return NULL; + } return PyUnicode_FromString(euler_order_str(self)); } @@ -632,8 +673,9 @@ static int Euler_order_set(EulerObject *self, PyObject *value, void *UNUSED(clos const char *order_str; short order; - if (BaseMath_Prepare_ForWrite(self) == -1) + if (BaseMath_Prepare_ForWrite(self) == -1) { return -1; + } if (((order_str = _PyUnicode_AsString(value)) == NULL) || ((order = euler_order_from_string(order_str, "euler.order")) == -1)) diff --git a/source/blender/python/mathutils/mathutils_Matrix.c b/source/blender/python/mathutils/mathutils_Matrix.c index 1f2d955c449..6477493d4a6 100644 --- a/source/blender/python/mathutils/mathutils_Matrix.c +++ b/source/blender/python/mathutils/mathutils_Matrix.c @@ -89,10 +89,12 @@ static int mathutils_matrix_row_get(BaseMathObject *bmo, int row) MatrixObject *self = (MatrixObject *)bmo->cb_user; int col; - if (BaseMath_ReadCallback(self) == -1) + if (BaseMath_ReadCallback(self) == -1) { return -1; - if (!matrix_row_vector_check(self, (VectorObject *)bmo, row)) + } + if (!matrix_row_vector_check(self, (VectorObject *)bmo, row)) { return -1; + } for (col = 0; col < self->num_col; col++) { bmo->data[col] = MATRIX_ITEM(self, row, col); @@ -106,10 +108,12 @@ static int mathutils_matrix_row_set(BaseMathObject *bmo, int row) MatrixObject *self = (MatrixObject *)bmo->cb_user; int col; - if (BaseMath_ReadCallback_ForWrite(self) == -1) + if (BaseMath_ReadCallback_ForWrite(self) == -1) { return -1; - if (!matrix_row_vector_check(self, (VectorObject *)bmo, row)) + } + if (!matrix_row_vector_check(self, (VectorObject *)bmo, row)) { return -1; + } for (col = 0; col < self->num_col; col++) { MATRIX_ITEM(self, row, col) = bmo->data[col]; @@ -123,10 +127,12 @@ static int mathutils_matrix_row_get_index(BaseMathObject *bmo, int row, int col) { MatrixObject *self = (MatrixObject *)bmo->cb_user; - if (BaseMath_ReadCallback(self) == -1) + if (BaseMath_ReadCallback(self) == -1) { return -1; - if (!matrix_row_vector_check(self, (VectorObject *)bmo, row)) + } + if (!matrix_row_vector_check(self, (VectorObject *)bmo, row)) { return -1; + } bmo->data[col] = MATRIX_ITEM(self, row, col); return 0; @@ -136,10 +142,12 @@ static int mathutils_matrix_row_set_index(BaseMathObject *bmo, int row, int col) { MatrixObject *self = (MatrixObject *)bmo->cb_user; - if (BaseMath_ReadCallback_ForWrite(self) == -1) + if (BaseMath_ReadCallback_ForWrite(self) == -1) { return -1; - if (!matrix_row_vector_check(self, (VectorObject *)bmo, row)) + } + if (!matrix_row_vector_check(self, (VectorObject *)bmo, row)) { return -1; + } MATRIX_ITEM(self, row, col) = bmo->data[col]; @@ -174,10 +182,12 @@ static int mathutils_matrix_col_get(BaseMathObject *bmo, int col) int num_row; int row; - if (BaseMath_ReadCallback(self) == -1) + if (BaseMath_ReadCallback(self) == -1) { return -1; - if (!matrix_col_vector_check(self, (VectorObject *)bmo, col)) + } + if (!matrix_col_vector_check(self, (VectorObject *)bmo, col)) { return -1; + } /* for 'translation' size will always be '3' even on 4x4 vec */ num_row = min_ii(self->num_row, ((VectorObject *)bmo)->size); @@ -195,10 +205,12 @@ static int mathutils_matrix_col_set(BaseMathObject *bmo, int col) int num_row; int row; - if (BaseMath_ReadCallback_ForWrite(self) == -1) + if (BaseMath_ReadCallback_ForWrite(self) == -1) { return -1; - if (!matrix_col_vector_check(self, (VectorObject *)bmo, col)) + } + if (!matrix_col_vector_check(self, (VectorObject *)bmo, col)) { return -1; + } /* for 'translation' size will always be '3' even on 4x4 vec */ num_row = min_ii(self->num_row, ((VectorObject *)bmo)->size); @@ -215,10 +227,12 @@ static int mathutils_matrix_col_get_index(BaseMathObject *bmo, int col, int row) { MatrixObject *self = (MatrixObject *)bmo->cb_user; - if (BaseMath_ReadCallback(self) == -1) + if (BaseMath_ReadCallback(self) == -1) { return -1; - if (!matrix_col_vector_check(self, (VectorObject *)bmo, col)) + } + if (!matrix_col_vector_check(self, (VectorObject *)bmo, col)) { return -1; + } bmo->data[row] = MATRIX_ITEM(self, row, col); return 0; @@ -228,10 +242,12 @@ static int mathutils_matrix_col_set_index(BaseMathObject *bmo, int col, int row) { MatrixObject *self = (MatrixObject *)bmo->cb_user; - if (BaseMath_ReadCallback_ForWrite(self) == -1) + if (BaseMath_ReadCallback_ForWrite(self) == -1) { return -1; - if (!matrix_col_vector_check(self, (VectorObject *)bmo, col)) + } + if (!matrix_col_vector_check(self, (VectorObject *)bmo, col)) { return -1; + } MATRIX_ITEM(self, row, col) = bmo->data[row]; @@ -266,8 +282,9 @@ static int mathutils_matrix_translation_get(BaseMathObject *bmo, int col) MatrixObject *self = (MatrixObject *)bmo->cb_user; int row; - if (BaseMath_ReadCallback(self) == -1) + if (BaseMath_ReadCallback(self) == -1) { return -1; + } for (row = 0; row < 3; row++) { bmo->data[row] = MATRIX_ITEM(self, row, col); @@ -281,8 +298,9 @@ static int mathutils_matrix_translation_set(BaseMathObject *bmo, int col) MatrixObject *self = (MatrixObject *)bmo->cb_user; int row; - if (BaseMath_ReadCallback_ForWrite(self) == -1) + if (BaseMath_ReadCallback_ForWrite(self) == -1) { return -1; + } for (row = 0; row < 3; row++) { MATRIX_ITEM(self, row, col) = bmo->data[row]; @@ -296,8 +314,9 @@ static int mathutils_matrix_translation_get_index(BaseMathObject *bmo, int col, { MatrixObject *self = (MatrixObject *)bmo->cb_user; - if (BaseMath_ReadCallback(self) == -1) + if (BaseMath_ReadCallback(self) == -1) { return -1; + } bmo->data[row] = MATRIX_ITEM(self, row, col); return 0; @@ -307,8 +326,9 @@ static int mathutils_matrix_translation_set_index(BaseMathObject *bmo, int col, { MatrixObject *self = (MatrixObject *)bmo->cb_user; - if (BaseMath_ReadCallback_ForWrite(self) == -1) + if (BaseMath_ReadCallback_ForWrite(self) == -1) { return -1; + } MATRIX_ITEM(self, row, col) = bmo->data[row]; @@ -516,8 +536,9 @@ static PyObject *C_Matrix_Rotation(PyObject *cls, PyObject *args) if (vec) { float tvec[3]; - if (mathutils_array_parse(tvec, 3, 3, vec, "Matrix.Rotation(angle, size, axis), invalid 'axis' arg") == -1) + if (mathutils_array_parse(tvec, 3, 3, vec, "Matrix.Rotation(angle, size, axis), invalid 'axis' arg") == -1) { return NULL; + } axis_angle_to_mat3((float (*)[3])mat, tvec, angle); } @@ -554,8 +575,9 @@ static PyObject *C_Matrix_Translation(PyObject *cls, PyObject *value) unit_m4(mat); - if (mathutils_array_parse(mat[3], 3, 4, value, "mathutils.Matrix.Translation(vector), invalid vector arg") == -1) + if (mathutils_array_parse(mat[3], 3, 4, value, "mathutils.Matrix.Translation(vector), invalid vector arg") == -1) { return NULL; + } return Matrix_CreatePyObject(&mat[0][0], 4, 4, (PyTypeObject *)cls); } @@ -1079,8 +1101,9 @@ static PyObject *Matrix_to_quaternion(MatrixObject *self) { float quat[4]; - if (BaseMath_ReadCallback(self) == -1) + if (BaseMath_ReadCallback(self) == -1) { return NULL; + } /* 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)) { @@ -1125,15 +1148,18 @@ static PyObject *Matrix_to_euler(MatrixObject *self, PyObject *args) float mat[3][3]; - if (BaseMath_ReadCallback(self) == -1) + if (BaseMath_ReadCallback(self) == -1) { return NULL; + } - if (!PyArg_ParseTuple(args, "|sO!:to_euler", &order_str, &euler_Type, &eul_compat)) + if (!PyArg_ParseTuple(args, "|sO!:to_euler", &order_str, &euler_Type, &eul_compat)) { return NULL; + } if (eul_compat) { - if (BaseMath_ReadCallback(eul_compat) == -1) + if (BaseMath_ReadCallback(eul_compat) == -1) { return NULL; + } copy_v3_v3(eul_compatf, eul_compat->eul); } @@ -1155,19 +1181,28 @@ static PyObject *Matrix_to_euler(MatrixObject *self, PyObject *args) if (order_str) { order = euler_order_from_string(order_str, "Matrix.to_euler()"); - if (order == -1) + if (order == -1) { return NULL; + } } normalize_m3(mat); if (eul_compat) { - if (order == 1) mat3_normalized_to_compatible_eul(eul, eul_compatf, mat); - else mat3_normalized_to_compatible_eulO(eul, eul_compatf, order, mat); + if (order == 1) { + mat3_normalized_to_compatible_eul(eul, eul_compatf, mat); + } + else { + mat3_normalized_to_compatible_eulO(eul, eul_compatf, order, mat); + } } else { - if (order == 1) mat3_normalized_to_eul(eul, mat); - else mat3_normalized_to_eulO(eul, order, mat); + if (order == 1) { + mat3_normalized_to_eul(eul, mat); + } + else { + mat3_normalized_to_eulO(eul, order, mat); + } } return Euler_CreatePyObject(eul, order, NULL); @@ -1228,8 +1263,9 @@ PyDoc_STRVAR(Matrix_to_4x4_doc, ); static PyObject *Matrix_to_4x4(MatrixObject *self) { - if (BaseMath_ReadCallback(self) == -1) + if (BaseMath_ReadCallback(self) == -1) { return NULL; + } if (self->num_row == 4 && self->num_col == 4) { return Matrix_CreatePyObject(self->matrix, 4, 4, Py_TYPE(self)); @@ -1259,8 +1295,9 @@ static PyObject *Matrix_to_3x3(MatrixObject *self) { float mat[3][3]; - if (BaseMath_ReadCallback(self) == -1) + if (BaseMath_ReadCallback(self) == -1) { return NULL; + } if ((self->num_row < 3) || (self->num_col < 3)) { PyErr_SetString(PyExc_ValueError, @@ -1283,8 +1320,9 @@ PyDoc_STRVAR(Matrix_to_translation_doc, ); static PyObject *Matrix_to_translation(MatrixObject *self) { - if (BaseMath_ReadCallback(self) == -1) + if (BaseMath_ReadCallback(self) == -1) { return NULL; + } if ((self->num_row < 3) || self->num_col < 4) { PyErr_SetString(PyExc_ValueError, @@ -1312,8 +1350,9 @@ static PyObject *Matrix_to_scale(MatrixObject *self) float mat[3][3]; float size[3]; - if (BaseMath_ReadCallback(self) == -1) + if (BaseMath_ReadCallback(self) == -1) { return NULL; + } /*must be 3-4 cols, 3-4 rows, square matrix */ if ((self->num_row < 3) || (self->num_col < 3)) { @@ -1401,8 +1440,9 @@ PyDoc_STRVAR(Matrix_invert_doc, ); static PyObject *Matrix_invert(MatrixObject *self, PyObject *args) { - if (BaseMath_ReadCallback_ForWrite(self) == -1) + if (BaseMath_ReadCallback_ForWrite(self) == -1) { return NULL; + } if (matrix_invert_is_compat(self) == false) { return NULL; @@ -1419,8 +1459,9 @@ static PyObject *Matrix_invert(MatrixObject *self, PyObject *args) if (PyTuple_GET_SIZE(args) == 1) { MatrixObject *fallback = (MatrixObject *)PyTuple_GET_ITEM(args, 0); - if (BaseMath_ReadCallback(fallback) == -1) + if (BaseMath_ReadCallback(fallback) == -1) { return NULL; + } if (self != fallback) { matrix_copy(self, fallback); @@ -1451,8 +1492,9 @@ static PyObject *Matrix_inverted(MatrixObject *self, PyObject *args) { float mat[MATRIX_MAX_DIM * MATRIX_MAX_DIM]; - if (BaseMath_ReadCallback(self) == -1) + if (BaseMath_ReadCallback(self) == -1) { return NULL; + } if (matrix_invert_args_check(self, args, false) == false) { return NULL; @@ -1482,8 +1524,9 @@ static PyObject *Matrix_inverted(MatrixObject *self, PyObject *args) static PyObject *Matrix_inverted_noargs(MatrixObject *self) { - if (BaseMath_ReadCallback_ForWrite(self) == -1) + if (BaseMath_ReadCallback_ForWrite(self) == -1) { return NULL; + } if (matrix_invert_is_compat(self) == false) { return NULL; @@ -1512,8 +1555,9 @@ PyDoc_STRVAR(Matrix_invert_safe_doc, ); static PyObject *Matrix_invert_safe(MatrixObject *self) { - if (BaseMath_ReadCallback_ForWrite(self) == -1) + if (BaseMath_ReadCallback_ForWrite(self) == -1) { return NULL; + } if (matrix_invert_is_compat(self) == false) { return NULL; @@ -1539,8 +1583,9 @@ static PyObject *Matrix_inverted_safe(MatrixObject *self) { float mat[MATRIX_MAX_DIM * MATRIX_MAX_DIM]; - if (BaseMath_ReadCallback(self) == -1) + if (BaseMath_ReadCallback(self) == -1) { return NULL; + } if (matrix_invert_is_compat(self) == false) { return NULL; @@ -1563,8 +1608,9 @@ PyDoc_STRVAR(Matrix_adjugate_doc, ); static PyObject *Matrix_adjugate(MatrixObject *self) { - if (BaseMath_ReadCallback_ForWrite(self) == -1) + if (BaseMath_ReadCallback_ForWrite(self) == -1) { return NULL; + } if (self->num_col != self->num_row) { PyErr_SetString(PyExc_ValueError, @@ -1618,11 +1664,13 @@ static PyObject *Matrix_rotate(MatrixObject *self, PyObject *value) { float self_rmat[3][3], other_rmat[3][3], rmat[3][3]; - if (BaseMath_ReadCallback_ForWrite(self) == -1) + if (BaseMath_ReadCallback_ForWrite(self) == -1) { return NULL; + } - if (mathutils_any_to_rotmat(other_rmat, value, "matrix.rotate(value)") == -1) + if (mathutils_any_to_rotmat(other_rmat, value, "matrix.rotate(value)") == -1) { return NULL; + } if (self->num_row != 3 || self->num_col != 3) { PyErr_SetString(PyExc_ValueError, @@ -1664,8 +1712,9 @@ static PyObject *Matrix_decompose(MatrixObject *self) return NULL; } - if (BaseMath_ReadCallback(self) == -1) + if (BaseMath_ReadCallback(self) == -1) { return NULL; + } mat4_to_loc_rot_size(loc, rot, size, (float (*)[4])self->matrix); mat3_to_quat(quat, rot); @@ -1698,8 +1747,9 @@ static PyObject *Matrix_lerp(MatrixObject *self, PyObject *args) MatrixObject *mat2 = NULL; float fac, mat[MATRIX_MAX_DIM * MATRIX_MAX_DIM]; - if (!PyArg_ParseTuple(args, "O!f:lerp", &matrix_Type, &mat2, &fac)) + if (!PyArg_ParseTuple(args, "O!f:lerp", &matrix_Type, &mat2, &fac)) { return NULL; + } if (self->num_col != mat2->num_col || self->num_row != mat2->num_row) { PyErr_SetString(PyExc_ValueError, @@ -1708,8 +1758,9 @@ static PyObject *Matrix_lerp(MatrixObject *self, PyObject *args) return NULL; } - if (BaseMath_ReadCallback(self) == -1 || BaseMath_ReadCallback(mat2) == -1) + if (BaseMath_ReadCallback(self) == -1 || BaseMath_ReadCallback(mat2) == -1) { return NULL; + } /* TODO, different sized matrix */ if (self->num_col == 4 && self->num_row == 4) { @@ -1749,8 +1800,9 @@ PyDoc_STRVAR(Matrix_determinant_doc, ); static PyObject *Matrix_determinant(MatrixObject *self) { - if (BaseMath_ReadCallback(self) == -1) + if (BaseMath_ReadCallback(self) == -1) { return NULL; + } if (self->num_col != self->num_row) { PyErr_SetString(PyExc_ValueError, @@ -1771,8 +1823,9 @@ PyDoc_STRVAR(Matrix_transpose_doc, ); static PyObject *Matrix_transpose(MatrixObject *self) { - if (BaseMath_ReadCallback_ForWrite(self) == -1) + if (BaseMath_ReadCallback_ForWrite(self) == -1) { return NULL; + } if (self->num_col != self->num_row) { PyErr_SetString(PyExc_ValueError, @@ -1818,8 +1871,9 @@ PyDoc_STRVAR(Matrix_normalize_doc, ); static PyObject *Matrix_normalize(MatrixObject *self) { - if (BaseMath_ReadCallback_ForWrite(self) == -1) + if (BaseMath_ReadCallback_ForWrite(self) == -1) { return NULL; + } if (self->num_col != self->num_row) { PyErr_SetString(PyExc_ValueError, @@ -1867,13 +1921,15 @@ PyDoc_STRVAR(Matrix_zero_doc, ); static PyObject *Matrix_zero(MatrixObject *self) { - if (BaseMath_Prepare_ForWrite(self) == -1) + if (BaseMath_Prepare_ForWrite(self) == -1) { return NULL; + } copy_vn_fl(self->matrix, self->num_col * self->num_row, 0.0f); - if (BaseMath_WriteCallback(self) == -1) + if (BaseMath_WriteCallback(self) == -1) { return NULL; + } Py_RETURN_NONE; @@ -1906,8 +1962,9 @@ PyDoc_STRVAR(Matrix_identity_doc, ); static PyObject *Matrix_identity(MatrixObject *self) { - if (BaseMath_ReadCallback_ForWrite(self) == -1) + if (BaseMath_ReadCallback_ForWrite(self) == -1) { return NULL; + } if (self->num_col != self->num_row) { PyErr_SetString(PyExc_ValueError, @@ -1918,8 +1975,9 @@ static PyObject *Matrix_identity(MatrixObject *self) matrix_identity_internal(self); - if (BaseMath_WriteCallback(self) == -1) + if (BaseMath_WriteCallback(self) == -1) { return NULL; + } Py_RETURN_NONE; } @@ -1941,8 +1999,9 @@ PyDoc_STRVAR(Matrix_copy_doc, ); static PyObject *Matrix_copy(MatrixObject *self) { - if (BaseMath_ReadCallback(self) == -1) + if (BaseMath_ReadCallback(self) == -1) { return NULL; + } return Matrix_copy_notest(self, self->matrix); } @@ -1961,8 +2020,9 @@ static PyObject *Matrix_repr(MatrixObject *self) int col, row; PyObject *rows[MATRIX_MAX_DIM] = {NULL}; - if (BaseMath_ReadCallback(self) == -1) + if (BaseMath_ReadCallback(self) == -1) { return NULL; + } for (row = 0; row < self->num_row; row++) { rows[row] = PyTuple_New(self->num_col); @@ -1998,8 +2058,9 @@ static PyObject *Matrix_str(MatrixObject *self) char dummy_buf[64]; - if (BaseMath_ReadCallback(self) == -1) + if (BaseMath_ReadCallback(self) == -1) { return NULL; + } ds = BLI_dynstr_new(); @@ -2035,8 +2096,9 @@ static PyObject *Matrix_richcmpr(PyObject *a, PyObject *b, int op) MatrixObject *matA = (MatrixObject *)a; MatrixObject *matB = (MatrixObject *)b; - if (BaseMath_ReadCallback(matA) == -1 || BaseMath_ReadCallback(matB) == -1) + if (BaseMath_ReadCallback(matA) == -1 || BaseMath_ReadCallback(matB) == -1) { return NULL; + } ok = ((matA->num_row == matB->num_row) && (matA->num_col == matB->num_col) && @@ -2070,11 +2132,13 @@ static Py_hash_t Matrix_hash(MatrixObject *self) { float mat[MATRIX_MAX_DIM * MATRIX_MAX_DIM]; - if (BaseMath_ReadCallback(self) == -1) + if (BaseMath_ReadCallback(self) == -1) { return -1; + } - if (BaseMathObject_Prepare_ForHash(self) == -1) + if (BaseMathObject_Prepare_ForHash(self) == -1) { return -1; + } matrix_transpose_internal(mat, self); @@ -2093,8 +2157,9 @@ static int Matrix_len(MatrixObject *self) * the wrapped vector gives direct access to the matrix data */ static PyObject *Matrix_item_row(MatrixObject *self, int row) { - if (BaseMath_ReadCallback_ForWrite(self) == -1) + if (BaseMath_ReadCallback_ForWrite(self) == -1) { return NULL; + } if (row < 0 || row >= self->num_row) { PyErr_SetString(PyExc_IndexError, @@ -2107,8 +2172,9 @@ static PyObject *Matrix_item_row(MatrixObject *self, int row) /* same but column access */ static PyObject *Matrix_item_col(MatrixObject *self, int col) { - if (BaseMath_ReadCallback_ForWrite(self) == -1) + if (BaseMath_ReadCallback_ForWrite(self) == -1) { return NULL; + } if (col < 0 || col >= self->num_col) { PyErr_SetString(PyExc_IndexError, @@ -2126,8 +2192,9 @@ static int Matrix_ass_item_row(MatrixObject *self, int row, PyObject *value) { int col; float vec[MATRIX_MAX_DIM]; - if (BaseMath_ReadCallback_ForWrite(self) == -1) + if (BaseMath_ReadCallback_ForWrite(self) == -1) { return -1; + } if (row >= self->num_row || row < 0) { PyErr_SetString(PyExc_IndexError, @@ -2151,8 +2218,9 @@ static int Matrix_ass_item_col(MatrixObject *self, int col, PyObject *value) { int row; float vec[MATRIX_MAX_DIM]; - if (BaseMath_ReadCallback_ForWrite(self) == -1) + if (BaseMath_ReadCallback_ForWrite(self) == -1) { return -1; + } if (col >= self->num_col || col < 0) { PyErr_SetString(PyExc_IndexError, @@ -2182,8 +2250,9 @@ static PyObject *Matrix_slice(MatrixObject *self, int begin, int end) PyObject *tuple; int count; - if (BaseMath_ReadCallback(self) == -1) + if (BaseMath_ReadCallback(self) == -1) { return NULL; + } CLAMP(begin, 0, self->num_row); CLAMP(end, 0, self->num_row); @@ -2203,8 +2272,9 @@ static int Matrix_ass_slice(MatrixObject *self, int begin, int end, PyObject *va { PyObject *value_fast; - if (BaseMath_ReadCallback_ForWrite(self) == -1) + if (BaseMath_ReadCallback_ForWrite(self) == -1) { return -1; + } CLAMP(begin, 0, self->num_row); CLAMP(end, 0, self->num_row); @@ -2276,8 +2346,9 @@ static PyObject *Matrix_add(PyObject *m1, PyObject *m2) return NULL; } - if (BaseMath_ReadCallback(mat1) == -1 || BaseMath_ReadCallback(mat2) == -1) + if (BaseMath_ReadCallback(mat1) == -1 || BaseMath_ReadCallback(mat2) == -1) { return NULL; + } if (mat1->num_col != mat2->num_col || mat1->num_row != mat2->num_row) { PyErr_SetString(PyExc_ValueError, @@ -2308,8 +2379,9 @@ static PyObject *Matrix_sub(PyObject *m1, PyObject *m2) return NULL; } - if (BaseMath_ReadCallback(mat1) == -1 || BaseMath_ReadCallback(mat2) == -1) + if (BaseMath_ReadCallback(mat1) == -1 || BaseMath_ReadCallback(mat2) == -1) { return NULL; + } if (mat1->num_col != mat2->num_col || mat1->num_row != mat2->num_row) { PyErr_SetString(PyExc_ValueError, @@ -2339,13 +2411,15 @@ static PyObject *Matrix_mul(PyObject *m1, PyObject *m2) if (MatrixObject_Check(m1)) { mat1 = (MatrixObject *)m1; - if (BaseMath_ReadCallback(mat1) == -1) + if (BaseMath_ReadCallback(mat1) == -1) { return NULL; + } } if (MatrixObject_Check(m2)) { mat2 = (MatrixObject *)m2; - if (BaseMath_ReadCallback(mat2) == -1) + if (BaseMath_ReadCallback(mat2) == -1) { return NULL; + } } if (mat1 && mat2) { @@ -2394,13 +2468,15 @@ static PyObject *Matrix_imul(PyObject *m1, PyObject *m2) if (MatrixObject_Check(m1)) { mat1 = (MatrixObject *)m1; - if (BaseMath_ReadCallback(mat1) == -1) + if (BaseMath_ReadCallback(mat1) == -1) { return NULL; + } } if (MatrixObject_Check(m2)) { mat2 = (MatrixObject *)m2; - if (BaseMath_ReadCallback(mat2) == -1) + if (BaseMath_ReadCallback(mat2) == -1) { return NULL; + } } if (mat1 && mat2) { @@ -2448,13 +2524,15 @@ static PyObject *Matrix_matmul(PyObject *m1, PyObject *m2) if (MatrixObject_Check(m1)) { mat1 = (MatrixObject *)m1; - if (BaseMath_ReadCallback(mat1) == -1) + if (BaseMath_ReadCallback(mat1) == -1) { return NULL; + } } if (MatrixObject_Check(m2)) { mat2 = (MatrixObject *)m2; - if (BaseMath_ReadCallback(mat2) == -1) + if (BaseMath_ReadCallback(mat2) == -1) { return NULL; + } } if (mat1 && mat2) { @@ -2487,8 +2565,9 @@ static PyObject *Matrix_matmul(PyObject *m1, PyObject *m2) if (VectorObject_Check(m2)) { VectorObject *vec2 = (VectorObject *)m2; float tvec[MATRIX_MAX_DIM]; - if (BaseMath_ReadCallback(vec2) == -1) + if (BaseMath_ReadCallback(vec2) == -1) { return NULL; + } if (column_vector_multiplication(tvec, vec2, mat1) == -1) { return NULL; } @@ -2518,13 +2597,15 @@ static PyObject *Matrix_imatmul(PyObject *m1, PyObject *m2) if (MatrixObject_Check(m1)) { mat1 = (MatrixObject *)m1; - if (BaseMath_ReadCallback(mat1) == -1) + if (BaseMath_ReadCallback(mat1) == -1) { return NULL; + } } if (MatrixObject_Check(m2)) { mat2 = (MatrixObject *)m2; - if (BaseMath_ReadCallback(mat2) == -1) + if (BaseMath_ReadCallback(mat2) == -1) { return NULL; + } } if (mat1 && mat2) { @@ -2587,17 +2668,20 @@ static PyObject *Matrix_subscript(MatrixObject *self, PyObject *item) if (PyIndex_Check(item)) { Py_ssize_t i; i = PyNumber_AsSsize_t(item, PyExc_IndexError); - if (i == -1 && PyErr_Occurred()) + if (i == -1 && PyErr_Occurred()) { return NULL; - if (i < 0) + } + if (i < 0) { i += self->num_row; + } return Matrix_item_row(self, i); } else 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->num_row, &start, &stop, &step, &slicelength) < 0) { return NULL; + } if (slicelength <= 0) { return PyTuple_New(0); @@ -2623,20 +2707,24 @@ static int Matrix_ass_subscript(MatrixObject *self, PyObject *item, PyObject *va { if (PyIndex_Check(item)) { Py_ssize_t i = PyNumber_AsSsize_t(item, PyExc_IndexError); - if (i == -1 && PyErr_Occurred()) + if (i == -1 && PyErr_Occurred()) { return -1; - if (i < 0) + } + if (i < 0) { i += self->num_row; + } return Matrix_ass_item_row(self, i, value); } else 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->num_row, &start, &stop, &step, &slicelength) < 0) { return -1; + } - if (step == 1) + if (step == 1) { return Matrix_ass_slice(self, start, stop, value); + } else { PyErr_SetString(PyExc_IndexError, "slice steps not supported with matrices"); @@ -2704,8 +2792,9 @@ static PyObject *Matrix_translation_get(MatrixObject *self, void *UNUSED(closure { PyObject *ret; - if (BaseMath_ReadCallback(self) == -1) + if (BaseMath_ReadCallback(self) == -1) { return NULL; + } /*must be 4x4 square matrix*/ if (self->num_row != 4 || self->num_col != 4) { @@ -2724,8 +2813,9 @@ static int Matrix_translation_set(MatrixObject *self, PyObject *value, void *UNU { float tvec[3]; - if (BaseMath_ReadCallback_ForWrite(self) == -1) + if (BaseMath_ReadCallback_ForWrite(self) == -1) { return -1; + } /*must be 4x4 square matrix*/ if (self->num_row != 4 || self->num_col != 4) { @@ -2769,8 +2859,9 @@ static PyObject *Matrix_median_scale_get(MatrixObject *self, void *UNUSED(closur { float mat[3][3]; - if (BaseMath_ReadCallback(self) == -1) + if (BaseMath_ReadCallback(self) == -1) { return NULL; + } /*must be 3-4 cols, 3-4 rows, square matrix*/ if ((self->num_row < 3) || (self->num_col < 3)) { @@ -2790,14 +2881,17 @@ PyDoc_STRVAR(Matrix_is_negative_doc, ); static PyObject *Matrix_is_negative_get(MatrixObject *self, void *UNUSED(closure)) { - if (BaseMath_ReadCallback(self) == -1) + if (BaseMath_ReadCallback(self) == -1) { return NULL; + } /*must be 3-4 cols, 3-4 rows, square matrix*/ - if (self->num_row == 4 && self->num_col == 4) + if (self->num_row == 4 && self->num_col == 4) { return PyBool_FromLong(is_negative_m4((float (*)[4])self->matrix)); - else if (self->num_row == 3 && self->num_col == 3) + } + else if (self->num_row == 3 && self->num_col == 3) { return PyBool_FromLong(is_negative_m3((float (*)[3])self->matrix)); + } else { PyErr_SetString(PyExc_AttributeError, "Matrix.is_negative: " @@ -2811,14 +2905,17 @@ PyDoc_STRVAR(Matrix_is_orthogonal_doc, ); static PyObject *Matrix_is_orthogonal_get(MatrixObject *self, void *UNUSED(closure)) { - if (BaseMath_ReadCallback(self) == -1) + if (BaseMath_ReadCallback(self) == -1) { return NULL; + } /*must be 3-4 cols, 3-4 rows, square matrix*/ - if (self->num_row == 4 && self->num_col == 4) + if (self->num_row == 4 && self->num_col == 4) { return PyBool_FromLong(is_orthonormal_m4((float (*)[4])self->matrix)); - else if (self->num_row == 3 && self->num_col == 3) + } + else if (self->num_row == 3 && self->num_col == 3) { return PyBool_FromLong(is_orthonormal_m3((float (*)[3])self->matrix)); + } else { PyErr_SetString(PyExc_AttributeError, "Matrix.is_orthogonal: " @@ -2832,14 +2929,17 @@ PyDoc_STRVAR(Matrix_is_orthogonal_axis_vectors_doc, ); static PyObject *Matrix_is_orthogonal_axis_vectors_get(MatrixObject *self, void *UNUSED(closure)) { - if (BaseMath_ReadCallback(self) == -1) + if (BaseMath_ReadCallback(self) == -1) { return NULL; + } /*must be 3-4 cols, 3-4 rows, square matrix*/ - if (self->num_row == 4 && self->num_col == 4) + if (self->num_row == 4 && self->num_col == 4) { return PyBool_FromLong(is_orthogonal_m4((float (*)[4])self->matrix)); - else if (self->num_row == 3 && self->num_col == 3) + } + else if (self->num_row == 3 && self->num_col == 3) { return PyBool_FromLong(is_orthogonal_m3((float (*)[3])self->matrix)); + } else { PyErr_SetString(PyExc_AttributeError, "Matrix.is_orthogonal_axis_vectors: " @@ -3208,7 +3308,9 @@ static PyObject *MatrixAccess_slice(MatrixAccessObject *self, int begin, int end } CLAMP(begin, 0, matrix_access_len); - if (end < 0) end = (matrix_access_len + 1) + end; + if (end < 0) { + end = (matrix_access_len + 1) + end; + } CLAMP(end, 0, matrix_access_len); begin = MIN2(begin, end); @@ -3227,24 +3329,28 @@ static PyObject *MatrixAccess_subscript(MatrixAccessObject *self, PyObject *item if (PyIndex_Check(item)) { Py_ssize_t i; i = PyNumber_AsSsize_t(item, PyExc_IndexError); - if (i == -1 && PyErr_Occurred()) + if (i == -1 && PyErr_Occurred()) { return NULL; + } if (self->type == MAT_ACCESS_ROW) { - if (i < 0) + if (i < 0) { i += matrix_user->num_row; + } return Matrix_item_row(matrix_user, i); } else { /* MAT_ACCESS_ROW */ - if (i < 0) + if (i < 0) { i += matrix_user->num_col; + } return Matrix_item_col(matrix_user, i); } } else if (PySlice_Check(item)) { Py_ssize_t start, stop, step, slicelength; - if (PySlice_GetIndicesEx(item, MatrixAccess_len(self), &start, &stop, &step, &slicelength) < 0) + if (PySlice_GetIndicesEx(item, MatrixAccess_len(self), &start, &stop, &step, &slicelength) < 0) { return NULL; + } if (slicelength <= 0) { return PyTuple_New(0); @@ -3272,17 +3378,20 @@ static int MatrixAccess_ass_subscript(MatrixAccessObject *self, PyObject *item, if (PyIndex_Check(item)) { Py_ssize_t i = PyNumber_AsSsize_t(item, PyExc_IndexError); - if (i == -1 && PyErr_Occurred()) + if (i == -1 && PyErr_Occurred()) { return -1; + } if (self->type == MAT_ACCESS_ROW) { - if (i < 0) + if (i < 0) { i += matrix_user->num_row; + } return Matrix_ass_item_row(matrix_user, i, value); } else { /* MAT_ACCESS_ROW */ - if (i < 0) + if (i < 0) { i += matrix_user->num_col; + } return Matrix_ass_item_col(matrix_user, i, value); } diff --git a/source/blender/python/mathutils/mathutils_Quaternion.c b/source/blender/python/mathutils/mathutils_Quaternion.c index 5f7ab5fface..422a1ff28fa 100644 --- a/source/blender/python/mathutils/mathutils_Quaternion.c +++ b/source/blender/python/mathutils/mathutils_Quaternion.c @@ -87,31 +87,43 @@ static PyObject *Quaternion_to_euler(QuaternionObject *self, PyObject *args) short order = EULER_ORDER_XYZ; EulerObject *eul_compat = NULL; - if (!PyArg_ParseTuple(args, "|sO!:to_euler", &order_str, &euler_Type, &eul_compat)) + if (!PyArg_ParseTuple(args, "|sO!:to_euler", &order_str, &euler_Type, &eul_compat)) { return NULL; + } - if (BaseMath_ReadCallback(self) == -1) + if (BaseMath_ReadCallback(self) == -1) { return NULL; + } if (order_str) { order = euler_order_from_string(order_str, "Matrix.to_euler()"); - if (order == -1) + if (order == -1) { return NULL; + } } normalize_qt_qt(tquat, self->quat); if (eul_compat) { - if (BaseMath_ReadCallback(eul_compat) == -1) + if (BaseMath_ReadCallback(eul_compat) == -1) { return NULL; + } - if (order == EULER_ORDER_XYZ) quat_to_compatible_eul(eul, eul_compat->eul, tquat); - else quat_to_compatible_eulO(eul, eul_compat->eul, order, tquat); + if (order == EULER_ORDER_XYZ) { + quat_to_compatible_eul(eul, eul_compat->eul, tquat); + } + else { + quat_to_compatible_eulO(eul, eul_compat->eul, order, tquat); + } } else { - if (order == EULER_ORDER_XYZ) quat_to_eul(eul, tquat); - else quat_to_eulO(eul, order, tquat); + if (order == EULER_ORDER_XYZ) { + quat_to_eul(eul, tquat); + } + else { + quat_to_eulO(eul, order, tquat); + } } return Euler_CreatePyObject(eul, order, NULL); @@ -129,8 +141,9 @@ static PyObject *Quaternion_to_matrix(QuaternionObject *self) { float mat[9]; /* all values are set */ - if (BaseMath_ReadCallback(self) == -1) + if (BaseMath_ReadCallback(self) == -1) { return NULL; + } quat_to_mat3((float (*)[3])mat, self->quat); return Matrix_CreatePyObject(mat, 3, 3, NULL); @@ -153,8 +166,9 @@ static PyObject *Quaternion_to_axis_angle(QuaternionObject *self) float axis[3]; float angle; - if (BaseMath_ReadCallback(self) == -1) + if (BaseMath_ReadCallback(self) == -1) { return NULL; + } normalize_qt_qt(tquat, self->quat); quat_to_axis_angle(axis, &angle, tquat); @@ -185,8 +199,9 @@ static PyObject *Quaternion_to_exponential_map(QuaternionObject *self) { float expmap[3]; - if (BaseMath_ReadCallback(self) == -1) + if (BaseMath_ReadCallback(self) == -1) { return NULL; + } quat_to_expmap(expmap, self->quat); return Vector_CreatePyObject(expmap, 3, NULL); @@ -206,8 +221,9 @@ static PyObject *Quaternion_cross(QuaternionObject *self, PyObject *value) { float quat[QUAT_SIZE], tquat[QUAT_SIZE]; - if (BaseMath_ReadCallback(self) == -1) + if (BaseMath_ReadCallback(self) == -1) { return NULL; + } if (mathutils_array_parse(tquat, QUAT_SIZE, QUAT_SIZE, value, "Quaternion.cross(other), invalid 'other' arg") == -1) @@ -233,8 +249,9 @@ static PyObject *Quaternion_dot(QuaternionObject *self, PyObject *value) { float tquat[QUAT_SIZE]; - if (BaseMath_ReadCallback(self) == -1) + if (BaseMath_ReadCallback(self) == -1) { return NULL; + } if (mathutils_array_parse(tquat, QUAT_SIZE, QUAT_SIZE, value, "Quaternion.dot(other), invalid 'other' arg") == -1) @@ -259,8 +276,9 @@ static PyObject *Quaternion_rotation_difference(QuaternionObject *self, PyObject { float tquat[QUAT_SIZE], quat[QUAT_SIZE]; - if (BaseMath_ReadCallback(self) == -1) + if (BaseMath_ReadCallback(self) == -1) { return NULL; + } if (mathutils_array_parse(tquat, QUAT_SIZE, QUAT_SIZE, value, "Quaternion.difference(other), invalid 'other' arg") == -1) @@ -297,8 +315,9 @@ static PyObject *Quaternion_slerp(QuaternionObject *self, PyObject *args) return NULL; } - if (BaseMath_ReadCallback(self) == -1) + if (BaseMath_ReadCallback(self) == -1) { return NULL; + } if (mathutils_array_parse(tquat, QUAT_SIZE, QUAT_SIZE, value, "Quaternion.slerp(other), invalid 'other' arg") == -1) @@ -331,11 +350,13 @@ static PyObject *Quaternion_rotate(QuaternionObject *self, PyObject *value) float self_rmat[3][3], other_rmat[3][3], rmat[3][3]; float tquat[4], length; - if (BaseMath_ReadCallback_ForWrite(self) == -1) + if (BaseMath_ReadCallback_ForWrite(self) == -1) { return NULL; + } - if (mathutils_any_to_rotmat(other_rmat, value, "Quaternion.rotate(value)") == -1) + if (mathutils_any_to_rotmat(other_rmat, value, "Quaternion.rotate(value)") == -1) { return NULL; + } length = normalize_qt_qt(tquat, self->quat); quat_to_mat3(self_rmat, tquat); @@ -358,8 +379,9 @@ PyDoc_STRVAR(Quaternion_normalize_doc, ); static PyObject *Quaternion_normalize(QuaternionObject *self) { - if (BaseMath_ReadCallback_ForWrite(self) == -1) + if (BaseMath_ReadCallback_ForWrite(self) == -1) { return NULL; + } normalize_qt(self->quat); @@ -386,8 +408,9 @@ PyDoc_STRVAR(Quaternion_invert_doc, ); static PyObject *Quaternion_invert(QuaternionObject *self) { - if (BaseMath_ReadCallback_ForWrite(self) == -1) + if (BaseMath_ReadCallback_ForWrite(self) == -1) { return NULL; + } invert_qt(self->quat); @@ -416,8 +439,9 @@ PyDoc_STRVAR(Quaternion_identity_doc, ); static PyObject *Quaternion_identity(QuaternionObject *self) { - if (BaseMath_ReadCallback_ForWrite(self) == -1) + if (BaseMath_ReadCallback_ForWrite(self) == -1) { return NULL; + } unit_qt(self->quat); @@ -434,8 +458,9 @@ PyDoc_STRVAR(Quaternion_negate_doc, ); static PyObject *Quaternion_negate(QuaternionObject *self) { - if (BaseMath_ReadCallback_ForWrite(self) == -1) + if (BaseMath_ReadCallback_ForWrite(self) == -1) { return NULL; + } mul_qt_fl(self->quat, -1.0f); @@ -450,8 +475,9 @@ PyDoc_STRVAR(Quaternion_conjugate_doc, ); static PyObject *Quaternion_conjugate(QuaternionObject *self) { - if (BaseMath_ReadCallback_ForWrite(self) == -1) + if (BaseMath_ReadCallback_ForWrite(self) == -1) { return NULL; + } conjugate_qt(self->quat); @@ -484,8 +510,9 @@ PyDoc_STRVAR(Quaternion_copy_doc, ); static PyObject *Quaternion_copy(QuaternionObject *self) { - if (BaseMath_ReadCallback(self) == -1) + if (BaseMath_ReadCallback(self) == -1) { return NULL; + } return Quaternion_CreatePyObject(self->quat, Py_TYPE(self)); } @@ -502,8 +529,9 @@ static PyObject *Quaternion_repr(QuaternionObject *self) { PyObject *ret, *tuple; - if (BaseMath_ReadCallback(self) == -1) + if (BaseMath_ReadCallback(self) == -1) { return NULL; + } tuple = Quaternion_to_tuple_ext(self, -1); @@ -518,8 +546,9 @@ static PyObject *Quaternion_str(QuaternionObject *self) { DynStr *ds; - if (BaseMath_ReadCallback(self) == -1) + if (BaseMath_ReadCallback(self) == -1) { return NULL; + } ds = BLI_dynstr_new(); @@ -539,8 +568,9 @@ static PyObject *Quaternion_richcmpr(PyObject *a, PyObject *b, int op) QuaternionObject *quatA = (QuaternionObject *)a; QuaternionObject *quatB = (QuaternionObject *)b; - if (BaseMath_ReadCallback(quatA) == -1 || BaseMath_ReadCallback(quatB) == -1) + if (BaseMath_ReadCallback(quatA) == -1 || BaseMath_ReadCallback(quatB) == -1) { return NULL; + } ok = (EXPP_VectorsAreEqual(quatA->quat, quatB->quat, QUAT_SIZE, 1)) ? 0 : -1; } @@ -569,11 +599,13 @@ static PyObject *Quaternion_richcmpr(PyObject *a, PyObject *b, int op) static Py_hash_t Quaternion_hash(QuaternionObject *self) { - if (BaseMath_ReadCallback(self) == -1) + if (BaseMath_ReadCallback(self) == -1) { return -1; + } - if (BaseMathObject_Prepare_ForHash(self) == -1) + if (BaseMathObject_Prepare_ForHash(self) == -1) { return -1; + } return mathutils_array_hash(self->quat, QUAT_SIZE); } @@ -589,7 +621,9 @@ static int Quaternion_len(QuaternionObject *UNUSED(self)) /* sequence accessor (get) */ static PyObject *Quaternion_item(QuaternionObject *self, int i) { - if (i < 0) i = QUAT_SIZE - i; + if (i < 0) { + i = QUAT_SIZE - i; + } if (i < 0 || i >= QUAT_SIZE) { PyErr_SetString(PyExc_IndexError, @@ -598,8 +632,9 @@ static PyObject *Quaternion_item(QuaternionObject *self, int i) return NULL; } - if (BaseMath_ReadIndexCallback(self, i) == -1) + if (BaseMath_ReadIndexCallback(self, i) == -1) { return NULL; + } return PyFloat_FromDouble(self->quat[i]); @@ -610,8 +645,9 @@ static int Quaternion_ass_item(QuaternionObject *self, int i, PyObject *ob) { float f; - if (BaseMath_Prepare_ForWrite(self) == -1) + if (BaseMath_Prepare_ForWrite(self) == -1) { return -1; + } f = (float)PyFloat_AsDouble(ob); @@ -622,7 +658,9 @@ static int Quaternion_ass_item(QuaternionObject *self, int i, PyObject *ob) return -1; } - if (i < 0) i = QUAT_SIZE - i; + if (i < 0) { + i = QUAT_SIZE - i; + } if (i < 0 || i >= QUAT_SIZE) { PyErr_SetString(PyExc_IndexError, @@ -632,8 +670,9 @@ static int Quaternion_ass_item(QuaternionObject *self, int i, PyObject *ob) } self->quat[i] = f; - if (BaseMath_WriteIndexCallback(self, i) == -1) + if (BaseMath_WriteIndexCallback(self, i) == -1) { return -1; + } return 0; } @@ -644,11 +683,14 @@ static PyObject *Quaternion_slice(QuaternionObject *self, int begin, int end) PyObject *tuple; int count; - if (BaseMath_ReadCallback(self) == -1) + if (BaseMath_ReadCallback(self) == -1) { return NULL; + } CLAMP(begin, 0, QUAT_SIZE); - if (end < 0) end = (QUAT_SIZE + 1) + end; + if (end < 0) { + end = (QUAT_SIZE + 1) + end; + } CLAMP(end, 0, QUAT_SIZE); begin = MIN2(begin, end); @@ -666,16 +708,20 @@ static int Quaternion_ass_slice(QuaternionObject *self, int begin, int end, PyOb int i, size; float quat[QUAT_SIZE]; - if (BaseMath_ReadCallback_ForWrite(self) == -1) + if (BaseMath_ReadCallback_ForWrite(self) == -1) { return -1; + } CLAMP(begin, 0, QUAT_SIZE); - if (end < 0) end = (QUAT_SIZE + 1) + end; + if (end < 0) { + end = (QUAT_SIZE + 1) + end; + } CLAMP(end, 0, QUAT_SIZE); begin = MIN2(begin, end); - if ((size = mathutils_array_parse(quat, 0, QUAT_SIZE, seq, "mathutils.Quaternion[begin:end] = []")) == -1) + if ((size = mathutils_array_parse(quat, 0, QUAT_SIZE, seq, "mathutils.Quaternion[begin:end] = []")) == -1) { return -1; + } if (size != (end - begin)) { PyErr_SetString(PyExc_ValueError, @@ -685,8 +731,9 @@ static int Quaternion_ass_slice(QuaternionObject *self, int begin, int end, PyOb } /* parsed well - now set in vector */ - for (i = 0; i < size; i++) + for (i = 0; i < size; i++) { self->quat[begin + i] = quat[i]; + } (void)BaseMath_WriteCallback(self); return 0; @@ -698,17 +745,20 @@ static PyObject *Quaternion_subscript(QuaternionObject *self, PyObject *item) if (PyIndex_Check(item)) { Py_ssize_t i; i = PyNumber_AsSsize_t(item, PyExc_IndexError); - if (i == -1 && PyErr_Occurred()) + if (i == -1 && PyErr_Occurred()) { return NULL; - if (i < 0) + } + if (i < 0) { i += QUAT_SIZE; + } return Quaternion_item(self, i); } else if (PySlice_Check(item)) { Py_ssize_t start, stop, step, slicelength; - if (PySlice_GetIndicesEx(item, QUAT_SIZE, &start, &stop, &step, &slicelength) < 0) + if (PySlice_GetIndicesEx(item, QUAT_SIZE, &start, &stop, &step, &slicelength) < 0) { return NULL; + } if (slicelength <= 0) { return PyTuple_New(0); @@ -735,20 +785,24 @@ static int Quaternion_ass_subscript(QuaternionObject *self, PyObject *item, PyOb { if (PyIndex_Check(item)) { Py_ssize_t i = PyNumber_AsSsize_t(item, PyExc_IndexError); - if (i == -1 && PyErr_Occurred()) + if (i == -1 && PyErr_Occurred()) { return -1; - if (i < 0) + } + if (i < 0) { i += QUAT_SIZE; + } return Quaternion_ass_item(self, i, value); } else if (PySlice_Check(item)) { Py_ssize_t start, stop, step, slicelength; - if (PySlice_GetIndicesEx(item, QUAT_SIZE, &start, &stop, &step, &slicelength) < 0) + if (PySlice_GetIndicesEx(item, QUAT_SIZE, &start, &stop, &step, &slicelength) < 0) { return -1; + } - if (step == 1) + if (step == 1) { return Quaternion_ass_slice(self, start, stop, value); + } else { PyErr_SetString(PyExc_IndexError, "slice steps not supported with quaternion"); @@ -781,8 +835,9 @@ static PyObject *Quaternion_add(PyObject *q1, PyObject *q2) quat1 = (QuaternionObject *)q1; quat2 = (QuaternionObject *)q2; - if (BaseMath_ReadCallback(quat1) == -1 || BaseMath_ReadCallback(quat2) == -1) + if (BaseMath_ReadCallback(quat1) == -1 || BaseMath_ReadCallback(quat2) == -1) { return NULL; + } add_qt_qtqt(quat, quat1->quat, quat2->quat, 1.0f); return Quaternion_CreatePyObject(quat, Py_TYPE(q1)); @@ -806,8 +861,9 @@ static PyObject *Quaternion_sub(PyObject *q1, PyObject *q2) quat1 = (QuaternionObject *)q1; quat2 = (QuaternionObject *)q2; - if (BaseMath_ReadCallback(quat1) == -1 || BaseMath_ReadCallback(quat2) == -1) + if (BaseMath_ReadCallback(quat1) == -1 || BaseMath_ReadCallback(quat2) == -1) { return NULL; + } for (x = 0; x < QUAT_SIZE; x++) { quat[x] = quat1->quat[x] - quat2->quat[x]; @@ -833,13 +889,15 @@ static PyObject *Quaternion_mul(PyObject *q1, PyObject *q2) if (QuaternionObject_Check(q1)) { quat1 = (QuaternionObject *)q1; - if (BaseMath_ReadCallback(quat1) == -1) + if (BaseMath_ReadCallback(quat1) == -1) { return NULL; + } } if (QuaternionObject_Check(q2)) { quat2 = (QuaternionObject *)q2; - if (BaseMath_ReadCallback(quat2) == -1) + if (BaseMath_ReadCallback(quat2) == -1) { return NULL; + } } if (quat1 && quat2) { /* QUAT * QUAT (element-wise product) */ @@ -876,13 +934,15 @@ static PyObject *Quaternion_imul(PyObject *q1, PyObject *q2) if (QuaternionObject_Check(q1)) { quat1 = (QuaternionObject *)q1; - if (BaseMath_ReadCallback(quat1) == -1) + if (BaseMath_ReadCallback(quat1) == -1) { return NULL; + } } if (QuaternionObject_Check(q2)) { quat2 = (QuaternionObject *)q2; - if (BaseMath_ReadCallback(quat2) == -1) + if (BaseMath_ReadCallback(quat2) == -1) { return NULL; + } } if (quat1 && quat2) { /* QUAT *= QUAT (inplace element-wise product) */ @@ -921,13 +981,15 @@ static PyObject *Quaternion_matmul(PyObject *q1, PyObject *q2) if (QuaternionObject_Check(q1)) { quat1 = (QuaternionObject *)q1; - if (BaseMath_ReadCallback(quat1) == -1) + if (BaseMath_ReadCallback(quat1) == -1) { return NULL; + } } if (QuaternionObject_Check(q2)) { quat2 = (QuaternionObject *)q2; - if (BaseMath_ReadCallback(quat2) == -1) + if (BaseMath_ReadCallback(quat2) == -1) { return NULL; + } } if (quat1 && quat2) { /* QUAT @ QUAT (cross product) */ @@ -973,13 +1035,15 @@ static PyObject *Quaternion_imatmul(PyObject *q1, PyObject *q2) if (QuaternionObject_Check(q1)) { quat1 = (QuaternionObject *)q1; - if (BaseMath_ReadCallback(quat1) == -1) + if (BaseMath_ReadCallback(quat1) == -1) { return NULL; + } } if (QuaternionObject_Check(q2)) { quat2 = (QuaternionObject *)q2; - if (BaseMath_ReadCallback(quat2) == -1) + if (BaseMath_ReadCallback(quat2) == -1) { return NULL; + } } if (quat1 && quat2) { /* QUAT @ QUAT (cross product) */ @@ -1005,8 +1069,9 @@ static PyObject *Quaternion_neg(QuaternionObject *self) { float tquat[QUAT_SIZE]; - if (BaseMath_ReadCallback(self) == -1) + if (BaseMath_ReadCallback(self) == -1) { return NULL; + } negate_v4_v4(tquat, self->quat); return Quaternion_CreatePyObject(tquat, Py_TYPE(self)); @@ -1090,8 +1155,9 @@ PyDoc_STRVAR(Quaternion_magnitude_doc, ); static PyObject *Quaternion_magnitude_get(QuaternionObject *self, void *UNUSED(closure)) { - if (BaseMath_ReadCallback(self) == -1) + if (BaseMath_ReadCallback(self) == -1) { return NULL; + } return PyFloat_FromDouble(sqrtf(dot_qtqt(self->quat, self->quat))); } @@ -1104,8 +1170,9 @@ static PyObject *Quaternion_angle_get(QuaternionObject *self, void *UNUSED(closu float tquat[4]; float angle; - if (BaseMath_ReadCallback(self) == -1) + if (BaseMath_ReadCallback(self) == -1) { return NULL; + } normalize_qt_qt(tquat, self->quat); @@ -1124,8 +1191,9 @@ static int Quaternion_angle_set(QuaternionObject *self, PyObject *value, void *U float axis[3], angle_dummy; float angle; - if (BaseMath_ReadCallback_ForWrite(self) == -1) + if (BaseMath_ReadCallback_ForWrite(self) == -1) { return -1; + } len = normalize_qt_qt(tquat, self->quat); quat_to_axis_angle(axis, &angle_dummy, tquat); @@ -1145,8 +1213,9 @@ static int Quaternion_angle_set(QuaternionObject *self, PyObject *value, void *U axis_angle_to_quat(self->quat, axis, angle); mul_qt_fl(self->quat, len); - if (BaseMath_WriteCallback(self) == -1) + if (BaseMath_WriteCallback(self) == -1) { return -1; + } return 0; } @@ -1161,8 +1230,9 @@ static PyObject *Quaternion_axis_vector_get(QuaternionObject *self, void *UNUSED float axis[3]; float angle_dummy; - if (BaseMath_ReadCallback(self) == -1) + if (BaseMath_ReadCallback(self) == -1) { return NULL; + } normalize_qt_qt(tquat, self->quat); quat_to_axis_angle(axis, &angle_dummy, tquat); @@ -1180,22 +1250,25 @@ static int Quaternion_axis_vector_set(QuaternionObject *self, PyObject *value, v float axis[3]; float angle; - if (BaseMath_ReadCallback_ForWrite(self) == -1) + if (BaseMath_ReadCallback_ForWrite(self) == -1) { return -1; + } len = normalize_qt_qt(tquat, self->quat); quat_to_axis_angle(axis, &angle, tquat); /* axis value is unused */ - if (mathutils_array_parse(axis, 3, 3, value, "quat.axis = other") == -1) + if (mathutils_array_parse(axis, 3, 3, value, "quat.axis = other") == -1) { return -1; + } quat__axis_angle_sanitize(axis, &angle); axis_angle_to_quat(self->quat, axis, angle); mul_qt_fl(self->quat, len); - if (BaseMath_WriteCallback(self) == -1) + if (BaseMath_WriteCallback(self) == -1) { return -1; + } return 0; } @@ -1215,8 +1288,9 @@ static PyObject *Quaternion_new(PyTypeObject *type, PyObject *args, PyObject *kw return NULL; } - if (!PyArg_ParseTuple(args, "|Od:mathutils.Quaternion", &seq, &angle)) + if (!PyArg_ParseTuple(args, "|Od:mathutils.Quaternion", &seq, &angle)) { return NULL; + } switch (PyTuple_GET_SIZE(args)) { case 0: @@ -1243,8 +1317,9 @@ static PyObject *Quaternion_new(PyTypeObject *type, PyObject *args, PyObject *kw case 2: { float axis[3]; - if (mathutils_array_parse(axis, 3, 3, seq, "mathutils.Quaternion()") == -1) + if (mathutils_array_parse(axis, 3, 3, seq, "mathutils.Quaternion()") == -1) { return NULL; + } angle = angle_wrap_rad(angle); /* clamp because of precision issues */ axis_angle_to_quat(quat, axis, angle); break; diff --git a/source/blender/python/mathutils/mathutils_Vector.c b/source/blender/python/mathutils/mathutils_Vector.c index 11b8eff85f6..1dd578096f9 100644 --- a/source/blender/python/mathutils/mathutils_Vector.c +++ b/source/blender/python/mathutils/mathutils_Vector.c @@ -197,8 +197,9 @@ static PyObject *C_Vector_Range(PyObject *cls, PyObject *args) size = (stop - start); - if ((size % step) != 0) + if ((size % step) != 0) { size += step; + } size /= step; @@ -338,13 +339,15 @@ PyDoc_STRVAR(Vector_zero_doc, ); static PyObject *Vector_zero(VectorObject *self) { - if (BaseMath_Prepare_ForWrite(self) == -1) + if (BaseMath_Prepare_ForWrite(self) == -1) { return NULL; + } copy_vn_fl(self->vec, self->size, 0.0f); - if (BaseMath_WriteCallback(self) == -1) + if (BaseMath_WriteCallback(self) == -1) { return NULL; + } Py_RETURN_NONE; } @@ -362,8 +365,9 @@ PyDoc_STRVAR(Vector_normalize_doc, static PyObject *Vector_normalize(VectorObject *self) { int size = (self->size == 4 ? 3 : self->size); - if (BaseMath_ReadCallback_ForWrite(self) == -1) + if (BaseMath_ReadCallback_ForWrite(self) == -1) { return NULL; + } normalize_vn(self->vec, size); @@ -533,8 +537,9 @@ static PyObject *Vector_resize_3d(VectorObject *self) return NULL; } - if (self->size == 2) + if (self->size == 2) { self->vec[2] = 0.0f; + } self->size = 3; Py_RETURN_NONE; @@ -588,8 +593,9 @@ PyDoc_STRVAR(Vector_to_2d_doc, ); static PyObject *Vector_to_2d(VectorObject *self) { - if (BaseMath_ReadCallback(self) == -1) + if (BaseMath_ReadCallback(self) == -1) { return NULL; + } return Vector_CreatePyObject(self->vec, 2, Py_TYPE(self)); } @@ -605,8 +611,9 @@ static PyObject *Vector_to_3d(VectorObject *self) { float tvec[3] = {0.0f}; - if (BaseMath_ReadCallback(self) == -1) + if (BaseMath_ReadCallback(self) == -1) { return NULL; + } memcpy(tvec, self->vec, sizeof(float) * MIN2(self->size, 3)); return Vector_CreatePyObject(tvec, 3, Py_TYPE(self)); @@ -623,8 +630,9 @@ static PyObject *Vector_to_4d(VectorObject *self) { float tvec[4] = {0.0f, 0.0f, 0.0f, 1.0f}; - if (BaseMath_ReadCallback(self) == -1) + if (BaseMath_ReadCallback(self) == -1) { return NULL; + } memcpy(tvec, self->vec, sizeof(float) * MIN2(self->size, 4)); return Vector_CreatePyObject(tvec, 4, Py_TYPE(self)); @@ -666,8 +674,9 @@ static PyObject *Vector_to_tuple(VectorObject *self, PyObject *args) { int ndigits = 0; - if (!PyArg_ParseTuple(args, "|i:to_tuple", &ndigits)) + if (!PyArg_ParseTuple(args, "|i:to_tuple", &ndigits)) { return NULL; + } if (ndigits > 22 || ndigits < 0) { PyErr_SetString(PyExc_ValueError, @@ -676,11 +685,13 @@ static PyObject *Vector_to_tuple(VectorObject *self, PyObject *args) return NULL; } - if (PyTuple_GET_SIZE(args) == 0) + if (PyTuple_GET_SIZE(args) == 0) { ndigits = -1; + } - if (BaseMath_ReadCallback(self) == -1) + if (BaseMath_ReadCallback(self) == -1) { return NULL; + } return Vector_to_tuple_ext(self, ndigits); } @@ -703,8 +714,9 @@ static PyObject *Vector_to_track_quat(VectorObject *self, PyObject *args) const char *strack, *sup; short track = 2, up = 1; - if (!PyArg_ParseTuple(args, "|ss:to_track_quat", &strack, &sup)) + if (!PyArg_ParseTuple(args, "|ss:to_track_quat", &strack, &sup)) { return NULL; + } if (self->size != 3) { PyErr_SetString(PyExc_TypeError, @@ -713,8 +725,9 @@ static PyObject *Vector_to_track_quat(VectorObject *self, PyObject *args) return NULL; } - if (BaseMath_ReadCallback(self) == -1) + if (BaseMath_ReadCallback(self) == -1) { return NULL; + } if (strack) { const char *axis_err_msg = "only X, -X, Y, -Y, Z or -Z for track axis"; @@ -826,13 +839,16 @@ static PyObject *Vector_orthogonal(VectorObject *self) return NULL; } - if (BaseMath_ReadCallback(self) == -1) + if (BaseMath_ReadCallback(self) == -1) { return NULL; + } - if (self->size == 3) + if (self->size == 3) { ortho_v3_v3(vec, self->vec); - else + } + else { ortho_v2_v2(vec, self->vec); + } return Vector_CreatePyObject(vec, self->size, Py_TYPE(self)); } @@ -861,11 +877,13 @@ static PyObject *Vector_reflect(VectorObject *self, PyObject *value) float reflect[3] = {0.0f}; float tvec[MAX_DIMENSIONS]; - if (BaseMath_ReadCallback(self) == -1) + if (BaseMath_ReadCallback(self) == -1) { return NULL; + } - if ((value_size = mathutils_array_parse(tvec, 2, 4, value, "Vector.reflect(other), invalid 'other' arg")) == -1) + if ((value_size = mathutils_array_parse(tvec, 2, 4, value, "Vector.reflect(other), invalid 'other' arg")) == -1) { return NULL; + } if (self->size < 2 || self->size > 4) { PyErr_SetString(PyExc_ValueError, @@ -904,8 +922,9 @@ static PyObject *Vector_cross(VectorObject *self, PyObject *value) PyObject *ret; float tvec[3]; - if (BaseMath_ReadCallback(self) == -1) + if (BaseMath_ReadCallback(self) == -1) { return NULL; + } if (self->size > 3) { PyErr_SetString(PyExc_ValueError, @@ -913,8 +932,9 @@ static PyObject *Vector_cross(VectorObject *self, PyObject *value) return NULL; } - if (mathutils_array_parse(tvec, self->size, self->size, value, "Vector.cross(other), invalid 'other' arg") == -1) + if (mathutils_array_parse(tvec, self->size, self->size, value, "Vector.cross(other), invalid 'other' arg") == -1) { return NULL; + } if (self->size == 3) { ret = Vector_CreatePyObject(NULL, 3, Py_TYPE(self)); @@ -942,8 +962,9 @@ static PyObject *Vector_dot(VectorObject *self, PyObject *value) float *tvec; PyObject *ret; - if (BaseMath_ReadCallback(self) == -1) + if (BaseMath_ReadCallback(self) == -1) { return NULL; + } if (mathutils_array_parse_alloc(&tvec, self->size, value, "Vector.dot(other), invalid 'other' arg") == -1) { return NULL; @@ -976,16 +997,19 @@ static PyObject *Vector_angle(VectorObject *self, PyObject *args) int x; PyObject *fallback = NULL; - if (!PyArg_ParseTuple(args, "O|O:angle", &value, &fallback)) + if (!PyArg_ParseTuple(args, "O|O:angle", &value, &fallback)) { return NULL; + } - if (BaseMath_ReadCallback(self) == -1) + if (BaseMath_ReadCallback(self) == -1) { return NULL; + } /* 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) + if (mathutils_array_parse(tvec, self->size, self->size, value, "Vector.angle(other), invalid 'other' arg") == -1) { return NULL; + } if (self->size > 4) { PyErr_SetString(PyExc_ValueError, @@ -1036,14 +1060,17 @@ static PyObject *Vector_angle_signed(VectorObject *self, PyObject *args) PyObject *value; PyObject *fallback = NULL; - if (!PyArg_ParseTuple(args, "O|O:angle_signed", &value, &fallback)) + if (!PyArg_ParseTuple(args, "O|O:angle_signed", &value, &fallback)) { return NULL; + } - if (BaseMath_ReadCallback(self) == -1) + if (BaseMath_ReadCallback(self) == -1) { return NULL; + } - if (mathutils_array_parse(tvec, 2, 2, value, "Vector.angle_signed(other), invalid 'other' arg") == -1) + if (mathutils_array_parse(tvec, 2, 2, value, "Vector.angle_signed(other), invalid 'other' arg") == -1) { return NULL; + } if (self->size != 2) { PyErr_SetString(PyExc_ValueError, @@ -1094,11 +1121,13 @@ static PyObject *Vector_rotation_difference(VectorObject *self, PyObject *value) return NULL; } - if (BaseMath_ReadCallback(self) == -1) + if (BaseMath_ReadCallback(self) == -1) { return NULL; + } - if (mathutils_array_parse(vec_b, 3, MAX_DIMENSIONS, value, "Vector.difference(other), invalid 'other' arg") == -1) + if (mathutils_array_parse(vec_b, 3, MAX_DIMENSIONS, value, "Vector.difference(other), invalid 'other' arg") == -1) { return NULL; + } normalize_v3_v3(vec_a, self->vec); normalize_v3(vec_b); @@ -1125,8 +1154,9 @@ static PyObject *Vector_project(VectorObject *self, PyObject *value) double dot = 0.0f, dot2 = 0.0f; int x; - if (BaseMath_ReadCallback(self) == -1) + if (BaseMath_ReadCallback(self) == -1) { return NULL; + } if (mathutils_array_parse_alloc(&tvec, size, value, "Vector.project(other), invalid 'other' arg") == -1) { return NULL; @@ -1164,8 +1194,9 @@ static PyObject *Vector_lerp(VectorObject *self, PyObject *args) float fac; float *tvec; - if (!PyArg_ParseTuple(args, "Of:lerp", &value, &fac)) + if (!PyArg_ParseTuple(args, "Of:lerp", &value, &fac)) { return NULL; + } if (BaseMath_ReadCallback(self) == -1) { return NULL; @@ -1205,8 +1236,9 @@ static PyObject *Vector_slerp(VectorObject *self, PyObject *args) int x; PyObject *fallback = NULL; - if (!PyArg_ParseTuple(args, "Of|O:slerp", &value, &fac, &fallback)) + if (!PyArg_ParseTuple(args, "Of|O:slerp", &value, &fac, &fallback)) { return NULL; + } if (BaseMath_ReadCallback(self) == -1) { return NULL; @@ -1281,11 +1313,13 @@ static PyObject *Vector_rotate(VectorObject *self, PyObject *value) { float other_rmat[3][3]; - if (BaseMath_ReadCallback_ForWrite(self) == -1) + if (BaseMath_ReadCallback_ForWrite(self) == -1) { return NULL; + } - if (mathutils_any_to_rotmat(other_rmat, value, "Vector.rotate(value)") == -1) + if (mathutils_any_to_rotmat(other_rmat, value, "Vector.rotate(value)") == -1) { return NULL; + } if (self->size < 3 || self->size > 4) { PyErr_SetString(PyExc_ValueError, @@ -1312,8 +1346,9 @@ PyDoc_STRVAR(Vector_copy_doc, ); static PyObject *Vector_copy(VectorObject *self) { - if (BaseMath_ReadCallback(self) == -1) + if (BaseMath_ReadCallback(self) == -1) { return NULL; + } return Vector_CreatePyObject(self->vec, self->size, Py_TYPE(self)); } @@ -1329,8 +1364,9 @@ static PyObject *Vector_repr(VectorObject *self) { PyObject *ret, *tuple; - if (BaseMath_ReadCallback(self) == -1) + if (BaseMath_ReadCallback(self) == -1) { return NULL; + } tuple = Vector_to_tuple_ext(self, -1); ret = PyUnicode_FromFormat("Vector(%R)", tuple); @@ -1345,8 +1381,9 @@ static PyObject *Vector_str(VectorObject *self) DynStr *ds; - if (BaseMath_ReadCallback(self) == -1) + if (BaseMath_ReadCallback(self) == -1) { return NULL; + } ds = BLI_dynstr_new(); @@ -1371,7 +1408,9 @@ static int Vector_len(VectorObject *self) /* 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; + if (i < 0) { + i = self->size - i; + } if (i < 0 || i >= self->size) { if (is_attr) { @@ -1386,8 +1425,9 @@ static PyObject *vector_item_internal(VectorObject *self, int i, const bool is_a return NULL; } - if (BaseMath_ReadIndexCallback(self, i) == -1) + if (BaseMath_ReadIndexCallback(self, i) == -1) { return NULL; + } return PyFloat_FromDouble(self->vec[i]); } @@ -1401,8 +1441,9 @@ static int vector_ass_item_internal(VectorObject *self, int i, PyObject *value, { float scalar; - if (BaseMath_Prepare_ForWrite(self) == -1) + if (BaseMath_Prepare_ForWrite(self) == -1) { return -1; + } if ((scalar = PyFloat_AsDouble(value)) == -1.0f && PyErr_Occurred()) { /* parsed item not a number */ PyErr_SetString(PyExc_TypeError, @@ -1411,7 +1452,9 @@ static int vector_ass_item_internal(VectorObject *self, int i, PyObject *value, return -1; } - if (i < 0) i = self->size - i; + if (i < 0) { + i = self->size - i; + } if (i < 0 || i >= self->size) { if (is_attr) { @@ -1428,8 +1471,9 @@ static int vector_ass_item_internal(VectorObject *self, int i, PyObject *value, } self->vec[i] = scalar; - if (BaseMath_WriteIndexCallback(self, i) == -1) + if (BaseMath_WriteIndexCallback(self, i) == -1) { return -1; + } return 0; } @@ -1444,11 +1488,14 @@ static PyObject *Vector_slice(VectorObject *self, int begin, int end) PyObject *tuple; int count; - if (BaseMath_ReadCallback(self) == -1) + if (BaseMath_ReadCallback(self) == -1) { return NULL; + } CLAMP(begin, 0, self->size); - if (end < 0) end = self->size + end + 1; + if (end < 0) { + end = self->size + end + 1; + } CLAMP(end, 0, self->size); begin = MIN2(begin, end); @@ -1465,8 +1512,9 @@ static int Vector_ass_slice(VectorObject *self, int begin, int end, PyObject *se int size = 0; float *vec = NULL; - if (BaseMath_ReadCallback_ForWrite(self) == -1) + if (BaseMath_ReadCallback_ForWrite(self) == -1) { return -1; + } CLAMP(begin, 0, self->size); CLAMP(end, 0, self->size); @@ -1489,8 +1537,9 @@ static int Vector_ass_slice(VectorObject *self, int begin, int end, PyObject *se PyMem_Free(vec); - if (BaseMath_WriteCallback(self) == -1) + if (BaseMath_WriteCallback(self) == -1) { return -1; + } return 0; } @@ -1512,8 +1561,9 @@ static PyObject *Vector_add(PyObject *v1, PyObject *v2) vec1 = (VectorObject *)v1; vec2 = (VectorObject *)v2; - if (BaseMath_ReadCallback(vec1) == -1 || BaseMath_ReadCallback(vec2) == -1) + if (BaseMath_ReadCallback(vec1) == -1 || BaseMath_ReadCallback(vec2) == -1) { return NULL; + } /*VECTOR + VECTOR*/ if (vec1->size != vec2->size) { @@ -1558,8 +1608,9 @@ static PyObject *Vector_iadd(PyObject *v1, PyObject *v2) return NULL; } - if (BaseMath_ReadCallback_ForWrite(vec1) == -1 || BaseMath_ReadCallback(vec2) == -1) + if (BaseMath_ReadCallback_ForWrite(vec1) == -1 || BaseMath_ReadCallback(vec2) == -1) { return NULL; + } add_vn_vn(vec1->vec, vec2->vec, vec1->size); @@ -1584,8 +1635,9 @@ static PyObject *Vector_sub(PyObject *v1, PyObject *v2) vec1 = (VectorObject *)v1; vec2 = (VectorObject *)v2; - if (BaseMath_ReadCallback(vec1) == -1 || BaseMath_ReadCallback(vec2) == -1) + if (BaseMath_ReadCallback(vec1) == -1 || BaseMath_ReadCallback(vec2) == -1) { return NULL; + } if (vec1->size != vec2->size) { PyErr_SetString(PyExc_AttributeError, @@ -1629,8 +1681,9 @@ static PyObject *Vector_isub(PyObject *v1, PyObject *v2) return NULL; } - if (BaseMath_ReadCallback_ForWrite(vec1) == -1 || BaseMath_ReadCallback(vec2) == -1) + if (BaseMath_ReadCallback_ForWrite(vec1) == -1 || BaseMath_ReadCallback(vec2) == -1) { return NULL; + } sub_vn_vn(vec1->vec, vec2->vec, vec1->size); @@ -1722,13 +1775,15 @@ static PyObject *Vector_mul(PyObject *v1, PyObject *v2) if (VectorObject_Check(v1)) { vec1 = (VectorObject *)v1; - if (BaseMath_ReadCallback(vec1) == -1) + if (BaseMath_ReadCallback(vec1) == -1) { return NULL; + } } if (VectorObject_Check(v2)) { vec2 = (VectorObject *)v2; - if (BaseMath_ReadCallback(vec2) == -1) + if (BaseMath_ReadCallback(vec2) == -1) { return NULL; + } } @@ -1774,17 +1829,20 @@ static PyObject *Vector_imul(PyObject *v1, PyObject *v2) if (VectorObject_Check(v1)) { vec1 = (VectorObject *)v1; - if (BaseMath_ReadCallback(vec1) == -1) + if (BaseMath_ReadCallback(vec1) == -1) { return NULL; + } } if (VectorObject_Check(v2)) { vec2 = (VectorObject *)v2; - if (BaseMath_ReadCallback(vec2) == -1) + if (BaseMath_ReadCallback(vec2) == -1) { return NULL; + } } - if (BaseMath_ReadCallback_ForWrite(vec1) == -1) + if (BaseMath_ReadCallback_ForWrite(vec1) == -1) { return NULL; + } /* Intentionally don't support (Quaternion, Matrix) here, uses reverse order instead. */ @@ -1830,13 +1888,15 @@ static PyObject *Vector_matmul(PyObject *v1, PyObject *v2) if (VectorObject_Check(v1)) { vec1 = (VectorObject *)v1; - if (BaseMath_ReadCallback(vec1) == -1) + if (BaseMath_ReadCallback(vec1) == -1) { return NULL; + } } if (VectorObject_Check(v2)) { vec2 = (VectorObject *)v2; - if (BaseMath_ReadCallback(vec2) == -1) + if (BaseMath_ReadCallback(vec2) == -1) { return NULL; + } } @@ -1859,8 +1919,9 @@ static PyObject *Vector_matmul(PyObject *v1, PyObject *v2) /* VEC @ MATRIX */ float tvec[MAX_DIMENSIONS]; - if (BaseMath_ReadCallback((MatrixObject *)v2) == -1) + if (BaseMath_ReadCallback((MatrixObject *)v2) == -1) { return NULL; + } if (row_vector_multiplication(tvec, vec1, (MatrixObject *)v2) == -1) { return NULL; } @@ -1906,8 +1967,9 @@ static PyObject *Vector_div(PyObject *v1, PyObject *v2) } vec1 = (VectorObject *)v1; /* vector */ - if (BaseMath_ReadCallback(vec1) == -1) + if (BaseMath_ReadCallback(vec1) == -1) { return NULL; + } if ((scalar = PyFloat_AsDouble(v2)) == -1.0f && PyErr_Occurred()) { /* parsed item not a number */ PyErr_SetString(PyExc_TypeError, @@ -1943,8 +2005,9 @@ static PyObject *Vector_idiv(PyObject *v1, PyObject *v2) float scalar; VectorObject *vec1 = (VectorObject *)v1; - if (BaseMath_ReadCallback_ForWrite(vec1) == -1) + if (BaseMath_ReadCallback_ForWrite(vec1) == -1) { return NULL; + } if ((scalar = PyFloat_AsDouble(v2)) == -1.0f && PyErr_Occurred()) { /* parsed item not a number */ PyErr_SetString(PyExc_TypeError, @@ -1974,8 +2037,9 @@ static PyObject *Vector_neg(VectorObject *self) { float *tvec; - if (BaseMath_ReadCallback(self) == -1) + if (BaseMath_ReadCallback(self) == -1) { return NULL; + } tvec = PyMem_Malloc(self->size * sizeof(float)); negate_vn_vn(tvec, self->vec, self->size); @@ -2002,8 +2066,9 @@ static PyObject *Vector_richcmpr(PyObject *objectA, PyObject *objectB, int compa vecA = (VectorObject *)objectA; vecB = (VectorObject *)objectB; - if (BaseMath_ReadCallback(vecA) == -1 || BaseMath_ReadCallback(vecB) == -1) + if (BaseMath_ReadCallback(vecA) == -1 || BaseMath_ReadCallback(vecB) == -1) { return NULL; + } if (vecA->size != vecB->size) { if (comparison_type == Py_NE) { @@ -2069,11 +2134,13 @@ static PyObject *Vector_richcmpr(PyObject *objectA, PyObject *objectB, int compa static Py_hash_t Vector_hash(VectorObject *self) { - if (BaseMath_ReadCallback(self) == -1) + if (BaseMath_ReadCallback(self) == -1) { return -1; + } - if (BaseMathObject_Prepare_ForHash(self) == -1) + if (BaseMathObject_Prepare_ForHash(self) == -1) { return -1; + } return mathutils_array_hash(self->vec, self->size); } @@ -2097,17 +2164,20 @@ static PyObject *Vector_subscript(VectorObject *self, PyObject *item) if (PyIndex_Check(item)) { Py_ssize_t i; i = PyNumber_AsSsize_t(item, PyExc_IndexError); - if (i == -1 && PyErr_Occurred()) + if (i == -1 && PyErr_Occurred()) { return NULL; - if (i < 0) + } + if (i < 0) { i += self->size; + } return Vector_item(self, i); } else 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->size, &start, &stop, &step, &slicelength) < 0) { return NULL; + } if (slicelength <= 0) { return PyTuple_New(0); @@ -2133,20 +2203,24 @@ static int Vector_ass_subscript(VectorObject *self, PyObject *item, PyObject *va { if (PyIndex_Check(item)) { Py_ssize_t i = PyNumber_AsSsize_t(item, PyExc_IndexError); - if (i == -1 && PyErr_Occurred()) + if (i == -1 && PyErr_Occurred()) { return -1; - if (i < 0) + } + if (i < 0) { i += self->size; + } return Vector_ass_item(self, i, value); } else 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->size, &start, &stop, &step, &slicelength) < 0) { return -1; + } - if (step == 1) + if (step == 1) { return Vector_ass_slice(self, start, stop, value); + } else { PyErr_SetString(PyExc_IndexError, "slice steps not supported with vectors"); @@ -2233,8 +2307,9 @@ PyDoc_STRVAR(Vector_length_doc, ); static PyObject *Vector_length_get(VectorObject *self, void *UNUSED(closure)) { - if (BaseMath_ReadCallback(self) == -1) + if (BaseMath_ReadCallback(self) == -1) { return NULL; + } return PyFloat_FromDouble(sqrt(dot_vn_vn(self->vec, self->vec, self->size))); } @@ -2243,8 +2318,9 @@ static int Vector_length_set(VectorObject *self, PyObject *value) { double dot = 0.0f, param; - if (BaseMath_ReadCallback_ForWrite(self) == -1) + if (BaseMath_ReadCallback_ForWrite(self) == -1) { return -1; + } if ((param = PyFloat_AsDouble(value)) == -1.0 && PyErr_Occurred()) { PyErr_SetString(PyExc_TypeError, @@ -2264,13 +2340,16 @@ static int Vector_length_set(VectorObject *self, PyObject *value) dot = dot_vn_vn(self->vec, self->vec, self->size); - if (!dot) /* cant sqrt zero */ + if (!dot) { + /* cant sqrt zero */ return 0; + } dot = sqrt(dot); - if (dot == param) + if (dot == param) { return 0; + } dot = dot / param; @@ -2287,8 +2366,9 @@ PyDoc_STRVAR(Vector_length_squared_doc, ); static PyObject *Vector_length_squared_get(VectorObject *self, void *UNUSED(closure)) { - if (BaseMath_ReadCallback(self) == -1) + if (BaseMath_ReadCallback(self) == -1) { return NULL; + } return PyFloat_FromDouble(dot_vn_vn(self->vec, self->vec, self->size)); } @@ -2359,8 +2439,9 @@ static PyObject *Vector_swizzle_get(VectorObject *self, void *closure) float vec[MAX_DIMENSIONS]; unsigned int swizzleClosure; - if (BaseMath_ReadCallback(self) == -1) + if (BaseMath_ReadCallback(self) == -1) { return NULL; + } /* Unpack the axes from the closure into an array. */ axis_to = 0; @@ -2406,8 +2487,9 @@ static int Vector_swizzle_set(VectorObject *self, PyObject *value, void *closure float tvec[MAX_DIMENSIONS]; float vec_assign[MAX_DIMENSIONS]; - if (BaseMath_ReadCallback_ForWrite(self) == -1) + if (BaseMath_ReadCallback_ForWrite(self) == -1) { return -1; + } /* Check that the closure can be used with this vector: even 2D vectors have * swizzles defined for axes z and w, but they would be invalid. */ @@ -2469,10 +2551,12 @@ static int Vector_swizzle_set(VectorObject *self, PyObject *value, void *closure memcpy(self->vec, tvec, self->size * sizeof(float)); /* continue with BaseMathObject_WriteCallback at the end */ - if (BaseMath_WriteCallback(self) == -1) + if (BaseMath_WriteCallback(self) == -1) { return -1; - else + } + else { return 0; + } } #define _SWIZZLE1(a) ((a) | SWIZZLE_VALID_AXIS) @@ -2876,8 +2960,9 @@ static int row_vector_multiplication(float r_vec[MAX_DIMENSIONS], VectorObject * } } - if (BaseMath_ReadCallback(vec) == -1 || BaseMath_ReadCallback(mat) == -1) + if (BaseMath_ReadCallback(vec) == -1 || BaseMath_ReadCallback(mat) == -1) { return -1; + } memcpy(vec_cpy, vec->vec, vec_size * sizeof(float)); @@ -2901,8 +2986,9 @@ PyDoc_STRVAR(Vector_negate_doc, ); static PyObject *Vector_negate(VectorObject *self) { - if (BaseMath_ReadCallback(self) == -1) + if (BaseMath_ReadCallback(self) == -1) { return NULL; + } negate_vn(self->vec, self->size); diff --git a/source/blender/python/mathutils/mathutils_bvhtree.c b/source/blender/python/mathutils/mathutils_bvhtree.c index 4ed4b0e3abb..b99b39ac998 100644 --- a/source/blender/python/mathutils/mathutils_bvhtree.c +++ b/source/blender/python/mathutils/mathutils_bvhtree.c @@ -924,10 +924,12 @@ static PyObject *C_BVHTree_FromPolygons(PyObject *UNUSED(cls), PyObject *args, P orig_index, orig_normal); } else { - if (coords) + if (coords) { MEM_freeN(coords); - if (tris) + } + if (tris) { MEM_freeN(tris); + } return NULL; } diff --git a/source/blender/python/mathutils/mathutils_geometry.c b/source/blender/python/mathutils/mathutils_geometry.c index 6106b01fd41..05ec57a004a 100644 --- a/source/blender/python/mathutils/mathutils_geometry.c +++ b/source/blender/python/mathutils/mathutils_geometry.c @@ -621,12 +621,12 @@ static PyObject *M_Geometry_intersect_line_sphere(PyObject *UNUSED(self), PyObje switch (isect_line_sphere_v3(line_a, line_b, sphere_co, sphere_radius, isect_a, isect_b)) { case 1: - if (!(!clip || (((lambda = line_point_factor_v3(isect_a, line_a, line_b)) >= 0.0f) && (lambda <= 1.0f)))) use_a = false; + if (!(!clip || (((lambda = line_point_factor_v3(isect_a, line_a, line_b)) >= 0.0f) && (lambda <= 1.0f)))) { use_a = false; } use_b = false; break; case 2: - if (!(!clip || (((lambda = line_point_factor_v3(isect_a, line_a, line_b)) >= 0.0f) && (lambda <= 1.0f)))) use_a = false; - if (!(!clip || (((lambda = line_point_factor_v3(isect_b, line_a, line_b)) >= 0.0f) && (lambda <= 1.0f)))) use_b = false; + if (!(!clip || (((lambda = line_point_factor_v3(isect_a, line_a, line_b)) >= 0.0f) && (lambda <= 1.0f)))) { use_a = false; } + if (!(!clip || (((lambda = line_point_factor_v3(isect_b, line_a, line_b)) >= 0.0f) && (lambda <= 1.0f)))) { use_b = false; } break; default: use_a = false; @@ -694,12 +694,12 @@ static PyObject *M_Geometry_intersect_line_sphere_2d(PyObject *UNUSED(self), PyO switch (isect_line_sphere_v2(line_a, line_b, sphere_co, sphere_radius, isect_a, isect_b)) { case 1: - if (!(!clip || (((lambda = line_point_factor_v2(isect_a, line_a, line_b)) >= 0.0f) && (lambda <= 1.0f)))) use_a = false; + if (!(!clip || (((lambda = line_point_factor_v2(isect_a, line_a, line_b)) >= 0.0f) && (lambda <= 1.0f)))) { use_a = false; } use_b = false; break; case 2: - if (!(!clip || (((lambda = line_point_factor_v2(isect_a, line_a, line_b)) >= 0.0f) && (lambda <= 1.0f)))) use_a = false; - if (!(!clip || (((lambda = line_point_factor_v2(isect_b, line_a, line_b)) >= 0.0f) && (lambda <= 1.0f)))) use_b = false; + if (!(!clip || (((lambda = line_point_factor_v2(isect_a, line_a, line_b)) >= 0.0f) && (lambda <= 1.0f)))) { use_a = false; } + if (!(!clip || (((lambda = line_point_factor_v2(isect_b, line_a, line_b)) >= 0.0f) && (lambda <= 1.0f)))) { use_b = false; } break; default: use_a = false; @@ -1225,15 +1225,19 @@ static PyObject *M_Geometry_tessellate_polygon(PyObject *UNUSED(self), PyObject polyVec = PySequence_GetItem(polyLine, index); if (VectorObject_Check(polyVec)) { - if (BaseMath_ReadCallback((VectorObject *)polyVec) == -1) + if (BaseMath_ReadCallback((VectorObject *)polyVec) == -1) { ls_error = 1; + } fp[0] = ((VectorObject *)polyVec)->vec[0]; fp[1] = ((VectorObject *)polyVec)->vec[1]; - if (((VectorObject *)polyVec)->size > 2) + if (((VectorObject *)polyVec)->size > 2) { fp[2] = ((VectorObject *)polyVec)->vec[2]; - else - fp[2] = 0.0f; /* if its a 2d vector then set the z to be zero */ + } + else { + /* if its a 2d vector then set the z to be zero */ + fp[2] = 0.0f; + } } else { ls_error = 1; diff --git a/source/blender/python/mathutils/mathutils_interpolate.c b/source/blender/python/mathutils/mathutils_interpolate.c index da2ed0ced7e..792f8b1f065 100644 --- a/source/blender/python/mathutils/mathutils_interpolate.c +++ b/source/blender/python/mathutils/mathutils_interpolate.c @@ -66,15 +66,19 @@ static PyObject *M_Interpolate_poly_3d_calc(PyObject *UNUSED(self), PyObject *ar return NULL; } - if (BaseMath_ReadCallback((VectorObject *)point) == -1) + if (BaseMath_ReadCallback((VectorObject *)point) == -1) { return NULL; + } fp[0] = ((VectorObject *)point)->vec[0]; fp[1] = ((VectorObject *)point)->vec[1]; - if (((VectorObject *)point)->size > 2) + if (((VectorObject *)point)->size > 2) { fp[2] = ((VectorObject *)point)->vec[2]; - else - fp[2] = 0.0f; /* if its a 2d vector then set the z to be zero */ + } + else { + /* if its a 2d vector then set the z to be zero */ + fp[2] = 0.0f; + } len = mathutils_array_parse_alloc_v(((float **)&vecs), 3, veclist, __func__); if (len == -1) { diff --git a/source/blender/python/mathutils/mathutils_kdtree.c b/source/blender/python/mathutils/mathutils_kdtree.c index f9cc99551bb..7228ac41bd6 100644 --- a/source/blender/python/mathutils/mathutils_kdtree.c +++ b/source/blender/python/mathutils/mathutils_kdtree.c @@ -148,8 +148,9 @@ static PyObject *py_kdtree_insert(PyKDTree *self, PyObject *args, PyObject *kwar return NULL; } - if (mathutils_array_parse(co, 3, 3, py_co, "insert: invalid 'co' arg") == -1) + if (mathutils_array_parse(co, 3, 3, py_co, "insert: invalid 'co' arg") == -1) { return NULL; + } if (index < 0) { PyErr_SetString(PyExc_ValueError, "negative index given"); @@ -238,8 +239,9 @@ static PyObject *py_kdtree_find(PyKDTree *self, PyObject *args, PyObject *kwargs return NULL; } - if (mathutils_array_parse(co, 3, 3, py_co, "find: invalid 'co' arg") == -1) + if (mathutils_array_parse(co, 3, 3, py_co, "find: invalid 'co' arg") == -1) { return NULL; + } if (self->count != self->count_balance) { PyErr_SetString(PyExc_RuntimeError, "KDTree must be balanced before calling find()"); @@ -299,8 +301,9 @@ static PyObject *py_kdtree_find_n(PyKDTree *self, PyObject *args, PyObject *kwar return NULL; } - if (mathutils_array_parse(co, 3, 3, py_co, "find_n: invalid 'co' arg") == -1) + if (mathutils_array_parse(co, 3, 3, py_co, "find_n: invalid 'co' arg") == -1) { return NULL; + } if (UINT_IS_NEG(n)) { PyErr_SetString(PyExc_RuntimeError, "negative 'n' given"); @@ -357,8 +360,9 @@ static PyObject *py_kdtree_find_range(PyKDTree *self, PyObject *args, PyObject * return NULL; } - if (mathutils_array_parse(co, 3, 3, py_co, "find_range: invalid 'co' arg") == -1) + if (mathutils_array_parse(co, 3, 3, py_co, "find_range: invalid 'co' arg") == -1) { return NULL; + } if (radius < 0.0f) { PyErr_SetString(PyExc_RuntimeError, "negative radius given"); diff --git a/source/blender/python/mathutils/mathutils_noise.c b/source/blender/python/mathutils/mathutils_noise.c index 364690c43eb..04cadb9b592 100644 --- a/source/blender/python/mathutils/mathutils_noise.c +++ b/source/blender/python/mathutils/mathutils_noise.c @@ -136,17 +136,20 @@ static void next_state(void) /* if init_genrand() has not been called, */ /* a default initial seed is used */ - if (initf == 0) + if (initf == 0) { init_genrand(5489UL); + } left = N; next = state; - for (j = N - M + 1; --j; p++) + for (j = N - M + 1; --j; p++) { *p = p[M] ^ TWIST(p[0], p[1]); + } - for (j = M; --j; p++) + for (j = M; --j; p++) { *p = p[M - N] ^ TWIST(p[0], p[1]); + } *p = p[M - N] ^ TWIST(p[0], state[0]); } @@ -155,10 +158,12 @@ static void next_state(void) static void setRndSeed(int seed) { - if (seed == 0) + if (seed == 0) { init_genrand(time(NULL)); - else + } + else { init_genrand(seed); + } } /* float number in range [0, 1) using the mersenne twister rng */ @@ -166,8 +171,9 @@ static float frand(void) { unsigned long y; - if (--left == 0) + if (--left == 0) { next_state(); + } y = *next++; /* Tempering */ @@ -253,16 +259,18 @@ static float turb( int i; amp = 1.f; out = (float)(2.0f * BLI_gNoise(1.f, x, y, z, 0, nb) - 1.0f); - if (hard) + if (hard) { out = fabsf(out); + } for (i = 1; i < oct; i++) { amp *= ampscale; x *= freqscale; y *= freqscale; z *= freqscale; t = (float)(amp * (2.0f * BLI_gNoise(1.f, x, y, z, 0, nb) - 1.0f)); - if (hard) + if (hard) { t = fabsf(t); + } out += t; } return out; @@ -406,8 +414,9 @@ PyDoc_STRVAR(M_Noise_seed_set_doc, static PyObject *M_Noise_seed_set(PyObject *UNUSED(self), PyObject *args) { int s; - if (!PyArg_ParseTuple(args, "i:seed_set", &s)) + if (!PyArg_ParseTuple(args, "i:seed_set", &s)) { return NULL; + } setRndSeed(s); Py_RETURN_NONE; } @@ -447,8 +456,9 @@ static PyObject *M_Noise_noise(PyObject *UNUSED(self), PyObject *args, PyObject return NULL; } - if (mathutils_array_parse(vec, 3, 3, value, "noise: invalid 'position' arg") == -1) + if (mathutils_array_parse(vec, 3, 3, value, "noise: invalid 'position' arg") == -1) { return NULL; + } return PyFloat_FromDouble((2.0f * BLI_gNoise(1.0f, vec[0], vec[1], vec[2], 0, noise_basis_enum) - 1.0f)); } @@ -488,8 +498,9 @@ static PyObject *M_Noise_noise_vector(PyObject *UNUSED(self), PyObject *args, Py return NULL; } - if (mathutils_array_parse(vec, 3, 3, value, "noise_vector: invalid 'position' arg") == -1) + if (mathutils_array_parse(vec, 3, 3, value, "noise_vector: invalid 'position' arg") == -1) { return NULL; + } noise_vector(vec[0], vec[1], vec[2], noise_basis_enum, r_vec); @@ -540,8 +551,9 @@ static PyObject *M_Noise_turbulence(PyObject *UNUSED(self), PyObject *args, PyOb return NULL; } - if (mathutils_array_parse(vec, 3, 3, value, "turbulence: invalid 'position' arg") == -1) + if (mathutils_array_parse(vec, 3, 3, value, "turbulence: invalid 'position' arg") == -1) { return NULL; + } return PyFloat_FromDouble(turb(vec[0], vec[1], vec[2], oct, hd, noise_basis_enum, as, fs)); } @@ -590,8 +602,9 @@ static PyObject *M_Noise_turbulence_vector(PyObject *UNUSED(self), PyObject *arg return NULL; } - if (mathutils_array_parse(vec, 3, 3, value, "turbulence_vector: invalid 'position' arg") == -1) + if (mathutils_array_parse(vec, 3, 3, value, "turbulence_vector: invalid 'position' arg") == -1) { return NULL; + } vTurb(vec[0], vec[1], vec[2], oct, hd, noise_basis_enum, as, fs, r_vec); @@ -641,8 +654,9 @@ static PyObject *M_Noise_fractal(PyObject *UNUSED(self), PyObject *args, PyObjec return NULL; } - if (mathutils_array_parse(vec, 3, 3, value, "fractal: invalid 'position' arg") == -1) + if (mathutils_array_parse(vec, 3, 3, value, "fractal: invalid 'position' arg") == -1) { return NULL; + } return PyFloat_FromDouble(mg_fBm(vec[0], vec[1], vec[2], H, lac, oct, noise_basis_enum)); } @@ -689,8 +703,9 @@ static PyObject *M_Noise_multi_fractal(PyObject *UNUSED(self), PyObject *args, P return NULL; } - if (mathutils_array_parse(vec, 3, 3, value, "multi_fractal: invalid 'position' arg") == -1) + if (mathutils_array_parse(vec, 3, 3, value, "multi_fractal: invalid 'position' arg") == -1) { return NULL; + } return PyFloat_FromDouble(mg_MultiFractal(vec[0], vec[1], vec[2], H, lac, oct, noise_basis_enum)); } @@ -749,8 +764,9 @@ static PyObject *M_Noise_variable_lacunarity(PyObject *UNUSED(self), PyObject *a return NULL; } - if (mathutils_array_parse(vec, 3, 3, value, "variable_lacunarity: invalid 'position' arg") == -1) + if (mathutils_array_parse(vec, 3, 3, value, "variable_lacunarity: invalid 'position' arg") == -1) { return NULL; + } return PyFloat_FromDouble(mg_VLNoise(vec[0], vec[1], vec[2], d, noise_type1_enum, noise_type2_enum)); } @@ -799,8 +815,9 @@ static PyObject *M_Noise_hetero_terrain(PyObject *UNUSED(self), PyObject *args, return NULL; } - if (mathutils_array_parse(vec, 3, 3, value, "hetero_terrain: invalid 'position' arg") == -1) + if (mathutils_array_parse(vec, 3, 3, value, "hetero_terrain: invalid 'position' arg") == -1) { return NULL; + } return PyFloat_FromDouble(mg_HeteroTerrain(vec[0], vec[1], vec[2], H, lac, oct, ofs, noise_basis_enum)); } @@ -851,8 +868,9 @@ static PyObject *M_Noise_hybrid_multi_fractal(PyObject *UNUSED(self), PyObject * return NULL; } - if (mathutils_array_parse(vec, 3, 3, value, "hybrid_multi_fractal: invalid 'position' arg") == -1) + if (mathutils_array_parse(vec, 3, 3, value, "hybrid_multi_fractal: invalid 'position' arg") == -1) { return NULL; + } return PyFloat_FromDouble(mg_HybridMultiFractal(vec[0], vec[1], vec[2], H, lac, oct, ofs, gn, noise_basis_enum)); } @@ -903,8 +921,9 @@ static PyObject *M_Noise_ridged_multi_fractal(PyObject *UNUSED(self), PyObject * return NULL; } - if (mathutils_array_parse(vec, 3, 3, value, "ridged_multi_fractal: invalid 'position' arg") == -1) + if (mathutils_array_parse(vec, 3, 3, value, "ridged_multi_fractal: invalid 'position' arg") == -1) { return NULL; + } return PyFloat_FromDouble(mg_RidgedMultiFractal(vec[0], vec[1], vec[2], H, lac, oct, ofs, gn, noise_basis_enum)); } @@ -952,8 +971,9 @@ static PyObject *M_Noise_voronoi(PyObject *UNUSED(self), PyObject *args, PyObjec return NULL; } - if (mathutils_array_parse(vec, 3, 3, value, "voronoi: invalid 'position' arg") == -1) + if (mathutils_array_parse(vec, 3, 3, value, "voronoi: invalid 'position' arg") == -1) { return NULL; + } list = PyList_New(4); @@ -984,11 +1004,13 @@ static PyObject *M_Noise_cell(PyObject *UNUSED(self), PyObject *args) PyObject *value; float vec[3]; - if (!PyArg_ParseTuple(args, "O:cell", &value)) + if (!PyArg_ParseTuple(args, "O:cell", &value)) { return NULL; + } - if (mathutils_array_parse(vec, 3, 3, value, "cell: invalid 'position' arg") == -1) + if (mathutils_array_parse(vec, 3, 3, value, "cell: invalid 'position' arg") == -1) { return NULL; + } return PyFloat_FromDouble(cellNoise(vec[0], vec[1], vec[2])); } @@ -1008,11 +1030,13 @@ static PyObject *M_Noise_cell_vector(PyObject *UNUSED(self), PyObject *args) PyObject *value; float vec[3], r_vec[3]; - if (!PyArg_ParseTuple(args, "O:cell_vector", &value)) + if (!PyArg_ParseTuple(args, "O:cell_vector", &value)) { return NULL; + } - if (mathutils_array_parse(vec, 3, 3, value, "cell_vector: invalid 'position' arg") == -1) + if (mathutils_array_parse(vec, 3, 3, value, "cell_vector: invalid 'position' arg") == -1) { return NULL; + } cellNoiseV(vec[0], vec[1], vec[2], r_vec); return Vector_CreatePyObject(r_vec, 3, NULL); |