[Bf-blender-cvs] SVN commit: /data/svn/bf-blender [28407] trunk/blender/source/blender: minor mathutils update

Campbell Barton ideasman42 at gmail.com
Sun Apr 25 05:34:18 CEST 2010


Revision: 28407
          http://projects.blender.org/plugins/scmsvn/viewcvs.php?view=rev&root=bf-blender&revision=28407
Author:   campbellbarton
Date:     2010-04-25 05:34:16 +0200 (Sun, 25 Apr 2010)

Log Message:
-----------
minor mathutils update
- docstring for Euler.rotate
- rotate_eul, use upper case in Py and C. 
- use less verbose repr method.

Modified Paths:
--------------
    trunk/blender/source/blender/blenkernel/intern/constraint.c
    trunk/blender/source/blender/blenlib/intern/math_rotation.c
    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_quat.c
    trunk/blender/source/blender/python/generic/mathutils_vector.c

Modified: trunk/blender/source/blender/blenkernel/intern/constraint.c
===================================================================
--- trunk/blender/source/blender/blenkernel/intern/constraint.c	2010-04-25 01:10:03 UTC (rev 28406)
+++ trunk/blender/source/blender/blenkernel/intern/constraint.c	2010-04-25 03:34:16 UTC (rev 28407)
@@ -1647,7 +1647,7 @@
 			eul[0] = obeul[0];
 		else {
 			if (data->flag & ROTLIKE_OFFSET)
-				rotate_eulO(eul, cob->rotOrder, 'x', obeul[0]);
+				rotate_eulO(eul, cob->rotOrder, 'X', obeul[0]);
 			
 			if (data->flag & ROTLIKE_X_INVERT)
 				eul[0] *= -1;
@@ -1657,7 +1657,7 @@
 			eul[1] = obeul[1];
 		else {
 			if (data->flag & ROTLIKE_OFFSET)
-				rotate_eulO(eul, cob->rotOrder, 'y', obeul[1]);
+				rotate_eulO(eul, cob->rotOrder, 'Y', obeul[1]);
 			
 			if (data->flag & ROTLIKE_Y_INVERT)
 				eul[1] *= -1;
@@ -1667,7 +1667,7 @@
 			eul[2] = obeul[2];
 		else {
 			if (data->flag & ROTLIKE_OFFSET)
-				rotate_eulO(eul, cob->rotOrder, 'z', obeul[2]);
+				rotate_eulO(eul, cob->rotOrder, 'Z', obeul[2]);
 			
 			if (data->flag & ROTLIKE_Z_INVERT)
 				eul[2] *= -1;

Modified: trunk/blender/source/blender/blenlib/intern/math_rotation.c
===================================================================
--- trunk/blender/source/blender/blenlib/intern/math_rotation.c	2010-04-25 01:10:03 UTC (rev 28406)
+++ trunk/blender/source/blender/blenlib/intern/math_rotation.c	2010-04-25 03:34:16 UTC (rev 28407)
@@ -919,8 +919,8 @@
 	float eul[3], mat1[3][3], mat2[3][3], totmat[3][3];
 	
 	eul[0]= eul[1]= eul[2]= 0.0f;
-	if(axis=='x') eul[0]= ang;
-	else if(axis=='y') eul[1]= ang;
+	if(axis=='X') eul[0]= ang;
+	else if(axis=='Y') eul[1]= ang;
 	else eul[2]= ang;
 	
 	eul_to_mat3(mat1,eul);
@@ -1238,9 +1238,9 @@
 	float eul[3], mat1[3][3], mat2[3][3], totmat[3][3];
 	
 	eul[0]= eul[1]= eul[2]= 0.0f;
-	if (axis=='x') 
+	if (axis=='X') 
 		eul[0]= ang;
-	else if (axis=='y') 
+	else if (axis=='Y')
 		eul[1]= ang;
 	else 
 		eul[2]= ang;

Modified: trunk/blender/source/blender/python/generic/mathutils_color.c
===================================================================
--- trunk/blender/source/blender/python/generic/mathutils_color.c	2010-04-25 01:10:03 UTC (rev 28406)
+++ trunk/blender/source/blender/python/generic/mathutils_color.c	2010-04-25 03:34:16 UTC (rev 28407)
@@ -79,9 +79,28 @@
 
 //-----------------------------METHODS----------------------------
 
-//----------------------------Color.rotate()-----------------------
-// return a copy of the color
+/* note: BaseMath_ReadCallback must be called beforehand */
+static PyObject *Color_ToTupleExt(ColorObject *self, int ndigits)
+{
+	PyObject *ret;
+	int i;
 
+	ret= PyTuple_New(3);
+
+	if(ndigits >= 0) {
+		for(i= 0; i < 3; i++) {
+			PyTuple_SET_ITEM(ret, i, PyFloat_FromDouble(double_round((double)self->col[i], ndigits)));
+		}
+	}
+	else {
+		for(i= 0; i < 3; i++) {
+			PyTuple_SET_ITEM(ret, i, PyFloat_FromDouble(self->col[i]));
+		}
+	}
+
+	return ret;
+}
+
 static char Color_copy_doc[] =
 ".. function:: copy()\n"
 "\n"
@@ -102,25 +121,22 @@
 
 //----------------------------print object (internal)--------------
 //print the object to screen
+
 static PyObject *Color_repr(ColorObject * self)
 {
-	PyObject *r, *g, *b, *ret;
-
+	PyObject *ret, *tuple;
+	
 	if(!BaseMath_ReadCallback(self))
 		return NULL;
 
-	r= PyFloat_FromDouble(self->col[0]);
-	g= PyFloat_FromDouble(self->col[1]);
-	b= PyFloat_FromDouble(self->col[2]);
+	tuple= Color_ToTupleExt(self, -1);
 
-	ret= PyUnicode_FromFormat("Color(%R, %R, %R)", r, g, b);
+	ret= PyUnicode_FromFormat("Color%R", tuple);
 
-	Py_DECREF(r);
-	Py_DECREF(g);
-	Py_DECREF(b);
-
+	Py_DECREF(tuple);
 	return ret;
 }
+
 //------------------------tp_richcmpr
 //returns -1 execption, 0 false, 1 true
 static PyObject* Color_richcmpr(PyObject *objectA, PyObject *objectB, int comparison_type)

Modified: trunk/blender/source/blender/python/generic/mathutils_euler.c
===================================================================
--- trunk/blender/source/blender/python/generic/mathutils_euler.c	2010-04-25 01:10:03 UTC (rev 28406)
+++ trunk/blender/source/blender/python/generic/mathutils_euler.c	2010-04-25 03:34:16 UTC (rev 28407)
@@ -102,8 +102,29 @@
 	return -1;
 }
 
+/* note: BaseMath_ReadCallback must be called beforehand */
+static PyObject *Euler_ToTupleExt(EulerObject *self, int ndigits)
+{
+	PyObject *ret;
+	int i;
+
+	ret= PyTuple_New(3);
+
+	if(ndigits >= 0) {
+		for(i= 0; i < 3; i++) {
+			PyTuple_SET_ITEM(ret, i, PyFloat_FromDouble(double_round((double)self->eul[i], ndigits)));
+		}
+	}
+	else {
+		for(i= 0; i < 3; i++) {
+			PyTuple_SET_ITEM(ret, i, PyFloat_FromDouble(self->eul[i]));
+		}
+	}
+
+	return ret;
+}
+
 //-----------------------------METHODS----------------------------
-//----------------------------Euler.toQuat()----------------------
 //return a quaternion representation of the euler
 
 static char Euler_ToQuat_doc[] =
@@ -126,7 +147,7 @@
 
 	return newQuaternionObject(quat, Py_NEW, NULL);
 }
-//----------------------------Euler.toMatrix()---------------------
+
 //return a matrix representation of the euler
 static char Euler_ToMatrix_doc[] =
 ".. method:: to_matrix()\n"
@@ -148,7 +169,7 @@
 
 	return newMatrixObject(mat, 3, 3 , Py_NEW, NULL);
 }
