Welcome to mirror list, hosted at ThFree Co, Russian Federation.

git.blender.org/blender.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorCampbell Barton <ideasman42@gmail.com>2011-07-25 05:44:19 +0400
committerCampbell Barton <ideasman42@gmail.com>2011-07-25 05:44:19 +0400
commitced8f1dffcb9b054d7197a21e2a0426056b2babf (patch)
tree2921b64ede86745a13e835a79345d72ef226cce7 /source/blender/python
parenta22de3f73c28b86f481376d52fbcfd7bb8ee25f2 (diff)
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.
Diffstat (limited to 'source/blender/python')
-rw-r--r--source/blender/python/mathutils/mathutils.h2
-rw-r--r--source/blender/python/mathutils/mathutils_Matrix.c14
-rw-r--r--source/blender/python/mathutils/mathutils_Quaternion.c26
-rw-r--r--source/blender/python/mathutils/mathutils_Vector.c80
4 files changed, 118 insertions, 4 deletions
diff --git a/source/blender/python/mathutils/mathutils.h b/source/blender/python/mathutils/mathutils.h
index 7454cfe78b3..b798b5e7003 100644
--- a/source/blender/python/mathutils/mathutils.h
+++ b/source/blender/python/mathutils/mathutils.h
@@ -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 */
diff --git a/source/blender/python/mathutils/mathutils_Matrix.c b/source/blender/python/mathutils/mathutils_Matrix.c
index 76a0994c3aa..3953171f263 100644
--- a/source/blender/python/mathutils/mathutils_Matrix.c
+++ b/source/blender/python/mathutils/mathutils_Matrix.c
@@ -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);
}
}
diff --git a/source/blender/python/mathutils/mathutils_Quaternion.c b/source/blender/python/mathutils/mathutils_Quaternion.c
index 3b05b9a250b..2be258a1ef0 100644
--- a/source/blender/python/mathutils/mathutils_Quaternion.c
+++ b/source/blender/python/mathutils/mathutils_Quaternion.c
@@ -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);
}
}
diff --git a/source/blender/python/mathutils/mathutils_Vector.c b/source/blender/python/mathutils/mathutils_Vector.c
index e2c958adaa5..a954c07c98d 100644
--- a/source/blender/python/mathutils/mathutils_Vector.c
+++ b/source/blender/python/mathutils/mathutils_Vector.c
@@ -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 */