[Bf-blender-cvs] SVN commit: /data/svn/bf-blender [34647] trunk/blender/source/blender: Rename python mathutils functions and split in-place methods from those that return new values .
Campbell Barton
ideasman42 at gmail.com
Sat Feb 5 07:14:51 CET 2011
Revision: 34647
http://projects.blender.org/scm/viewvc.php?view=rev&root=bf-blender&revision=34647
Author: campbellbarton
Date: 2011-02-05 06:14:50 +0000 (Sat, 05 Feb 2011)
Log Message:
-----------
Rename python mathutils functions and split in-place methods from those that return new values.
http://wiki.blender.org/index.php/Dev:2.5/Source/Python/Mathutils
This completes the changes proposed.
This will break scripts (fixing coming up next), for full list of changes see mathutils.c comments.
Modified Paths:
--------------
trunk/blender/source/blender/blenlib/BLI_math_vector.h
trunk/blender/source/blender/blenlib/intern/math_vector.c
trunk/blender/source/blender/python/generic/mathutils.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
trunk/blender/source/blender/python/generic/mathutils_vector.c
Modified: trunk/blender/source/blender/blenlib/BLI_math_vector.h
===================================================================
--- trunk/blender/source/blender/blenlib/BLI_math_vector.h 2011-02-04 21:25:57 UTC (rev 34646)
+++ trunk/blender/source/blender/blenlib/BLI_math_vector.h 2011-02-05 06:14:50 UTC (rev 34647)
@@ -173,6 +173,8 @@
/***************************** Array Functions *******************************/
/* attempted to follow fixed length vertex functions. names could be improved*/
void range_vni(int *array, const int size, const int start);
+void negate_vn(float *array_tar, const int size);
+void negate_vn_vn(float *array_tar, const float *array_src, const int size);
void mul_vn_fl(float *array, const int size, const float f);
void mul_vn_vn_fl(float *array_tar, const float *array_src, const int size, const float f);
void add_vn_vn(float *array_tar, const float *array_src, const int size);
Modified: trunk/blender/source/blender/blenlib/intern/math_vector.c
===================================================================
--- trunk/blender/source/blender/blenlib/intern/math_vector.c 2011-02-04 21:25:57 UTC (rev 34646)
+++ trunk/blender/source/blender/blenlib/intern/math_vector.c 2011-02-05 06:14:50 UTC (rev 34647)
@@ -375,6 +375,21 @@
while(i--) { *(array_pt--) = j--; }
}
+void negate_vn(float *array_tar, const int size)
+{
+ float *array_pt= array_tar + (size-1);
+ int i= size;
+ while(i--) { *(array_pt--) *= -1.0f; }
+}
+
+void negate_vn_vn(float *array_tar, const float *array_src, const int size)
+{
+ float *tar= array_tar + (size-1);
+ const float *src= array_src + (size-1);
+ int i= size;
+ while(i--) { *(tar--) = - *(src--); }
+}
+
void mul_vn_fl(float *array_tar, const int size, const float f)
{
float *array_pt= array_tar + (size-1);
Modified: trunk/blender/source/blender/python/generic/mathutils.c
===================================================================
--- trunk/blender/source/blender/python/generic/mathutils.c 2011-02-04 21:25:57 UTC (rev 34646)
+++ trunk/blender/source/blender/python/generic/mathutils.c 2011-02-05 06:14:50 UTC (rev 34647)
@@ -50,7 +50,20 @@
* - Quaternion * Quaternion --> cross product (not dot product)
* - Euler.rotate(angle, axis) --> Euler.rotate_axis(axis, angle)
* - Euler.unique() *removed*, not a standard function only toggled different rotations.
- *
+ * - Matrix.rotation_part() -> to_3x3()
+ * - Matrix.scale_part() -> to_scale()
+ * - Matrix.translation_part() -> to_translation()
+ * - Matrix.resize4x4() -> resize_4x4()
+ * - Euler.to_quat() -> to_quaternion()
+ * - Matrix.to_quat() -> to_quaternion()
+ * resizing nolonger returns the resized value.
+ * - Vector.resize2D -> resize_2d
+ * - Vector.resize3D -> resize_3d
+ * - Vector.resize4D -> resize_4d
+ * added new functions.
+ * - Vector.to_2d()
+ * - Vector.to_3d()
+ * - Vector.to_4d()
* moved into class functions.
* - Mathutils.RotationMatrix -> mathutils.Matrix.Rotation
* - Mathutils.ScaleMatrix -> mathutils.Matrix.Scale
Modified: trunk/blender/source/blender/python/generic/mathutils_euler.c
===================================================================
--- trunk/blender/source/blender/python/generic/mathutils_euler.c 2011-02-04 21:25:57 UTC (rev 34646)
+++ trunk/blender/source/blender/python/generic/mathutils_euler.c 2011-02-05 06:14:50 UTC (rev 34647)
@@ -146,7 +146,7 @@
;
static PyObject *Euler_to_matrix(EulerObject * self)
{
- float mat[9] = {0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f};
+ float mat[9];
if(!BaseMath_ReadCallback(self))
return NULL;
@@ -162,19 +162,13 @@
".. method:: zero()\n"
"\n"
" Set all values to zero.\n"
-"\n"
-" :return: an instance of itself\n"
-" :rtype: :class:`Euler`\n"
;
static PyObject *Euler_zero(EulerObject * self)
{
- self->eul[0] = 0.0;
- self->eul[1] = 0.0;
- self->eul[2] = 0.0;
+ zero_v3(self->eul);
(void)BaseMath_WriteCallback(self);
- Py_INCREF(self);
- return (PyObject *)self;
+ Py_RETURN_NONE;
}
static char Euler_rotate_axis_doc[] =
@@ -568,7 +562,7 @@
static struct PyMethodDef Euler_methods[] = {
{"zero", (PyCFunction) Euler_zero, METH_NOARGS, Euler_zero_doc},
{"to_matrix", (PyCFunction) Euler_to_matrix, METH_NOARGS, Euler_to_matrix_doc},
- {"to_quat", (PyCFunction) Euler_to_quaternion, METH_NOARGS, Euler_to_quaternion_doc},
+ {"to_quaternion", (PyCFunction) Euler_to_quaternion, METH_NOARGS, Euler_to_quaternion_doc},
{"rotate_axis", (PyCFunction) Euler_rotate_axis, METH_VARARGS, Euler_rotate_axis_doc},
{"make_compatible", (PyCFunction) Euler_make_compatible, METH_O, Euler_make_compatible_doc},
{"__copy__", (PyCFunction) Euler_copy, METH_NOARGS, Euler_copy_doc},
Modified: trunk/blender/source/blender/python/generic/mathutils_matrix.c
===================================================================
--- trunk/blender/source/blender/python/generic/mathutils_matrix.c 2011-02-04 21:25:57 UTC (rev 34646)
+++ trunk/blender/source/blender/python/generic/mathutils_matrix.c 2011-02-05 06:14:50 UTC (rev 34647)
@@ -31,6 +31,21 @@
#include "BLI_blenlib.h"
#include "BLI_utildefines.h"
+#define MATRIX_APPLY_TO_COPY(matrix_meth_noargs, _self) \
+ MatrixObject *ret= (MatrixObject *)Matrix_copy(_self); \
+ PyObject *ret_dummy= matrix_meth_noargs(ret); \
+ if(ret_dummy) { \
+ Py_DECREF(ret_dummy); \
+ return (PyObject *)ret; \
+ } \
+ else { /* error */ \
+ Py_DECREF(ret); \
+ return NULL; \
+ } \
+
+
+static PyObject *Matrix_copy(MatrixObject *self);
+
static int Matrix_ass_slice(MatrixObject *self, int begin, int end, PyObject *value);
/* matrix vector callbacks */
@@ -661,7 +676,7 @@
" :return: Euler representation of the matrix.\n"
" :rtype: :class:`Euler`\n"
;
-PyObject *Matrix_to_euler(MatrixObject *self, PyObject *args)
+static PyObject *Matrix_to_euler(MatrixObject *self, PyObject *args)
{
const char *order_str= NULL;
short order= EULER_ORDER_XYZ;
@@ -713,16 +728,16 @@
return newEulerObject(eul, order, Py_NEW, NULL);
}
-/*---------------------------Matrix.resize4x4() ------------------*/
-static char Matrix_resize4x4_doc[] =
-".. method:: resize4x4()\n"
+
+static char Matrix_resize_4x4_doc[] =
+".. method:: resize_4x4()\n"
"\n"
" Resize the matrix to 4x4.\n"
"\n"
" :return: an instance of itself.\n"
" :rtype: :class:`Matrix`\n"
;
-PyObject *Matrix_resize4x4(MatrixObject *self)
+static PyObject *Matrix_resize_4x4(MatrixObject *self)
{
int x, first_row_elem, curr_pos, new_pos, blank_columns, blank_rows, index;
@@ -737,7 +752,7 @@
self->contigPtr = PyMem_Realloc(self->contigPtr, (sizeof(float) * 16));
if(self->contigPtr == NULL) {
- PyErr_SetString(PyExc_MemoryError, "matrix.resize4x4(): problem allocating pointer space");
+ PyErr_SetString(PyExc_MemoryError, "matrix.resize_4x4(): problem allocating pointer space");
return NULL;
}
/*set row pointers*/
@@ -782,7 +797,7 @@
" :return: a new matrix.\n"
" :rtype: :class:`Matrix`\n"
;
-PyObject *Matrix_to_4x4(MatrixObject *self)
+static PyObject *Matrix_to_4x4(MatrixObject *self)
{
if(!BaseMath_ReadCallback(self))
return NULL;
@@ -809,7 +824,7 @@
" :return: a new matrix.\n"
" :rtype: :class:`Matrix`\n"
;
-PyObject *Matrix_to_3x3(MatrixObject *self)
+static PyObject *Matrix_to_3x3(MatrixObject *self)
{
float mat[3][3];
@@ -826,57 +841,29 @@
return newMatrixObject((float *)mat, 3, 3, Py_NEW, Py_TYPE(self));
}
-/*---------------------------Matrix.translationPart() ------------*/
-static char Matrix_translation_part_doc[] =
-".. method:: translation_part()\n"
+static char Matrix_to_translation_doc[] =
+".. method:: to_translation()\n"
"\n"
" Return a the translation part of a 4 row matrix.\n"
"\n"
" :return: Return a the translation of a matrix.\n"
" :rtype: :class:`Vector`\n"
;
-PyObject *Matrix_translation_part(MatrixObject *self)
+static PyObject *Matrix_to_translation(MatrixObject *self)
{
if(!BaseMath_ReadCallback(self))
return NULL;
if((self->colSize < 3) || self->rowSize < 4){
- PyErr_SetString(PyExc_AttributeError, "Matrix.translation_part(): inappropriate matrix size");
+ PyErr_SetString(PyExc_AttributeError, "Matrix.to_translation(): inappropriate matrix size");
return NULL;
}
return newVectorObject(self->matrix[3], 3, Py_NEW, NULL);
}
-/*---------------------------Matrix.rotationPart() ---------------*/
-static char Matrix_rotation_part_doc[] =
-".. method:: rotation_part()\n"
-"\n"
-" Return the 3d submatrix corresponding to the linear term of the embedded affine transformation in 3d. This matrix represents rotation and scale.\n"
-"\n"
-" :return: Return the 3d matrix for rotation and scale.\n"
-" :rtype: :class:`Matrix`\n"
-"\n"
-" .. note:: Note that the (4,4) element of a matrix can be used for uniform scaling too.\n"
-;
-PyObject *Matrix_rotation_part(MatrixObject *self)
-{
- float mat[3][3];
- if(!BaseMath_ReadCallback(self))
- return NULL;
-
- if((self->colSize < 3) || (self->rowSize < 3)) {
- PyErr_SetString(PyExc_AttributeError, "Matrix.rotation_part(): inappropriate matrix size");
- return NULL;
- }
-
- matrix_as_3x3(mat, self);
-
- return newMatrixObject((float *)mat, 3, 3, Py_NEW, Py_TYPE(self));
-}
-/*---------------------------Matrix.scalePart() --------------------*/
-static char Matrix_scale_part_doc[] =
-".. method:: scale_part()\n"
+static char Matrix_to_scale_doc[] =
+".. method:: to_scale()\n"
"\n"
" Return a the scale part of a 3x3 or 4x4 matrix.\n"
"\n"
@@ -885,7 +872,7 @@
"\n"
" .. note:: This method does not return negative a scale on any axis because it is not possible to obtain this data from the matrix alone.\n"
;
-PyObject *Matrix_scale_part(MatrixObject *self)
+static PyObject *Matrix_to_scale(MatrixObject *self)
{
float rot[3][3];
float mat[3][3];
@@ -896,7 +883,7 @@
/*must be 3-4 cols, 3-4 rows, square matrix*/
if((self->colSize < 3) || (self->rowSize < 3)) {
- PyErr_SetString(PyExc_AttributeError, "Matrix.scale_part(): inappropriate matrix size, 3x3 minimum size");
+ PyErr_SetString(PyExc_AttributeError, "Matrix.to_scale(): inappropriate matrix size, 3x3 minimum size");
return NULL;
}
@@ -921,7 +908,7 @@
"\n"
" .. seealso:: <http://en.wikipedia.org/wiki/Inverse_matrix>\n"
;
-PyObject *Matrix_invert(MatrixObject *self)
+static PyObject *Matrix_invert(MatrixObject *self)
{
int x, y, z = 0;
@@ -971,10 +958,24 @@
}
(void)BaseMath_WriteCallback(self);
- Py_INCREF(self);
- return (PyObject *)self;
+ Py_RETURN_NONE;
}
@@ Diff output truncated at 10240 characters. @@
More information about the Bf-blender-cvs
mailing list