-//----------------------------Euler.unique()-----------------------
+
 //sets the x,y,z values to a unique euler rotation
 // TODO, check if this works with rotation order!!!
 static char Euler_Unique_doc[] =
@@ -207,7 +228,7 @@
 	Py_INCREF(self);
 	return (PyObject *)self;
 }
-//----------------------------Euler.zero()-------------------------
+
 //sets the euler to 0,0,0
 static char Euler_Zero_doc[] =
 ".. method:: zero()\n"
@@ -227,20 +248,30 @@
 	Py_INCREF(self);
 	return (PyObject *)self;
 }
-//----------------------------Euler.rotate()-----------------------
-//rotates a euler a certain amount and returns the result
-//should return a unique euler rotation (i.e. no 720 degree pitches :)
+
+static char Euler_Rotate_doc[] =
+".. method:: rotate(angle, axis)\n"
+"\n"
+"   Rotates the euler a certain amount and returning a unique euler rotation (no 720 degree pitches).\n"
+"\n"
+"   :arg angle: angle in radians.\n"
+"   :type angle: float\n"
+"   :arg axis: single character in ['X, 'Y', 'Z'].\n"
+"   :type axis: string\n"
+"   :return: an instance of itself\n"
+"   :rtype: :class:`Euler`";
+
 static PyObject *Euler_Rotate(EulerObject * self, PyObject *args)
 {
 	float angle = 0.0f;
 	char *axis;
 
-	if(!PyArg_ParseTuple(args, "fs", &angle, &axis)){
-		PyErr_SetString(PyExc_TypeError, "euler.rotate():expected angle (float) and axis (x,y,z)");
+	if(!PyArg_ParseTuple(args, "fs:rotate", &angle, &axis)){
+		PyErr_SetString(PyExc_TypeError, "euler.rotate(): expected angle (float) and axis (x,y,z)");
 		return NULL;
 	}
-	if(ELEM3(*axis, 'x', 'y', 'z') && axis[1]=='\0'){
-		PyErr_SetString(PyExc_TypeError, "euler.rotate(): expected axis to be 'x', 'y' or 'z'");
+	if(ELEM3(*axis, 'X', 'Y', 'Z') && axis[1]=='\0'){
+		PyErr_SetString(PyExc_TypeError, "euler.rotate(): expected axis to be 'X', 'Y' or 'Z'");
 		return NULL;
 	}
 
@@ -312,25 +343,22 @@
 
 //----------------------------print object (internal)--------------
 //print the object to screen
+
 static PyObject *Euler_repr(EulerObject * self)
 {
-	PyObject *x, *y, *z, *ret;
-
+	PyObject *ret, *tuple;
+	
 	if(!BaseMath_ReadCallback(self))
 		return NULL;
 
-	x= PyFloat_FromDouble(self->eul[0]);
-	y= PyFloat_FromDouble(self->eul[1]);
-	z= PyFloat_FromDouble(self->eul[2]);
+	tuple= Euler_ToTupleExt(self, -1);
 
-	ret= PyUnicode_FromFormat("Euler(%R, %R, %R)", x, y, z);
+	ret= PyUnicode_FromFormat("Euler%R", tuple);
 
-	Py_DECREF(x);
-	Py_DECREF(y);
-	Py_DECREF(z);
-
+	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)
@@ -565,7 +593,7 @@
 	{"unique", (PyCFunction) Euler_Unique, METH_NOARGS, Euler_Unique_doc},
 	{"to_matrix", (PyCFunction) Euler_ToMatrix, METH_NOARGS, Euler_ToMatrix_doc},
 	{"to_quat", (PyCFunction) Euler_ToQuat, METH_NOARGS, Euler_ToQuat_doc},
-	{"rotate", (PyCFunction) Euler_Rotate, METH_VARARGS, NULL},
+	{"rotate", (PyCFunction) Euler_Rotate, METH_VARARGS, Euler_Rotate_doc},
 	{"make_compatible", (PyCFunction) Euler_MakeCompatible, METH_O, Euler_MakeCompatible_doc},
 	{"__copy__", (PyCFunction) Euler_copy, METH_VARARGS, Euler_copy_doc},
 	{"copy", (PyCFunction) Euler_copy, METH_VARARGS, Euler_copy_doc},

Modified: trunk/blender/source/blender/python/generic/mathutils_quat.c
===================================================================
--- trunk/blender/source/blender/python/generic/mathutils_quat.c	2010-04-25 01:10:03 UTC (rev 28406)
+++ trunk/blender/source/blender/python/generic/mathutils_quat.c	2010-04-25 03:34:16 UTC (rev 28407)
@@ -32,6 +32,29 @@
 #include "BKE_utildefines.h"
 
 //-----------------------------METHODS------------------------------
+
+/* note: BaseMath_ReadCallback must be called beforehand */
+static PyObject *Quaternion_ToTupleExt(QuaternionObject *self, int ndigits)
+{
+	PyObject *ret;
+	int i;
+
+	ret= PyTuple_New(4);
+
+	if(ndigits >= 0) {
+		for(i= 0; i < 4; i++) {
+			PyTuple_SET_ITEM(ret, i, PyFloat_FromDouble(double_round((double)self->quat[i], ndigits)));
+		}
+	}
+	else {
+		for(i= 0; i < 4; i++) {
+			PyTuple_SET_ITEM(ret, i, PyFloat_FromDouble(self->quat[i]));
+		}
+	}
+
+	return ret;
+}
+
 static char Quaternion_ToEuler_doc[] =
 ".. method:: to_euler(order, euler_compat)\n"
 "\n"
@@ -351,25 +374,19 @@
 //print the object to screen
 static PyObject *Quaternion_repr(QuaternionObject * self)
 {
-	PyObject *w, *x, *y, *z, *ret;
-
+	PyObject *ret, *tuple;
+	
 	if(!BaseMath_ReadCallback(self))
 		return NULL;
 
-	w= PyFloat_FromDouble(self->quat[0]);
-	x= PyFloat_FromDouble(self->quat[1]);
-	y= PyFloat_FromDouble(self->quat[2]);
-	z= PyFloat_FromDouble(self->quat[3]);
+	tuple= Quaternion_ToTupleExt(self, -1);
 
-	ret= PyUnicode_FromFormat("Quaternion(%R, %R, %R, %R)", w, x, y, z);
+	ret= PyUnicode_FromFormat("Quaternion%R", tuple);
 
-	Py_DECREF(w);
-	Py_DECREF(x);
-	Py_DECREF(y);
-	Py_DECREF(z);
-
+	Py_DECREF(tuple);
 	return ret;
 }
+
 //------------------------tp_richcmpr
 //returns -1 execption, 0 false, 1 true
 static PyObject* Quaternion_richcmpr(PyObject *objectA, PyObject *objectB, int comparison_type)

Modified: trunk/blender/source/blender/python/generic/mathutils_vector.c

@@ Diff output truncated at 10240 characters. @@




More information about the Bf-blender-cvs mailing list