Welcome to mirror list, hosted at ThFree Co, Russian Federation.

git.blender.org/blender.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorCampbell Barton <ideasman42@gmail.com>2010-04-20 02:02:53 +0400
committerCampbell Barton <ideasman42@gmail.com>2010-04-20 02:02:53 +0400
commit4d39e0410288497455ace549a931d2b07fe49f86 (patch)
tree8a359045b118e7cd05b3446b23fa8c04eef19229 /source/blender/python/generic/mathutils_vector.c
parent4a993039674403815ab144cbaad80c805e9c36b4 (diff)
change mathutils 'repr' functions to closer match input
Diffstat (limited to 'source/blender/python/generic/mathutils_vector.c')
-rw-r--r--source/blender/python/generic/mathutils_vector.c33
1 files changed, 20 insertions, 13 deletions
diff --git a/source/blender/python/generic/mathutils_vector.c b/source/blender/python/generic/mathutils_vector.c
index e013a358393..1f51724c731 100644
--- a/source/blender/python/generic/mathutils_vector.c
+++ b/source/blender/python/generic/mathutils_vector.c
@@ -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);
- }
+
+ 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;
}
- strcat(str, "](vector)");
- return PyUnicode_FromString(str);
+ for(i = 0; i < self->size; i++)
+ Py_DECREF(axis[i]);
+
+ return ret;
}
+
/*---------------------SEQUENCE PROTOCOLS------------------------
----------------------------len(object)------------------------
sequence length*/