change mathutils 'repr' functions to closer match input

This commit is contained in:
2010-04-19 22:02:53 +00:00
parent 4a99303967
commit 4d39e04102
6 changed files with 70 additions and 36 deletions

View File

@@ -104,13 +104,22 @@ static PyObject *Color_copy(ColorObject * self, PyObject *args)
//print the object to screen
static PyObject *Color_repr(ColorObject * self)
{
char str[64];
PyObject *r, *g, *b, *ret;
if(!BaseMath_ReadCallback(self))
return NULL;
sprintf(str, "[%.6f, %.6f, %.6f](color)", self->col[0], self->col[1], self->col[2]);
return PyUnicode_FromString(str);
r= PyFloat_FromDouble(self->col[0]);
g= PyFloat_FromDouble(self->col[1]);
b= PyFloat_FromDouble(self->col[2]);
ret= PyUnicode_FromFormat("Color(%R, %R, %R)", r, g, b);
Py_DECREF(r);
Py_DECREF(g);
Py_DECREF(b);
return ret;
}
//------------------------tp_richcmpr
//returns -1 execption, 0 false, 1 true

View File

@@ -314,13 +314,22 @@ static PyObject *Euler_copy(EulerObject * self, PyObject *args)
//print the object to screen
static PyObject *Euler_repr(EulerObject * self)
{
char str[64];
PyObject *x, *y, *z, *ret;
if(!BaseMath_ReadCallback(self))
return NULL;
sprintf(str, "[%.6f, %.6f, %.6f](euler)", self->eul[0], self->eul[1], self->eul[2]);
return PyUnicode_FromString(str);
x= PyFloat_FromDouble(self->eul[0]);
y= PyFloat_FromDouble(self->eul[1]);
z= PyFloat_FromDouble(self->eul[2]);
ret= PyUnicode_FromFormat("Euler(%R, %R, %R)", x, y, z);
Py_DECREF(x);
Py_DECREF(y);
Py_DECREF(z);
return ret;
}
//------------------------tp_richcmpr
//returns -1 execption, 0 false, 1 true

View File

@@ -723,27 +723,25 @@ PyObject *Matrix_copy(MatrixObject * self)
static PyObject *Matrix_repr(MatrixObject * self)
{
int x, y;
char buffer[48], str[1024];
char str[1024]="Matrix((", *str_p;
if(!BaseMath_ReadCallback(self))
return NULL;
BLI_strncpy(str,"",1024);
str_p= &str[8];
for(x = 0; x < self->colSize; x++){
sprintf(buffer, "[");
strcat(str,buffer);
for(y = 0; y < (self->rowSize - 1); y++) {
sprintf(buffer, "%.6f, ", self->matrix[y][x]);
strcat(str,buffer);
str_p += sprintf(str_p, "%f, ", self->matrix[y][x]);
}
if(x < (self->colSize-1)){
sprintf(buffer, "%.6f](matrix [row %d])\n", self->matrix[y][x], x);
strcat(str,buffer);
}else{
sprintf(buffer, "%.6f](matrix [row %d])", self->matrix[y][x], x);
strcat(str,buffer);
str_p += sprintf(str_p, "%f), (", self->matrix[y][x]);
}
else{
str_p += sprintf(str_p, "%f)", self->matrix[y][x]);
}
}
strcat(str_p, ")");
return PyUnicode_FromString(str);
}

View File

@@ -351,13 +351,24 @@ static PyObject *Quaternion_copy(QuaternionObject * self)
//print the object to screen
static PyObject *Quaternion_repr(QuaternionObject * self)
{
char str[64];
PyObject *w, *x, *y, *z, *ret;
if(!BaseMath_ReadCallback(self))
return NULL;
sprintf(str, "[%.6f, %.6f, %.6f, %.6f](quaternion)", self->quat[0], self->quat[1], self->quat[2], self->quat[3]);
return PyUnicode_FromString(str);
w= PyFloat_FromDouble(self->quat[0]);
x= PyFloat_FromDouble(self->quat[1]);
y= PyFloat_FromDouble(self->quat[2]);
z= PyFloat_FromDouble(self->quat[3]);
ret= PyUnicode_FromFormat("Quaternion(%R, %R, %R, %R)", w, x, y, z);
Py_DECREF(w);
Py_DECREF(x);
Py_DECREF(y);
Py_DECREF(z);
return ret;
}
//------------------------tp_richcmpr
//returns -1 execption, 0 false, 1 true

View File

@@ -704,26 +704,33 @@ static PyObject *Vector_copy(VectorObject * self)
print the object to screen */
static PyObject *Vector_repr(VectorObject * self)
{
PyObject *axis[4], *ret;
int i;
char buffer[48], str[1024];
if(!BaseMath_ReadCallback(self))
return NULL;
BLI_strncpy(str,"[",1024);
for(i = 0; i < self->size; i++){
if(i < (self->size - 1)){
sprintf(buffer, "%.6f, ", self->vec[i]);
strcat(str,buffer);
}else{
sprintf(buffer, "%.6f", self->vec[i]);
strcat(str,buffer);
}
}
strcat(str, "](vector)");
return PyUnicode_FromString(str);
for(i = 0; i < self->size; i++)
axis[i] = PyFloat_FromDouble(self->vec[i]);
switch(self->size) {
case 2:
ret= PyUnicode_FromFormat("Vector(%R, %R)", axis[0], axis[1]);
break;
case 3:
ret= PyUnicode_FromFormat("Vector(%R, %R, %R)", axis[0], axis[1], axis[2]);
break;
case 4:
ret= PyUnicode_FromFormat("Vector(%R, %R, %R, %R)", axis[0], axis[1], axis[2], axis[3]);
break;
}
for(i = 0; i < self->size; i++)
Py_DECREF(axis[i]);
return ret;
}
/*---------------------SEQUENCE PROTOCOLS------------------------
----------------------------len(object)------------------------
sequence length*/

View File

@@ -1346,7 +1346,7 @@ static int prop_subscript_ass_array_slice(PointerRNA *ptr, PropertyRNA *prop, in
return -1;
}
if(!(value=PySequence_Fast(value_orig, "bpy_prop_array[slice] = value: type is not a sequence"))) {
if(!(value=PySequence_Fast(value_orig, "bpy_prop_array[slice] = value: assignment is not a sequence type"))) {
return -1;
}