revert recent matrix multiplication patch:
authorCampbell Barton <ideasman42@gmail.com>
Thu, 21 Jul 2011 02:00:29 +0000 (02:00 +0000)
committerCampbell Barton <ideasman42@gmail.com>
Thu, 21 Jul 2011 02:00:29 +0000 (02:00 +0000)
 [#28032] Python Mathutils: Matrix Multiplication Error

Since they ended up reversing the order we better keep old code unless its proven to be incorrect.
also change Matrix.__repr__ function args to evaluate correctly (need to be inside a tuple).

source/blender/python/mathutils/mathutils_Matrix.c

index a7ed63776a573ebff3b79ddaf8f719001d356a4b..76a0994c3aa0a7744e8d55310dc738f52fc0fb8d 100644 (file)
@@ -1318,21 +1318,20 @@ static PyObject *Matrix_repr(MatrixObject *self)
                }
        }
        switch(self->row_size) {
-       case 2: return PyUnicode_FromFormat("Matrix(%R,\n"
-                                                                               "       %R)", rows[0], rows[1]);
+       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 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]);
+       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,
-                       "internal error!");
+       Py_FatalError("Matrix(): invalid row size!");
        return NULL;
 }
 
@@ -1587,26 +1586,24 @@ static PyObject *Matrix_mul(PyObject *m1, PyObject *m2)
 
        if(mat1 && mat2) {
                /*MATRIX * MATRIX*/
-               if(mat2->row_size != mat1->col_size){
-                       PyErr_SetString(PyExc_ValueError,
-                                       "Matrix multiplication: "
-                                       "matrix A rowsize must equal matrix B colsize");
-                       return NULL;
-               }
-               else {
-                       float mat[16]= {0.0f};
-                       int x, y, z;
-
-                       for(x = 0; x < mat2->row_size; x++) {
-                               for(y = 0; y < mat1->col_size; y++) {
-                                       for(z = 0; z < mat1->row_size; z++) {
-                                               mat[x * mat2->col_size + y] += (mat2->matrix[x][z] * mat1->matrix[z][y]);
-                                       }
+               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};
+               double dot = 0.0f;
+               int x, y, z;
+
+               for(x = 0; x < mat2->row_size; x++) {
+                       for(y = 0; y < mat1->col_size; y++) {
+                               for(z = 0; z < mat1->row_size; z++) {
+                                       dot += (mat1->matrix[z][y] * mat2->matrix[x][z]);
                                }
+                               mat[((x * mat1->col_size) + y)] = (float)dot;
+                               dot = 0.0f;
                        }
-
-                       return newMatrixObject(mat, mat1->row_size, mat2->col_size, Py_NEW, Py_TYPE(mat1));
                }
+
+               return newMatrixObject(mat, mat2->row_size, mat1->col_size, Py_NEW, Py_TYPE(mat1));
        }
        else if(mat2) {
                /*FLOAT/INT * MATRIX */