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
path: root/source
diff options
context:
space:
mode:
authorCampbell Barton <ideasman42@gmail.com>2011-02-09 12:20:17 +0300
committerCampbell Barton <ideasman42@gmail.com>2011-02-09 12:20:17 +0300
commit81a00cf2eb1984787e175bcd254bee8a149fc7d5 (patch)
treedf6cc5574b494ee6d2f2e69b34537e11e14e59e6 /source
parent08841476983f490c4dbf16934bc05602bbd4d5c5 (diff)
use static functions rather then defines for internal matrix__apply_to_copy() and similar.
+ other minor internal changes.
Diffstat (limited to 'source')
-rw-r--r--source/blender/python/generic/mathutils.c2
-rw-r--r--source/blender/python/generic/mathutils_matrix.c212
-rw-r--r--source/blender/python/generic/mathutils_matrix.h8
-rw-r--r--source/blender/python/generic/mathutils_quat.c32
-rw-r--r--source/blender/python/generic/mathutils_vector.c170
5 files changed, 215 insertions, 209 deletions
diff --git a/source/blender/python/generic/mathutils.c b/source/blender/python/generic/mathutils.c
index b3bff5cf67f..dc6fbac7eac 100644
--- a/source/blender/python/generic/mathutils.c
+++ b/source/blender/python/generic/mathutils.c
@@ -191,7 +191,7 @@ int mathutils_any_to_rotmat(float rmat[3][3], PyObject *value, const char *error
if(!BaseMath_ReadCallback((BaseMathObject *)value)) {
return -1;
}
- else if(((MatrixObject *)value)->colSize < 3 || ((MatrixObject *)value)->rowSize < 3) {
+ else if(((MatrixObject *)value)->col_size < 3 || ((MatrixObject *)value)->row_size < 3) {
PyErr_Format(PyExc_ValueError, "%.200s: matrix must have minimum 3x3 dimensions", error_prefix);
return -1;
}
diff --git a/source/blender/python/generic/mathutils_matrix.c b/source/blender/python/generic/mathutils_matrix.c
index 4603d9d4251..9144da4fa22 100644
--- a/source/blender/python/generic/mathutils_matrix.c
+++ b/source/blender/python/generic/mathutils_matrix.c
@@ -31,21 +31,9 @@
#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);
+static PyObject *matrix__apply_to_copy(PyNoArgsFunction matrix_func, MatrixObject *self);
/* matrix vector callbacks */
int mathutils_matrix_vector_cb_index= -1;
@@ -64,7 +52,7 @@ static int mathutils_matrix_vector_get(BaseMathObject *bmo, int subtype)
if(!BaseMath_ReadCallback(self))
return 0;
- for(i=0; i < self->colSize; i++)
+ for(i=0; i < self->col_size; i++)
bmo->data[i]= self->matrix[subtype][i];
return 1;
@@ -78,7 +66,7 @@ static int mathutils_matrix_vector_set(BaseMathObject *bmo, int subtype)
if(!BaseMath_ReadCallback(self))
return 0;
- for(i=0; i < self->colSize; i++)
+ for(i=0; i < self->col_size; i++)
self->matrix[subtype][i]= bmo->data[i];
(void)BaseMath_WriteCallback(self);
@@ -161,6 +149,20 @@ static PyObject *Matrix_new(PyTypeObject *type, PyObject *args, PyObject *kwds)
return NULL;
}
+static PyObject *matrix__apply_to_copy(PyNoArgsFunction matrix_func, MatrixObject *self)
+{
+ PyObject *ret= Matrix_copy(self);
+ PyObject *ret_dummy= matrix_func(ret);
+ if(ret_dummy) {
+ Py_DECREF(ret_dummy);
+ return (PyObject *)ret;
+ }
+ else { /* error */
+ Py_DECREF(ret);
+ return NULL;
+ }
+}
+
/* when a matrix is 4x4 size but initialized as a 3x3, re-assign values for 4x4 */
static void matrix_3x3_as_4x4(float mat[16])
{
@@ -598,10 +600,10 @@ void matrix_as_3x3(float mat[3][3], MatrixObject *self)
/* assumes rowsize == colsize is checked and the read callback has run */
static float matrix_determinant_internal(MatrixObject *self)
{
- if(self->rowSize == 2) {
+ if(self->row_size == 2) {
return determinant_m2(self->matrix[0][0], self->matrix[0][1],
self->matrix[1][0], self->matrix[1][1]);
- } else if(self->rowSize == 3) {
+ } else if(self->row_size == 3) {
return determinant_m3(self->matrix[0][0], self->matrix[0][1],
self->matrix[0][2], self->matrix[1][0],
self->matrix[1][1], self->matrix[1][2],
@@ -630,11 +632,11 @@ static PyObject *Matrix_to_quaternion(MatrixObject *self)
return NULL;
/*must be 3-4 cols, 3-4 rows, square matrix*/
- if((self->colSize < 3) || (self->rowSize < 3) || (self->colSize != self->rowSize)) {
+ if((self->col_size < 3) || (self->row_size < 3) || (self->col_size != self->row_size)) {
PyErr_SetString(PyExc_AttributeError, "Matrix.to_quat(): inappropriate matrix size - expects 3x3 or 4x4 matrix");
return NULL;
}
- if(self->colSize == 3){
+ if(self->col_size == 3){
mat3_to_quat( quat,(float (*)[3])self->contigPtr);
}else{
mat4_to_quat( quat,(float (*)[4])self->contigPtr);
@@ -680,9 +682,9 @@ static PyObject *Matrix_to_euler(MatrixObject *self, PyObject *args)
}
/*must be 3-4 cols, 3-4 rows, square matrix*/
- if(self->colSize ==3 && self->rowSize ==3) {
+ if(self->col_size ==3 && self->row_size ==3) {
mat= (float (*)[3])self->contigPtr;
- }else if (self->colSize ==4 && self->rowSize ==4) {
+ }else if (self->col_size ==4 && self->row_size ==4) {
copy_m3_m4(tmat, (float (*)[4])self->contigPtr);
mat= tmat;
}else {
@@ -737,9 +739,9 @@ static PyObject *Matrix_resize_4x4(MatrixObject *self)
self->matrix[x] = self->contigPtr + (x * 4);
}
/*move data to new spot in array + clean*/
- for(blank_rows = (4 - self->rowSize); blank_rows > 0; blank_rows--){
+ for(blank_rows = (4 - self->row_size); blank_rows > 0; blank_rows--){
for(x = 0; x < 4; x++){
- index = (4 * (self->rowSize + (blank_rows - 1))) + x;
+ index = (4 * (self->row_size + (blank_rows - 1))) + x;
if (index == 10 || index == 15){
self->contigPtr[index] = 1.0f;
}else{
@@ -747,11 +749,11 @@ static PyObject *Matrix_resize_4x4(MatrixObject *self)
}
}
}
- for(x = 1; x <= self->rowSize; x++){
- first_row_elem = (self->colSize * (self->rowSize - x));
- curr_pos = (first_row_elem + (self->colSize -1));
- new_pos = (4 * (self->rowSize - x )) + (curr_pos - first_row_elem);
- for(blank_columns = (4 - self->colSize); blank_columns > 0; blank_columns--){
+ for(x = 1; x <= self->row_size; x++){
+ first_row_elem = (self->col_size * (self->row_size - x));
+ curr_pos = (first_row_elem + (self->col_size -1));
+ new_pos = (4 * (self->row_size - x )) + (curr_pos - first_row_elem);
+ for(blank_columns = (4 - self->col_size); blank_columns > 0; blank_columns--){
self->contigPtr[new_pos + blank_columns] = 0.0f;
}
for(curr_pos = curr_pos; curr_pos >= first_row_elem; curr_pos--){
@@ -759,8 +761,8 @@ static PyObject *Matrix_resize_4x4(MatrixObject *self)
new_pos--;
}
}
- self->rowSize = 4;
- self->colSize = 4;
+ self->row_size = 4;
+ self->col_size = 4;
Py_RETURN_NONE;
}
@@ -778,10 +780,10 @@ static PyObject *Matrix_to_4x4(MatrixObject *self)
if(!BaseMath_ReadCallback(self))
return NULL;
- if(self->colSize==4 && self->rowSize==4) {
+ if(self->col_size==4 && self->row_size==4) {
return (PyObject *)newMatrixObject(self->contigPtr, 4, 4, Py_NEW, Py_TYPE(self));
}
- else if(self->colSize==3 && self->rowSize==3) {
+ else if(self->col_size==3 && self->row_size==3) {
float mat[4][4];
copy_m4_m3(mat, (float (*)[3])self->contigPtr);
return (PyObject *)newMatrixObject((float *)mat, 4, 4, Py_NEW, Py_TYPE(self));
@@ -807,7 +809,7 @@ static PyObject *Matrix_to_3x3(MatrixObject *self)
if(!BaseMath_ReadCallback(self))
return NULL;
- if((self->colSize < 3) || (self->rowSize < 3)) {
+ if((self->col_size < 3) || (self->row_size < 3)) {
PyErr_SetString(PyExc_AttributeError, "Matrix.to_3x3(): inappropriate matrix size");
return NULL;
}
@@ -830,7 +832,7 @@ static PyObject *Matrix_to_translation(MatrixObject *self)
if(!BaseMath_ReadCallback(self))
return NULL;
- if((self->colSize < 3) || self->rowSize < 4){
+ if((self->col_size < 3) || self->row_size < 4){
PyErr_SetString(PyExc_AttributeError, "Matrix.to_translation(): inappropriate matrix size");
return NULL;
}
@@ -858,7 +860,7 @@ static PyObject *Matrix_to_scale(MatrixObject *self)
return NULL;
/*must be 3-4 cols, 3-4 rows, square matrix*/
- if((self->colSize < 3) || (self->rowSize < 3)) {
+ if((self->col_size < 3) || (self->row_size < 3)) {
PyErr_SetString(PyExc_AttributeError, "Matrix.to_scale(): inappropriate matrix size, 3x3 minimum size");
return NULL;
}
@@ -895,7 +897,7 @@ static PyObject *Matrix_invert(MatrixObject *self)
if(!BaseMath_ReadCallback(self))
return NULL;
- if(self->rowSize != self->colSize){
+ if(self->row_size != self->col_size){
PyErr_SetString(PyExc_AttributeError, "Matrix.invert(ed): only square matrices are supported");
return NULL;
}
@@ -905,23 +907,23 @@ static PyObject *Matrix_invert(MatrixObject *self)
if(det != 0) {
/*calculate the classical adjoint*/
- if(self->rowSize == 2) {
+ if(self->row_size == 2) {
mat[0] = self->matrix[1][1];
mat[1] = -self->matrix[0][1];
mat[2] = -self->matrix[1][0];
mat[3] = self->matrix[0][0];
- } else if(self->rowSize == 3) {
+ } else if(self->row_size == 3) {
adjoint_m3_m3((float (*)[3]) mat,(float (*)[3])self->contigPtr);
- } else if(self->rowSize == 4) {
+ } else if(self->row_size == 4) {
adjoint_m4_m4((float (*)[4]) mat, (float (*)[4])self->contigPtr);
}
/*divide by determinate*/
- for(x = 0; x < (self->rowSize * self->colSize); x++) {
+ for(x = 0; x < (self->row_size * self->col_size); x++) {
mat[x] /= det;
}
/*set values*/
- for(x = 0; x < self->rowSize; x++) {
- for(y = 0; y < self->colSize; y++) {
+ for(x = 0; x < self->row_size; x++) {
+ for(y = 0; y < self->col_size; y++) {
self->matrix[x][y] = mat[z];
z++;
}
@@ -938,7 +940,7 @@ static PyObject *Matrix_invert(MatrixObject *self)
}
static char Matrix_inverted_doc[] =
-".. method:: invert()\n"
+".. method:: inverted()\n"
"\n"
" Return an inverted copy of the matrix.\n"
"\n"
@@ -949,7 +951,7 @@ static char Matrix_inverted_doc[] =
;
static PyObject *Matrix_inverted(MatrixObject *self)
{
- MATRIX_APPLY_TO_COPY(Matrix_invert, self);
+ return matrix__apply_to_copy((PyNoArgsFunction)Matrix_invert, self);
}
static char Matrix_rotate_doc[] =
@@ -972,7 +974,7 @@ static PyObject *Matrix_rotate(MatrixObject *self, PyObject *value)
if(mathutils_any_to_rotmat(other_rmat, value, "matrix.rotate(value)") == -1)
return NULL;
- if(self->colSize != 3 || self->rowSize != 3) {
+ if(self->col_size != 3 || self->row_size != 3) {
PyErr_SetString(PyExc_ValueError, "Matrix must have 3x3 dimensions");
return NULL;
}
@@ -1003,7 +1005,7 @@ static PyObject *Matrix_decompose(MatrixObject *self)
float quat[4];
float size[3];
- if(self->colSize != 4 || self->rowSize != 4) {
+ if(self->col_size != 4 || self->row_size != 4) {
PyErr_SetString(PyExc_AttributeError, "Matrix.decompose(): inappropriate matrix size - expects 4x4 matrix");
return NULL;
}
@@ -1044,7 +1046,7 @@ static PyObject *Matrix_lerp(MatrixObject *self, PyObject *args)
if(!PyArg_ParseTuple(args, "O!f:lerp", &matrix_Type, &mat2, &fac))
return NULL;
- if(self->rowSize != mat2->rowSize || self->colSize != mat2->colSize) {
+ if(self->row_size != mat2->row_size || self->col_size != mat2->col_size) {
PyErr_SetString(PyExc_AttributeError, "matrix.lerp(): expects both matrix objects of the same dimensions");
return NULL;
}
@@ -1053,10 +1055,10 @@ static PyObject *Matrix_lerp(MatrixObject *self, PyObject *args)
return NULL;
/* TODO, different sized matrix */
- if(self->rowSize==4 && self->colSize==4) {
+ if(self->row_size==4 && self->col_size==4) {
blend_m4_m4m4((float (*)[4])mat, (float (*)[4])self->contigPtr, (float (*)[4])mat2->contigPtr, fac);
}
- else if (self->rowSize==3 && self->colSize==3) {
+ else if (self->row_size==3 && self->col_size==3) {
blend_m3_m3m3((float (*)[3])mat, (float (*)[3])self->contigPtr, (float (*)[3])mat2->contigPtr, fac);
}
else {
@@ -1064,7 +1066,7 @@ static PyObject *Matrix_lerp(MatrixObject *self, PyObject *args)
return NULL;
}
- return (PyObject*)newMatrixObject(mat, self->rowSize, self->colSize, Py_NEW, Py_TYPE(self));
+ return (PyObject*)newMatrixObject(mat, self->row_size, self->col_size, Py_NEW, Py_TYPE(self));
}
/*---------------------------Matrix.determinant() ----------------*/
@@ -1083,7 +1085,7 @@ static PyObject *Matrix_determinant(MatrixObject *self)
if(!BaseMath_ReadCallback(self))
return NULL;
- if(self->rowSize != self->colSize){
+ if(self->row_size != self->col_size){
PyErr_SetString(PyExc_AttributeError, "Matrix.determinant: only square matrices are supported");
return NULL;
}
@@ -1105,16 +1107,16 @@ static PyObject *Matrix_transpose(MatrixObject *self)
if(!BaseMath_ReadCallback(self))
return NULL;
- if(self->rowSize != self->colSize){
+ if(self->row_size != self->col_size){
PyErr_SetString(PyExc_AttributeError, "Matrix.transpose(d): only square matrices are supported");
return NULL;
}
- if(self->rowSize == 2) {
+ if(self->row_size == 2) {
t = self->matrix[1][0];
self->matrix[1][0] = self->matrix[0][1];
self->matrix[0][1] = t;
- } else if(self->rowSize == 3) {
+ } else if(self->row_size == 3) {
transpose_m3((float (*)[3])self->contigPtr);
} else {
transpose_m4((float (*)[4])self->contigPtr);
@@ -1134,7 +1136,7 @@ static char Matrix_transposed_doc[] =
;
static PyObject *Matrix_transposed(MatrixObject *self)
{
- MATRIX_APPLY_TO_COPY(Matrix_transpose, self);
+ return matrix__apply_to_copy((PyNoArgsFunction)Matrix_transpose, self);
}
/*---------------------------Matrix.zero() -----------------------*/
@@ -1148,7 +1150,7 @@ static char Matrix_zero_doc[] =
;
static PyObject *Matrix_zero(MatrixObject *self)
{
- fill_vn(self->contigPtr, self->rowSize * self->colSize, 0.0f);
+ fill_vn(self->contigPtr, self->row_size * self->col_size, 0.0f);
if(!BaseMath_WriteCallback(self))
return NULL;
@@ -1170,17 +1172,17 @@ static PyObject *Matrix_identity(MatrixObject *self)
if(!BaseMath_ReadCallback(self))
return NULL;
- if(self->rowSize != self->colSize){
+ if(self->row_size != self->col_size){
PyErr_SetString(PyExc_AttributeError, "Matrix.identity: only square matrices are supported");
return NULL;
}
- if(self->rowSize == 2) {
+ if(self->row_size == 2) {
self->matrix[0][0] = 1.0f;
self->matrix[0][1] = 0.0f;
self->matrix[1][0] = 0.0f;
self->matrix[1][1] = 1.0f;
- } else if(self->rowSize == 3) {
+ } else if(self->row_size == 3) {
unit_m3((float (*)[3])self->contigPtr);
} else {
unit_m4((float (*)[4])self->contigPtr);
@@ -1206,7 +1208,7 @@ static PyObject *Matrix_copy(MatrixObject *self)
if(!BaseMath_ReadCallback(self))
return NULL;
- return (PyObject*)newMatrixObject((float (*))self->contigPtr, self->rowSize, self->colSize, Py_NEW, Py_TYPE(self));
+ return (PyObject*)newMatrixObject((float (*))self->contigPtr, self->row_size, self->col_size, Py_NEW, Py_TYPE(self));
}
/*----------------------------print object (internal)-------------*/
@@ -1219,13 +1221,13 @@ static PyObject *Matrix_repr(MatrixObject *self)
if(!BaseMath_ReadCallback(self))
return NULL;
- for(x = 0; x < self->rowSize; x++){
- rows[x]= PyTuple_New(self->colSize);
- for(y = 0; y < self->colSize; y++) {
+ for(x = 0; x < self->row_size; x++){
+ rows[x]= PyTuple_New(self->col_size);
+ for(y = 0; y < self->col_size; y++) {
PyTuple_SET_ITEM(rows[x], y, PyFloat_FromDouble(self->matrix[x][y]));
}
}
- switch(self->rowSize) {
+ switch(self->row_size) {
case 2: return PyUnicode_FromFormat("Matrix(%R,\n"
" %R)", rows[0], rows[1]);
@@ -1255,9 +1257,9 @@ static PyObject* Matrix_richcmpr(PyObject *a, PyObject *b, int op)
if(!BaseMath_ReadCallback(matA) || !BaseMath_ReadCallback(matB))
return NULL;
- ok= ( (matA->colSize == matB->colSize) &&
- (matA->rowSize == matB->rowSize) &&
- EXPP_VectorsAreEqual(matA->contigPtr, matB->contigPtr, (matA->rowSize * matA->colSize), 1)
+ ok= ( (matA->col_size == matB->col_size) &&
+ (matA->row_size == matB->row_size) &&
+ EXPP_VectorsAreEqual(matA->contigPtr, matB->contigPtr, (matA->row_size * matA->col_size), 1)
) ? 0 : -1;
}
@@ -1287,7 +1289,7 @@ static PyObject* Matrix_richcmpr(PyObject *a, PyObject *b, int op)
sequence length*/
static int Matrix_len(MatrixObject *self)
{
- return (self->rowSize);
+ return (self->row_size);
}
/*----------------------------object[]---------------------------
sequence accessor (get)
@@ -1297,11 +1299,11 @@ static PyObject *Matrix_item(MatrixObject *self, int i)
if(!BaseMath_ReadCallback(self))
return NULL;
- if(i < 0 || i >= self->rowSize) {
+ if(i < 0 || i >= self->row_size) {
PyErr_SetString(PyExc_IndexError, "matrix[attribute]: array index out of range");
return NULL;
}
- return newVectorObject_cb((PyObject *)self, self->colSize, mathutils_matrix_vector_cb_index, i);
+ return newVectorObject_cb((PyObject *)self, self->col_size, mathutils_matrix_vector_cb_index, i);
}
/*----------------------------object[]-------------------------
sequence accessor (set) */
@@ -1312,16 +1314,16 @@ static int Matrix_ass_item(MatrixObject *self, int i, PyObject *value)
if(!BaseMath_ReadCallback(self))
return -1;
- if(i >= self->rowSize || i < 0){
+ if(i >= self->row_size || i < 0){
PyErr_SetString(PyExc_TypeError, "matrix[attribute] = x: bad column");
return -1;
}
- if(mathutils_array_parse(vec, self->colSize, self->colSize, value, "matrix[i] = value assignment") < 0) {
+ if(mathutils_array_parse(vec, self->col_size, self->col_size, value, "matrix[i] = value assignment") < 0) {
return -1;
}
- memcpy(self->matrix[i], vec, self->colSize *sizeof(float));
+ memcpy(self->matrix[i], vec, self->col_size *sizeof(float));
(void)BaseMath_WriteCallback(self);
return 0;
@@ -1338,14 +1340,14 @@ static PyObject *Matrix_slice(MatrixObject *self, int begin, int end)
if(!BaseMath_ReadCallback(self))
return NULL;
- CLAMP(begin, 0, self->rowSize);
- CLAMP(end, 0, self->rowSize);
+ CLAMP(begin, 0, self->row_size);
+ CLAMP(end, 0, self->row_size);
begin= MIN2(begin,end);
tuple= PyTuple_New(end - begin);
for(count= begin; count < end; count++) {
PyTuple_SET_ITEM(tuple, count - begin,
- newVectorObject_cb((PyObject *)self, self->colSize, mathutils_matrix_vector_cb_index, count));
+ newVectorObject_cb((PyObject *)self, self->col_size, mathutils_matrix_vector_cb_index, count));
}
@@ -1360,8 +1362,8 @@ static int Matrix_ass_slice(MatrixObject *self, int begin, int end, PyObject *va
if(!BaseMath_ReadCallback(self))
return -1;
- CLAMP(begin, 0, self->rowSize);
- CLAMP(end, 0, self->rowSize);
+ CLAMP(begin, 0, self->row_size);
+ CLAMP(end, 0, self->row_size);
begin = MIN2(begin,end);
/* non list/tuple cases */
@@ -1385,7 +1387,7 @@ static int Matrix_ass_slice(MatrixObject *self, int begin, int end, PyObject *va
/*parse each sub sequence*/
PyObject *item= PySequence_Fast_GET_ITEM(value_fast, i);
- if(mathutils_array_parse(&mat[i * self->colSize], self->colSize, self->colSize, item, "matrix[begin:end] = value assignment") < 0) {
+ if(mathutils_array_parse(&mat[i * self->col_size], self->col_size, self->col_size, item, "matrix[begin:end] = value assignment") < 0) {
return -1;
}
}
@@ -1393,7 +1395,7 @@ static int Matrix_ass_slice(MatrixObject *self, int begin, int end, PyObject *va
Py_DECREF(value_fast);
/*parsed well - now set in matrix*/
- memcpy(self->contigPtr + (begin * self->colSize), mat, sizeof(float) * (size * self->colSize));
+ memcpy(self->contigPtr + (begin * self->col_size), mat, sizeof(float) * (size * self->col_size));
(void)BaseMath_WriteCallback(self);
return 0;
@@ -1417,14 +1419,14 @@ static PyObject *Matrix_add(PyObject *m1, PyObject *m2)
if(!BaseMath_ReadCallback(mat1) || !BaseMath_ReadCallback(mat2))
return NULL;
- if(mat1->rowSize != mat2->rowSize || mat1->colSize != mat2->colSize){
+ if(mat1->row_size != mat2->row_size || mat1->col_size != mat2->col_size){
PyErr_SetString(PyExc_AttributeError, "Matrix addition: matrices must have the same dimensions for this operation");
return NULL;
}
- add_vn_vnvn(mat, mat1->contigPtr, mat2->contigPtr, mat1->rowSize * mat1->colSize);
+ add_vn_vnvn(mat, mat1->contigPtr, mat2->contigPtr, mat1->row_size * mat1->col_size);
- return newMatrixObject(mat, mat1->rowSize, mat1->colSize, Py_NEW, Py_TYPE(mat1));
+ return newMatrixObject(mat, mat1->row_size, mat1->col_size, Py_NEW, Py_TYPE(mat1));
}
/*------------------------obj - obj------------------------------
subtraction*/
@@ -1444,22 +1446,22 @@ static PyObject *Matrix_sub(PyObject *m1, PyObject *m2)
if(!BaseMath_ReadCallback(mat1) || !BaseMath_ReadCallback(mat2))
return NULL;
- if(mat1->rowSize != mat2->rowSize || mat1->colSize != mat2->colSize){
+ if(mat1->row_size != mat2->row_size || mat1->col_size != mat2->col_size){
PyErr_SetString(PyExc_AttributeError, "Matrix addition: matrices must have the same dimensions for this operation");
return NULL;
}
- sub_vn_vnvn(mat, mat1->contigPtr, mat2->contigPtr, mat1->rowSize * mat1->colSize);
+ sub_vn_vnvn(mat, mat1->contigPtr, mat2->contigPtr, mat1->row_size * mat1->col_size);
- return newMatrixObject(mat, mat1->rowSize, mat1->colSize, Py_NEW, Py_TYPE(mat1));
+ return newMatrixObject(mat, mat1->row_size, mat1->col_size, Py_NEW, Py_TYPE(mat1));
}
/*------------------------obj * obj------------------------------
mulplication*/
static PyObject *matrix_mul_float(MatrixObject *mat, const float scalar)
{
float tmat[16];
- mul_vn_vn_fl(tmat, mat->contigPtr, mat->rowSize * mat->colSize, scalar);
- return newMatrixObject(tmat, mat->rowSize, mat->colSize, Py_NEW, Py_TYPE(mat));
+ mul_vn_vn_fl(tmat, mat->contigPtr, mat->row_size * mat->col_size, scalar);
+ return newMatrixObject(tmat, mat->row_size, mat->col_size, Py_NEW, Py_TYPE(mat));
}
static PyObject *Matrix_mul(PyObject * m1, PyObject * m2)
@@ -1480,7 +1482,7 @@ static PyObject *Matrix_mul(PyObject * m1, PyObject * m2)
}
if(mat1 && mat2) { /*MATRIX * MATRIX*/
- if(mat1->rowSize != mat2->colSize){
+ if(mat1->row_size != mat2->col_size){
PyErr_SetString(PyExc_AttributeError,"Matrix multiplication: matrix A rowsize must equal matrix B colsize");
return NULL;
}
@@ -1492,17 +1494,17 @@ static PyObject *Matrix_mul(PyObject * m1, PyObject * m2)
double dot = 0.0f;
int x, y, z;
- for(x = 0; x < mat2->rowSize; x++) {
- for(y = 0; y < mat1->colSize; y++) {
- for(z = 0; z < mat1->rowSize; z++) {
+ for(x = 0; x < mat2->row_size; x++) {
+ for(y = 0; y < mat1->col_size; y++) {
+ for(z = 0; z < mat1->row_size; z++) {
dot += (mat1->matrix[z][y] * mat2->matrix[x][z]);
}
- mat[((x * mat1->colSize) + y)] = (float)dot;
+ mat[((x * mat1->col_size) + y)] = (float)dot;
dot = 0.0f;
}
}
- return newMatrixObject(mat, mat2->rowSize, mat1->colSize, Py_NEW, Py_TYPE(mat1));
+ return newMatrixObject(mat, mat2->row_size, mat1->col_size, Py_NEW, Py_TYPE(mat1));
}
}
else if(mat2) {
@@ -1553,12 +1555,12 @@ static PyObject *Matrix_subscript(MatrixObject* self, PyObject* item)
if (i == -1 && PyErr_Occurred())
return NULL;
if (i < 0)
- i += self->rowSize;
+ i += self->row_size;
return Matrix_item(self, i);
} else if (PySlice_Check(item)) {
Py_ssize_t start, stop, step, slicelength;
- if (PySlice_GetIndicesEx((void *)item, self->rowSize, &start, &stop, &step, &slicelength) < 0)
+ if (PySlice_GetIndicesEx((void *)item, self->row_size, &start, &stop, &step, &slicelength) < 0)
return NULL;
if (slicelength <= 0) {
@@ -1585,13 +1587,13 @@ static int Matrix_ass_subscript(MatrixObject* self, PyObject* item, PyObject* va
if (i == -1 && PyErr_Occurred())
return -1;
if (i < 0)
- i += self->rowSize;
+ i += self->row_size;
return Matrix_ass_item(self, i, value);
}
else if (PySlice_Check(item)) {
Py_ssize_t start, stop, step, slicelength;
- if (PySlice_GetIndicesEx((void *)item, self->rowSize, &start, &stop, &step, &slicelength) < 0)
+ if (PySlice_GetIndicesEx((void *)item, self->row_size, &start, &stop, &step, &slicelength) < 0)
return -1;
if (step == 1)
@@ -1653,12 +1655,12 @@ static PyNumberMethods Matrix_NumMethods = {
static PyObject *Matrix_getRowSize(MatrixObject *self, void *UNUSED(closure))
{
- return PyLong_FromLong((long) self->rowSize);
+ return PyLong_FromLong((long) self->row_size);
}
static PyObject *Matrix_getColSize(MatrixObject *self, void *UNUSED(closure))
{
- return PyLong_FromLong((long) self->colSize);
+ return PyLong_FromLong((long) self->col_size);
}
static PyObject *Matrix_getMedianScale(MatrixObject *self, void *UNUSED(closure))
@@ -1669,7 +1671,7 @@ static PyObject *Matrix_getMedianScale(MatrixObject *self, void *UNUSED(closure)
return NULL;
/*must be 3-4 cols, 3-4 rows, square matrix*/
- if((self->colSize < 3) || (self->rowSize < 3)) {
+ if((self->col_size < 3) || (self->row_size < 3)) {
PyErr_SetString(PyExc_AttributeError, "Matrix.median_scale: inappropriate matrix size, 3x3 minimum");
return NULL;
}
@@ -1685,9 +1687,9 @@ static PyObject *Matrix_getIsNegative(MatrixObject *self, void *UNUSED(closure))
return NULL;
/*must be 3-4 cols, 3-4 rows, square matrix*/
- if(self->colSize == 4 && self->rowSize == 4)
+ if(self->col_size == 4 && self->row_size == 4)
return PyBool_FromLong(is_negative_m4((float (*)[4])self->contigPtr));
- else if(self->colSize == 3 && self->rowSize == 3)
+ else if(self->col_size == 3 && self->row_size == 3)
return PyBool_FromLong(is_negative_m3((float (*)[3])self->contigPtr));
else {
PyErr_SetString(PyExc_AttributeError, "Matrix.is_negative: inappropriate matrix size - expects 3x3 or 4x4 matrix");
@@ -1833,8 +1835,8 @@ PyObject *newMatrixObject(float *mat, const unsigned short rowSize, const unsign
if(base_type) self = (MatrixObject *)base_type->tp_alloc(base_type, 0);
else self = PyObject_NEW(MatrixObject, &matrix_Type);
- self->rowSize = rowSize;
- self->colSize = colSize;
+ self->row_size = rowSize;
+ self->col_size = colSize;
/* init callbacks as NULL */
self->cb_user= NULL;
diff --git a/source/blender/python/generic/mathutils_matrix.h b/source/blender/python/generic/mathutils_matrix.h
index 125846e1ddd..7b980222048 100644
--- a/source/blender/python/generic/mathutils_matrix.h
+++ b/source/blender/python/generic/mathutils_matrix.h
@@ -39,8 +39,8 @@ extern PyTypeObject matrix_Type;
typedef struct {
BASE_MATH_MEMBERS(contigPtr)
float *matrix[MATRIX_MAX_DIM]; /* ptr to the contigPtr (accessor) */
- unsigned short rowSize;
- unsigned short colSize;
+ unsigned short row_size;
+ unsigned short col_size;
} MatrixObject;
/*struct data contains a pointer to the actual data that the
@@ -49,8 +49,8 @@ be stored in py_data) or be a wrapper for data allocated through
blender (stored in blend_data). This is an either/or struct not both*/
/*prototypes*/
-PyObject *newMatrixObject(float *mat, const unsigned short rowSize, const unsigned short colSize, int type, PyTypeObject *base_type);
-PyObject *newMatrixObject_cb(PyObject *user, int rowSize, int colSize, int cb_type, int cb_subtype);
+PyObject *newMatrixObject(float *mat, const unsigned short row_size, const unsigned short col_size, int type, PyTypeObject *base_type);
+PyObject *newMatrixObject_cb(PyObject *user, int row_size, int col_size, int cb_type, int cb_subtype);
extern int mathutils_matrix_vector_cb_index;
extern struct Mathutils_Callback mathutils_matrix_vector_cb;
diff --git a/source/blender/python/generic/mathutils_quat.c b/source/blender/python/generic/mathutils_quat.c
index b28ef866fea..88cd7358ad5 100644
--- a/source/blender/python/generic/mathutils_quat.c
+++ b/source/blender/python/generic/mathutils_quat.c
@@ -33,18 +33,7 @@
#define QUAT_SIZE 4
-#define QUAT_APPLY_TO_COPY(quat_meth_noargs, _self) \
- QuaternionObject *ret= (QuaternionObject *)Quaternion_copy(_self); \
- PyObject *ret_dummy= quat_meth_noargs(ret); \
- if(ret_dummy) { \
- Py_DECREF(ret_dummy); \
- return (PyObject *)ret; \
- } \
- else { /* error */ \
- Py_DECREF(ret); \
- return NULL; \
- } \
-
+static PyObject *quat__apply_to_copy(PyNoArgsFunction quat_func, QuaternionObject *self);
static PyObject *Quaternion_copy(QuaternionObject *self);
//-----------------------------METHODS------------------------------
@@ -313,7 +302,7 @@ static char Quaternion_normalized_doc[] =
;
static PyObject *Quaternion_normalized(QuaternionObject *self)
{
- QUAT_APPLY_TO_COPY(Quaternion_normalize, self);
+ return quat__apply_to_copy((PyNoArgsFunction)Quaternion_normalize, self);
}
//----------------------------Quaternion.invert()------------------
@@ -342,7 +331,7 @@ static char Quaternion_inverted_doc[] =
;
static PyObject *Quaternion_inverted(QuaternionObject *self)
{
- QUAT_APPLY_TO_COPY(Quaternion_invert, self);
+ return quat__apply_to_copy((PyNoArgsFunction)Quaternion_invert, self);
}
//----------------------------Quaternion.identity()-----------------
@@ -409,7 +398,7 @@ static char Quaternion_conjugated_doc[] =
;
static PyObject *Quaternion_conjugated(QuaternionObject *self)
{
- QUAT_APPLY_TO_COPY(Quaternion_conjugate, self);
+ return quat__apply_to_copy((PyNoArgsFunction)Quaternion_conjugate, self);
}
//----------------------------Quaternion.copy()----------------
@@ -967,6 +956,19 @@ static PyObject *Quaternion_new(PyTypeObject *type, PyObject *args, PyObject *kw
return newQuaternionObject(quat, Py_NEW, type);
}
+static PyObject *quat__apply_to_copy(PyNoArgsFunction quat_func, QuaternionObject *self)
+{
+ PyObject *ret= Quaternion_copy(self);
+ PyObject *ret_dummy= quat_func(ret);
+ if(ret_dummy) {
+ Py_DECREF(ret_dummy);
+ return (PyObject *)ret;
+ }
+ else { /* error */
+ Py_DECREF(ret);
+ return NULL;
+ }
+}
//-----------------------METHOD DEFINITIONS ----------------------
static struct PyMethodDef Quaternion_methods[] = {
diff --git a/source/blender/python/generic/mathutils_vector.c b/source/blender/python/generic/mathutils_vector.c
index da0da6ddba6..27eb531ff21 100644
--- a/source/blender/python/generic/mathutils_vector.c
+++ b/source/blender/python/generic/mathutils_vector.c
@@ -19,7 +19,7 @@
* The Original Code is Copyright (C) 2001-2002 by NaN Holding BV.
* All rights reserved.
*
- *
+ *
* Contributor(s): Willian P. Germano, Joseph Gilbert, Ken Hughes, Alex Fraser, Campbell Barton
*
* ***** END GPL LICENSE BLOCK *****
@@ -33,18 +33,6 @@
#define MAX_DIMENSIONS 4
-#define VEC_APPLY_TO_COPY(vec_meth_noargs, _self) \
- VectorObject *ret= (VectorObject *)Vector_copy(_self); \
- PyObject *ret_dummy= vec_meth_noargs(ret); \
- if(ret_dummy) { \
- Py_DECREF(ret_dummy); \
- return (PyObject *)ret; \
- } \
- else { /* error */ \
- Py_DECREF(ret); \
- return NULL; \
- } \
-
/* Swizzle axes get packed into a single value that is used as a closure. Each
axis uses SWIZZLE_BITS_PER_AXIS bits. The first bit (SWIZZLE_VALID_AXIS) is
used as a sentinel: if it is unset, the axis is not valid. */
@@ -77,6 +65,20 @@ static PyObject *Vector_new(PyTypeObject *type, PyObject *args, PyObject *UNUSED
return newVectorObject(vec, size, Py_NEW, type);
}
+static PyObject *vec__apply_to_copy(PyNoArgsFunction vec_func, VectorObject *self)
+{
+ PyObject *ret= Vector_copy(self);
+ PyObject *ret_dummy= vec_func(ret);
+ if(ret_dummy) {
+ Py_DECREF(ret_dummy);
+ return (PyObject *)ret;
+ }
+ else { /* error */
+ Py_DECREF(ret);
+ return NULL;
+ }
+}
+
/*-----------------------------METHODS---------------------------- */
static char Vector_zero_doc[] =
".. method:: zero()\n"
@@ -107,7 +109,7 @@ static PyObject *Vector_normalize(VectorObject *self)
if(!BaseMath_ReadCallback(self))
return NULL;
-
+
for(i = 0; i < self->size; i++) {
norm += self->vec[i] * self->vec[i];
}
@@ -115,7 +117,7 @@ static PyObject *Vector_normalize(VectorObject *self)
for(i = 0; i < self->size; i++) {
self->vec[i] /= norm;
}
-
+
(void)BaseMath_WriteCallback(self);
Py_RETURN_NONE;
}
@@ -129,7 +131,7 @@ static char Vector_normalized_doc[] =
;
static PyObject *Vector_normalized(VectorObject *self)
{
- VEC_APPLY_TO_COPY(Vector_normalize, self);
+ return vec__apply_to_copy((PyNoArgsFunction)Vector_normalize, self);
}
static char Vector_resize_2d_doc[] =
@@ -150,13 +152,13 @@ static PyObject *Vector_resize_2d(VectorObject *self)
PyErr_SetString(PyExc_TypeError, "vector.resize_2d(): cannot resize a vector that has an owner");
return NULL;
}
-
+
self->vec = PyMem_Realloc(self->vec, (sizeof(float) * 2));
if(self->vec == NULL) {
PyErr_SetString(PyExc_MemoryError, "vector.resize_2d(): problem allocating pointer space");
return NULL;
}
-
+
self->size = 2;
Py_RETURN_NONE;
}
@@ -179,16 +181,16 @@ static PyObject *Vector_resize_3d(VectorObject *self)
PyErr_SetString(PyExc_TypeError, "vector.resize_3d(): cannot resize a vector that has an owner");
return NULL;
}
-
+
self->vec = PyMem_Realloc(self->vec, (sizeof(float) * 3));
if(self->vec == NULL) {
PyErr_SetString(PyExc_MemoryError, "vector.resize_3d(): problem allocating pointer space");
return NULL;
}
-
+
if(self->size == 2)
self->vec[2] = 0.0f;
-
+
self->size = 3;
Py_RETURN_NONE;
}
@@ -211,7 +213,7 @@ static PyObject *Vector_resize_4d(VectorObject *self)
PyErr_SetString(PyExc_TypeError, "vector.resize_4d(): cannot resize a vector that has an owner");
return NULL;
}
-
+
self->vec = PyMem_Realloc(self->vec, (sizeof(float) * 4));
if(self->vec == NULL) {
PyErr_SetString(PyExc_MemoryError, "vector.resize_4d(): problem allocating pointer space");
@@ -356,7 +358,7 @@ static PyObject *Vector_to_track_quat(VectorObject *self, PyObject *args )
PyErr_SetString(PyExc_TypeError, "only for 3D vectors");
return NULL;
}
-
+
if(!BaseMath_ReadCallback(self))
return NULL;
@@ -435,7 +437,7 @@ static PyObject *Vector_to_track_quat(VectorObject *self, PyObject *args )
}
/*
- flip vector around, since vectoquat expect a vector from target to tracking object
+ flip vector around, since vectoquat expect a vector from target to tracking object
and the python function expects the inverse (a vector to the target).
*/
negate_v3_v3(vec, self->vec);
@@ -465,10 +467,10 @@ static PyObject *Vector_reflect(VectorObject *self, PyObject *value)
float mirror[3], vec[3];
float reflect[3] = {0.0f};
float tvec[MAX_DIMENSIONS];
-
+
if(!BaseMath_ReadCallback(self))
return NULL;
-
+
if((value_size= mathutils_array_parse(tvec, 2, 4, value, "vector.reflect(other), invalid 'other' arg")) == -1)
return NULL;
@@ -476,7 +478,7 @@ static PyObject *Vector_reflect(VectorObject *self, PyObject *value)
mirror[1] = tvec[1];
if (value_size > 2) mirror[2] = tvec[2];
else mirror[2] = 0.0;
-
+
vec[0] = self->vec[0];
vec[1] = self->vec[1];
if (self->size > 2) vec[2] = self->vec[2];
@@ -545,7 +547,7 @@ static PyObject *Vector_dot(VectorObject *self, PyObject *value)
return PyFloat_FromDouble(dot);
}
-static char Vector_angle_doc[] =
+static char Vector_angle_doc[] =
".. function:: angle(other, fallback)\n"
"\n"
" Return the angle between two vectors.\n"
@@ -567,7 +569,7 @@ static PyObject *Vector_angle(VectorObject *self, PyObject *args)
double dot = 0.0f, test_v1 = 0.0f, test_v2 = 0.0f;
int x;
PyObject *fallback= NULL;
-
+
if(!PyArg_ParseTuple(args, "O|O:angle", &value, &fallback))
return NULL;
@@ -757,7 +759,7 @@ static PyObject *Vector_copy(VectorObject *self)
{
if(!BaseMath_ReadCallback(self))
return NULL;
-
+
return newVectorObject(self->vec, self->size, Py_NEW, Py_TYPE(self));
}
@@ -792,7 +794,7 @@ static PyObject *Vector_item(VectorObject *self, int i)
if(!BaseMath_ReadIndexCallback(self, i))
return NULL;
-
+
return PyFloat_FromDouble(self->vec[i]);
}
/* sequence accessor (set): vector[index] = value */
@@ -811,7 +813,7 @@ static int Vector_ass_item(VectorObject *self, int i, PyObject * ob)
return -1;
}
self->vec[i] = scalar;
-
+
if(!BaseMath_WriteIndexCallback(self, i))
return -1;
return 0;
@@ -825,7 +827,7 @@ static PyObject *Vector_slice(VectorObject *self, int begin, int end)
if(!BaseMath_ReadCallback(self))
return NULL;
-
+
CLAMP(begin, 0, self->size);
if (end<0) end= self->size+end+1;
CLAMP(end, 0, self->size);
@@ -906,12 +908,12 @@ static PyObject *Vector_iadd(PyObject * v1, PyObject * v2)
}
vec1 = (VectorObject*)v1;
vec2 = (VectorObject*)v2;
-
+
if(vec1->size != vec2->size) {
PyErr_SetString(PyExc_AttributeError, "Vector addition: vectors must have the same dimensions for this operation");
return NULL;
}
-
+
if(!BaseMath_ReadCallback(vec1) || !BaseMath_ReadCallback(vec2))
return NULL;
@@ -934,10 +936,10 @@ static PyObject *Vector_sub(PyObject * v1, PyObject * v2)
}
vec1 = (VectorObject*)v1;
vec2 = (VectorObject*)v2;
-
+
if(!BaseMath_ReadCallback(vec1) || !BaseMath_ReadCallback(vec2))
return NULL;
-
+
if(vec1->size != vec2->size) {
PyErr_SetString(PyExc_AttributeError, "Vector subtraction: vectors must have the same dimensions for this operation");
return NULL;
@@ -959,12 +961,12 @@ static PyObject *Vector_isub(PyObject * v1, PyObject * v2)
}
vec1 = (VectorObject*)v1;
vec2 = (VectorObject*)v2;
-
+
if(vec1->size != vec2->size) {
PyErr_SetString(PyExc_AttributeError, "Vector subtraction: vectors must have the same dimensions for this operation");
return NULL;
}
-
+
if(!BaseMath_ReadCallback(vec1) || !BaseMath_ReadCallback(vec2))
return NULL;
@@ -992,9 +994,9 @@ static int column_vector_multiplication(float rvec[MAX_DIMENSIONS], VectorObject
float vec_cpy[MAX_DIMENSIONS];
double dot = 0.0f;
int x, y, z = 0;
-
- if(mat->rowSize != vec->size){
- if(mat->rowSize == 4 && vec->size == 3) {
+
+ if(mat->row_size != vec->size){
+ if(mat->row_size == 4 && vec->size == 3) {
vec_cpy[3] = 1.0f;
}
else {
@@ -1007,14 +1009,14 @@ static int column_vector_multiplication(float rvec[MAX_DIMENSIONS], VectorObject
rvec[3] = 1.0f;
- for(x = 0; x < mat->colSize; x++) {
- for(y = 0; y < mat->rowSize; y++) {
+ for(x = 0; x < mat->col_size; x++) {
+ for(y = 0; y < mat->row_size; y++) {
dot += mat->matrix[y][x] * vec_cpy[y];
}
rvec[z++] = (float)dot;
dot = 0.0f;
}
-
+
return 0;
}
@@ -1029,7 +1031,7 @@ static PyObject *Vector_mul(PyObject * v1, PyObject * v2)
{
VectorObject *vec1 = NULL, *vec2 = NULL;
float scalar;
-
+
if VectorObject_Check(v1) {
vec1= (VectorObject *)v1;
if(!BaseMath_ReadCallback(vec1))
@@ -1040,18 +1042,18 @@ static PyObject *Vector_mul(PyObject * v1, PyObject * v2)
if(!BaseMath_ReadCallback(vec2))
return NULL;
}
-
-
+
+
/* make sure v1 is always the vector */
if (vec1 && vec2 ) {
int i;
double dot = 0.0f;
-
+
if(vec1->size != vec2->size) {
PyErr_SetString(PyExc_AttributeError, "Vector multiplication: vectors must have the same dimensions for this operation");
return NULL;
}
-
+
/*dot product*/
for(i = 0; i < vec1->size; i++) {
dot += vec1->vec[i] * vec2->vec[i];
@@ -1108,17 +1110,17 @@ static PyObject *Vector_imul(PyObject * v1, PyObject * v2)
{
VectorObject *vec = (VectorObject *)v1;
float scalar;
-
+
if(!BaseMath_ReadCallback(vec))
return NULL;
-
+
/* only support vec*=float and vec*=mat
vec*=vec result is a float so that wont work */
if (MatrixObject_Check(v2)) {
float rvec[MAX_DIMENSIONS];
if(!BaseMath_ReadCallback((MatrixObject *)v2))
return NULL;
-
+
if(column_vector_multiplication(rvec, vec, (MatrixObject*)v2) == -1)
return NULL;
@@ -1145,7 +1147,7 @@ static PyObject *Vector_imul(PyObject * v1, PyObject * v2)
PyErr_SetString(PyExc_TypeError, "Vector multiplication: arguments not acceptable for this operation");
return NULL;
}
-
+
(void)BaseMath_WriteCallback(vec);
Py_INCREF( v1 );
return v1;
@@ -1157,13 +1159,13 @@ static PyObject *Vector_div(PyObject * v1, PyObject * v2)
int i;
float vec[4], scalar;
VectorObject *vec1 = NULL;
-
+
if(!VectorObject_Check(v1)) { /* not a vector */
PyErr_SetString(PyExc_TypeError, "Vector division: Vector must be divided by a float");
return NULL;
}
vec1 = (VectorObject*)v1; /* vector */
-
+
if(!BaseMath_ReadCallback(vec1))
return NULL;
@@ -1171,12 +1173,12 @@ static PyObject *Vector_div(PyObject * v1, PyObject * v2)
PyErr_SetString(PyExc_TypeError, "Vector division: Vector must be divided by a float");
return NULL;
}
-
+
if(scalar==0.0) {
PyErr_SetString(PyExc_ZeroDivisionError, "Vector division: divide by zero error");
return NULL;
}
-
+
for(i = 0; i < vec1->size; i++) {
vec[i] = vec1->vec[i] / scalar;
}
@@ -1189,7 +1191,7 @@ static PyObject *Vector_idiv(PyObject * v1, PyObject * v2)
int i;
float scalar;
VectorObject *vec1 = (VectorObject*)v1;
-
+
if(!BaseMath_ReadCallback(vec1))
return NULL;
@@ -1205,9 +1207,9 @@ static PyObject *Vector_idiv(PyObject * v1, PyObject * v2)
for(i = 0; i < vec1->size; i++) {
vec1->vec[i] /= scalar;
}
-
+
(void)BaseMath_WriteCallback(vec1);
-
+
Py_INCREF( v1 );
return v1;
}
@@ -1217,10 +1219,10 @@ static PyObject *Vector_idiv(PyObject * v1, PyObject * v2)
static PyObject *Vector_neg(VectorObject *self)
{
float tvec[MAX_DIMENSIONS];
-
+
if(!BaseMath_ReadCallback(self))
return NULL;
-
+
negate_vn_vn(tvec, self->vec, self->size);
return newVectorObject(tvec, self->size, Py_NEW, Py_TYPE(self));
}
@@ -1263,7 +1265,7 @@ static PyObject* Vector_richcmpr(PyObject *objectA, PyObject *objectB, int compa
if(!BaseMath_ReadCallback(vecA) || !BaseMath_ReadCallback(vecB))
return NULL;
-
+
if (vecA->size != vecB->size){
if (comparison_type == Py_NE){
Py_RETURN_TRUE;
@@ -1447,7 +1449,7 @@ static PyNumberMethods Vector_NumMethods = {
/*
* vector axis, vector.x/y/z/w
*/
-
+
static PyObject *Vector_getAxis(VectorObject *self, void *type)
{
return Vector_item(self, GET_INT_FROM_POINTER(type));
@@ -1463,10 +1465,10 @@ static PyObject *Vector_getLength(VectorObject *self, void *UNUSED(closure))
{
double dot = 0.0f;
int i;
-
+
if(!BaseMath_ReadCallback(self))
return NULL;
-
+
for(i = 0; i < self->size; i++){
dot += (self->vec[i] * self->vec[i]);
}
@@ -1477,7 +1479,7 @@ static int Vector_setLength(VectorObject *self, PyObject *value)
{
double dot = 0.0f, param;
int i;
-
+
if(!BaseMath_ReadCallback(self))
return -1;
@@ -1485,7 +1487,7 @@ static int Vector_setLength(VectorObject *self, PyObject *value)
PyErr_SetString(PyExc_TypeError, "length must be set to a number");
return -1;
}
-
+
if (param < 0.0f) {
PyErr_SetString(PyExc_TypeError, "cannot set a vectors length to a negative value");
return -1;
@@ -1494,27 +1496,27 @@ static int Vector_setLength(VectorObject *self, PyObject *value)
fill_vn(self->vec, self->size, 0.0f);
return 0;
}
-
+
for(i = 0; i < self->size; i++){
dot += (self->vec[i] * self->vec[i]);
}
if (!dot) /* cant sqrt zero */
return 0;
-
+
dot = sqrt(dot);
-
+
if (dot==param)
return 0;
-
+
dot= dot/param;
-
+
for(i = 0; i < self->size; i++){
self->vec[i]= self->vec[i] / (float)dot;
}
-
+
(void)BaseMath_WriteCallback(self); /* checked already */
-
+
return 0;
}
@@ -1527,10 +1529,10 @@ static PyObject *Vector_getSwizzle(VectorObject *self, void *closure)
size_t axis_from;
float vec[MAX_DIMENSIONS];
unsigned int swizzleClosure;
-
+
if(!BaseMath_ReadCallback(self))
return NULL;
-
+
/* Unpack the axes from the closure into an array. */
axis_to = 0;
swizzleClosure = GET_INT_FROM_POINTER(closure);
@@ -1546,7 +1548,7 @@ static PyObject *Vector_getSwizzle(VectorObject *self, void *closure)
swizzleClosure = swizzleClosure >> SWIZZLE_BITS_PER_AXIS;
axis_to++;
}
-
+
return newVectorObject(vec, axis_to, Py_NEW, Py_TYPE(self));
}
@@ -1569,13 +1571,13 @@ static int Vector_setSwizzle(VectorObject *self, PyObject * value, void *closure
size_t axis_to;
unsigned int swizzleClosure;
-
+
float tvec[MAX_DIMENSIONS];
float vec_assign[MAX_DIMENSIONS];
-
+
if(!BaseMath_ReadCallback(self))
return -1;
-
+
/* Check that the closure can be used with this vector: even 2D vectors have
swizzles defined for axes z and w, but they would be invalid. */
swizzleClosure = GET_INT_FROM_POINTER(closure);
@@ -1621,7 +1623,7 @@ static int Vector_setSwizzle(VectorObject *self, PyObject * value, void *closure
memcpy(self->vec, tvec, axis_from * sizeof(float));
/* continue with BaseMathObject_WriteCallback at the end */
-
+
if(!BaseMath_WriteCallback(self))
return -1;
else
@@ -1640,7 +1642,7 @@ static PyGetSetDef Vector_getseters[] = {
{(char *)"magnitude", (getter)Vector_getLength, (setter)Vector_setLength, (char *)"Vector Length.\n\n:type: float", NULL},
{(char *)"is_wrapped", (getter)BaseMathObject_getWrapped, (setter)NULL, (char *)BaseMathObject_Wrapped_doc, NULL},
{(char *)"owner", (getter)BaseMathObject_getOwner, (setter)NULL, (char *)BaseMathObject_Owner_doc, NULL},
-
+
/* autogenerated swizzle attrs, see python script below */
{(char *)"xx", (getter)Vector_getSwizzle, (setter)NULL, NULL, SET_INT_IN_POINTER(((0|SWIZZLE_VALID_AXIS) | ((0|SWIZZLE_VALID_AXIS)<<SWIZZLE_BITS_PER_AXIS)))}, // 36
{(char *)"xxx", (getter)Vector_getSwizzle, (setter)NULL, NULL, SET_INT_IN_POINTER(((0|SWIZZLE_VALID_AXIS) | ((0|SWIZZLE_VALID_AXIS)<<SWIZZLE_BITS_PER_AXIS) | ((0|SWIZZLE_VALID_AXIS)<<(SWIZZLE_BITS_PER_AXIS*2))))}, // 292