deprecate multiplication orders:
authorCampbell Barton <ideasman42@gmail.com>
Mon, 25 Jul 2011 01:44:19 +0000 (01:44 +0000)
committerCampbell Barton <ideasman42@gmail.com>
Mon, 25 Jul 2011 01:44:19 +0000 (01:44 +0000)
 vector * matrix
 vector *= matrix
 vector * quaternion
 vector *= quaternion

Use the reverse order instead, enable WITH_ASSERT_ABORT in cmake to promote the warnings into errors.

release/scripts/startup/bl_operators/uvcalc_smart_project.py
source/blender/python/mathutils/mathutils.h
source/blender/python/mathutils/mathutils_Matrix.c
source/blender/python/mathutils/mathutils_Quaternion.c
source/blender/python/mathutils/mathutils_Vector.c

index 9c3be84b807e29b94ce70eed87aef2adcc8b73ef..851f33bde115091a6d0b89c6ca9ca783d6b92e8b 100644 (file)
@@ -243,7 +243,7 @@ def testNewVecLs2DRotIsBetter(vecs, mat=-1, bestAreaSoFar = -1):
 
         # Do this allong the way
         if mat != -1:
-            v = vecs[i] = v*mat
+            v = vecs[i] = mat * v
             x= v.x
             y= v.y
             if x<minx: minx= x
@@ -1064,7 +1064,7 @@ def main(context,
                 f_uv = f.uv
                 for j, v in enumerate(f.v):
                     # XXX - note, between mathutils in 2.4 and 2.5 the order changed.
-                    f_uv[j][:] = (v.co * MatQuat).xy
+                    f_uv[j][:] = (MatQuat * v.co).xy
 
 
         if USER_SHARE_SPACE:
index 7454cfe78b3de481e0df632f7a5e04d1c9b0d67a..b798b5e7003ef85a5306e525fe74c8c75f02e346 100644 (file)
@@ -108,4 +108,6 @@ int _BaseMathObject_WriteIndexCallback(BaseMathObject *self, int index);
 int mathutils_array_parse(float *array, int array_min, int array_max, PyObject *value, const char *error_prefix);
 int mathutils_any_to_rotmat(float rmat[3][3], PyObject *value, const char *error_prefix);
 
+int column_vector_multiplication(float rvec[4], VectorObject *vec, MatrixObject *mat);
+
 #endif /* MATHUTILS_H */
index 76a0994c3aa0a7744e8d55310dc738f52fc0fb8d..3953171f263d7834c9c3a30e90811c101c599a79 100644 (file)
@@ -1612,8 +1612,20 @@ static PyObject *Matrix_mul(PyObject *m1, PyObject *m2)
                }
        }
        else if(mat1) {
+               /*VEC * MATRIX */
+               if(VectorObject_Check(m2)) {
+                       VectorObject *vec2= (VectorObject *)m2;
+                       float tvec[4];
+                       if(BaseMath_ReadCallback(vec2) == -1)
+                               return NULL;
+                       if(column_vector_multiplication(tvec, vec2, mat1) == -1) {
+                               return NULL;
+                       }
+
+                       return newVectorObject(tvec, vec2->size, Py_NEW, Py_TYPE(m2));
+               }
                /*FLOAT/INT * MATRIX */
-               if (((scalar= PyFloat_AsDouble(m2)) == -1.0f && PyErr_Occurred())==0) {
+               else if (((scalar= PyFloat_AsDouble(m2)) == -1.0f && PyErr_Occurred())==0) {
                        return matrix_mul_float(mat1, scalar);
                }
        }
index 3b05b9a250b91674c15d6f52019a9783b0a1b7bd..2be258a1ef0e73a2778f08b1faaa67b61686badb 100644 (file)
@@ -753,8 +753,30 @@ static PyObject *Quaternion_mul(PyObject *q1, PyObject *q2)
                        return quat_mul_float(quat2, scalar);
                }
        }
