[Bf-blender-cvs] SVN commit: /data/svn/bf-blender [33030] trunk/blender/source/blender/ python/generic/mathutils_matrix.c: bugfix [#24665] mathutils. Matrix initialization is counter-intuitive and generates bugs
Campbell Barton
ideasman42 at gmail.com
Fri Nov 12 03:50:58 CET 2010
Revision: 33030
http://projects.blender.org/plugins/scmsvn/viewcvs.php?view=rev&root=bf-blender&revision=33030
Author: campbellbarton
Date: 2010-11-12 03:50:57 +0100 (Fri, 12 Nov 2010)
Log Message:
-----------
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))
Modified Paths:
--------------
trunk/blender/source/blender/python/generic/mathutils_matrix.c
Modified: trunk/blender/source/blender/python/generic/mathutils_matrix.c
===================================================================
--- trunk/blender/source/blender/python/generic/mathutils_matrix.c 2010-11-12 01:38:18 UTC (rev 33029)
+++ trunk/blender/source/blender/python/generic/mathutils_matrix.c 2010-11-12 02:50:57 UTC (rev 33030)
@@ -1193,28 +1193,35 @@
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]);
+ 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]));
}
- 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]);
- }
}
- strcat(str_p, ")");
+ switch(self->rowSize) {
+ case 2: return PyUnicode_FromFormat("Matrix(%R,\n"
+ " %R)", rows[0], rows[1]);
- return PyUnicode_FromString(str);
+ 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]);
+ }
+
+ 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)
More information about the Bf-blender-cvs
mailing list