add back mathutils Matrix() * Vector(), this is row_vector multiplication.
authorCampbell Barton <ideasman42@gmail.com>
Mon, 19 Sep 2011 14:29:21 +0000 (14:29 +0000)
committerCampbell Barton <ideasman42@gmail.com>
Mon, 19 Sep 2011 14:29:21 +0000 (14:29 +0000)
some minor changes to exception messages.

source/blender/python/mathutils/mathutils_Matrix.c
source/blender/python/mathutils/mathutils_Vector.c

index 2da96dc..a2a1560 100644 (file)
@@ -119,7 +119,7 @@ static PyObject *Matrix_new(PyTypeObject *type, PyObject *args, PyObject *kwds)
 {
        if(kwds && PyDict_Size(kwds)) {
                PyErr_SetString(PyExc_TypeError,
-                               "mathutils.Matrix(): "
+                               "Matrix(): "
                                "takes no keyword args");
                return NULL;
        }
@@ -155,7 +155,7 @@ static PyObject *Matrix_new(PyTypeObject *type, PyObject *args, PyObject *kwds)
 
        /* will overwrite error */
        PyErr_SetString(PyExc_TypeError,
-                       "mathutils.Matrix(): "
+                       "Matrix(): "
                        "expects no args or 2-4 numeric sequences");
        return NULL;
 }
@@ -216,7 +216,7 @@ static PyObject *C_Matrix_Rotation(PyObject *cls, PyObject *args)
 
        if(!PyArg_ParseTuple(args, "di|O", &angle, &matSize, &vec)) {
                PyErr_SetString(PyExc_TypeError,
-                               "mathutils.RotationMatrix(angle, size, axis): "
+                               "Matrix.Rotation(angle, size, axis): "
                                "expected float int and a string or vector");
                return NULL;
        }
@@ -225,7 +225,7 @@ static PyObject *C_Matrix_Rotation(PyObject *cls, PyObject *args)
                axis= _PyUnicode_AsString((PyObject *)vec);
                if(axis==NULL || axis[0]=='\0' || axis[1]!='\0' || axis[0] < 'X' || axis[0] > 'Z') {
                        PyErr_SetString(PyExc_ValueError,
-                                       "mathutils.RotationMatrix(): "
+                                       "Matrix.Rotation(): "
                                        "3rd argument axis value must be a 3D vector "
                                        "or a string in 'X', 'Y', 'Z'");
                        return NULL;
@@ -240,19 +240,19 @@ static PyObject *C_Matrix_Rotation(PyObject *cls, PyObject *args)
 
        if(matSize != 2 && matSize != 3 && matSize != 4) {
                PyErr_SetString(PyExc_ValueError,
-                               "mathutils.RotationMatrix(): "
+                               "Matrix.Rotation(): "
                                "can only return a 2x2 3x3 or 4x4 matrix");
                return NULL;
        }
        if(matSize == 2 && (vec != NULL)) {
                PyErr_SetString(PyExc_ValueError,
-                               "mathutils.RotationMatrix(): "
+                               "Matrix.Rotation(): "
                                "cannot create a 2x2 rotation matrix around arbitrary axis");
                return NULL;
        }
        if((matSize == 3 || matSize == 4) && (axis == NULL) && (vec == NULL)) {
                PyErr_SetString(PyExc_ValueError,
-                               "mathutils.RotationMatrix(): "
+                               "Matrix.Rotation(): "
                                "axis of rotation for 3d and 4d matrices is required");
                return NULL;
        }
@@ -261,7 +261,7 @@ static PyObject *C_Matrix_Rotation(PyObject *cls, PyObject *args)
        if(vec) {
                float tvec[3];
 
-               if (mathutils_array_parse(tvec, 3, 3, vec, "mathutils.RotationMatrix(angle, size, axis), invalid 'axis' arg") == -1)
+               if (mathutils_array_parse(tvec, 3, 3, vec, "Matrix.Rotation(angle, size, axis), invalid 'axis' arg") == -1)
                        return NULL;
 
                axis_angle_to_mat3((float (*)[3])mat, tvec, angle);
@@ -428,7 +428,7 @@ static PyObject *C_Matrix_OrthoProjection(PyObject *cls, PyObject *args)
        }
        if(matSize != 2 && matSize != 3 && matSize != 4) {
                PyErr_SetString(PyExc_ValueError,
-                               "mathutils.Matrix.OrthoProjection(): "
+                               "Matrix.OrthoProjection(): "
                                "can only return a 2x2 3x3 or 4x4 matrix");
                return NULL;
        }
@@ -445,7 +445,7 @@ static PyObject *C_Matrix_OrthoProjection(PyObject *cls, PyObject *args)
                        }
                        else {
                                PyErr_Format(PyExc_ValueError,
-                                            "mathutils.Matrix.OrthoProjection(): "
+                                            "Matrix.OrthoProjection(): "
                                             "unknown plane, expected: X, Y, not '%.200s'",
                                             plane);
                                return NULL;
@@ -466,7 +466,7 @@ static PyObject *C_Matrix_OrthoProjection(PyObject *cls, PyObject *args)
                        }
                        else {
                                PyErr_Format(PyExc_ValueError,
-                                            "mathutils.Matrix.OrthoProjection(): "
+                                            "Matrix.OrthoProjection(): "
                                             "unknown plane, expected: XY, XZ, YZ, not '%.200s'",
                                             plane);
                                return NULL;
@@ -545,7 +545,7 @@ static PyObject *C_Matrix_Shear(PyObject *cls, PyObject *args)
        }
        if(matSize != 2 && matSize != 3 && matSize != 4) {
                PyErr_SetString(PyExc_ValueError,
-                               "mathutils.Matrix.Shear(): "
+                               "Matrix.Shear(): "
                                "can only return a 2x2 3x3 or 4x4 matrix");
                return NULL;
        }
