formatting edits (120 width max) and remove some redundant casts
authorCampbell Barton <ideasman42@gmail.com>
Tue, 29 Nov 2011 20:22:35 +0000 (20:22 +0000)
committerCampbell Barton <ideasman42@gmail.com>
Tue, 29 Nov 2011 20:22:35 +0000 (20:22 +0000)
source/blender/python/mathutils/mathutils.c
source/blender/python/mathutils/mathutils.h
source/blender/python/mathutils/mathutils_Color.h
source/blender/python/mathutils/mathutils_Euler.c
source/blender/python/mathutils/mathutils_Euler.h
source/blender/python/mathutils/mathutils_Matrix.c
source/blender/python/mathutils/mathutils_Matrix.h
source/blender/python/mathutils/mathutils_Quaternion.c
source/blender/python/mathutils/mathutils_Quaternion.h
source/blender/python/mathutils/mathutils_Vector.h

index f0fe69259fec5a514dc94baebc50e49ce7197d86..121c5e26e7381b1cc6f7a3859e1779739ad22689 100644 (file)
@@ -39,7 +39,9 @@
 PyDoc_STRVAR(M_Mathutils_doc,
 "This module provides access to matrices, eulers, quaternions and vectors."
 );
-static int mathutils_array_parse_fast(float *array, int array_min, int array_max, PyObject *value, const char *error_prefix)
+static int mathutils_array_parse_fast(float *array,
+                                      int array_min, int array_max,
+                                      PyObject *value, const char *error_prefix)
 {
        PyObject *value_fast= NULL;
        PyObject *item;
@@ -72,7 +74,9 @@ static int mathutils_array_parse_fast(float *array, int array_min, int array_max
        i= size;
        do {
                i--;
-               if (((array[i]= PyFloat_AsDouble((item= PySequence_Fast_GET_ITEM(value_fast, i)))) == -1.0f) && PyErr_Occurred()) {
+               if ( ((array[i]= PyFloat_AsDouble((item= PySequence_Fast_GET_ITEM(value_fast, i)))) == -1.0f) &&
+                    PyErr_Occurred())
+               {
                        PyErr_Format(PyExc_TypeError,
                                     "%.200s: sequence index %d expected a number, "
                                     "found '%.200s' type, ",
index b50535bd70903c4f96510b9989c895671a2031eb..a8170b8145ca2f2d54b3d2d1e0c05162c33918d0 100644 (file)
 extern char BaseMathObject_Wrapped_doc[];
 extern char BaseMathObject_Owner_doc[];
 
-#define BASE_MATH_MEMBERS(_data) \
-       PyObject_VAR_HEAD \
-       float *_data;                           /* array of data (alias), wrapped status depends on wrapped status */ \
-       PyObject *cb_user;                      /* if this vector references another object, otherwise NULL, *Note* this owns its reference */ \
-       unsigned char cb_type;          /* which user funcs do we adhere to, RNA, GameObject, etc */ \
-       unsigned char cb_subtype;       /* subtype: location, rotation... to avoid defining many new functions for every attribute of the same type */ \
-       unsigned char wrapped;          /* wrapped data type? */ \
+#define BASE_MATH_MEMBERS(_data)                                                                                 \
+       PyObject_VAR_HEAD                                                                                            \
+       float *_data;               /* array of data (alias), wrapped status depends on wrapped status */            \
+       PyObject *cb_user;          /* if this vector references another object, otherwise NULL,                     \
+                                    * *Note* this owns its reference */                                             \
+       unsigned char cb_type;      /* which user funcs do we adhere to, RNA, GameObject, etc */                     \
+       unsigned char cb_subtype;   /* subtype: location, rotation...                                                \
+                                    * to avoid defining many new functions for every attribute of the same type */  \
+       unsigned char wrapped       /* wrapped data type? */                                                         \
 
 typedef struct {
-       BASE_MATH_MEMBERS(data)
+       BASE_MATH_MEMBERS(data);
 } BaseMathObject;
 
 /* types */
@@ -80,11 +82,11 @@ int EXPP_VectorsAreEqual(float *vecA, float *vecB, int size, int floatSteps);
 
 typedef struct Mathutils_Callback Mathutils_Callback;
 
-typedef int (*BaseMathCheckFunc)(BaseMathObject *);                                                    /* checks the user is still valid */
-typedef int (*BaseMathGetFunc)(BaseMathObject *, int);                         /* gets the vector from the user */
-typedef int (*BaseMathSetFunc)(BaseMathObject *, int);                         /* sets the users vector values once the vector is modified */
-typedef int (*BaseMathGetIndexFunc)(BaseMathObject *, int, int);       /* same as above but only for an index */
-typedef int (*BaseMathSetIndexFunc)(BaseMathObject *, int, int);       /* same as above but only for an index */
+typedef int (*BaseMathCheckFunc)(BaseMathObject *);               /* checks the user is still valid */
+typedef int (*BaseMathGetFunc)(BaseMathObject *, int);            /* gets the vector from the user */
+typedef int (*BaseMathSetFunc)(BaseMathObject *, int);            /* sets the users vector values once its modified */
+typedef int (*BaseMathGetIndexFunc)(BaseMathObject *, int, int);  /* same as above but only for an index */
+typedef int (*BaseMathSetIndexFunc)(BaseMathObject *, int, int);  /* same as above but only for an index */
 
 struct Mathutils_Callback {
        BaseMathCheckFunc               check;
@@ -102,10 +104,14 @@ int _BaseMathObject_ReadIndexCallback(BaseMathObject *self, int index);
 int _BaseMathObject_WriteIndexCallback(BaseMathObject *self, int index);
 
 /* since this is called so often avoid where possible */
-#define BaseMath_ReadCallback(_self) (((_self)->cb_user ?      _BaseMathObject_ReadCallback((BaseMathObject *)_self):0))
-#define BaseMath_WriteCallback(_self) (((_self)->cb_user ?_BaseMathObject_WriteCallback((BaseMathObject *)_self):0))
-#define BaseMath_ReadIndexCallback(_self, _index) (((_self)->cb_user ? _BaseMathObject_ReadIndexCallback((BaseMathObject *)_self, _index):0))
-#define BaseMath_WriteIndexCallback(_self, _index) (((_self)->cb_user ?        _BaseMathObject_WriteIndexCallback((BaseMathObject *)_self, _index):0))
+#define BaseMath_ReadCallback(_self) \
+       (((_self)->cb_user ?    _BaseMathObject_ReadCallback((BaseMathObject *)_self):0))
+#define BaseMath_WriteCallback(_self) \
+       (((_self)->cb_user ?_BaseMathObject_WriteCallback((BaseMathObject *)_self):0))
+#define BaseMath_ReadIndexCallback(_self, _index) \
+       (((_self)->cb_user ?    _BaseMathObject_ReadIndexCallback((BaseMathObject *)_self, _index):0))
+#define BaseMath_WriteIndexCallback(_self, _index) \
+       (((_self)->cb_user ?    _BaseMathObject_WriteIndexCallback((BaseMathObject *)_self, _index):0))
 
 /* utility func */
 int mathutils_array_parse(float *array, int array_min, int array_max, PyObject *value, const char *error_prefix);
index f218d653ec9993683f3f53e846c9d969a87cbbee..7e8a99089ad2ba788cc9431adff29632604770e6 100644 (file)
@@ -39,7 +39,7 @@ extern PyTypeObject color_Type;
 #define ColorObject_Check(_v) PyObject_TypeCheck((_v), &color_Type)
 
 typedef struct {
-       BASE_MATH_MEMBERS(col)
+       BASE_MATH_MEMBERS(col);
 } ColorObject;
 
 /*struct data contains a pointer to the actual data that the
index 9bf6687fb5ee1341c487a17357eda4004f0ac768..7e769da14cb80d97f3fb30be97518350dd6ae4e3 100644 (file)
@@ -264,8 +264,11 @@ static PyObject *Euler_make_compatible(EulerObject * self, PyObject *value)
        if (BaseMath_ReadCallback(self) == -1)
                return NULL;
 
-       if (mathutils_array_parse(teul, EULER_SIZE, EULER_SIZE, value, "euler.make_compatible(other), invalid 'other' arg") == -1)
+       if (mathutils_array_parse(teul, EULER_SIZE, EULER_SIZE, value,
+                                 "euler.make_compatible(other), invalid 'other' arg") == -1)
+       {
                return NULL;
+       }
 
        compatible_eul(self->eul, teul);
 
index 5760d08e1f6e6408f000805ea2c1792d4ded483e..130384a1792a623e3082555da65c14e72aa499c9 100644 (file)
@@ -39,7 +39,7 @@ extern PyTypeObject euler_Type;
 #define EulerObject_Check(_v) PyObject_TypeCheck((_v), &euler_Type)
 
 typedef struct {
-       BASE_MATH_MEMBERS(eul)
+       BASE_MATH_MEMBERS(eul);
        unsigned char order;            /* rotation order */
 
 } EulerObject;
index 2f62f7141cf59af4185c66abff6dea79e8971e01..ea636ef52fbc0ee180551f14a99830f61f2b79f0 100644 (file)
@@ -125,7 +125,7 @@ static PyObject *Matrix_new(PyTypeObject *type, PyObject *args, PyObject *kwds)
 
        switch(PyTuple_GET_SIZE(args)) {
                case 0:
-                       return (PyObject *) Matrix_CreatePyObject(NULL, 4, 4, Py_NEW, type);
+                       return Matrix_CreatePyObject(NULL, 4, 4, Py_NEW, type);
                case 1:
                {
                        PyObject *arg= PyTuple_GET_ITEM(args, 0);
@@ -478,7 +478,9 @@ static PyObject *C_Matrix_OrthoProjection(PyObject *cls, PyObject *args)
                int vec_size= (matSize == 2 ? 2 : 3);
                float tvec[4];
 
-               if (mathutils_array_parse(tvec, vec_size, vec_size, axis, "Matrix.OrthoProjection(axis, size), invalid 'axis' arg") == -1) {
+               if (mathutils_array_parse(tvec, vec_size, vec_size, axis,
+                                         "Matrix.OrthoProjection(axis, size), invalid 'axis' arg") == -1)
+               {
                        return NULL;
                }
 
@@ -827,12 +829,12 @@ static PyObject *Matrix_to_4x4(MatrixObject *self)
                return NULL;
 
        if (self->col_size==4 && self->row_size==4) {
-               return (PyObject *)Matrix_CreatePyObject(self->contigPtr, 4, 4, Py_NEW, Py_TYPE(self));
+               return Matrix_CreatePyObject(self->contigPtr, 4, 4, Py_NEW, Py_TYPE(self));
        }
        else if (self->col_size==3 && self->row_size==3) {
                float mat[4][4];
                copy_m4_m3(mat, (float (*)[3])self->contigPtr);
-               return (PyObject *)Matrix_CreatePyObject((float *)mat, 4, 4, Py_NEW, Py_TYPE(self));
+               return Matrix_CreatePyObject((float *)mat, 4, 4, Py_NEW, Py_TYPE(self));
        }
        /* TODO, 2x2 matrix */
 
@@ -1133,7 +1135,7 @@ static PyObject *Matrix_lerp(MatrixObject *self, PyObject *args)
                return NULL;
        }
 
-       return (PyObject*)Matrix_CreatePyObject(mat, self->row_size, self->col_size, Py_NEW, Py_TYPE(self));
+       return Matrix_CreatePyObject(mat, self->row_size, self->col_size, Py_NEW, Py_TYPE(self));
 }
 
 /*---------------------------matrix.determinant() ----------------*/
@@ -1286,7 +1288,7 @@ static PyObject *Matrix_copy(MatrixObject *self)
        if (BaseMath_ReadCallback(self) == -1)
                return NULL;
 
-       return (PyObject*)Matrix_CreatePyObject((float (*))self->contigPtr, self->row_size, self->col_size, Py_NEW, Py_TYPE(self));
+       return Matrix_CreatePyObject((float (*))self->contigPtr, self->row_size, self->col_size, Py_NEW, Py_TYPE(self));
 }
 
 /*----------------------------print object (internal)-------------*/
@@ -1470,7 +1472,9 @@ static int Matrix_ass_slice(MatrixObject *self, int begin, int end, PyObject *va
                        /*parse each sub sequence*/
                        PyObject *item= PySequence_Fast_GET_ITEM(value_fast, i);
 
-                       if (mathutils_array_parse(&mat[i * self->col_size], self->col_size, self->col_size, item, "matrix[begin:end] = value assignment") < 0) {
+                       if (mathutils_array_parse(&mat[i * self->col_size], self->col_size, self->col_size, item,
+                                                 "matrix[begin:end] = value assignment") < 0)
+                       {
                                return -1;
                        }
                }
@@ -1956,7 +1960,9 @@ self->matrix[1][1] = self->contigPtr[4] */
  (i.e. it was allocated elsewhere by MEM_mallocN())
   pass Py_NEW - if vector is not a WRAPPER and managed by PYTHON
  (i.e. it must be created here with PyMEM_malloc())*/
-PyObject *Matrix_CreatePyObject(float *mat, const unsigned short rowSize, const unsigned short colSize, int type, PyTypeObject *base_type)
+PyObject *Matrix_CreatePyObject(float *mat,
+                                const unsigned short rowSize, const unsigned short colSize,
+                                int type, PyTypeObject *base_type)
 {
        MatrixObject *self;
        int x, row, col;
index d1984d7299da3edaaf83a43de3bd9597192e6509..6dfcbb1faf9bd4a3f126d0ec3c43ed901b17300c 100644 (file)
@@ -39,7 +39,7 @@ extern PyTypeObject matrix_Type;
 #define MATRIX_MAX_DIM 4
 
 typedef struct {
-       BASE_MATH_MEMBERS(contigPtr)
+       BASE_MATH_MEMBERS(contigPtr);
        float *matrix[MATRIX_MAX_DIM];          /* ptr to the contigPtr (accessor) */
        unsigned short row_size;
        unsigned short col_size;
@@ -51,7 +51,9 @@ be stored in py_data) or be a wrapper for data allocated through
 blender (stored in blend_data). This is an either/or struct not both*/
 
 /*prototypes*/
-PyObject *Matrix_CreatePyObject(float *mat, const unsigned short row_size, const unsigned short col_size, int type, PyTypeObject *base_type);
+PyObject *Matrix_CreatePyObject(float *mat,
+                                const unsigned short row_size, const unsigned short col_size,
+                                int type, PyTypeObject *base_type);
 PyObject *Matrix_CreatePyObject_cb(PyObject *user, int row_size, int col_size, int cb_type, int cb_subtype);
 
 extern int mathutils_matrix_vector_cb_index;
index 44cd28a7c3d0eaf152fa55cff1c8fce1442820ae..cf817003a986eac95d3a1e1fa420ca3aef885a24 100644 (file)
@@ -218,8 +218,11 @@ static PyObject *Quaternion_dot(QuaternionObject *self, PyObject *value)
        if (BaseMath_ReadCallback(self) == -1)
                return NULL;
 
-       if (mathutils_array_parse(tquat, QUAT_SIZE, QUAT_SIZE, value, "Quaternion.dot(other), invalid 'other' arg") == -1)
+       if (mathutils_array_parse(tquat, QUAT_SIZE, QUAT_SIZE, value,
+                                 "Quaternion.dot(other), invalid 'other' arg") == -1)
+       {
                return NULL;
+       }
 
        return PyFloat_FromDouble(dot_qtqt(self->quat, tquat));
 }
@@ -241,8 +244,11 @@ static PyObject *Quaternion_rotation_difference(QuaternionObject *self, PyObject
        if (BaseMath_ReadCallback(self) == -1)
                return NULL;
 
-       if (mathutils_array_parse(tquat, QUAT_SIZE, QUAT_SIZE, value, "Quaternion.difference(other), invalid 'other' arg") == -1)
+       if (mathutils_array_parse(tquat, QUAT_SIZE, QUAT_SIZE, value,
+                                 "Quaternion.difference(other), invalid 'other' arg") == -1)
+       {
                return NULL;
+       }
 
        rotation_between_quats_to_quat(quat, self->quat, tquat);
 
@@ -276,8 +282,11 @@ static PyObject *Quaternion_slerp(QuaternionObject *self, PyObject *args)
        if (BaseMath_ReadCallback(self) == -1)
                return NULL;
 
-       if (mathutils_array_parse(tquat, QUAT_SIZE, QUAT_SIZE, value, "Quaternion.slerp(other), invalid 'other' arg") == -1)
+       if (mathutils_array_parse(tquat, QUAT_SIZE, QUAT_SIZE, value,
+                                 "Quaternion.slerp(other), invalid 'other' arg") == -1)
+       {
                return NULL;
+       }
 
        if (fac > 1.0f || fac < 0.0f) {
                PyErr_SetString(PyExc_ValueError,
@@ -982,7 +991,7 @@ static PyObject *Quaternion_getAxisVec(QuaternionObject *self, void *UNUSED(clos
 
        quat__axis_angle_sanitize(axis, NULL);
 
-       return (PyObject *) Vector_CreatePyObject(axis, 3, Py_NEW, NULL);
+       return Vector_CreatePyObject(axis, 3, Py_NEW, NULL);
 }
 
 static int Quaternion_setAxisVec(QuaternionObject *self, PyObject *value, void *UNUSED(closure))
@@ -1054,7 +1063,7 @@ static PyObject *quat__apply_to_copy(PyNoArgsFunction quat_func, QuaternionObjec
        PyObject *ret_dummy= quat_func(ret);
        if (ret_dummy) {
                Py_DECREF(ret_dummy);
-               return (PyObject *)ret;
+               return ret;
        }
        else { /* error */
                Py_DECREF(ret);
index a34720769fab1d161d58f0b3b0a4ef1c31175eb0..edd5ec55312129c2155c5075ea1e961f22cb72ca 100644 (file)
@@ -39,7 +39,7 @@ extern PyTypeObject quaternion_Type;
 #define QuaternionObject_Check(_v) PyObject_TypeCheck((_v), &quaternion_Type)
 
 typedef struct {
-       BASE_MATH_MEMBERS(quat)
+       BASE_MATH_MEMBERS(quat);
 } QuaternionObject;
 
 /*struct data contains a pointer to the actual data that the
index c1550aabb2512c8446e9fc2b497e181a59b148a6..0f7fa174d186e66fc755a6ba43f45c5837d13f96 100644 (file)
@@ -39,7 +39,7 @@ extern PyTypeObject vector_Type;
 #define VectorObject_Check(_v) PyObject_TypeCheck((_v), &vector_Type)
 
 typedef struct {
-       BASE_MATH_MEMBERS(vec)
+       BASE_MATH_MEMBERS(vec);
 
        unsigned char size;                     /* vec size 2,3 or 4 */
 } VectorObject;