Revision: 38674
          
http://projects.blender.org/scm/viewvc.php?view=rev&root=bf-blender&revision=38674
Author:   campbellbarton
Date:     2011-07-25 01:44:19 +0000 (Mon, 25 Jul 2011)
Log Message:
-----------
deprecate multiplication orders:
 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.

Modified Paths:
--------------
    trunk/blender/release/scripts/startup/bl_operators/uvcalc_smart_project.py
    trunk/blender/source/blender/python/mathutils/mathutils.h
    trunk/blender/source/blender/python/mathutils/mathutils_Matrix.c
    trunk/blender/source/blender/python/mathutils/mathutils_Quaternion.c
    trunk/blender/source/blender/python/mathutils/mathutils_Vector.c

Modified: 
trunk/blender/release/scripts/startup/bl_operators/uvcalc_smart_project.py
===================================================================
--- trunk/blender/release/scripts/startup/bl_operators/uvcalc_smart_project.py  
2011-07-25 00:21:35 UTC (rev 38673)
+++ trunk/blender/release/scripts/startup/bl_operators/uvcalc_smart_project.py  
2011-07-25 01:44:19 UTC (rev 38674)
@@ -243,7 +243,7 @@
 
         # 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 @@
                 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:

Modified: trunk/blender/source/blender/python/mathutils/mathutils.h
===================================================================
--- trunk/blender/source/blender/python/mathutils/mathutils.h   2011-07-25 
00:21:35 UTC (rev 38673)
+++ trunk/blender/source/blender/python/mathutils/mathutils.h   2011-07-25 
01:44:19 UTC (rev 38674)
@@ -108,4 +108,6 @@
 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 */

Modified: trunk/blender/source/blender/python/mathutils/mathutils_Matrix.c
===================================================================
--- trunk/blender/source/blender/python/mathutils/mathutils_Matrix.c    
2011-07-25 00:21:35 UTC (rev 38673)
+++ trunk/blender/source/blender/python/mathutils/mathutils_Matrix.c    
2011-07-25 01:44:19 UTC (rev 38674)
@@ -1612,8 +1612,20 @@
                }
        }
        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);
                }
        }

Modified: trunk/blender/source/blender/python/mathutils/mathutils_Quaternion.c
===================================================================
--- trunk/blender/source/blender/python/mathutils/mathutils_Quaternion.c        
2011-07-25 00:21:35 UTC (rev 38673)
+++ trunk/blender/source/blender/python/mathutils/mathutils_Quaternion.c        
2011-07-25 01:44:19 UTC (rev 38674)
@@ -753,8 +753,30 @@
                        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);
                }
        }

Modified: trunk/blender/source/blender/python/mathutils/mathutils_Vector.c
===================================================================
--- trunk/blender/source/blender/python/mathutils/mathutils_Vector.c    
2011-07-25 00:21:35 UTC (rev 38673)
+++ trunk/blender/source/blender/python/mathutils/mathutils_Vector.c    
2011-07-25 01:44:19 UTC (rev 38674)
@@ -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 @@
  * 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 @@
        }
        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 @@
                        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 @@
                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 @@
                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 */

_______________________________________________
Bf-blender-cvs mailing list
[email protected]
http://lists.blender.org/mailman/listinfo/bf-blender-cvs

Reply via email to