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-11-12 05:50:57 +0300
committerCampbell Barton <ideasman42@gmail.com>2010-11-12 05:50:57 +0300
commit4f4bd275129f12ef3a8f021d95a5423985752f7b (patch)
treeb54a11bc5644b22b4f25ec965a47c5c73be1cfdd /source/blender/python
parenta34f525a21eff2ec1f5691ce3ec2056408bacd5d (diff)
bugfix [#24665] mathutils.Matrix initialization is counter-intuitive and generates bugs
was printing transposed, also nicer printing. >>> from mathutils import Matrix >>> Matrix() Matrix((1.0, 0.0, 0.0, 0.0), (0.0, 1.0, 0.0, 0.0), (0.0, 0.0, 1.0, 0.0), (0.0, 0.0, 0.0, 1.0)) was... Matrix((1.000000, 0.000000, 0.000000, 0.000000), (0.000000, 1.000000, 0.000000, 0.000000), (0.000000, 0.000000, 1.000000, 0.000000), (0.000000, 0.000000, 0.000000, 1.000000))
Diffstat (limited to 'source/blender/python')
-rw-r--r--source/blender/python/generic/mathutils_matrix.c35
1 files changed, 21 insertions, 14 deletions
diff --git a/source/blender/python/generic/mathutils_matrix.c b/source/blender/python/generic/mathutils_matrix.c
index 4c481e799e2..34a31768b69 100644
--- a/source/blender/python/generic/mathutils_matrix.c
+++ b/source/blender/python/generic/mathutils_matrix.c
@@ -1193,28 +1193,35 @@ PyObject *Matrix_copy(MatrixObject *self)
static PyObject *Matrix_repr(MatrixObject * self)
{
int x, y;
- char str[1024]="Matrix((", *str_p;
+ PyObject *rows[MATRIX_MAX_DIM]= {0};
if(!BaseMath_ReadCallback(self))
return NULL;
- str_p= &str[8];
-
- for(x = 0; x < self->colSize; x++){
- for(y = 0; y < (self->rowSize - 1); y++) {
- str_p += sprintf(str_p, "%f, ", self->matrix[y][x]);
- }
- if(x < (self->colSize-1)){
- str_p += sprintf(str_p, "%f), (", self->matrix[y][x]);
- }
- else{
- str_p += sprintf(str_p, "%f)", self->matrix[y][x]);
+ for(x = 0; x < self->rowSize; x++){
+ rows[x]= PyTuple_New(self->rowSize);
+ for(y = 0; y < self->colSize; y++) {
+ PyTuple_SET_ITEM(rows[x], y, PyFloat_FromDouble(self->matrix[x][y]));
}
}
- strcat(str_p, ")");
+ switch(self->rowSize) {
+ 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 4: return PyUnicode_FromFormat("Matrix(%R,\n"
+ " %R,\n"
+ " %R,\n"
+ " %R)", rows[0], rows[1], rows[2], rows[3]);
+ }
- return PyUnicode_FromString(str);
+ PyErr_SetString(PyExc_RuntimeError, "invalid matrix size");
+ return NULL;
}
+
/*------------------------tp_richcmpr*/
/*returns -1 execption, 0 false, 1 true*/
static PyObject* Matrix_richcmpr(PyObject *objectA, PyObject *objectB, int comparison_type)