[Bf-blender-cvs] SVN commit: /data/svn/bf-blender [34650] trunk/blender/source/blender/ python/generic: mathutils fixes noticed when refactoring.
Campbell Barton
ideasman42 at gmail.com
Sat Feb 5 11:40:42 CET 2011
Revision: 34650
http://projects.blender.org/scm/viewvc.php?view=rev&root=bf-blender&revision=34650
Author: campbellbarton
Date: 2011-02-05 10:40:42 +0000 (Sat, 05 Feb 2011)
Log Message:
-----------
mathutils fixes noticed when refactoring.
- comparing eulers was ignoring the order.
- printing Euler()'s now prints the order too.
- un-orderable types (all except for Vector's), were not raising an exception when compared with >=, >, <, <=.
Modified Paths:
--------------
trunk/blender/source/blender/python/generic/mathutils_color.c
trunk/blender/source/blender/python/generic/mathutils_euler.c
trunk/blender/source/blender/python/generic/mathutils_matrix.c
trunk/blender/source/blender/python/generic/mathutils_quat.c
Modified: trunk/blender/source/blender/python/generic/mathutils_color.c
===================================================================
--- trunk/blender/source/blender/python/generic/mathutils_color.c 2011-02-05 09:57:02 UTC (rev 34649)
+++ trunk/blender/source/blender/python/generic/mathutils_color.c 2011-02-05 10:40:42 UTC (rev 34650)
@@ -118,48 +118,40 @@
//------------------------tp_richcmpr
//returns -1 execption, 0 false, 1 true
-static PyObject* Color_richcmpr(PyObject *objectA, PyObject *objectB, int comparison_type)
+static PyObject* Color_richcmpr(PyObject *a, PyObject *b, int op)
{
- ColorObject *colA = NULL, *colB = NULL;
- int result = 0;
+ PyObject *res;
+ int ok= -1; /* zero is true */
- if(ColorObject_Check(objectA)) {
- colA = (ColorObject*)objectA;
- if(!BaseMath_ReadCallback(colA))
+ if (ColorObject_Check(a) && ColorObject_Check(b)) {
+ ColorObject *colA= (ColorObject*)a;
+ ColorObject *colB= (ColorObject*)b;
+
+ if(!BaseMath_ReadCallback(colA) || !BaseMath_ReadCallback(colB))
return NULL;
- }
- if(ColorObject_Check(objectB)) {
- colB = (ColorObject*)objectB;
- if(!BaseMath_ReadCallback(colB))
- return NULL;
- }
- if (!colA || !colB){
- if (comparison_type == Py_NE){
- Py_RETURN_TRUE;
- }else{
- Py_RETURN_FALSE;
- }
+ ok= EXPP_VectorsAreEqual(colA->col, colB->col, COLOR_SIZE, 1) ? 0 : -1;
}
- colA = (ColorObject*)objectA;
- colB = (ColorObject*)objectB;
- switch (comparison_type){
- case Py_EQ:
- result = EXPP_VectorsAreEqual(colA->col, colB->col, COLOR_SIZE, 1);
- break;
- case Py_NE:
- result = !EXPP_VectorsAreEqual(colA->col, colB->col, COLOR_SIZE, 1);
- break;
- default:
- printf("The result of the comparison could not be evaluated");
- break;
+ switch (op) {
+ case Py_NE:
+ ok = !ok; /* pass through */
+ case Py_EQ:
+ res = ok ? Py_False : Py_True;
+ break;
+
+ case Py_LT:
+ case Py_LE:
+ case Py_GT:
+ case Py_GE:
+ res = Py_NotImplemented;
+ break;
+ default:
+ PyErr_BadArgument();
+ return NULL;
}
- if (result == 1){
- Py_RETURN_TRUE;
- }else{
- Py_RETURN_FALSE;
- }
+
+ return Py_INCREF(res), res;
}
//---------------------SEQUENCE PROTOCOLS------------------------
Modified: trunk/blender/source/blender/python/generic/mathutils_euler.c
===================================================================
--- trunk/blender/source/blender/python/generic/mathutils_euler.c 2011-02-05 09:57:02 UTC (rev 34649)
+++ trunk/blender/source/blender/python/generic/mathutils_euler.c 2011-02-05 10:40:42 UTC (rev 34650)
@@ -72,6 +72,13 @@
return newEulerObject(eul, order, Py_NEW, type);
}
+/* internal use, assuem read callback is done */
+static const char *euler_order_str(EulerObject *self)
+{
+ static const char order[][4] = {"XYZ", "XZY", "YXZ", "YZX", "ZXY", "ZYX"};
+ return order[self->order-EULER_ORDER_XYZ];
+}
+
short euler_order_from_string(const char *str, const char *error_prefix)
{
if((str[0] && str[1] && str[2] && str[3]=='\0')) {
@@ -129,8 +136,7 @@
if(!BaseMath_ReadCallback(self))
return NULL;
- if(self->order==EULER_ORDER_XYZ) eul_to_quat(quat, self->eul);
- else eulO_to_quat(quat, self->eul, self->order);
+ eulO_to_quat(quat, self->eul, self->order);
return newQuaternionObject(quat, Py_NEW, NULL);
}
@@ -151,8 +157,7 @@
if(!BaseMath_ReadCallback(self))
return NULL;
- if(self->order==EULER_ORDER_XYZ) eul_to_mat3((float (*)[3])mat, self->eul);
- else eulO_to_mat3((float (*)[3])mat, self->eul, self->order);
+ eulO_to_mat3((float (*)[3])mat, self->eul, self->order);
return newMatrixObject(mat, 3, 3 , Py_NEW, NULL);
}
@@ -198,9 +203,9 @@
if(!BaseMath_ReadCallback(self))
return NULL;
- if(self->order == EULER_ORDER_XYZ) rotate_eul(self->eul, *axis, angle);
- else rotate_eulO(self->eul, self->order, *axis, angle);
+ rotate_eulO(self->eul, self->order, *axis, angle);
+
(void)BaseMath_WriteCallback(self);
Py_RETURN_NONE;
@@ -293,56 +298,46 @@
tuple= Euler_ToTupleExt(self, -1);
- ret= PyUnicode_FromFormat("Euler(%R)", tuple);
+ ret= PyUnicode_FromFormat("Euler(%R, '%s')", tuple, euler_order_str(self));
Py_DECREF(tuple);
return ret;
}
-//------------------------tp_richcmpr
-//returns -1 execption, 0 false, 1 true
-static PyObject* Euler_richcmpr(PyObject *objectA, PyObject *objectB, int comparison_type)
+static PyObject* Euler_richcmpr(PyObject *a, PyObject *b, int op)
{
- EulerObject *eulA = NULL, *eulB = NULL;
- int result = 0;
+ PyObject *res;
+ int ok= -1; /* zero is true */
- if(EulerObject_Check(objectA)) {
- eulA = (EulerObject*)objectA;
- if(!BaseMath_ReadCallback(eulA))
+ if (EulerObject_Check(a) && EulerObject_Check(b)) {
+ EulerObject *eulA= (EulerObject*)a;
+ EulerObject *eulB= (EulerObject*)b;
+
+ if(!BaseMath_ReadCallback(eulA) || !BaseMath_ReadCallback(eulB))
return NULL;
- }
- if(EulerObject_Check(objectB)) {
- eulB = (EulerObject*)objectB;
- if(!BaseMath_ReadCallback(eulB))
- return NULL;
- }
- if (!eulA || !eulB){
- if (comparison_type == Py_NE){
- Py_RETURN_TRUE;
- }else{
- Py_RETURN_FALSE;
- }
+ ok= ((eulA->order == eulB->order) && EXPP_VectorsAreEqual(eulA->eul, eulB->eul, EULER_SIZE, 1)) ? 0 : -1;
}
- eulA = (EulerObject*)objectA;
- eulB = (EulerObject*)objectB;
- switch (comparison_type){
- case Py_EQ:
- result = EXPP_VectorsAreEqual(eulA->eul, eulB->eul, EULER_SIZE, 1);
- break;
- case Py_NE:
- result = !EXPP_VectorsAreEqual(eulA->eul, eulB->eul, EULER_SIZE, 1);
- break;
- default:
- printf("The result of the comparison could not be evaluated");
- break;
+ switch (op) {
+ case Py_NE:
+ ok = !ok; /* pass through */
+ case Py_EQ:
+ res = ok ? Py_False : Py_True;
+ break;
+
+ case Py_LT:
+ case Py_LE:
+ case Py_GT:
+ case Py_GE:
+ res = Py_NotImplemented;
+ break;
+ default:
+ PyErr_BadArgument();
+ return NULL;
}
- if (result == 1){
- Py_RETURN_TRUE;
- }else{
- Py_RETURN_FALSE;
- }
+
+ return Py_INCREF(res), res;
}
//---------------------SEQUENCE PROTOCOLS------------------------
@@ -545,12 +540,10 @@
/* rotation order */
static PyObject *Euler_getOrder(EulerObject *self, void *UNUSED(closure))
{
- const char order[][4] = {"XYZ", "XZY", "YXZ", "YZX", "ZXY", "ZYX"};
-
if(!BaseMath_ReadCallback(self)) /* can read order too */
return NULL;
- return PyUnicode_FromString(order[self->order-EULER_ORDER_XYZ]);
+ return PyUnicode_FromString(euler_order_str(self));
}
static int Euler_setOrder(EulerObject *self, PyObject *value, void *UNUSED(closure))
Modified: trunk/blender/source/blender/python/generic/mathutils_matrix.c
===================================================================
--- trunk/blender/source/blender/python/generic/mathutils_matrix.c 2011-02-05 09:57:02 UTC (rev 34649)
+++ trunk/blender/source/blender/python/generic/mathutils_matrix.c 2011-02-05 10:40:42 UTC (rev 34650)
@@ -1263,58 +1263,43 @@
return NULL;
}
-/*------------------------tp_richcmpr*/
-/*returns -1 execption, 0 false, 1 true*/
-static PyObject* Matrix_richcmpr(PyObject *objectA, PyObject *objectB, int comparison_type)
+static PyObject* Matrix_richcmpr(PyObject *a, PyObject *b, int op)
{
- MatrixObject *matA = NULL, *matB = NULL;
- int result = 0;
+ PyObject *res;
+ int ok= -1; /* zero is true */
- if (!MatrixObject_Check(objectA) || !MatrixObject_Check(objectB)){
- if (comparison_type == Py_NE){
- Py_RETURN_TRUE;
- }else{
- Py_RETURN_FALSE;
- }
- }
- matA = (MatrixObject*)objectA;
- matB = (MatrixObject*)objectB;
+ if (MatrixObject_Check(a) && MatrixObject_Check(b)) {
+ MatrixObject *matA= (MatrixObject*)a;
+ MatrixObject *matB= (MatrixObject*)b;
- if(!BaseMath_ReadCallback(matA) || !BaseMath_ReadCallback(matB))
- return NULL;
+ if(!BaseMath_ReadCallback(matA) || !BaseMath_ReadCallback(matB))
+ return NULL;
- if (matA->colSize != matB->colSize || matA->rowSize != matB->rowSize){
- if (comparison_type == Py_NE){
- Py_RETURN_TRUE;
- }else{
- Py_RETURN_FALSE;
- }
+ ok= ( (matA->colSize == matB->colSize) &&
+ (matA->rowSize == matB->rowSize) &&
+ EXPP_VectorsAreEqual(matA->contigPtr, matB->contigPtr, (matA->rowSize * matA->colSize), 1)
+ ) ? 0 : -1;
}
- switch (comparison_type){
- case Py_EQ:
- /*contigPtr is basically a really long vector*/
- result = EXPP_VectorsAreEqual(matA->contigPtr, matB->contigPtr,
- (matA->rowSize * matA->colSize), 1);
- break;
- case Py_NE:
- result = EXPP_VectorsAreEqual(matA->contigPtr, matB->contigPtr,
- (matA->rowSize * matA->colSize), 1);
- if (result == 0){
- result = 1;
- }else{
- result = 0;
- }
- break;
- default:
- printf("The result of the comparison could not be evaluated");
- break;
+ switch (op) {
+ case Py_NE:
+ ok = !ok; /* pass through */
+ case Py_EQ:
+ res = ok ? Py_False : Py_True;
+ break;
+
+ case Py_LT:
+ case Py_LE:
+ case Py_GT:
+ case Py_GE:
+ res = Py_NotImplemented;
+ break;
+ default:
+ PyErr_BadArgument();
+ return NULL;
}
- if (result == 1){
- Py_RETURN_TRUE;
- }else{
- Py_RETURN_FALSE;
- }
+
+ return Py_INCREF(res), res;
}
/*---------------------SEQUENCE PROTOCOLS------------------------
Modified: trunk/blender/source/blender/python/generic/mathutils_quat.c
===================================================================
--- trunk/blender/source/blender/python/generic/mathutils_quat.c 2011-02-05 09:57:02 UTC (rev 34649)
+++ trunk/blender/source/blender/python/generic/mathutils_quat.c 2011-02-05 10:40:42 UTC (rev 34650)
@@ -448,53 +448,40 @@
return ret;
}
-//------------------------tp_richcmpr
-//returns -1 execption, 0 false, 1 true
-static PyObject* Quaternion_richcmpr(PyObject *objectA, PyObject *objectB, int comparison_type)
+static PyObject* Quaternion_richcmpr(PyObject *a, PyObject *b, int op)
{
- QuaternionObject *quatA = NULL, *quatB = NULL;
- int result = 0;
+ PyObject *res;
+ int ok= -1; /* zero is true */
- if(QuaternionObject_Check(objectA)) {
- quatA = (QuaternionObject*)objectA;
- if(!BaseMath_ReadCallback(quatA))
+ if (QuaternionObject_Check(a) && QuaternionObject_Check(b)) {
+ QuaternionObject *quatA= (QuaternionObject *)a;
+ QuaternionObject *quatB= (QuaternionObject *)b;
+
+ if(!BaseMath_ReadCallback(quatA) || !BaseMath_ReadCallback(quatB))
return NULL;
- }
- if(QuaternionObject_Check(objectB)) {
- quatB = (QuaternionObject*)objectB;
- if(!BaseMath_ReadCallback(quatB))
- return NULL;
- }
- if (!quatA || !quatB){
- if (comparison_type == Py_NE){
- Py_RETURN_TRUE;
- }else{
- Py_RETURN_FALSE;
- }
+ ok= (EXPP_VectorsAreEqual(quatA->quat, quatB->quat, QUAT_SIZE, 1)) ? 0 : -1;
@@ Diff output truncated at 10240 characters. @@
More information about the Bf-blender-cvs
mailing list