@@ -555,7 +555,7 @@ static PyObject *C_Matrix_Shear(PyObject *cls, PyObject *args)
 
                if(factor==-1.0f && PyErr_Occurred()) {
                        PyErr_SetString(PyExc_TypeError,
-                                       "mathutils.Matrix.Shear(): "
+                                       "Matrix.Shear(): "
                                        "the factor to be a float");
                        return NULL;
                }
@@ -604,7 +604,7 @@ static PyObject *C_Matrix_Shear(PyObject *cls, PyObject *args)
                }
                else {
                        PyErr_SetString(PyExc_ValueError,
-                                       "mathutils.Matrix.Shear(): "
+                                       "Matrix.Shear(): "
                                        "expected: X, Y, XY, XZ, YZ");
                        return NULL;
                }
@@ -663,7 +663,7 @@ static PyObject *Matrix_to_quaternion(MatrixObject *self)
        /*must be 3-4 cols, 3-4 rows, square matrix*/
        if((self->col_size < 3) || (self->row_size < 3) || (self->col_size != self->row_size)) {
                PyErr_SetString(PyExc_ValueError,
-                               "matrix.to_quat(): "
+                               "Matrix.to_quat(): "
                                "inappropriate matrix size - expects 3x3 or 4x4 matrix");
                return NULL;
        }
