Cleanup: style, use braces for the Python API
This commit is contained in:
@@ -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))
|
||||
|
||||
Reference in New Issue
Block a user