-       else if (quat1) { /* QUAT*FLOAT */
-               if((((scalar= PyFloat_AsDouble(q2)) == -1.0f && PyErr_Occurred())==0)) {
+       else if (quat1) {
+               /* QUAT * VEC */
+               if (VectorObject_Check(q2)) {
+                       VectorObject *vec2 = (VectorObject *)q2;
+                       float tvec[3];
+
+                       if(vec2->size != 3) {
+                               PyErr_SetString(PyExc_ValueError,
+                                                               "Vector multiplication: "
+                                                               "only 3D vector rotations (with quats) "
+                                               "currently supported");
+                               return NULL;
+                       }
+                       if(BaseMath_ReadCallback(vec2) == -1) {
+                               return NULL;
+                       }
+
+                       copy_v3_v3(tvec, vec2->vec);
+                       mul_qt_v3(quat1->quat, tvec);
+
+                       return newVectorObject(tvec, 3, Py_NEW, Py_TYPE(vec2));
+               }
+               /* QUAT * FLOAT */
+               else if((((scalar= PyFloat_AsDouble(q2)) == -1.0f && PyErr_Occurred())==0)) {
                        return quat_mul_float(quat1, scalar);
                }
        }
index e2c958adaa5a348b709988a58f95f01696a10165..a954c07c98d311aad85295fff70a79b723017024 100644 (file)
@@ -37,6 +37,8 @@
 #include "BLI_math.h"
 #include "BLI_utildefines.h"
 
+extern void PyC_LineSpit(void);
+
 #define MAX_DIMENSIONS 4
 
 /* Swizzle axes get packed into a single value that is used as a closure. Each
@@ -1081,7 +1083,7 @@ static PyObject *Vector_isub(PyObject *v1, PyObject *v2)
  * note: vector/matrix multiplication IS NOT COMMUTATIVE!!!!
  * note: assume read callbacks have been done first.
  */
-static int column_vector_multiplication(float rvec[MAX_DIMENSIONS], VectorObject* vec, MatrixObject * mat)
+int column_vector_multiplication(float rvec[MAX_DIMENSIONS], VectorObject* vec, MatrixObject * mat)
 {
        float vec_cpy[MAX_DIMENSIONS];
        double dot = 0.0f;
@@ -1159,8 +1161,29 @@ static PyObject *Vector_mul(PyObject *v1, PyObject *v2)
        }
        else if (vec1) {
                if (MatrixObject_Check(v2)) {
+                       extern void PyC_LineSpit(void);
+
                        /* VEC * MATRIX */
+                       /* this is deprecated!, use the reverse instead */
                        float tvec[MAX_DIMENSIONS];
+
+
+/* ------ to be removed ------*/
+#ifndef MATH_STANDALONE
+#ifdef WITH_ASSERT_ABORT
+                       PyErr_SetString(PyExc_ValueError,
+                                       "(Vector * Matrix) is now removed, reverse the "
+                                       "order (promoted to an Error for Debug builds)");
+                       return NULL;
+#else
+                       printf("Warning: (Vector * Matrix) is now deprecated, "
+                              "reverse the multiplication order in the script.\n");
+                       PyC_LineSpit();
+#endif
+#endif         /* ifndef MATH_STANDALONE */
+/* ------ to be removed ------*/
+
+
                        if(BaseMath_ReadCallback((MatrixObject *)v2) == -1)
                                return NULL;
                        if(column_vector_multiplication(tvec, vec1, (MatrixObject*)v2) == -1) {
@@ -1183,6 +1206,24 @@ static PyObject *Vector_mul(PyObject *v1, PyObject *v2)
                        if(BaseMath_ReadCallback(quat2) == -1) {
                                return NULL;
                        }
+
+
+/* ------ to be removed ------*/
+#ifndef MATH_STANDALONE
+#ifdef WITH_ASSERT_ABORT
+                       PyErr_SetString(PyExc_ValueError,
+                                       "(Vector * Quat) is now removed, reverse the "
+                                       "order (promoted to an Error for Debug builds)");
+                       return NULL;
+#else
+                       printf("Warning: (Vector * Quat) is now deprecated, "
+                              "reverse the multiplication order in the script.\n");
+                       PyC_LineSpit();
+#endif
+#endif         /* ifndef MATH_STANDALONE */
+/* ------ to be removed ------*/
+
+
                        copy_v3_v3(tvec, vec1->vec);
                        mul_qt_v3(quat2->quat, tvec);
                        return newVectorObject(tvec, 3, Py_NEW, Py_TYPE(vec1));
@@ -1226,6 +1267,24 @@ static PyObject *Vector_imul(PyObject *v1, PyObject *v2)
                if(column_vector_multiplication(rvec, vec, (MatrixObject*)v2) == -1)
                        return NULL;
 
+
+/* ------ to be removed ------*/
+#ifndef MATH_STANDALONE
+#ifdef WITH_ASSERT_ABORT
+                       PyErr_SetString(PyExc_ValueError,
+                                                       "(Vector *= Matrix) is now removed, reverse the "
+                                                       "order (promoted to an Error for Debug builds) "
+                                       "and uses the non in-place multiplication.");
+                       return NULL;
+#else
+                       printf("Warning: (Vector *= Matrix) is now deprecated, "
+                                  "reverse the (non in-place) multiplication order in the script.\n");
+                       PyC_LineSpit();
+#endif
+#endif         /* ifndef MATH_STANDALONE */
+/* ------ to be removed ------*/
+
+
                memcpy(vec->vec, rvec, sizeof(float) * vec->size);
        }
        else if (QuaternionObject_Check(v2)) {
@@ -1242,6 +1301,25 @@ static PyObject *Vector_imul(PyObject *v1, PyObject *v2)
                if(BaseMath_ReadCallback(quat2) == -1) {
                        return NULL;
                }
+
+
+/* ------ to be removed ------*/
+#ifndef MATH_STANDALONE
+#ifdef WITH_ASSERT_ABORT
+                       PyErr_SetString(PyExc_ValueError,
+                                                       "(Vector *= Quat) is now removed, reverse the "
+                                                       "order (promoted to an Error for Debug builds) "
+                                       "and uses the non in-place multiplication.");
+                       return NULL;
+#else
+                       printf("Warning: (Vector *= Quat) is now deprecated, "
+                                  "reverse the (non in-place) multiplication order in the script.\n");
+                       PyC_LineSpit();
+#endif
+#endif         /* ifndef MATH_STANDALONE */
+/* ------ to be removed ------*/
+
+
                mul_qt_v3(quat2->quat, vec->vec);
        }
        else if (((scalar= PyFloat_AsDouble(v2)) == -1.0f && PyErr_Occurred())==0) { /* VEC *= FLOAT */