@@ -727,13 +727,13 @@ static PyObject *Matrix_to_euler(MatrixObject *self, PyObject *args)
        }
        else {
                PyErr_SetString(PyExc_ValueError,
-                               "matrix.to_euler(): "
+                               "Matrix.to_euler(): "
                                "inappropriate matrix size - expects 3x3 or 4x4 matrix");
                return NULL;
        }
 
        if(order_str) {
-               order= euler_order_from_string(order_str, "matrix.to_euler()");
+               order= euler_order_from_string(order_str, "Matrix.to_euler()");
 
                if(order == -1)
                        return NULL;
@@ -762,11 +762,13 @@ static PyObject *Matrix_resize_4x4(MatrixObject *self)
 
        if(self->wrapped==Py_WRAP){
                PyErr_SetString(PyExc_TypeError,
+                               "Matrix.resize_4x4(): "
                                "cannot resize wrapped data - make a copy and resize that");
                return NULL;
        }
        if(self->cb_user){
                PyErr_SetString(PyExc_TypeError,
+                               "Matrix.resize_4x4(): "
                                "cannot resize owned data - make a copy and resize that");
                return NULL;
        }
@@ -774,7 +776,8 @@ static PyObject *Matrix_resize_4x4(MatrixObject *self)
        self->contigPtr = PyMem_Realloc(self->contigPtr, (sizeof(float) * 16));
        if(self->contigPtr == NULL) {
                PyErr_SetString(PyExc_MemoryError,
-                               "matrix.resize_4x4(): problem allocating pointer space");
+                               "Matrix.resize_4x4(): "
+                               "problem allocating pointer space");
                return NULL;
        }
        /*set row pointers*/
@@ -835,7 +838,8 @@ static PyObject *Matrix_to_4x4(MatrixObject *self)
        /* TODO, 2x2 matrix */
 
        PyErr_SetString(PyExc_TypeError,
-                       "matrix.to_4x4(): inappropriate matrix size");
+                       "Matrix.to_4x4(): "
+                       "inappropriate matrix size");
        return NULL;
 }
 
@@ -856,7 +860,7 @@ static PyObject *Matrix_to_3x3(MatrixObject *self)
 
        if((self->col_size < 3) || (self->row_size < 3)) {
                PyErr_SetString(PyExc_TypeError,
-                               "matrix.to_3x3(): inappropriate matrix size");
+                               "Matrix.to_3x3(): inappropriate matrix size");
                return NULL;
        }
 
@@ -880,7 +884,7 @@ static PyObject *Matrix_to_translation(MatrixObject *self)
 
        if((self->col_size < 3) || self->row_size < 4){
                PyErr_SetString(PyExc_TypeError,
-                               "matrix.to_translation(): "
+                               "Matrix.to_translation(): "
                                "inappropriate matrix size");
                return NULL;
        }
@@ -910,7 +914,7 @@ static PyObject *Matrix_to_scale(MatrixObject *self)
        /*must be 3-4 cols, 3-4 rows, square matrix*/
        if((self->col_size < 3) || (self->row_size < 3)) {
                PyErr_SetString(PyExc_TypeError,
-                               "matrix.to_scale(): "
+                               "Matrix.to_scale(): "
                                "inappropriate matrix size, 3x3 minimum size");
                return NULL;
        }
@@ -946,7 +950,7 @@ static PyObject *Matrix_invert(MatrixObject *self)
 
        if(self->row_size != self->col_size){
                PyErr_SetString(PyExc_TypeError,
-                               "matrix.invert(ed): "
+                               "Matrix.invert(ed): "
                                "only square matrices are supported");
                return NULL;
        }
@@ -982,6 +986,7 @@ static PyObject *Matrix_invert(MatrixObject *self)
        }
        else {
                PyErr_SetString(PyExc_ValueError,
+                               "Matrix.invert(ed): "
                                "matrix does not have an inverse");
                return NULL;
        }
@@ -1027,7 +1032,8 @@ static PyObject *Matrix_rotate(MatrixObject *self, PyObject *value)
 
        if(self->col_size != 3 || self->row_size != 3) {
                PyErr_SetString(PyExc_TypeError,
-                               "Matrix must have 3x3 dimensions");
+                               "Matrix.rotate(): "
+                               "must have 3x3 dimensions");
                return NULL;
        }
 
