style cleanup: python api

This commit is contained in:
2012-03-26 06:55:09 +00:00
parent 7c8c1a0718
commit 11d12d945e
12 changed files with 1092 additions and 1092 deletions

View File

@@ -431,8 +431,8 @@ static PyObject *C_Matrix_Identity(PyObject *cls, PyObject *args)
if (matSize < 2 || matSize > 4) {
PyErr_SetString(PyExc_RuntimeError,
"Matrix.Identity(): "
"size must be between 2 and 4");
"Matrix.Identity(): "
"size must be between 2 and 4");
return NULL;
}
@@ -461,9 +461,9 @@ static PyObject *C_Matrix_Rotation(PyObject *cls, PyObject *args)
int matSize;
double angle; /* use double because of precision problems at high values */
float mat[16] = {0.0f, 0.0f, 0.0f, 0.0f,
0.0f, 0.0f, 0.0f, 0.0f,
0.0f, 0.0f, 0.0f, 0.0f,
0.0f, 0.0f, 0.0f, 1.0f};
0.0f, 0.0f, 0.0f, 0.0f,
0.0f, 0.0f, 0.0f, 0.0f,
0.0f, 0.0f, 0.0f, 1.0f};
if (!PyArg_ParseTuple(args, "di|O:Matrix.Rotation", &angle, &matSize, &vec)) {
return NULL;
@@ -549,7 +549,7 @@ PyDoc_STRVAR(C_Matrix_Translation_doc,
);
static PyObject *C_Matrix_Translation(PyObject *cls, PyObject *value)
{
float mat[4][4]= MAT4_UNITY;
float mat[4][4] = MAT4_UNITY;
if (mathutils_array_parse(mat[3], 3, 4, value, "mathutils.Matrix.Translation(vector), invalid vector arg") == -1)
return NULL;
@@ -601,7 +601,7 @@ static PyObject *C_Matrix_Scale(PyObject *cls, PyObject *args)
return NULL;
}
}
if (vec == NULL) { //scaling along axis
if (vec == NULL) { //scaling along axis
if (matSize == 2) {
mat[0] = factor;
mat[3] = factor;
@@ -612,8 +612,9 @@ static PyObject *C_Matrix_Scale(PyObject *cls, PyObject *args)
mat[8] = factor;
}
}
else { //scaling in arbitrary direction
//normalize arbitrary axis
else {
/* scaling in arbitrary direction
* normalize arbitrary axis */
float norm = 0.0f;
int x;
for (x = 0; x < vec_size; x++) {
@@ -624,21 +625,21 @@ static PyObject *C_Matrix_Scale(PyObject *cls, PyObject *args)
tvec[x] /= norm;
}
if (matSize == 2) {
mat[0] = 1 + ((factor - 1) *(tvec[0] * tvec[0]));
mat[1] = ((factor - 1) *(tvec[0] * tvec[1]));
mat[2] = ((factor - 1) *(tvec[0] * tvec[1]));
mat[3] = 1 + ((factor - 1) *(tvec[1] * tvec[1]));
mat[0] = 1 + ((factor - 1) * (tvec[0] * tvec[0]));
mat[1] = ((factor - 1) * (tvec[0] * tvec[1]));
mat[2] = ((factor - 1) * (tvec[0] * tvec[1]));
mat[3] = 1 + ((factor - 1) * (tvec[1] * tvec[1]));
}
else {
mat[0] = 1 + ((factor - 1) *(tvec[0] * tvec[0]));
mat[1] = ((factor - 1) *(tvec[0] * tvec[1]));
mat[2] = ((factor - 1) *(tvec[0] * tvec[2]));
mat[3] = ((factor - 1) *(tvec[0] * tvec[1]));
mat[4] = 1 + ((factor - 1) *(tvec[1] * tvec[1]));
mat[5] = ((factor - 1) *(tvec[1] * tvec[2]));
mat[6] = ((factor - 1) *(tvec[0] * tvec[2]));
mat[7] = ((factor - 1) *(tvec[1] * tvec[2]));
mat[8] = 1 + ((factor - 1) *(tvec[2] * tvec[2]));
mat[0] = 1 + ((factor - 1) * (tvec[0] * tvec[0]));
mat[1] = ((factor - 1) * (tvec[0] * tvec[1]));
mat[2] = ((factor - 1) * (tvec[0] * tvec[2]));
mat[3] = ((factor - 1) * (tvec[0] * tvec[1]));
mat[4] = 1 + ((factor - 1) * (tvec[1] * tvec[1]));
mat[5] = ((factor - 1) * (tvec[1] * tvec[2]));
mat[6] = ((factor - 1) * (tvec[0] * tvec[2]));
mat[7] = ((factor - 1) * (tvec[1] * tvec[2]));
mat[8] = 1 + ((factor - 1) * (tvec[2] * tvec[2]));
}
}
if (matSize == 4) {
@@ -684,7 +685,7 @@ static PyObject *C_Matrix_OrthoProjection(PyObject *cls, PyObject *args)
return NULL;
}
if (PyUnicode_Check(axis)) { //ortho projection onto cardinal plane
if (PyUnicode_Check(axis)) { //ortho projection onto cardinal plane
Py_ssize_t plane_len;
const char *plane = _PyUnicode_AsStringAndSize(axis, &plane_len);
if (matSize == 2) {
@@ -971,10 +972,10 @@ static PyObject *Matrix_to_euler(MatrixObject *self, PyObject *args)
}
/*must be 3-4 cols, 3-4 rows, square matrix */
if (self->num_row ==3 && self->num_col ==3) {
if (self->num_row == 3 && self->num_col == 3) {
mat = (float (*)[3])self->matrix;
}
else if (self->num_row ==4 && self->num_col ==4) {
else if (self->num_row == 4 && self->num_col == 4) {
copy_m3_m4(tmat, (float (*)[4])self->matrix);
mat = tmat;
}
@@ -993,12 +994,12 @@ static PyObject *Matrix_to_euler(MatrixObject *self, PyObject *args)
}
if (eul_compat) {
if (order == 1) mat3_to_compatible_eul(eul, eul_compatf, mat);
else mat3_to_compatible_eulO(eul, eul_compatf, order, mat);
if (order == 1) mat3_to_compatible_eul(eul, eul_compatf, mat);
else mat3_to_compatible_eulO(eul, eul_compatf, order, mat);
}
else {
if (order == 1) mat3_to_eul(eul, mat);
else mat3_to_eulO(eul, order, mat);
if (order == 1) mat3_to_eul(eul, mat);
else mat3_to_eulO(eul, order, mat);
}
return Euler_CreatePyObject(eul, order, Py_NEW, NULL);
@@ -1202,10 +1203,10 @@ static PyObject *Matrix_invert(MatrixObject *self)
mat[3] = MATRIX_ITEM(self, 0, 0);
}
else if (self->num_col == 3) {
adjoint_m3_m3((float (*)[3]) mat,(float (*)[3])self->matrix);
adjoint_m3_m3((float (*)[3])mat, (float (*)[3])self->matrix);
}
else if (self->num_col == 4) {
adjoint_m4_m4((float (*)[4]) mat, (float (*)[4])self->matrix);
adjoint_m4_m4((float (*)[4])mat, (float (*)[4])self->matrix);
}
/* divide by determinate */
for (x = 0; x < (self->num_col * self->num_row); x++) {
@@ -1536,17 +1537,17 @@ static PyObject *Matrix_repr(MatrixObject *self)
}
}
switch (self->num_row) {
case 2: return PyUnicode_FromFormat("Matrix((%R,\n"
" %R))", rows[0], rows[1]);
case 2: return PyUnicode_FromFormat("Matrix((%R,\n"
" %R))", rows[0], rows[1]);
case 3: return PyUnicode_FromFormat("Matrix((%R,\n"
" %R,\n"
" %R))", rows[0], rows[1], rows[2]);
case 3: return PyUnicode_FromFormat("Matrix((%R,\n"
" %R,\n"
" %R))", rows[0], rows[1], rows[2]);
case 4: return PyUnicode_FromFormat("Matrix((%R,\n"
" %R,\n"
" %R,\n"
" %R))", rows[0], rows[1], rows[2], rows[3]);
case 4: return PyUnicode_FromFormat("Matrix((%R,\n"
" %R,\n"
" %R,\n"
" %R))", rows[0], rows[1], rows[2], rows[3]);
}
Py_FatalError("Matrix(): invalid row size!");
@@ -1905,8 +1906,8 @@ static PyObject *Matrix_mul(PyObject *m1, PyObject *m2)
if (mat1->num_col != mat2->num_row) {
PyErr_SetString(PyExc_ValueError,
"matrix1 * matrix2: matrix1 number of columns "
"and the matrix2 number of rows must be the same");
"matrix1 * matrix2: matrix1 number of columns "
"and the matrix2 number of rows must be the same");
return NULL;
}
@@ -1966,16 +1967,16 @@ static PyObject *Matrix_mul(PyObject *m1, PyObject *m2)
/*-----------------PROTOCOL DECLARATIONS--------------------------*/
static PySequenceMethods Matrix_SeqMethods = {
(lenfunc) Matrix_len, /* sq_length */
(binaryfunc) NULL, /* sq_concat */
(ssizeargfunc) NULL, /* sq_repeat */
(ssizeargfunc) Matrix_item_row, /* sq_item */
(ssizessizeargfunc) NULL, /* sq_slice, deprecated */
(ssizeobjargproc) Matrix_ass_item_row, /* sq_ass_item */
(ssizessizeobjargproc) NULL, /* sq_ass_slice, deprecated */
(objobjproc) NULL, /* sq_contains */
(binaryfunc) NULL, /* sq_inplace_concat */
(ssizeargfunc) NULL, /* sq_inplace_repeat */
(lenfunc) Matrix_len, /* sq_length */
(binaryfunc) NULL, /* sq_concat */
(ssizeargfunc) NULL, /* sq_repeat */
(ssizeargfunc) Matrix_item_row, /* sq_item */
(ssizessizeargfunc) NULL, /* sq_slice, deprecated */
(ssizeobjargproc) Matrix_ass_item_row, /* sq_ass_item */
(ssizessizeobjargproc) NULL, /* sq_ass_slice, deprecated */
(objobjproc) NULL, /* sq_contains */
(binaryfunc) NULL, /* sq_inplace_concat */
(ssizeargfunc) NULL, /* sq_inplace_repeat */
};
@@ -2056,40 +2057,40 @@ static PyMappingMethods Matrix_AsMapping = {
static PyNumberMethods Matrix_NumMethods = {
(binaryfunc) Matrix_add, /*nb_add*/
(binaryfunc) Matrix_sub, /*nb_subtract*/
(binaryfunc) Matrix_mul, /*nb_multiply*/
NULL, /*nb_remainder*/
NULL, /*nb_divmod*/
NULL, /*nb_power*/
(unaryfunc) 0, /*nb_negative*/
(unaryfunc) 0, /*tp_positive*/
(unaryfunc) 0, /*tp_absolute*/
(inquiry) 0, /*tp_bool*/
(unaryfunc) Matrix_inverted, /*nb_invert*/
NULL, /*nb_lshift*/
(binaryfunc)0, /*nb_rshift*/
NULL, /*nb_and*/
NULL, /*nb_xor*/
NULL, /*nb_or*/
NULL, /*nb_int*/
NULL, /*nb_reserved*/
NULL, /*nb_float*/
NULL, /* nb_inplace_add */
NULL, /* nb_inplace_subtract */
NULL, /* nb_inplace_multiply */
NULL, /* nb_inplace_remainder */
NULL, /* nb_inplace_power */
NULL, /* nb_inplace_lshift */
NULL, /* nb_inplace_rshift */
NULL, /* nb_inplace_and */
NULL, /* nb_inplace_xor */
NULL, /* nb_inplace_or */
NULL, /* nb_floor_divide */
NULL, /* nb_true_divide */
NULL, /* nb_inplace_floor_divide */
NULL, /* nb_inplace_true_divide */
NULL, /* nb_index */
(binaryfunc) Matrix_add, /*nb_add*/
(binaryfunc) Matrix_sub, /*nb_subtract*/
(binaryfunc) Matrix_mul, /*nb_multiply*/
NULL, /*nb_remainder*/
NULL, /*nb_divmod*/
NULL, /*nb_power*/
(unaryfunc) 0, /*nb_negative*/
(unaryfunc) 0, /*tp_positive*/
(unaryfunc) 0, /*tp_absolute*/
(inquiry) 0, /*tp_bool*/
(unaryfunc) Matrix_inverted, /*nb_invert*/
NULL, /*nb_lshift*/
(binaryfunc)0, /*nb_rshift*/
NULL, /*nb_and*/
NULL, /*nb_xor*/
NULL, /*nb_or*/
NULL, /*nb_int*/
NULL, /*nb_reserved*/
NULL, /*nb_float*/
NULL, /* nb_inplace_add */
NULL, /* nb_inplace_subtract */
NULL, /* nb_inplace_multiply */
NULL, /* nb_inplace_remainder */
NULL, /* nb_inplace_power */
NULL, /* nb_inplace_lshift */
NULL, /* nb_inplace_rshift */
NULL, /* nb_inplace_and */
NULL, /* nb_inplace_xor */
NULL, /* nb_inplace_or */
NULL, /* nb_floor_divide */
NULL, /* nb_true_divide */
NULL, /* nb_inplace_floor_divide */
NULL, /* nb_inplace_true_divide */
NULL, /* nb_index */
};
PyDoc_STRVAR(Matrix_translation_doc,
@@ -2233,7 +2234,7 @@ static PyGetSetDef Matrix_getseters[] = {
{(char *)"is_negative", (getter)Matrix_is_negative_get, (setter)NULL, Matrix_is_negative_doc, NULL},
{(char *)"is_orthogonal", (getter)Matrix_is_orthogonal_get, (setter)NULL, Matrix_is_orthogonal_doc, NULL},
{(char *)"is_wrapped", (getter)BaseMathObject_is_wrapped_get, (setter)NULL, BaseMathObject_is_wrapped_doc, NULL},
{(char *)"owner",(getter)BaseMathObject_owner_get, (setter)NULL, BaseMathObject_owner_doc, NULL},
{(char *)"owner", (getter)BaseMathObject_owner_get, (setter)NULL, BaseMathObject_owner_doc, NULL},
{NULL, NULL, NULL, NULL, NULL} /* Sentinel */
};
@@ -2285,51 +2286,51 @@ PyDoc_STRVAR(matrix_doc,
);
PyTypeObject matrix_Type = {
PyVarObject_HEAD_INIT(NULL, 0)
"mathutils.Matrix", /*tp_name*/
sizeof(MatrixObject), /*tp_basicsize*/
0, /*tp_itemsize*/
(destructor)BaseMathObject_dealloc, /*tp_dealloc*/
NULL, /*tp_print*/
NULL, /*tp_getattr*/
NULL, /*tp_setattr*/
NULL, /*tp_compare*/
(reprfunc) Matrix_repr, /*tp_repr*/
&Matrix_NumMethods, /*tp_as_number*/
&Matrix_SeqMethods, /*tp_as_sequence*/
&Matrix_AsMapping, /*tp_as_mapping*/
NULL, /*tp_hash*/
NULL, /*tp_call*/
(reprfunc) Matrix_str, /*tp_str*/
NULL, /*tp_getattro*/
NULL, /*tp_setattro*/
NULL, /*tp_as_buffer*/
"mathutils.Matrix", /*tp_name*/
sizeof(MatrixObject), /*tp_basicsize*/
0, /*tp_itemsize*/
(destructor)BaseMathObject_dealloc, /*tp_dealloc*/
NULL, /*tp_print*/
NULL, /*tp_getattr*/
NULL, /*tp_setattr*/
NULL, /*tp_compare*/
(reprfunc) Matrix_repr, /*tp_repr*/
&Matrix_NumMethods, /*tp_as_number*/
&Matrix_SeqMethods, /*tp_as_sequence*/
&Matrix_AsMapping, /*tp_as_mapping*/
NULL, /*tp_hash*/
NULL, /*tp_call*/
(reprfunc) Matrix_str, /*tp_str*/
NULL, /*tp_getattro*/
NULL, /*tp_setattro*/
NULL, /*tp_as_buffer*/
Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE | Py_TPFLAGS_HAVE_GC, /*tp_flags*/
matrix_doc, /*tp_doc*/
(traverseproc)BaseMathObject_traverse, //tp_traverse
(inquiry)BaseMathObject_clear, //tp_clear
(richcmpfunc)Matrix_richcmpr, /*tp_richcompare*/
0, /*tp_weaklistoffset*/
NULL, /*tp_iter*/
NULL, /*tp_iternext*/
Matrix_methods, /*tp_methods*/
NULL, /*tp_members*/
Matrix_getseters, /*tp_getset*/
NULL, /*tp_base*/
NULL, /*tp_dict*/
NULL, /*tp_descr_get*/
NULL, /*tp_descr_set*/
0, /*tp_dictoffset*/
NULL, /*tp_init*/
NULL, /*tp_alloc*/
Matrix_new, /*tp_new*/
NULL, /*tp_free*/
NULL, /*tp_is_gc*/
NULL, /*tp_bases*/
NULL, /*tp_mro*/
NULL, /*tp_cache*/
NULL, /*tp_subclasses*/
NULL, /*tp_weaklist*/
NULL /*tp_del*/
matrix_doc, /*tp_doc*/
(traverseproc)BaseMathObject_traverse, //tp_traverse
(inquiry)BaseMathObject_clear, //tp_clear
(richcmpfunc)Matrix_richcmpr, /*tp_richcompare*/
0, /*tp_weaklistoffset*/
NULL, /*tp_iter*/
NULL, /*tp_iternext*/
Matrix_methods, /*tp_methods*/
NULL, /*tp_members*/
Matrix_getseters, /*tp_getset*/
NULL, /*tp_base*/
NULL, /*tp_dict*/
NULL, /*tp_descr_get*/
NULL, /*tp_descr_set*/
0, /*tp_dictoffset*/
NULL, /*tp_init*/
NULL, /*tp_alloc*/
Matrix_new, /*tp_new*/
NULL, /*tp_free*/
NULL, /*tp_is_gc*/
NULL, /*tp_bases*/
NULL, /*tp_mro*/
NULL, /*tp_cache*/
NULL, /*tp_subclasses*/
NULL, /*tp_weaklist*/
NULL /*tp_del*/
};
/* pass Py_WRAP - if vector is a WRAPPER for data allocated by BLENDER
@@ -2374,7 +2375,7 @@ PyObject *Matrix_CreatePyObject(float *mat,
return NULL;
}
if (mat) { /*if a float array passed*/
if (mat) { /*if a float array passed*/
memcpy(self->matrix, mat, num_col * num_row * sizeof(float));
}
else if (num_col == num_row) {
@@ -2448,8 +2449,8 @@ static void MatrixAccess_dealloc(MatrixAccessObject *self)
static int MatrixAccess_len(MatrixAccessObject *self)
{
return (self->type == MAT_ACCESS_ROW) ?
self->matrix_user->num_row :
self->matrix_user->num_col;
self->matrix_user->num_row :
self->matrix_user->num_col;
}
static PyObject *MatrixAccess_slice(MatrixAccessObject *self, int begin, int end)
@@ -2585,30 +2586,30 @@ static PyMappingMethods MatrixAccess_AsMapping = {
PyTypeObject matrix_access_Type = {
PyVarObject_HEAD_INIT(NULL, 0)
"MatrixAccess", /*tp_name*/
sizeof(MatrixAccessObject), /*tp_basicsize*/
0, /*tp_itemsize*/
(destructor)MatrixAccess_dealloc, /*tp_dealloc*/
NULL, /*tp_print*/
NULL, /*tp_getattr*/
NULL, /*tp_setattr*/
NULL, /*tp_compare*/
NULL, /*tp_repr*/
NULL, /*tp_as_number*/
NULL /*&MatrixAccess_SeqMethods*/ /* TODO */, /*tp_as_sequence*/
&MatrixAccess_AsMapping, /*tp_as_mapping*/
NULL, /*tp_hash*/
NULL, /*tp_call*/
NULL, /*tp_str*/
NULL, /*tp_getattro*/
NULL, /*tp_setattro*/
NULL, /*tp_as_buffer*/
"MatrixAccess", /*tp_name*/
sizeof(MatrixAccessObject), /*tp_basicsize*/
0, /*tp_itemsize*/
(destructor)MatrixAccess_dealloc, /*tp_dealloc*/
NULL, /*tp_print*/
NULL, /*tp_getattr*/
NULL, /*tp_setattr*/
NULL, /*tp_compare*/
NULL, /*tp_repr*/
NULL, /*tp_as_number*/
NULL /*&MatrixAccess_SeqMethods*/ /* TODO */, /*tp_as_sequence*/
&MatrixAccess_AsMapping, /*tp_as_mapping*/
NULL, /*tp_hash*/
NULL, /*tp_call*/
NULL, /*tp_str*/
NULL, /*tp_getattro*/
NULL, /*tp_setattro*/
NULL, /*tp_as_buffer*/
Py_TPFLAGS_DEFAULT | Py_TPFLAGS_HAVE_GC, /*tp_flags*/
NULL, /*tp_doc*/
(traverseproc)MatrixAccess_traverse, //tp_traverse
(inquiry)MatrixAccess_clear, //tp_clear
NULL, /*tp_doc*/
(traverseproc)MatrixAccess_traverse, //tp_traverse
(inquiry)MatrixAccess_clear, //tp_clear
NULL /* (richcmpfunc)MatrixAccess_richcmpr */ /* TODO*/, /*tp_richcompare*/
0, /*tp_weaklistoffset*/
0, /*tp_weaklistoffset*/
(getiterfunc)MatrixAccess_iter, /* getiterfunc tp_iter; */
};