forked from bartvdbraak/blender
formatting edits (120 width max) and remove some redundant casts
This commit is contained in:
parent
1a7ae3634d
commit
083297fbf1
@ -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, ",
|
||||
|
@ -40,16 +40,18 @@
|
||||
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);
|
||||
|
@ -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
|
||||
|
@ -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);
|
||||
|
||||
|
@ -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;
|
||||
|
@ -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;
|
||||
|
@ -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;
|
||||
|
@ -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);
|
||||
|
@ -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
|
||||
|
@ -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;
|
||||
|
Loading…
Reference in New Issue
Block a user