@@ -1059,7 +1065,7 @@ static PyObject *Matrix_decompose(MatrixObject *self)
 
        if(self->col_size != 4 || self->row_size != 4) {
                PyErr_SetString(PyExc_TypeError,
-                               "matrix.decompose(): "
+                               "Matrix.decompose(): "
                                "inappropriate matrix size - expects 4x4 matrix");
                return NULL;
        }
@@ -1102,7 +1108,7 @@ static PyObject *Matrix_lerp(MatrixObject *self, PyObject *args)
 
        if(self->row_size != mat2->row_size || self->col_size != mat2->col_size) {
                PyErr_SetString(PyExc_ValueError,
-                               "matrix.lerp(): "
+                               "Matrix.lerp(): "
                                "expects both matrix objects of the same dimensions");
                return NULL;
        }
@@ -1119,7 +1125,7 @@ static PyObject *Matrix_lerp(MatrixObject *self, PyObject *args)
        }
        else {
                PyErr_SetString(PyExc_ValueError,
-                               "matrix.lerp(): "
+                               "Matrix.lerp(): "
                                "only 3x3 and 4x4 matrices supported");
                return NULL;
        }
@@ -1145,7 +1151,7 @@ static PyObject *Matrix_determinant(MatrixObject *self)
 
        if(self->row_size != self->col_size){
                PyErr_SetString(PyExc_TypeError,
-                               "matrix.determinant: "
+                               "Matrix.determinant(): "
                                "only square matrices are supported");
                return NULL;
        }
@@ -1169,7 +1175,7 @@ static PyObject *Matrix_transpose(MatrixObject *self)
 
        if(self->row_size != self->col_size){
                PyErr_SetString(PyExc_TypeError,
-                               "matrix.transpose(d): "
+                               "Matrix.transpose(d): "
                                "only square matrices are supported");
                return NULL;
        }
@@ -1238,7 +1244,7 @@ static PyObject *Matrix_identity(MatrixObject *self)
 
        if(self->row_size != self->col_size){
                PyErr_SetString(PyExc_TypeError,
-                               "matrix.identity: "
+                               "Matrix.identity(): "
                                "only square matrices are supported");
                return NULL;
        }
