change return values from mathutils callbacks to match pythons (-1 is error), so error macro's can be used in both.

This commit is contained in:
2011-02-28 18:42:41 +00:00
parent 506e8aa437
commit 7348a50d79
12 changed files with 224 additions and 220 deletions

View File

@@ -56,13 +56,13 @@ static int mathutils_matrix_vector_get(BaseMathObject *bmo, int subtype)
MatrixObject *self= (MatrixObject *)bmo->cb_user;
int i;
if(!BaseMath_ReadCallback(self))
return 0;
if(BaseMath_ReadCallback(self) == -1)
return -1;
for(i=0; i < self->col_size; i++)
bmo->data[i]= self->matrix[subtype][i];
return 1;
return 0;
}
static int mathutils_matrix_vector_set(BaseMathObject *bmo, int subtype)
@@ -70,38 +70,38 @@ static int mathutils_matrix_vector_set(BaseMathObject *bmo, int subtype)
MatrixObject *self= (MatrixObject *)bmo->cb_user;
int i;
if(!BaseMath_ReadCallback(self))
return 0;
if(BaseMath_ReadCallback(self) == -1)
return -1;
for(i=0; i < self->col_size; i++)
self->matrix[subtype][i]= bmo->data[i];
(void)BaseMath_WriteCallback(self);
return 1;
return 0;
}
static int mathutils_matrix_vector_get_index(BaseMathObject *bmo, int subtype, int index)
{
MatrixObject *self= (MatrixObject *)bmo->cb_user;
if(!BaseMath_ReadCallback(self))
return 0;
if(BaseMath_ReadCallback(self) == -1)
return -1;
bmo->data[index]= self->matrix[subtype][index];
return 1;
return 0;
}
static int mathutils_matrix_vector_set_index(BaseMathObject *bmo, int subtype, int index)
{
MatrixObject *self= (MatrixObject *)bmo->cb_user;
if(!BaseMath_ReadCallback(self))
return 0;
if(BaseMath_ReadCallback(self) == -1)
return -1;
self->matrix[subtype][index]= bmo->data[index];
(void)BaseMath_WriteCallback(self);
return 1;
return 0;
}
Mathutils_Callback mathutils_matrix_vector_cb = {
@@ -635,7 +635,7 @@ static PyObject *Matrix_to_quaternion(MatrixObject *self)
{
float quat[4];
if(!BaseMath_ReadCallback(self))
if(BaseMath_ReadCallback(self) == -1)
return NULL;
/*must be 3-4 cols, 3-4 rows, square matrix*/
@@ -675,14 +675,14 @@ static PyObject *Matrix_to_euler(MatrixObject *self, PyObject *args)
float tmat[3][3];
float (*mat)[3];
if(!BaseMath_ReadCallback(self))
if(BaseMath_ReadCallback(self) == -1)
return NULL;
if(!PyArg_ParseTuple(args, "|sO!:to_euler", &order_str, &euler_Type, &eul_compat))
return NULL;
if(eul_compat) {
if(!BaseMath_ReadCallback(eul_compat))
if(BaseMath_ReadCallback(eul_compat) == -1)
return NULL;
copy_v3_v3(eul_compatf, eul_compat->eul);
@@ -784,7 +784,7 @@ static char Matrix_to_4x4_doc[] =
;
static PyObject *Matrix_to_4x4(MatrixObject *self)
{
if(!BaseMath_ReadCallback(self))
if(BaseMath_ReadCallback(self) == -1)
return NULL;
if(self->col_size==4 && self->row_size==4) {
@@ -813,7 +813,7 @@ static PyObject *Matrix_to_3x3(MatrixObject *self)
{
float mat[3][3];
if(!BaseMath_ReadCallback(self))
if(BaseMath_ReadCallback(self) == -1)
return NULL;
if((self->col_size < 3) || (self->row_size < 3)) {
@@ -836,7 +836,7 @@ static char Matrix_to_translation_doc[] =
;
static PyObject *Matrix_to_translation(MatrixObject *self)
{
if(!BaseMath_ReadCallback(self))
if(BaseMath_ReadCallback(self) == -1)
return NULL;
if((self->col_size < 3) || self->row_size < 4){
@@ -863,7 +863,7 @@ static PyObject *Matrix_to_scale(MatrixObject *self)
float mat[3][3];
float size[3];
if(!BaseMath_ReadCallback(self))
if(BaseMath_ReadCallback(self) == -1)
return NULL;
/*must be 3-4 cols, 3-4 rows, square matrix*/
@@ -898,7 +898,7 @@ static PyObject *Matrix_invert(MatrixObject *self)
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};
if(!BaseMath_ReadCallback(self))
if(BaseMath_ReadCallback(self) == -1)
return NULL;
if(self->row_size != self->col_size){
@@ -972,7 +972,7 @@ static PyObject *Matrix_rotate(MatrixObject *self, PyObject *value)
{
float self_rmat[3][3], other_rmat[3][3], rmat[3][3];
if(!BaseMath_ReadCallback(self))
if(BaseMath_ReadCallback(self) == -1)
return NULL;
if(mathutils_any_to_rotmat(other_rmat, value, "matrix.rotate(value)") == -1)
@@ -1014,7 +1014,7 @@ static PyObject *Matrix_decompose(MatrixObject *self)
return NULL;
}
if(!BaseMath_ReadCallback(self))
if(BaseMath_ReadCallback(self) == -1)
return NULL;
mat4_to_loc_rot_size(loc, rot, size, (float (*)[4])self->contigPtr);
@@ -1055,7 +1055,7 @@ static PyObject *Matrix_lerp(MatrixObject *self, PyObject *args)
return NULL;
}
if(!BaseMath_ReadCallback(self) || !BaseMath_ReadCallback(mat2))
if(BaseMath_ReadCallback(self) == -1 || BaseMath_ReadCallback(mat2) == -1)
return NULL;
/* TODO, different sized matrix */
@@ -1086,7 +1086,7 @@ static char Matrix_determinant_doc[] =
;
static PyObject *Matrix_determinant(MatrixObject *self)
{
if(!BaseMath_ReadCallback(self))
if(BaseMath_ReadCallback(self) == -1)
return NULL;
if(self->row_size != self->col_size){
@@ -1108,7 +1108,7 @@ static PyObject *Matrix_transpose(MatrixObject *self)
{
float t = 0.0f;
if(!BaseMath_ReadCallback(self))
if(BaseMath_ReadCallback(self) == -1)
return NULL;
if(self->row_size != self->col_size){
@@ -1156,7 +1156,7 @@ static PyObject *Matrix_zero(MatrixObject *self)
{
fill_vn(self->contigPtr, self->row_size * self->col_size, 0.0f);
if(!BaseMath_WriteCallback(self))
if(BaseMath_WriteCallback(self) == -1)
return NULL;
Py_RETURN_NONE;
@@ -1173,7 +1173,7 @@ static char Matrix_identity_doc[] =
;
static PyObject *Matrix_identity(MatrixObject *self)
{
if(!BaseMath_ReadCallback(self))
if(BaseMath_ReadCallback(self) == -1)
return NULL;
if(self->row_size != self->col_size){
@@ -1192,7 +1192,7 @@ static PyObject *Matrix_identity(MatrixObject *self)
unit_m4((float (*)[4])self->contigPtr);
}
if(!BaseMath_WriteCallback(self))
if(BaseMath_WriteCallback(self) == -1)
return NULL;
Py_RETURN_NONE;
@@ -1209,7 +1209,7 @@ static char Matrix_copy_doc[] =
;
static PyObject *Matrix_copy(MatrixObject *self)
{
if(!BaseMath_ReadCallback(self))
if(BaseMath_ReadCallback(self) == -1)
return NULL;
return (PyObject*)newMatrixObject((float (*))self->contigPtr, self->row_size, self->col_size, Py_NEW, Py_TYPE(self));
@@ -1222,7 +1222,7 @@ static PyObject *Matrix_repr(MatrixObject *self)
int x, y;
PyObject *rows[MATRIX_MAX_DIM]= {NULL};
if(!BaseMath_ReadCallback(self))
if(BaseMath_ReadCallback(self) == -1)
return NULL;
for(x = 0; x < self->row_size; x++){
@@ -1258,7 +1258,7 @@ static PyObject* Matrix_richcmpr(PyObject *a, PyObject *b, int op)
MatrixObject *matA= (MatrixObject*)a;
MatrixObject *matB= (MatrixObject*)b;
if(!BaseMath_ReadCallback(matA) || !BaseMath_ReadCallback(matB))
if(BaseMath_ReadCallback(matA) == -1 || BaseMath_ReadCallback(matB) == -1)
return NULL;
ok= ( (matA->col_size == matB->col_size) &&
@@ -1300,7 +1300,7 @@ static int Matrix_len(MatrixObject *self)
the wrapped vector gives direct access to the matrix data*/
static PyObject *Matrix_item(MatrixObject *self, int i)
{
if(!BaseMath_ReadCallback(self))
if(BaseMath_ReadCallback(self) == -1)
return NULL;
if(i < 0 || i >= self->row_size) {
@@ -1315,7 +1315,7 @@ static PyObject *Matrix_item(MatrixObject *self, int i)
static int Matrix_ass_item(MatrixObject *self, int i, PyObject *value)
{
float vec[4];
if(!BaseMath_ReadCallback(self))
if(BaseMath_ReadCallback(self) == -1)
return -1;
if(i >= self->row_size || i < 0){
@@ -1341,7 +1341,7 @@ static PyObject *Matrix_slice(MatrixObject *self, int begin, int end)
PyObject *tuple;
int count;
if(!BaseMath_ReadCallback(self))
if(BaseMath_ReadCallback(self) == -1)
return NULL;
CLAMP(begin, 0, self->row_size);
@@ -1363,7 +1363,7 @@ static int Matrix_ass_slice(MatrixObject *self, int begin, int end, PyObject *va
{
PyObject *value_fast= NULL;
if(!BaseMath_ReadCallback(self))
if(BaseMath_ReadCallback(self) == -1)
return -1;
CLAMP(begin, 0, self->row_size);
@@ -1420,7 +1420,7 @@ static PyObject *Matrix_add(PyObject *m1, PyObject *m2)
return NULL;
}
if(!BaseMath_ReadCallback(mat1) || !BaseMath_ReadCallback(mat2))
if(BaseMath_ReadCallback(mat1) == -1 || BaseMath_ReadCallback(mat2) == -1)
return NULL;
if(mat1->row_size != mat2->row_size || mat1->col_size != mat2->col_size){
@@ -1447,7 +1447,7 @@ static PyObject *Matrix_sub(PyObject *m1, PyObject *m2)
return NULL;
}
if(!BaseMath_ReadCallback(mat1) || !BaseMath_ReadCallback(mat2))
if(BaseMath_ReadCallback(mat1) == -1 || BaseMath_ReadCallback(mat2) == -1)
return NULL;
if(mat1->row_size != mat2->row_size || mat1->col_size != mat2->col_size){
@@ -1476,12 +1476,12 @@ static PyObject *Matrix_mul(PyObject * m1, PyObject * m2)
if(MatrixObject_Check(m1)) {
mat1 = (MatrixObject*)m1;
if(!BaseMath_ReadCallback(mat1))
if(BaseMath_ReadCallback(mat1) == -1)
return NULL;
}
if(MatrixObject_Check(m2)) {
mat2 = (MatrixObject*)m2;
if(!BaseMath_ReadCallback(mat2))
if(BaseMath_ReadCallback(mat2) == -1)
return NULL;
}
@@ -1530,7 +1530,7 @@ static PyObject *Matrix_mul(PyObject * m1, PyObject * m2)
}
static PyObject* Matrix_inv(MatrixObject *self)
{
if(!BaseMath_ReadCallback(self))
if(BaseMath_ReadCallback(self) == -1)
return NULL;
return Matrix_invert(self);
@@ -1671,7 +1671,7 @@ static PyObject *Matrix_getMedianScale(MatrixObject *self, void *UNUSED(closure)
{
float mat[3][3];
if(!BaseMath_ReadCallback(self))
if(BaseMath_ReadCallback(self) == -1)
return NULL;
/*must be 3-4 cols, 3-4 rows, square matrix*/
@@ -1687,7 +1687,7 @@ static PyObject *Matrix_getMedianScale(MatrixObject *self, void *UNUSED(closure)
static PyObject *Matrix_getIsNegative(MatrixObject *self, void *UNUSED(closure))
{
if(!BaseMath_ReadCallback(self))
if(BaseMath_ReadCallback(self) == -1)
return NULL;
/*must be 3-4 cols, 3-4 rows, square matrix*/