@@ -1771,7 +1777,7 @@ static PyObject *Matrix_median_scale_get(MatrixObject *self, void *UNUSED(closur
        /*must be 3-4 cols, 3-4 rows, square matrix*/
        if((self->col_size < 3) || (self->row_size < 3)) {
                PyErr_SetString(PyExc_AttributeError,
-                               "matrix.median_scale: "
+                               "Matrix.median_scale: "
                                "inappropriate matrix size, 3x3 minimum");
                return NULL;
        }
@@ -1793,7 +1799,7 @@ static PyObject *Matrix_is_negative_get(MatrixObject *self, void *UNUSED(closure
                return PyBool_FromLong(is_negative_m3((float (*)[3])self->contigPtr));
        else {
                PyErr_SetString(PyExc_AttributeError,
-                               "matrix.is_negative: "
+                               "Matrix.is_negative: "
                                "inappropriate matrix size - expects 3x3 or 4x4 matrix");
                return NULL;
        }
@@ -1811,7 +1817,7 @@ static PyObject *Matrix_is_orthogonal_get(MatrixObject *self, void *UNUSED(closu
                return PyBool_FromLong(is_orthogonal_m3((float (*)[3])self->contigPtr));
        else {
                PyErr_SetString(PyExc_AttributeError,
-                               "matrix.is_orthogonal: "
+                               "Matrix.is_orthogonal: "
                                "inappropriate matrix size - expects 3x3 or 4x4 matrix");
                return NULL;
        }
index 56c1334..b7cbbde 100644 (file)
@@ -48,6 +48,7 @@
 
 static PyObject *Vector_copy(VectorObject *self);
 static PyObject *Vector_to_tuple_ext(VectorObject *self, int ndigits);
+static int row_vector_multiplication(float rvec[MAX_DIMENSIONS], VectorObject *vec, MatrixObject *mat);
 
 /* Supports 2D, 3D, and 4D vector objects both int and float values
  * accepted. Mixed float and int values accepted. Ints are parsed to float
@@ -1159,28 +1160,16 @@ static PyObject *Vector_mul(PyObject *v1, PyObject *v2)
        }
        else if (vec1) {
                if (MatrixObject_Check(v2)) {
-
-/* ------ to be removed ------*/
-#if 1
-                       PyErr_SetString(PyExc_ValueError,
-                                       "(Vector * Matrix) is now removed, reverse the "
-                                       "order (promoted to an Error for Debug builds)");
-                       return NULL;
-#else
-
                        /* VEC * MATRIX */
-                       /* this is deprecated!, use the reverse instead */
                        float tvec[MAX_DIMENSIONS];
 
                        if(BaseMath_ReadCallback((MatrixObject *)v2) == -1)
                                return NULL;
-                       if(column_vector_multiplication(tvec, vec1, (MatrixObject*)v2) == -1) {
+                       if(row_vector_multiplication(tvec, vec1, (MatrixObject*)v2) == -1) {
                                return NULL;
                        }
 
                        return newVectorObject(tvec, vec1->size, Py_NEW, Py_TYPE(vec1));
-#endif
-/* ------ to be removed ------*/
                }
                else if (QuaternionObject_Check(v2)) {
                        /* VEC * QUAT */
@@ -2219,20 +2208,19 @@ if len(unique) != len(items):
        print "ERROR"
 */
 
-#if 0
-//ROW VECTOR Multiplication - Vector X Matrix
-//[x][y][z] *  [1][4][7]
-//             [2][5][8]
-//             [3][6][9]
-//vector/matrix multiplication IS NOT COMMUTATIVE!!!!
-static int row_vector_multiplication(float rvec[4], VectorObject* vec, MatrixObject * mat)
+/* ROW VECTOR Multiplication - Vector X Matrix
+ * [x][y][z] *  [1][4][7]
+ *             [2][5][8]
+ *             [3][6][9]
+ * vector/matrix multiplication IS NOT COMMUTATIVE!!!! */
+static int row_vector_multiplication(float rvec[MAX_DIMENSIONS], VectorObject *vec, MatrixObject *mat)
 {
-       float vec_cpy[4];
+       float vec_cpy[MAX_DIMENSIONS];
        double dot = 0.0f;
-       int x, y, z = 0, vec_size = vec->size;
+       int x, y, z= 0, vec_size= vec->size;
 
-       if(mat->colSize != vec_size){
-               if(mat->colSize == 4 && vec_size != 3){
+       if(mat->col_size != vec_size){
+               if(mat->col_size == 4 && vec_size != 3){
                        PyErr_SetString(PyExc_ValueError,
                                        "vector * matrix: matrix column size "
                                        "and the vector size must be the same");
@@ -2247,11 +2235,11 @@ static int row_vector_multiplication(float rvec[4], VectorObject* vec, MatrixObj
                return -1;
 
        memcpy(vec_cpy, vec->vec, vec_size * sizeof(float));
-
+printf("asasas\n");
        rvec[3] = 1.0f;
        //muliplication
-       for(x = 0; x < mat->rowSize; x++) {
-               for(y = 0; y < mat->colSize; y++) {
+       for(x = 0; x < mat->row_size; x++) {
+               for(y = 0; y < mat->col_size; y++) {
                        dot += mat->matrix[x][y] * vec_cpy[y];
                }
                rvec[z++] = (float)dot;
@@ -2259,7 +2247,6 @@ static int row_vector_multiplication(float rvec[4], VectorObject* vec, MatrixObj
        }
        return 0;
 }
-#endif
 
 /*----------------------------Vector.negate() -------------------- */
 PyDoc_STRVAR(Vector_negate_doc,