svn merge ^/trunk/blender -r40950:40997, bmesh is in sync with head again
This commit is contained in:
@@ -49,14 +49,14 @@ static int mathutils_array_parse_fast(float *array, int array_min, int array_max
|
||||
int i, size;
|
||||
|
||||
/* non list/tuple cases */
|
||||
if(!(value_fast=PySequence_Fast(value, error_prefix))) {
|
||||
if (!(value_fast=PySequence_Fast(value, error_prefix))) {
|
||||
/* PySequence_Fast sets the error */
|
||||
return -1;
|
||||
}
|
||||
|
||||
size= PySequence_Fast_GET_SIZE(value_fast);
|
||||
|
||||
if(size > array_max || size < array_min) {
|
||||
if (size > array_max || size < array_min) {
|
||||
if (array_max == array_min) {
|
||||
PyErr_Format(PyExc_ValueError,
|
||||
"%.200s: sequence size is %d, expected %d",
|
||||
@@ -74,7 +74,7 @@ static int mathutils_array_parse_fast(float *array, int array_min, int array_max
|
||||
i= size;
|
||||
do {
|
||||
i--;
|
||||
if(((array[i]= PyFloat_AsDouble((item= PySequence_Fast_GET_ITEM(value_fast, i)))) == -1.0f) && PyErr_Occurred()) {
|
||||
if (((array[i]= PyFloat_AsDouble((item= PySequence_Fast_GET_ITEM(value_fast, i)))) == -1.0f) && PyErr_Occurred()) {
|
||||
PyErr_Format(PyExc_TypeError,
|
||||
"%.200s: sequence index %d expected a number, "
|
||||
"found '%.200s' type, ",
|
||||
@@ -82,7 +82,7 @@ static int mathutils_array_parse_fast(float *array, int array_min, int array_max
|
||||
Py_DECREF(value_fast);
|
||||
return -1;
|
||||
}
|
||||
} while(i);
|
||||
} while (i);
|
||||
|
||||
Py_XDECREF(value_fast);
|
||||
return size;
|
||||
@@ -94,16 +94,16 @@ int mathutils_array_parse(float *array, int array_min, int array_max, PyObject *
|
||||
#if 1 /* approx 6x speedup for mathutils types */
|
||||
int size;
|
||||
|
||||
if( (size= VectorObject_Check(value) ? ((VectorObject *)value)->size : 0) ||
|
||||
if ( (size= VectorObject_Check(value) ? ((VectorObject *)value)->size : 0) ||
|
||||
(size= EulerObject_Check(value) ? 3 : 0) ||
|
||||
(size= QuaternionObject_Check(value) ? 4 : 0) ||
|
||||
(size= ColorObject_Check(value) ? 3 : 0))
|
||||
{
|
||||
if(BaseMath_ReadCallback((BaseMathObject *)value) == -1) {
|
||||
if (BaseMath_ReadCallback((BaseMathObject *)value) == -1) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
if(size > array_max || size < array_min) {
|
||||
if (size > array_max || size < array_min) {
|
||||
if (array_max == array_min) {
|
||||
PyErr_Format(PyExc_ValueError,
|
||||
"%.200s: sequence size is %d, expected %d",
|
||||
@@ -129,8 +129,8 @@ int mathutils_array_parse(float *array, int array_min, int array_max, PyObject *
|
||||
|
||||
int mathutils_any_to_rotmat(float rmat[3][3], PyObject *value, const char *error_prefix)
|
||||
{
|
||||
if(EulerObject_Check(value)) {
|
||||
if(BaseMath_ReadCallback((BaseMathObject *)value) == -1) {
|
||||
if (EulerObject_Check(value)) {
|
||||
if (BaseMath_ReadCallback((BaseMathObject *)value) == -1) {
|
||||
return -1;
|
||||
}
|
||||
else {
|
||||
@@ -139,7 +139,7 @@ int mathutils_any_to_rotmat(float rmat[3][3], PyObject *value, const char *error
|
||||
}
|
||||
}
|
||||
else if (QuaternionObject_Check(value)) {
|
||||
if(BaseMath_ReadCallback((BaseMathObject *)value) == -1) {
|
||||
if (BaseMath_ReadCallback((BaseMathObject *)value) == -1) {
|
||||
return -1;
|
||||
}
|
||||
else {
|
||||
@@ -150,10 +150,10 @@ int mathutils_any_to_rotmat(float rmat[3][3], PyObject *value, const char *error
|
||||
}
|
||||
}
|
||||
else if (MatrixObject_Check(value)) {
|
||||
if(BaseMath_ReadCallback((BaseMathObject *)value) == -1) {
|
||||
if (BaseMath_ReadCallback((BaseMathObject *)value) == -1) {
|
||||
return -1;
|
||||
}
|
||||
else if(((MatrixObject *)value)->col_size < 3 || ((MatrixObject *)value)->row_size < 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);
|
||||
@@ -202,7 +202,7 @@ int EXPP_FloatsAreEqual(float af, float bf, int maxDiff)
|
||||
int EXPP_VectorsAreEqual(float *vecA, float *vecB, int size, int floatSteps)
|
||||
{
|
||||
int x;
|
||||
for (x=0; x< size; x++){
|
||||
for (x=0; x< size; x++) {
|
||||
if (EXPP_FloatsAreEqual(vecA[x], vecB[x], floatSteps) == 0)
|
||||
return 0;
|
||||
}
|
||||
@@ -220,8 +220,8 @@ int Mathutils_RegisterCallback(Mathutils_Callback *cb)
|
||||
int i;
|
||||
|
||||
/* find the first free slot */
|
||||
for(i= 0; mathutils_callbacks[i]; i++) {
|
||||
if(mathutils_callbacks[i]==cb) /* already registered? */
|
||||
for (i= 0; mathutils_callbacks[i]; i++) {
|
||||
if (mathutils_callbacks[i]==cb) /* already registered? */
|
||||
return i;
|
||||
}
|
||||
|
||||
@@ -233,10 +233,10 @@ int Mathutils_RegisterCallback(Mathutils_Callback *cb)
|
||||
int _BaseMathObject_ReadCallback(BaseMathObject *self)
|
||||
{
|
||||
Mathutils_Callback *cb= mathutils_callbacks[self->cb_type];
|
||||
if(cb->get(self, self->cb_subtype) != -1)
|
||||
if (cb->get(self, self->cb_subtype) != -1)
|
||||
return 0;
|
||||
|
||||
if(!PyErr_Occurred()) {
|
||||
if (!PyErr_Occurred()) {
|
||||
PyErr_Format(PyExc_RuntimeError,
|
||||
"%s read, user has become invalid",
|
||||
Py_TYPE(self)->tp_name);
|
||||
@@ -247,10 +247,10 @@ int _BaseMathObject_ReadCallback(BaseMathObject *self)
|
||||
int _BaseMathObject_WriteCallback(BaseMathObject *self)
|
||||
{
|
||||
Mathutils_Callback *cb= mathutils_callbacks[self->cb_type];
|
||||
if(cb->set(self, self->cb_subtype) != -1)
|
||||
if (cb->set(self, self->cb_subtype) != -1)
|
||||
return 0;
|
||||
|
||||
if(!PyErr_Occurred()) {
|
||||
if (!PyErr_Occurred()) {
|
||||
PyErr_Format(PyExc_RuntimeError,
|
||||
"%s write, user has become invalid",
|
||||
Py_TYPE(self)->tp_name);
|
||||
@@ -261,10 +261,10 @@ int _BaseMathObject_WriteCallback(BaseMathObject *self)
|
||||
int _BaseMathObject_ReadIndexCallback(BaseMathObject *self, int index)
|
||||
{
|
||||
Mathutils_Callback *cb= mathutils_callbacks[self->cb_type];
|
||||
if(cb->get_index(self, self->cb_subtype, index) != -1)
|
||||
if (cb->get_index(self, self->cb_subtype, index) != -1)
|
||||
return 0;
|
||||
|
||||
if(!PyErr_Occurred()) {
|
||||
if (!PyErr_Occurred()) {
|
||||
PyErr_Format(PyExc_RuntimeError,
|
||||
"%s read index, user has become invalid",
|
||||
Py_TYPE(self)->tp_name);
|
||||
@@ -275,10 +275,10 @@ int _BaseMathObject_ReadIndexCallback(BaseMathObject *self, int index)
|
||||
int _BaseMathObject_WriteIndexCallback(BaseMathObject *self, int index)
|
||||
{
|
||||
Mathutils_Callback *cb= mathutils_callbacks[self->cb_type];
|
||||
if(cb->set_index(self, self->cb_subtype, index) != -1)
|
||||
if (cb->set_index(self, self->cb_subtype, index) != -1)
|
||||
return 0;
|
||||
|
||||
if(!PyErr_Occurred()) {
|
||||
if (!PyErr_Occurred()) {
|
||||
PyErr_Format(PyExc_RuntimeError,
|
||||
"%s write index, user has become invalid",
|
||||
Py_TYPE(self)->tp_name);
|
||||
@@ -316,11 +316,11 @@ int BaseMathObject_clear(BaseMathObject *self)
|
||||
void BaseMathObject_dealloc(BaseMathObject *self)
|
||||
{
|
||||
/* only free non wrapped */
|
||||
if(self->wrapped != Py_WRAP) {
|
||||
if (self->wrapped != Py_WRAP) {
|
||||
PyMem_Free(self->data);
|
||||
}
|
||||
|
||||
if(self->cb_user) {
|
||||
if (self->cb_user) {
|
||||
PyObject_GC_UnTrack(self);
|
||||
BaseMathObject_clear(self);
|
||||
}
|
||||
@@ -350,15 +350,15 @@ PyMODINIT_FUNC PyInit_mathutils(void)
|
||||
PyObject *submodule;
|
||||
PyObject *item;
|
||||
|
||||
if(PyType_Ready(&vector_Type) < 0)
|
||||
if (PyType_Ready(&vector_Type) < 0)
|
||||
return NULL;
|
||||
if(PyType_Ready(&matrix_Type) < 0)
|
||||
if (PyType_Ready(&matrix_Type) < 0)
|
||||
return NULL;
|
||||
if(PyType_Ready(&euler_Type) < 0)
|
||||
if (PyType_Ready(&euler_Type) < 0)
|
||||
return NULL;
|
||||
if(PyType_Ready(&quaternion_Type) < 0)
|
||||
if (PyType_Ready(&quaternion_Type) < 0)
|
||||
return NULL;
|
||||
if(PyType_Ready(&color_Type) < 0)
|
||||
if (PyType_Ready(&color_Type) < 0)
|
||||
return NULL;
|
||||
|
||||
submodule = PyModule_Create(&M_Mathutils_module_def);
|
||||
|
||||
@@ -42,7 +42,7 @@ static PyObject *Color_new(PyTypeObject *type, PyObject *args, PyObject *kwds)
|
||||
{
|
||||
float col[3]= {0.0f, 0.0f, 0.0f};
|
||||
|
||||
if(kwds && PyDict_Size(kwds)) {
|
||||
if (kwds && PyDict_Size(kwds)) {
|
||||
PyErr_SetString(PyExc_TypeError,
|
||||
"mathutils.Color(): "
|
||||
"takes no keyword args");
|
||||
@@ -53,7 +53,7 @@ static PyObject *Color_new(PyTypeObject *type, PyObject *args, PyObject *kwds)
|
||||
case 0:
|
||||
break;
|
||||
case 1:
|
||||
if((mathutils_array_parse(col, COLOR_SIZE, COLOR_SIZE, PyTuple_GET_ITEM(args, 0), "mathutils.Color()")) == -1)
|
||||
if ((mathutils_array_parse(col, COLOR_SIZE, COLOR_SIZE, PyTuple_GET_ITEM(args, 0), "mathutils.Color()")) == -1)
|
||||
return NULL;
|
||||
break;
|
||||
default:
|
||||
@@ -75,13 +75,13 @@ static PyObject *Color_ToTupleExt(ColorObject *self, int ndigits)
|
||||
|
||||
ret= PyTuple_New(COLOR_SIZE);
|
||||
|
||||
if(ndigits >= 0) {
|
||||
for(i= 0; i < COLOR_SIZE; i++) {
|
||||
if (ndigits >= 0) {
|
||||
for (i= 0; i < COLOR_SIZE; i++) {
|
||||
PyTuple_SET_ITEM(ret, i, PyFloat_FromDouble(double_round((double)self->col[i], ndigits)));
|
||||
}
|
||||
}
|
||||
else {
|
||||
for(i= 0; i < COLOR_SIZE; i++) {
|
||||
for (i= 0; i < COLOR_SIZE; i++) {
|
||||
PyTuple_SET_ITEM(ret, i, PyFloat_FromDouble(self->col[i]));
|
||||
}
|
||||
}
|
||||
@@ -102,7 +102,7 @@ PyDoc_STRVAR(Color_copy_doc,
|
||||
);
|
||||
static PyObject *Color_copy(ColorObject *self)
|
||||
{
|
||||
if(BaseMath_ReadCallback(self) == -1)
|
||||
if (BaseMath_ReadCallback(self) == -1)
|
||||
return NULL;
|
||||
|
||||
return newColorObject(self->col, Py_NEW, Py_TYPE(self));
|
||||
@@ -115,7 +115,7 @@ static PyObject *Color_repr(ColorObject * self)
|
||||
{
|
||||
PyObject *ret, *tuple;
|
||||
|
||||
if(BaseMath_ReadCallback(self) == -1)
|
||||
if (BaseMath_ReadCallback(self) == -1)
|
||||
return NULL;
|
||||
|
||||
tuple= Color_ToTupleExt(self, -1);
|
||||
@@ -137,7 +137,7 @@ static PyObject* Color_richcmpr(PyObject *a, PyObject *b, int op)
|
||||
ColorObject *colA= (ColorObject*)a;
|
||||
ColorObject *colB= (ColorObject*)b;
|
||||
|
||||
if(BaseMath_ReadCallback(colA) == -1 || BaseMath_ReadCallback(colB) == -1)
|
||||
if (BaseMath_ReadCallback(colA) == -1 || BaseMath_ReadCallback(colB) == -1)
|
||||
return NULL;
|
||||
|
||||
ok= EXPP_VectorsAreEqual(colA->col, colB->col, COLOR_SIZE, 1) ? 0 : -1;
|
||||
@@ -175,16 +175,16 @@ static int Color_len(ColorObject *UNUSED(self))
|
||||
//sequence accessor (get)
|
||||
static PyObject *Color_item(ColorObject * self, int i)
|
||||
{
|
||||
if(i<0) i= COLOR_SIZE-i;
|
||||
if (i<0) i= COLOR_SIZE-i;
|
||||
|
||||
if(i < 0 || i >= COLOR_SIZE) {
|
||||
if (i < 0 || i >= COLOR_SIZE) {
|
||||
PyErr_SetString(PyExc_IndexError,
|
||||
"color[attribute]: "
|
||||
"array index out of range");
|
||||
return NULL;
|
||||
}
|
||||
|
||||
if(BaseMath_ReadIndexCallback(self, i) == -1)
|
||||
if (BaseMath_ReadIndexCallback(self, i) == -1)
|
||||
return NULL;
|
||||
|
||||
return PyFloat_FromDouble(self->col[i]);
|
||||
@@ -196,16 +196,16 @@ static int Color_ass_item(ColorObject * self, int i, PyObject *value)
|
||||
{
|
||||
float f = PyFloat_AsDouble(value);
|
||||
|
||||
if(f == -1 && PyErr_Occurred()) { // parsed item not a number
|
||||
if (f == -1 && PyErr_Occurred()) { // parsed item not a number
|
||||
PyErr_SetString(PyExc_TypeError,
|
||||
"color[attribute] = x: "
|
||||
"argument not a number");
|
||||
return -1;
|
||||
}
|
||||
|
||||
if(i<0) i= COLOR_SIZE-i;
|
||||
if (i<0) i= COLOR_SIZE-i;
|
||||
|
||||
if(i < 0 || i >= COLOR_SIZE){
|
||||
if (i < 0 || i >= COLOR_SIZE) {
|
||||
PyErr_SetString(PyExc_IndexError, "color[attribute] = x: "
|
||||
"array assignment index out of range");
|
||||
return -1;
|
||||
@@ -213,7 +213,7 @@ static int Color_ass_item(ColorObject * self, int i, PyObject *value)
|
||||
|
||||
self->col[i] = f;
|
||||
|
||||
if(BaseMath_WriteIndexCallback(self, i) == -1)
|
||||
if (BaseMath_WriteIndexCallback(self, i) == -1)
|
||||
return -1;
|
||||
|
||||
return 0;
|
||||
@@ -225,7 +225,7 @@ static PyObject *Color_slice(ColorObject * self, int begin, int end)
|
||||
PyObject *tuple;
|
||||
int count;
|
||||
|
||||
if(BaseMath_ReadCallback(self) == -1)
|
||||
if (BaseMath_ReadCallback(self) == -1)
|
||||
return NULL;
|
||||
|
||||
CLAMP(begin, 0, COLOR_SIZE);
|
||||
@@ -234,7 +234,7 @@ static PyObject *Color_slice(ColorObject * self, int begin, int end)
|
||||
begin= MIN2(begin, end);
|
||||
|
||||
tuple= PyTuple_New(end - begin);
|
||||
for(count= begin; count < end; count++) {
|
||||
for (count= begin; count < end; count++) {
|
||||
PyTuple_SET_ITEM(tuple, count - begin, PyFloat_FromDouble(self->col[count]));
|
||||
}
|
||||
|
||||
@@ -247,7 +247,7 @@ static int Color_ass_slice(ColorObject *self, int begin, int end, PyObject *seq)
|
||||
int i, size;
|
||||
float col[COLOR_SIZE];
|
||||
|
||||
if(BaseMath_ReadCallback(self) == -1)
|
||||
if (BaseMath_ReadCallback(self) == -1)
|
||||
return -1;
|
||||
|
||||
CLAMP(begin, 0, COLOR_SIZE);
|
||||
@@ -255,17 +255,17 @@ static int Color_ass_slice(ColorObject *self, int begin, int end, PyObject *seq)
|
||||
CLAMP(end, 0, COLOR_SIZE);
|
||||
begin = MIN2(begin, end);
|
||||
|
||||
if((size=mathutils_array_parse(col, 0, COLOR_SIZE, seq, "mathutils.Color[begin:end] = []")) == -1)
|
||||
if ((size=mathutils_array_parse(col, 0, COLOR_SIZE, seq, "mathutils.Color[begin:end] = []")) == -1)
|
||||
return -1;
|
||||
|
||||
if(size != (end - begin)){
|
||||
if (size != (end - begin)) {
|
||||
PyErr_SetString(PyExc_ValueError,
|
||||
"color[begin:end] = []: "
|
||||
"size mismatch in slice assignment");
|
||||
return -1;
|
||||
}
|
||||
|
||||
for(i= 0; i < COLOR_SIZE; i++)
|
||||
for (i= 0; i < COLOR_SIZE; i++)
|
||||
self->col[begin + i] = col[i];
|
||||
|
||||
(void)BaseMath_WriteCallback(self);
|
||||
@@ -379,7 +379,7 @@ static PyObject *Color_add(PyObject *v1, PyObject *v2)
|
||||
color1 = (ColorObject*)v1;
|
||||
color2 = (ColorObject*)v2;
|
||||
|
||||
if(BaseMath_ReadCallback(color1) == -1 || BaseMath_ReadCallback(color2) == -1)
|
||||
if (BaseMath_ReadCallback(color1) == -1 || BaseMath_ReadCallback(color2) == -1)
|
||||
return NULL;
|
||||
|
||||
add_vn_vnvn(col, color1->col, color2->col, COLOR_SIZE);
|
||||
@@ -401,7 +401,7 @@ static PyObject *Color_iadd(PyObject *v1, PyObject *v2)
|
||||
color1 = (ColorObject*)v1;
|
||||
color2 = (ColorObject*)v2;
|
||||
|
||||
if(BaseMath_ReadCallback(color1) == -1 || BaseMath_ReadCallback(color2) == -1)
|
||||
if (BaseMath_ReadCallback(color1) == -1 || BaseMath_ReadCallback(color2) == -1)
|
||||
return NULL;
|
||||
|
||||
add_vn_vn(color1->col, color2->col, COLOR_SIZE);
|
||||
@@ -426,7 +426,7 @@ static PyObject *Color_sub(PyObject *v1, PyObject *v2)
|
||||
color1 = (ColorObject*)v1;
|
||||
color2 = (ColorObject*)v2;
|
||||
|
||||
if(BaseMath_ReadCallback(color1) == -1 || BaseMath_ReadCallback(color2) == -1)
|
||||
if (BaseMath_ReadCallback(color1) == -1 || BaseMath_ReadCallback(color2) == -1)
|
||||
return NULL;
|
||||
|
||||
sub_vn_vnvn(col, color1->col, color2->col, COLOR_SIZE);
|
||||
@@ -448,7 +448,7 @@ static PyObject *Color_isub(PyObject *v1, PyObject *v2)
|
||||
color1 = (ColorObject*)v1;
|
||||
color2 = (ColorObject*)v2;
|
||||
|
||||
if(BaseMath_ReadCallback(color1) == -1 || BaseMath_ReadCallback(color2) == -1)
|
||||
if (BaseMath_ReadCallback(color1) == -1 || BaseMath_ReadCallback(color2) == -1)
|
||||
return NULL;
|
||||
|
||||
sub_vn_vn(color1->col, color2->col, COLOR_SIZE);
|
||||
@@ -473,12 +473,12 @@ static PyObject *Color_mul(PyObject *v1, PyObject *v2)
|
||||
|
||||
if ColorObject_Check(v1) {
|
||||
color1= (ColorObject *)v1;
|
||||
if(BaseMath_ReadCallback(color1) == -1)
|
||||
if (BaseMath_ReadCallback(color1) == -1)
|
||||
return NULL;
|
||||
}
|
||||
if ColorObject_Check(v2) {
|
||||
color2= (ColorObject *)v2;
|
||||
if(BaseMath_ReadCallback(color2) == -1)
|
||||
if (BaseMath_ReadCallback(color2) == -1)
|
||||
return NULL;
|
||||
}
|
||||
|
||||
@@ -515,7 +515,7 @@ static PyObject *Color_div(PyObject *v1, PyObject *v2)
|
||||
|
||||
if ColorObject_Check(v1) {
|
||||
color1= (ColorObject *)v1;
|
||||
if(BaseMath_ReadCallback(color1) == -1)
|
||||
if (BaseMath_ReadCallback(color1) == -1)
|
||||
return NULL;
|
||||
}
|
||||
else {
|
||||
@@ -526,7 +526,7 @@ static PyObject *Color_div(PyObject *v1, PyObject *v2)
|
||||
|
||||
/* make sure v1 is always the vector */
|
||||
if (((scalar= PyFloat_AsDouble(v2)) == -1.0f && PyErr_Occurred())==0) { /* COLOR * FLOAT */
|
||||
if(scalar==0.0f) {
|
||||
if (scalar==0.0f) {
|
||||
PyErr_SetString(PyExc_ZeroDivisionError,
|
||||
"Color division: divide by zero error");
|
||||
return NULL;
|
||||
@@ -547,7 +547,7 @@ static PyObject *Color_imul(PyObject *v1, PyObject *v2)
|
||||
ColorObject *color = (ColorObject *)v1;
|
||||
float scalar;
|
||||
|
||||
if(BaseMath_ReadCallback(color) == -1)
|
||||
if (BaseMath_ReadCallback(color) == -1)
|
||||
return NULL;
|
||||
|
||||
/* only support color *= float */
|
||||
@@ -572,12 +572,12 @@ static PyObject *Color_idiv(PyObject *v1, PyObject *v2)
|
||||
ColorObject *color = (ColorObject *)v1;
|
||||
float scalar;
|
||||
|
||||
if(BaseMath_ReadCallback(color) == -1)
|
||||
if (BaseMath_ReadCallback(color) == -1)
|
||||
return NULL;
|
||||
|
||||
/* only support color /= float */
|
||||
if (((scalar= PyFloat_AsDouble(v2)) == -1.0f && PyErr_Occurred())==0) { /* COLOR /= FLOAT */
|
||||
if(scalar==0.0f) {
|
||||
if (scalar==0.0f) {
|
||||
PyErr_SetString(PyExc_ZeroDivisionError,
|
||||
"Color division: divide by zero error");
|
||||
return NULL;
|
||||
@@ -603,7 +603,7 @@ static PyObject *Color_neg(ColorObject *self)
|
||||
{
|
||||
float tcol[COLOR_SIZE];
|
||||
|
||||
if(BaseMath_ReadCallback(self) == -1)
|
||||
if (BaseMath_ReadCallback(self) == -1)
|
||||
return NULL;
|
||||
|
||||
negate_vn_vn(tcol, self->col, COLOR_SIZE);
|
||||
@@ -665,7 +665,7 @@ static PyObject *Color_getChannelHSV(ColorObject * self, void *type)
|
||||
float hsv[3];
|
||||
int i= GET_INT_FROM_POINTER(type);
|
||||
|
||||
if(BaseMath_ReadCallback(self) == -1)
|
||||
if (BaseMath_ReadCallback(self) == -1)
|
||||
return NULL;
|
||||
|
||||
rgb_to_hsv(self->col[0], self->col[1], self->col[2], &(hsv[0]), &(hsv[1]), &(hsv[2]));
|
||||
@@ -679,14 +679,14 @@ static int Color_setChannelHSV(ColorObject * self, PyObject *value, void * type)
|
||||
int i= GET_INT_FROM_POINTER(type);
|
||||
float f = PyFloat_AsDouble(value);
|
||||
|
||||
if(f == -1 && PyErr_Occurred()) {
|
||||
if (f == -1 && PyErr_Occurred()) {
|
||||
PyErr_SetString(PyExc_TypeError,
|
||||
"color.h/s/v = value: "
|
||||
"argument not a number");
|
||||
return -1;
|
||||
}
|
||||
|
||||
if(BaseMath_ReadCallback(self) == -1)
|
||||
if (BaseMath_ReadCallback(self) == -1)
|
||||
return -1;
|
||||
|
||||
rgb_to_hsv(self->col[0], self->col[1], self->col[2], &(hsv[0]), &(hsv[1]), &(hsv[2]));
|
||||
@@ -694,7 +694,7 @@ static int Color_setChannelHSV(ColorObject * self, PyObject *value, void * type)
|
||||
hsv[i] = f;
|
||||
hsv_to_rgb(hsv[0], hsv[1], hsv[2], &(self->col[0]), &(self->col[1]), &(self->col[2]));
|
||||
|
||||
if(BaseMath_WriteCallback(self) == -1)
|
||||
if (BaseMath_WriteCallback(self) == -1)
|
||||
return -1;
|
||||
|
||||
return 0;
|
||||
@@ -706,7 +706,7 @@ static PyObject *Color_getHSV(ColorObject * self, void *UNUSED(closure))
|
||||
float hsv[3];
|
||||
PyObject *ret;
|
||||
|
||||
if(BaseMath_ReadCallback(self) == -1)
|
||||
if (BaseMath_ReadCallback(self) == -1)
|
||||
return NULL;
|
||||
|
||||
rgb_to_hsv(self->col[0], self->col[1], self->col[2], &(hsv[0]), &(hsv[1]), &(hsv[2]));
|
||||
@@ -722,7 +722,7 @@ static int Color_setHSV(ColorObject * self, PyObject *value, void *UNUSED(closur
|
||||
{
|
||||
float hsv[3];
|
||||
|
||||
if(mathutils_array_parse(hsv, 3, 3, value, "mathutils.Color.hsv = value") == -1)
|
||||
if (mathutils_array_parse(hsv, 3, 3, value, "mathutils.Color.hsv = value") == -1)
|
||||
return -1;
|
||||
|
||||
CLAMP(hsv[0], 0.0f, 1.0f);
|
||||
@@ -731,7 +731,7 @@ static int Color_setHSV(ColorObject * self, PyObject *value, void *UNUSED(closur
|
||||
|
||||
hsv_to_rgb(hsv[0], hsv[1], hsv[2], &(self->col[0]), &(self->col[1]), &(self->col[2]));
|
||||
|
||||
if(BaseMath_WriteCallback(self) == -1)
|
||||
if (BaseMath_WriteCallback(self) == -1)
|
||||
return -1;
|
||||
|
||||
return 0;
|
||||
@@ -834,11 +834,11 @@ PyObject *newColorObject(float *col, int type, PyTypeObject *base_type)
|
||||
self->cb_user= NULL;
|
||||
self->cb_type= self->cb_subtype= 0;
|
||||
|
||||
if(type == Py_WRAP){
|
||||
if(type == Py_WRAP) {
|
||||
self->col = col;
|
||||
self->wrapped = Py_WRAP;
|
||||
}
|
||||
else if (type == Py_NEW){
|
||||
else if (type == Py_NEW) {
|
||||
self->col = PyMem_Malloc(COLOR_SIZE * sizeof(float));
|
||||
if(col)
|
||||
copy_v3_v3(self->col, col);
|
||||
|
||||
@@ -50,21 +50,21 @@ static PyObject *Euler_new(PyTypeObject *type, PyObject *args, PyObject *kwds)
|
||||
float eul[EULER_SIZE]= {0.0f, 0.0f, 0.0f};
|
||||
short order= EULER_ORDER_XYZ;
|
||||
|
||||
if(kwds && PyDict_Size(kwds)) {
|
||||
if (kwds && PyDict_Size(kwds)) {
|
||||
PyErr_SetString(PyExc_TypeError,
|
||||
"mathutils.Euler(): "
|
||||
"takes no keyword args");
|
||||
return NULL;
|
||||
}
|
||||
|
||||
if(!PyArg_ParseTuple(args, "|Os:mathutils.Euler", &seq, &order_str))
|
||||
if (!PyArg_ParseTuple(args, "|Os:mathutils.Euler", &seq, &order_str))
|
||||
return NULL;
|
||||
|
||||
switch(PyTuple_GET_SIZE(args)) {
|
||||
case 0:
|
||||
break;
|
||||
case 2:
|
||||
if((order=euler_order_from_string(order_str, "mathutils.Euler()")) == -1)
|
||||
if ((order=euler_order_from_string(order_str, "mathutils.Euler()")) == -1)
|
||||
return NULL;
|
||||
/* intentionally pass through */
|
||||
case 1:
|
||||
@@ -84,7 +84,7 @@ static const char *euler_order_str(EulerObject *self)
|
||||
|
||||
short euler_order_from_string(const char *str, const char *error_prefix)
|
||||
{
|
||||
if((str[0] && str[1] && str[2] && str[3]=='\0')) {
|
||||
if ((str[0] && str[1] && str[2] && str[3]=='\0')) {
|
||||
switch(*((PY_INT32_T *)str)) {
|
||||
case 'X'|'Y'<<8|'Z'<<16: return EULER_ORDER_XYZ;
|
||||
case 'X'|'Z'<<8|'Y'<<16: return EULER_ORDER_XZY;
|
||||
@@ -109,13 +109,13 @@ static PyObject *Euler_ToTupleExt(EulerObject *self, int ndigits)
|
||||
|
||||
ret= PyTuple_New(EULER_SIZE);
|
||||
|
||||
if(ndigits >= 0) {
|
||||
for(i= 0; i < EULER_SIZE; i++) {
|
||||
if (ndigits >= 0) {
|
||||
for (i= 0; i < EULER_SIZE; i++) {
|
||||
PyTuple_SET_ITEM(ret, i, PyFloat_FromDouble(double_round((double)self->eul[i], ndigits)));
|
||||
}
|
||||
}
|
||||
else {
|
||||
for(i= 0; i < EULER_SIZE; i++) {
|
||||
for (i= 0; i < EULER_SIZE; i++) {
|
||||
PyTuple_SET_ITEM(ret, i, PyFloat_FromDouble(self->eul[i]));
|
||||
}
|
||||
}
|
||||
@@ -138,7 +138,7 @@ static PyObject *Euler_to_quaternion(EulerObject * self)
|
||||
{
|
||||
float quat[4];
|
||||
|
||||
if(BaseMath_ReadCallback(self) == -1)
|
||||
if (BaseMath_ReadCallback(self) == -1)
|
||||
return NULL;
|
||||
|
||||
eulO_to_quat(quat, self->eul, self->order);
|
||||
@@ -159,7 +159,7 @@ static PyObject *Euler_to_matrix(EulerObject * self)
|
||||
{
|
||||
float mat[9];
|
||||
|
||||
if(BaseMath_ReadCallback(self) == -1)
|
||||
if (BaseMath_ReadCallback(self) == -1)
|
||||
return NULL;
|
||||
|
||||
eulO_to_mat3((float (*)[3])mat, self->eul, self->order);
|
||||
@@ -176,7 +176,7 @@ static PyObject *Euler_zero(EulerObject * self)
|
||||
{
|
||||
zero_v3(self->eul);
|
||||
|
||||
if(BaseMath_WriteCallback(self) == -1)
|
||||
if (BaseMath_WriteCallback(self) == -1)
|
||||
return NULL;
|
||||
|
||||
Py_RETURN_NONE;
|
||||
@@ -198,21 +198,21 @@ static PyObject *Euler_rotate_axis(EulerObject * self, PyObject *args)
|
||||
float angle = 0.0f;
|
||||
int axis; /* actually a character */
|
||||
|
||||
if(!PyArg_ParseTuple(args, "Cf:rotate", &axis, &angle)){
|
||||
if (!PyArg_ParseTuple(args, "Cf:rotate", &axis, &angle)) {
|
||||
PyErr_SetString(PyExc_TypeError,
|
||||
"Euler.rotate_axis(): "
|
||||
"expected an axis 'X', 'Y', 'Z' and an angle (float)");
|
||||
return NULL;
|
||||
}
|
||||
|
||||
if(!(ELEM3(axis, 'X', 'Y', 'Z'))){
|
||||
if (!(ELEM3(axis, 'X', 'Y', 'Z'))) {
|
||||
PyErr_SetString(PyExc_ValueError,
|
||||
"Euler.rotate_axis(): "
|
||||
"expected axis to be 'X', 'Y' or 'Z'");
|
||||
return NULL;
|
||||
}
|
||||
|
||||
if(BaseMath_ReadCallback(self) == -1)
|
||||
if (BaseMath_ReadCallback(self) == -1)
|
||||
return NULL;
|
||||
|
||||
|
||||
@@ -235,10 +235,10 @@ static PyObject *Euler_rotate(EulerObject * self, PyObject *value)
|
||||
{
|
||||
float self_rmat[3][3], other_rmat[3][3], rmat[3][3];
|
||||
|
||||
if(BaseMath_ReadCallback(self) == -1)
|
||||
if (BaseMath_ReadCallback(self) == -1)
|
||||
return NULL;
|
||||
|
||||
if(mathutils_any_to_rotmat(other_rmat, value, "euler.rotate(value)") == -1)
|
||||
if (mathutils_any_to_rotmat(other_rmat, value, "euler.rotate(value)") == -1)
|
||||
return NULL;
|
||||
|
||||
eulO_to_mat3(self_rmat, self->eul, self->order);
|
||||
@@ -262,10 +262,10 @@ static PyObject *Euler_make_compatible(EulerObject * self, PyObject *value)
|
||||
{
|
||||
float teul[EULER_SIZE];
|
||||
|
||||
if(BaseMath_ReadCallback(self) == -1)
|
||||
if (BaseMath_ReadCallback(self) == -1)
|
||||
return NULL;
|
||||
|
||||
if(mathutils_array_parse(teul, EULER_SIZE, EULER_SIZE, value, "euler.make_compatible(other), invalid 'other' arg") == -1)
|
||||
if (mathutils_array_parse(teul, EULER_SIZE, EULER_SIZE, value, "euler.make_compatible(other), invalid 'other' arg") == -1)
|
||||
return NULL;
|
||||
|
||||
compatible_eul(self->eul, teul);
|
||||
@@ -291,7 +291,7 @@ PyDoc_STRVAR(Euler_copy_doc,
|
||||
);
|
||||
static PyObject *Euler_copy(EulerObject *self)
|
||||
{
|
||||
if(BaseMath_ReadCallback(self) == -1)
|
||||
if (BaseMath_ReadCallback(self) == -1)
|
||||
return NULL;
|
||||
|
||||
return newEulerObject(self->eul, self->order, Py_NEW, Py_TYPE(self));
|
||||
@@ -304,7 +304,7 @@ static PyObject *Euler_repr(EulerObject * self)
|
||||
{
|
||||
PyObject *ret, *tuple;
|
||||
|
||||
if(BaseMath_ReadCallback(self) == -1)
|
||||
if (BaseMath_ReadCallback(self) == -1)
|
||||
return NULL;
|
||||
|
||||
tuple= Euler_ToTupleExt(self, -1);
|
||||
@@ -324,7 +324,7 @@ static PyObject* Euler_richcmpr(PyObject *a, PyObject *b, int op)
|
||||
EulerObject *eulA= (EulerObject*)a;
|
||||
EulerObject *eulB= (EulerObject*)b;
|
||||
|
||||
if(BaseMath_ReadCallback(eulA) == -1 || BaseMath_ReadCallback(eulB) == -1)
|
||||
if (BaseMath_ReadCallback(eulA) == -1 || BaseMath_ReadCallback(eulB) == -1)
|
||||
return NULL;
|
||||
|
||||
ok= ((eulA->order == eulB->order) && EXPP_VectorsAreEqual(eulA->eul, eulB->eul, EULER_SIZE, 1)) ? 0 : -1;
|
||||
@@ -362,16 +362,16 @@ static int Euler_len(EulerObject *UNUSED(self))
|
||||
//sequence accessor (get)
|
||||
static PyObject *Euler_item(EulerObject * self, int i)
|
||||
{
|
||||
if(i<0) i= EULER_SIZE-i;
|
||||
if (i<0) i= EULER_SIZE-i;
|
||||
|
||||
if(i < 0 || i >= EULER_SIZE) {
|
||||
if (i < 0 || i >= EULER_SIZE) {
|
||||
PyErr_SetString(PyExc_IndexError,
|
||||
"euler[attribute]: "
|
||||
"array index out of range");
|
||||
return NULL;
|
||||
}
|
||||
|
||||
if(BaseMath_ReadIndexCallback(self, i) == -1)
|
||||
if (BaseMath_ReadIndexCallback(self, i) == -1)
|
||||
return NULL;
|
||||
|
||||
return PyFloat_FromDouble(self->eul[i]);
|
||||
@@ -383,16 +383,16 @@ static int Euler_ass_item(EulerObject * self, int i, PyObject *value)
|
||||
{
|
||||
float f = PyFloat_AsDouble(value);
|
||||
|
||||
if(f == -1 && PyErr_Occurred()) { // parsed item not a number
|
||||
if (f == -1 && PyErr_Occurred()) { // parsed item not a number
|
||||
PyErr_SetString(PyExc_TypeError,
|
||||
"euler[attribute] = x: "
|
||||
"argument not a number");
|
||||
return -1;
|
||||
}
|
||||
|
||||
if(i<0) i= EULER_SIZE-i;
|
||||
if (i<0) i= EULER_SIZE-i;
|
||||
|
||||
if(i < 0 || i >= EULER_SIZE){
|
||||
if (i < 0 || i >= EULER_SIZE) {
|
||||
PyErr_SetString(PyExc_IndexError,
|
||||
"euler[attribute] = x: "
|
||||
"array assignment index out of range");
|
||||
@@ -401,7 +401,7 @@ static int Euler_ass_item(EulerObject * self, int i, PyObject *value)
|
||||
|
||||
self->eul[i] = f;
|
||||
|
||||
if(BaseMath_WriteIndexCallback(self, i) == -1)
|
||||
if (BaseMath_WriteIndexCallback(self, i) == -1)
|
||||
return -1;
|
||||
|
||||
return 0;
|
||||
@@ -413,7 +413,7 @@ static PyObject *Euler_slice(EulerObject * self, int begin, int end)
|
||||
PyObject *tuple;
|
||||
int count;
|
||||
|
||||
if(BaseMath_ReadCallback(self) == -1)
|
||||
if (BaseMath_ReadCallback(self) == -1)
|
||||
return NULL;
|
||||
|
||||
CLAMP(begin, 0, EULER_SIZE);
|
||||
@@ -422,7 +422,7 @@ static PyObject *Euler_slice(EulerObject * self, int begin, int end)
|
||||
begin= MIN2(begin, end);
|
||||
|
||||
tuple= PyTuple_New(end - begin);
|
||||
for(count = begin; count < end; count++) {
|
||||
for (count = begin; count < end; count++) {
|
||||
PyTuple_SET_ITEM(tuple, count - begin, PyFloat_FromDouble(self->eul[count]));
|
||||
}
|
||||
|
||||
@@ -435,7 +435,7 @@ static int Euler_ass_slice(EulerObject *self, int begin, int end, PyObject *seq)
|
||||
int i, size;
|
||||
float eul[EULER_SIZE];
|
||||
|
||||
if(BaseMath_ReadCallback(self) == -1)
|
||||
if (BaseMath_ReadCallback(self) == -1)
|
||||
return -1;
|
||||
|
||||
CLAMP(begin, 0, EULER_SIZE);
|
||||
@@ -443,17 +443,17 @@ static int Euler_ass_slice(EulerObject *self, int begin, int end, PyObject *seq)
|
||||
CLAMP(end, 0, EULER_SIZE);
|
||||
begin = MIN2(begin, end);
|
||||
|
||||
if((size=mathutils_array_parse(eul, 0, EULER_SIZE, seq, "mathutils.Euler[begin:end] = []")) == -1)
|
||||
if ((size=mathutils_array_parse(eul, 0, EULER_SIZE, seq, "mathutils.Euler[begin:end] = []")) == -1)
|
||||
return -1;
|
||||
|
||||
if(size != (end - begin)){
|
||||
if (size != (end - begin)) {
|
||||
PyErr_SetString(PyExc_ValueError,
|
||||
"euler[begin:end] = []: "
|
||||
"size mismatch in slice assignment");
|
||||
return -1;
|
||||
}
|
||||
|
||||
for(i= 0; i < EULER_SIZE; i++)
|
||||
for (i= 0; i < EULER_SIZE; i++)
|
||||
self->eul[begin + i] = eul[i];
|
||||
|
||||
(void)BaseMath_WriteCallback(self);
|
||||
@@ -566,7 +566,7 @@ static int Euler_setAxis(EulerObject *self, PyObject *value, void *type)
|
||||
/* rotation order */
|
||||
static PyObject *Euler_getOrder(EulerObject *self, void *UNUSED(closure))
|
||||
{
|
||||
if(BaseMath_ReadCallback(self) == -1) /* can read order too */
|
||||
if (BaseMath_ReadCallback(self) == -1) /* can read order too */
|
||||
return NULL;
|
||||
|
||||
return PyUnicode_FromString(euler_order_str(self));
|
||||
@@ -577,7 +577,7 @@ static int Euler_setOrder(EulerObject *self, PyObject *value, void *UNUSED(closu
|
||||
const char *order_str= _PyUnicode_AsString(value);
|
||||
short order= euler_order_from_string(order_str, "euler.order");
|
||||
|
||||
if(order == -1)
|
||||
if (order == -1)
|
||||
return -1;
|
||||
|
||||
self->order= order;
|
||||
@@ -678,18 +678,18 @@ PyObject *newEulerObject(float *eul, short order, int type, PyTypeObject *base_t
|
||||
self= base_type ? (EulerObject *)base_type->tp_alloc(base_type, 0) :
|
||||
(EulerObject *)PyObject_GC_New(EulerObject, &euler_Type);
|
||||
|
||||
if(self) {
|
||||
if (self) {
|
||||
/* init callbacks as NULL */
|
||||
self->cb_user= NULL;
|
||||
self->cb_type= self->cb_subtype= 0;
|
||||
|
||||
if(type == Py_WRAP) {
|
||||
if (type == Py_WRAP) {
|
||||
self->eul = eul;
|
||||
self->wrapped = Py_WRAP;
|
||||
}
|
||||
else if (type == Py_NEW) {
|
||||
self->eul = PyMem_Malloc(EULER_SIZE * sizeof(float));
|
||||
if(eul) {
|
||||
if (eul) {
|
||||
copy_v3_v3(self->eul, eul);
|
||||
}
|
||||
else {
|
||||
@@ -711,7 +711,7 @@ PyObject *newEulerObject(float *eul, short order, int type, PyTypeObject *base_t
|
||||
PyObject *newEulerObject_cb(PyObject *cb_user, short order, int cb_type, int cb_subtype)
|
||||
{
|
||||
EulerObject *self= (EulerObject *)newEulerObject(NULL, order, Py_NEW, NULL);
|
||||
if(self) {
|
||||
if (self) {
|
||||
Py_INCREF(cb_user);
|
||||
self->cb_user= cb_user;
|
||||
self->cb_type= (unsigned char)cb_type;
|
||||
|
||||
@@ -55,10 +55,10 @@ static int mathutils_matrix_vector_get(BaseMathObject *bmo, int subtype)
|
||||
MatrixObject *self= (MatrixObject *)bmo->cb_user;
|
||||
int i;
|
||||
|
||||
if(BaseMath_ReadCallback(self) == -1)
|
||||
if (BaseMath_ReadCallback(self) == -1)
|
||||
return -1;
|
||||
|
||||
for(i=0; i < self->col_size; i++)
|
||||
for (i=0; i < self->col_size; i++)
|
||||
bmo->data[i]= self->matrix[subtype][i];
|
||||
|
||||
return 0;
|
||||
@@ -69,10 +69,10 @@ static int mathutils_matrix_vector_set(BaseMathObject *bmo, int subtype)
|
||||
MatrixObject *self= (MatrixObject *)bmo->cb_user;
|
||||
int i;
|
||||
|
||||
if(BaseMath_ReadCallback(self) == -1)
|
||||
if (BaseMath_ReadCallback(self) == -1)
|
||||
return -1;
|
||||
|
||||
for(i=0; i < self->col_size; i++)
|
||||
for (i=0; i < self->col_size; i++)
|
||||
self->matrix[subtype][i]= bmo->data[i];
|
||||
|
||||
(void)BaseMath_WriteCallback(self);
|
||||
@@ -83,7 +83,7 @@ static int mathutils_matrix_vector_get_index(BaseMathObject *bmo, int subtype, i
|
||||
{
|
||||
MatrixObject *self= (MatrixObject *)bmo->cb_user;
|
||||
|
||||
if(BaseMath_ReadCallback(self) == -1)
|
||||
if (BaseMath_ReadCallback(self) == -1)
|
||||
return -1;
|
||||
|
||||
bmo->data[index]= self->matrix[subtype][index];
|
||||
@@ -94,7 +94,7 @@ static int mathutils_matrix_vector_set_index(BaseMathObject *bmo, int subtype, i
|
||||
{
|
||||
MatrixObject *self= (MatrixObject *)bmo->cb_user;
|
||||
|
||||
if(BaseMath_ReadCallback(self) == -1)
|
||||
if (BaseMath_ReadCallback(self) == -1)
|
||||
return -1;
|
||||
|
||||
self->matrix[subtype][index]= bmo->data[index];
|
||||
@@ -117,7 +117,7 @@ Mathutils_Callback mathutils_matrix_vector_cb = {
|
||||
//create a new matrix type
|
||||
static PyObject *Matrix_new(PyTypeObject *type, PyObject *args, PyObject *kwds)
|
||||
{
|
||||
if(kwds && PyDict_Size(kwds)) {
|
||||
if (kwds && PyDict_Size(kwds)) {
|
||||
PyErr_SetString(PyExc_TypeError,
|
||||
"Matrix(): "
|
||||
"takes no keyword args");
|
||||
@@ -134,15 +134,15 @@ static PyObject *Matrix_new(PyTypeObject *type, PyObject *args, PyObject *kwds)
|
||||
/* -1 is an error, size checks will accunt for this */
|
||||
const unsigned short row_size= PySequence_Size(arg);
|
||||
|
||||
if(row_size >= 2 && row_size <= 4) {
|
||||
if (row_size >= 2 && row_size <= 4) {
|
||||
PyObject *item= PySequence_GetItem(arg, 0);
|
||||
const unsigned short col_size= PySequence_Size(item);
|
||||
Py_XDECREF(item);
|
||||
|
||||
if(col_size >= 2 && col_size <= 4) {
|
||||
if (col_size >= 2 && col_size <= 4) {
|
||||
/* sane row & col size, new matrix and assign as slice */
|
||||
PyObject *matrix= newMatrixObject(NULL, row_size, col_size, Py_NEW, type);
|
||||
if(Matrix_ass_slice((MatrixObject *)matrix, 0, INT_MAX, arg) == 0) {
|
||||
if (Matrix_ass_slice((MatrixObject *)matrix, 0, INT_MAX, arg) == 0) {
|
||||
return matrix;
|
||||
}
|
||||
else { /* matrix ok, slice assignment not */
|
||||
@@ -164,7 +164,7 @@ static PyObject *matrix__apply_to_copy(PyNoArgsFunction matrix_func, MatrixObjec
|
||||
{
|
||||
PyObject *ret= Matrix_copy(self);
|
||||
PyObject *ret_dummy= matrix_func(ret);
|
||||
if(ret_dummy) {
|
||||
if (ret_dummy) {
|
||||
Py_DECREF(ret_dummy);
|
||||
return (PyObject *)ret;
|
||||
}
|
||||
@@ -214,16 +214,16 @@ static PyObject *C_Matrix_Rotation(PyObject *cls, PyObject *args)
|
||||
float mat[16] = {0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f,
|
||||
0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 1.0f};
|
||||
|
||||
if(!PyArg_ParseTuple(args, "di|O", &angle, &matSize, &vec)) {
|
||||
if (!PyArg_ParseTuple(args, "di|O", &angle, &matSize, &vec)) {
|
||||
PyErr_SetString(PyExc_TypeError,
|
||||
"Matrix.Rotation(angle, size, axis): "
|
||||
"expected float int and a string or vector");
|
||||
return NULL;
|
||||
}
|
||||
|
||||
if(vec && PyUnicode_Check(vec)) {
|
||||
if (vec && PyUnicode_Check(vec)) {
|
||||
axis= _PyUnicode_AsString((PyObject *)vec);
|
||||
if(axis==NULL || axis[0]=='\0' || axis[1]!='\0' || axis[0] < 'X' || axis[0] > 'Z') {
|
||||
if (axis==NULL || axis[0]=='\0' || axis[1]!='\0' || axis[0] < 'X' || axis[0] > 'Z') {
|
||||
PyErr_SetString(PyExc_ValueError,
|
||||
"Matrix.Rotation(): "
|
||||
"3rd argument axis value must be a 3D vector "
|
||||
@@ -238,19 +238,19 @@ static PyObject *C_Matrix_Rotation(PyObject *cls, PyObject *args)
|
||||
|
||||
angle= angle_wrap_rad(angle);
|
||||
|
||||
if(matSize != 2 && matSize != 3 && matSize != 4) {
|
||||
if (matSize != 2 && matSize != 3 && matSize != 4) {
|
||||
PyErr_SetString(PyExc_ValueError,
|
||||
"Matrix.Rotation(): "
|
||||
"can only return a 2x2 3x3 or 4x4 matrix");
|
||||
return NULL;
|
||||
}
|
||||
if(matSize == 2 && (vec != NULL)) {
|
||||
if (matSize == 2 && (vec != NULL)) {
|
||||
PyErr_SetString(PyExc_ValueError,
|
||||
"Matrix.Rotation(): "
|
||||
"cannot create a 2x2 rotation matrix around arbitrary axis");
|
||||
return NULL;
|
||||
}
|
||||
if((matSize == 3 || matSize == 4) && (axis == NULL) && (vec == NULL)) {
|
||||
if ((matSize == 3 || matSize == 4) && (axis == NULL) && (vec == NULL)) {
|
||||
PyErr_SetString(PyExc_ValueError,
|
||||
"Matrix.Rotation(): "
|
||||
"axis of rotation for 3d and 4d matrices is required");
|
||||
@@ -258,7 +258,7 @@ static PyObject *C_Matrix_Rotation(PyObject *cls, PyObject *args)
|
||||
}
|
||||
|
||||
/* check for valid vector/axis above */
|
||||
if(vec) {
|
||||
if (vec) {
|
||||
float tvec[3];
|
||||
|
||||
if (mathutils_array_parse(tvec, 3, 3, vec, "Matrix.Rotation(angle, size, axis), invalid 'axis' arg") == -1)
|
||||
@@ -281,7 +281,7 @@ static PyObject *C_Matrix_Rotation(PyObject *cls, PyObject *args)
|
||||
single_axis_angle_to_mat3((float (*)[3])mat, axis[0], angle);
|
||||
}
|
||||
|
||||
if(matSize == 4) {
|
||||
if (matSize == 4) {
|
||||
matrix_3x3_as_4x4(mat);
|
||||
}
|
||||
//pass to matrix creation
|
||||
@@ -337,23 +337,23 @@ static PyObject *C_Matrix_Scale(PyObject *cls, PyObject *args)
|
||||
float mat[16] = {0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f,
|
||||
0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 1.0f};
|
||||
|
||||
if(!PyArg_ParseTuple(args, "fi|O:Matrix.Scale", &factor, &matSize, &vec)) {
|
||||
if (!PyArg_ParseTuple(args, "fi|O:Matrix.Scale", &factor, &matSize, &vec)) {
|
||||
return NULL;
|
||||
}
|
||||
if(matSize != 2 && matSize != 3 && matSize != 4) {
|
||||
if (matSize != 2 && matSize != 3 && matSize != 4) {
|
||||
PyErr_SetString(PyExc_ValueError,
|
||||
"Matrix.Scale(): "
|
||||
"can only return a 2x2 3x3 or 4x4 matrix");
|
||||
return NULL;
|
||||
}
|
||||
if(vec) {
|
||||
if (vec) {
|
||||
vec_size= (matSize == 2 ? 2 : 3);
|
||||
if(mathutils_array_parse(tvec, vec_size, vec_size, vec, "Matrix.Scale(factor, size, axis), invalid 'axis' arg") == -1) {
|
||||
if (mathutils_array_parse(tvec, vec_size, vec_size, vec, "Matrix.Scale(factor, size, axis), invalid 'axis' arg") == -1) {
|
||||
return NULL;
|
||||
}
|
||||
}
|
||||
if(vec == NULL) { //scaling along axis
|
||||
if(matSize == 2) {
|
||||
if (vec == NULL) { //scaling along axis
|
||||
if (matSize == 2) {
|
||||
mat[0] = factor;
|
||||
mat[3] = factor;
|
||||
}
|
||||
@@ -367,14 +367,14 @@ static PyObject *C_Matrix_Scale(PyObject *cls, PyObject *args)
|
||||
//normalize arbitrary axis
|
||||
float norm = 0.0f;
|
||||
int x;
|
||||
for(x = 0; x < vec_size; x++) {
|
||||
for (x = 0; x < vec_size; x++) {
|
||||
norm += tvec[x] * tvec[x];
|
||||
}
|
||||
norm = (float) sqrt(norm);
|
||||
for(x = 0; x < vec_size; x++) {
|
||||
for (x = 0; x < vec_size; x++) {
|
||||
tvec[x] /= norm;
|
||||
}
|
||||
if(matSize == 2) {
|
||||
if (matSize == 2) {
|
||||
mat[0] = 1 + ((factor - 1) *(tvec[0] * tvec[0]));
|
||||
mat[1] = ((factor - 1) *(tvec[0] * tvec[1]));
|
||||
mat[2] = ((factor - 1) *(tvec[0] * tvec[1]));
|
||||
@@ -392,7 +392,7 @@ static PyObject *C_Matrix_Scale(PyObject *cls, PyObject *args)
|
||||
mat[8] = 1 + ((factor - 1) *(tvec[2] * tvec[2]));
|
||||
}
|
||||
}
|
||||
if(matSize == 4) {
|
||||
if (matSize == 4) {
|
||||
matrix_3x3_as_4x4(mat);
|
||||
}
|
||||
//pass to matrix creation
|
||||
@@ -423,21 +423,21 @@ static PyObject *C_Matrix_OrthoProjection(PyObject *cls, PyObject *args)
|
||||
float mat[16] = {0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f,
|
||||
0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 1.0f};
|
||||
|
||||
if(!PyArg_ParseTuple(args, "Oi:Matrix.OrthoProjection", &axis, &matSize)) {
|
||||
if (!PyArg_ParseTuple(args, "Oi:Matrix.OrthoProjection", &axis, &matSize)) {
|
||||
return NULL;
|
||||
}
|
||||
if(matSize != 2 && matSize != 3 && matSize != 4) {
|
||||
if (matSize != 2 && matSize != 3 && matSize != 4) {
|
||||
PyErr_SetString(PyExc_ValueError,
|
||||
"Matrix.OrthoProjection(): "
|
||||
"can only return a 2x2 3x3 or 4x4 matrix");
|
||||
return NULL;
|
||||
}
|
||||
|
||||
if(PyUnicode_Check(axis)) { //ortho projection onto cardinal plane
|
||||
if (PyUnicode_Check(axis)) { //ortho projection onto cardinal plane
|
||||
Py_ssize_t plane_len;
|
||||
const char *plane= _PyUnicode_AsStringAndSize(axis, &plane_len);
|
||||
if(matSize == 2) {
|
||||
if(plane_len == 1 && plane[0]=='X') {
|
||||
if (matSize == 2) {
|
||||
if (plane_len == 1 && plane[0]=='X') {
|
||||
mat[0]= 1.0f;
|
||||
}
|
||||
else if (plane_len == 1 && plane[0]=='Y') {
|
||||
@@ -452,7 +452,7 @@ static PyObject *C_Matrix_OrthoProjection(PyObject *cls, PyObject *args)
|
||||
}
|
||||
}
|
||||
else {
|
||||
if(plane_len == 2 && plane[0]=='X' && plane[1]=='Y') {
|
||||
if (plane_len == 2 && plane[0]=='X' && plane[1]=='Y') {
|
||||
mat[0]= 1.0f;
|
||||
mat[4]= 1.0f;
|
||||
}
|
||||
@@ -479,25 +479,25 @@ static PyObject *C_Matrix_OrthoProjection(PyObject *cls, PyObject *args)
|
||||
int vec_size= (matSize == 2 ? 2 : 3);
|
||||
float tvec[4];
|
||||
|
||||
if(mathutils_array_parse(tvec, vec_size, vec_size, axis, "Matrix.OrthoProjection(axis, size), invalid 'axis' arg") == -1) {
|
||||
if (mathutils_array_parse(tvec, vec_size, vec_size, axis, "Matrix.OrthoProjection(axis, size), invalid 'axis' arg") == -1) {
|
||||
return NULL;
|
||||
}
|
||||
|
||||
//normalize arbitrary axis
|
||||
for(x = 0; x < vec_size; x++) {
|
||||
for (x = 0; x < vec_size; x++) {
|
||||
norm += tvec[x] * tvec[x];
|
||||
}
|
||||
norm = (float) sqrt(norm);
|
||||
for(x = 0; x < vec_size; x++) {
|
||||
for (x = 0; x < vec_size; x++) {
|
||||
tvec[x] /= norm;
|
||||
}
|
||||
if(matSize == 2) {
|
||||
if (matSize == 2) {
|
||||
mat[0] = 1 - (tvec[0] * tvec[0]);
|
||||
mat[1] = -(tvec[0] * tvec[1]);
|
||||
mat[2] = -(tvec[0] * tvec[1]);
|
||||
mat[3] = 1 - (tvec[1] * tvec[1]);
|
||||
}
|
||||
else if(matSize > 2) {
|
||||
else if (matSize > 2) {
|
||||
mat[0] = 1 - (tvec[0] * tvec[0]);
|
||||
mat[1] = -(tvec[0] * tvec[1]);
|
||||
mat[2] = -(tvec[0] * tvec[2]);
|
||||
@@ -509,7 +509,7 @@ static PyObject *C_Matrix_OrthoProjection(PyObject *cls, PyObject *args)
|
||||
mat[8] = 1 - (tvec[2] * tvec[2]);
|
||||
}
|
||||
}
|
||||
if(matSize == 4) {
|
||||
if (matSize == 4) {
|
||||
matrix_3x3_as_4x4(mat);
|
||||
}
|
||||
//pass to matrix creation
|
||||
@@ -540,20 +540,20 @@ static PyObject *C_Matrix_Shear(PyObject *cls, PyObject *args)
|
||||
float mat[16] = {0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f,
|
||||
0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 1.0f};
|
||||
|
||||
if(!PyArg_ParseTuple(args, "siO:Matrix.Shear", &plane, &matSize, &fac)) {
|
||||
if (!PyArg_ParseTuple(args, "siO:Matrix.Shear", &plane, &matSize, &fac)) {
|
||||
return NULL;
|
||||
}
|
||||
if(matSize != 2 && matSize != 3 && matSize != 4) {
|
||||
if (matSize != 2 && matSize != 3 && matSize != 4) {
|
||||
PyErr_SetString(PyExc_ValueError,
|
||||
"Matrix.Shear(): "
|
||||
"can only return a 2x2 3x3 or 4x4 matrix");
|
||||
return NULL;
|
||||
}
|
||||
|
||||
if(matSize == 2) {
|
||||
if (matSize == 2) {
|
||||
float const factor= PyFloat_AsDouble(fac);
|
||||
|
||||
if(factor==-1.0f && PyErr_Occurred()) {
|
||||
if (factor==-1.0f && PyErr_Occurred()) {
|
||||
PyErr_SetString(PyExc_TypeError,
|
||||
"Matrix.Shear(): "
|
||||
"the factor to be a float");
|
||||
@@ -564,10 +564,10 @@ static PyObject *C_Matrix_Shear(PyObject *cls, PyObject *args)
|
||||
mat[0] = 1.0f;
|
||||
mat[3] = 1.0f;
|
||||
|
||||
if(strcmp(plane, "X") == 0) {
|
||||
if (strcmp(plane, "X") == 0) {
|
||||
mat[2] = factor;
|
||||
}
|
||||
else if(strcmp(plane, "Y") == 0) {
|
||||
else if (strcmp(plane, "Y") == 0) {
|
||||
mat[1] = factor;
|
||||
}
|
||||
else {
|
||||
@@ -581,7 +581,7 @@ static PyObject *C_Matrix_Shear(PyObject *cls, PyObject *args)
|
||||
/* 3 or 4, apply as 3x3, resize later if needed */
|
||||
float factor[2];
|
||||
|
||||
if(mathutils_array_parse(factor, 2, 2, fac, "Matrix.Shear()") < 0) {
|
||||
if (mathutils_array_parse(factor, 2, 2, fac, "Matrix.Shear()") < 0) {
|
||||
return NULL;
|
||||
}
|
||||
|
||||
@@ -590,15 +590,15 @@ static PyObject *C_Matrix_Shear(PyObject *cls, PyObject *args)
|
||||
mat[4] = 1.0f;
|
||||
mat[8] = 1.0f;
|
||||
|
||||
if(strcmp(plane, "XY") == 0) {
|
||||
if (strcmp(plane, "XY") == 0) {
|
||||
mat[6] = factor[0];
|
||||
mat[7] = factor[1];
|
||||
}
|
||||
else if(strcmp(plane, "XZ") == 0) {
|
||||
else if (strcmp(plane, "XZ") == 0) {
|
||||
mat[3] = factor[0];
|
||||
mat[5] = factor[1];
|
||||
}
|
||||
else if(strcmp(plane, "YZ") == 0) {
|
||||
else if (strcmp(plane, "YZ") == 0) {
|
||||
mat[1] = factor[0];
|
||||
mat[2] = factor[1];
|
||||
}
|
||||
@@ -610,7 +610,7 @@ static PyObject *C_Matrix_Shear(PyObject *cls, PyObject *args)
|
||||
}
|
||||
}
|
||||
|
||||
if(matSize == 4) {
|
||||
if (matSize == 4) {
|
||||
matrix_3x3_as_4x4(mat);
|
||||
}
|
||||
//pass to matrix creation
|
||||
@@ -627,11 +627,11 @@ 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->row_size == 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->row_size == 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],
|
||||
@@ -657,17 +657,17 @@ static PyObject *Matrix_to_quaternion(MatrixObject *self)
|
||||
{
|
||||
float quat[4];
|
||||
|
||||
if(BaseMath_ReadCallback(self) == -1)
|
||||
if (BaseMath_ReadCallback(self) == -1)
|
||||
return NULL;
|
||||
|
||||
/*must be 3-4 cols, 3-4 rows, square matrix*/
|
||||
if((self->col_size < 3) || (self->row_size < 3) || (self->col_size != self->row_size)) {
|
||||
if ((self->col_size < 3) || (self->row_size < 3) || (self->col_size != self->row_size)) {
|
||||
PyErr_SetString(PyExc_ValueError,
|
||||
"Matrix.to_quat(): "
|
||||
"inappropriate matrix size - expects 3x3 or 4x4 matrix");
|
||||
return NULL;
|
||||
}
|
||||
if(self->col_size == 3){
|
||||
if (self->col_size == 3) {
|
||||
mat3_to_quat(quat, (float (*)[3])self->contigPtr);
|
||||
}
|
||||
else {
|
||||
@@ -704,21 +704,21 @@ static PyObject *Matrix_to_euler(MatrixObject *self, PyObject *args)
|
||||
float tmat[3][3];
|
||||
float (*mat)[3];
|
||||
|
||||
if(BaseMath_ReadCallback(self) == -1)
|
||||
if (BaseMath_ReadCallback(self) == -1)
|
||||
return NULL;
|
||||
|
||||
if(!PyArg_ParseTuple(args, "|sO!:to_euler", &order_str, &euler_Type, &eul_compat))
|
||||
if (!PyArg_ParseTuple(args, "|sO!:to_euler", &order_str, &euler_Type, &eul_compat))
|
||||
return NULL;
|
||||
|
||||
if(eul_compat) {
|
||||
if(BaseMath_ReadCallback(eul_compat) == -1)
|
||||
if (eul_compat) {
|
||||
if (BaseMath_ReadCallback(eul_compat) == -1)
|
||||
return NULL;
|
||||
|
||||
copy_v3_v3(eul_compatf, eul_compat->eul);
|
||||
}
|
||||
|
||||
/*must be 3-4 cols, 3-4 rows, square matrix*/
|
||||
if(self->col_size ==3 && self->row_size ==3) {
|
||||
if (self->col_size ==3 && self->row_size ==3) {
|
||||
mat= (float (*)[3])self->contigPtr;
|
||||
}
|
||||
else if (self->col_size ==4 && self->row_size ==4) {
|
||||
@@ -732,19 +732,19 @@ static PyObject *Matrix_to_euler(MatrixObject *self, PyObject *args)
|
||||
return NULL;
|
||||
}
|
||||
|
||||
if(order_str) {
|
||||
if (order_str) {
|
||||
order= euler_order_from_string(order_str, "Matrix.to_euler()");
|
||||
|
||||
if(order == -1)
|
||||
if (order == -1)
|
||||
return NULL;
|
||||
}
|
||||
|
||||
if(eul_compat) {
|
||||
if(order == 1) mat3_to_compatible_eul(eul, eul_compatf, mat);
|
||||
if (eul_compat) {
|
||||
if (order == 1) mat3_to_compatible_eul(eul, eul_compatf, mat);
|
||||
else mat3_to_compatible_eulO(eul, eul_compatf, order, mat);
|
||||
}
|
||||
else {
|
||||
if(order == 1) mat3_to_eul(eul, mat);
|
||||
if (order == 1) mat3_to_eul(eul, mat);
|
||||
else mat3_to_eulO(eul, order, mat);
|
||||
}
|
||||
|
||||
@@ -760,13 +760,13 @@ static PyObject *Matrix_resize_4x4(MatrixObject *self)
|
||||
{
|
||||
int x, first_row_elem, curr_pos, new_pos, blank_columns, blank_rows, index;
|
||||
|
||||
if(self->wrapped==Py_WRAP){
|
||||
if (self->wrapped==Py_WRAP) {
|
||||
PyErr_SetString(PyExc_TypeError,
|
||||
"Matrix.resize_4x4(): "
|
||||
"cannot resize wrapped data - make a copy and resize that");
|
||||
return NULL;
|
||||
}
|
||||
if(self->cb_user){
|
||||
if (self->cb_user) {
|
||||
PyErr_SetString(PyExc_TypeError,
|
||||
"Matrix.resize_4x4(): "
|
||||
"cannot resize owned data - make a copy and resize that");
|
||||
@@ -774,21 +774,21 @@ static PyObject *Matrix_resize_4x4(MatrixObject *self)
|
||||
}
|
||||
|
||||
self->contigPtr = PyMem_Realloc(self->contigPtr, (sizeof(float) * 16));
|
||||
if(self->contigPtr == NULL) {
|
||||
if (self->contigPtr == NULL) {
|
||||
PyErr_SetString(PyExc_MemoryError,
|
||||
"Matrix.resize_4x4(): "
|
||||
"problem allocating pointer space");
|
||||
return NULL;
|
||||
}
|
||||
/*set row pointers*/
|
||||
for(x = 0; x < 4; x++) {
|
||||
for (x = 0; x < 4; x++) {
|
||||
self->matrix[x] = self->contigPtr + (x * 4);
|
||||
}
|
||||
/*move data to new spot in array + clean*/
|
||||
for(blank_rows = (4 - self->row_size); blank_rows > 0; blank_rows--){
|
||||
for(x = 0; x < 4; x++){
|
||||
for (blank_rows = (4 - self->row_size); blank_rows > 0; blank_rows--) {
|
||||
for (x = 0; x < 4; x++) {
|
||||
index = (4 * (self->row_size + (blank_rows - 1))) + x;
|
||||
if (index == 10 || index == 15){
|
||||
if (index == 10 || index == 15) {
|
||||
self->contigPtr[index] = 1.0f;
|
||||
}
|
||||
else {
|
||||
@@ -796,14 +796,14 @@ static PyObject *Matrix_resize_4x4(MatrixObject *self)
|
||||
}
|
||||
}
|
||||
}
|
||||
for(x = 1; x <= self->row_size; x++){
|
||||
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--){
|
||||
for (blank_columns = (4 - self->col_size); blank_columns > 0; blank_columns--) {
|
||||
self->contigPtr[new_pos + blank_columns] = 0.0f;
|
||||
}
|
||||
for( ; curr_pos >= first_row_elem; curr_pos--){
|
||||
for ( ; curr_pos >= first_row_elem; curr_pos--) {
|
||||
self->contigPtr[new_pos] = self->contigPtr[curr_pos];
|
||||
new_pos--;
|
||||
}
|
||||
@@ -824,13 +824,13 @@ PyDoc_STRVAR(Matrix_to_4x4_doc,
|
||||
);
|
||||
static PyObject *Matrix_to_4x4(MatrixObject *self)
|
||||
{
|
||||
if(BaseMath_ReadCallback(self) == -1)
|
||||
if (BaseMath_ReadCallback(self) == -1)
|
||||
return NULL;
|
||||
|
||||
if(self->col_size==4 && self->row_size==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->col_size==3 && self->row_size==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));
|
||||
@@ -855,10 +855,10 @@ static PyObject *Matrix_to_3x3(MatrixObject *self)
|
||||
{
|
||||
float mat[3][3];
|
||||
|
||||
if(BaseMath_ReadCallback(self) == -1)
|
||||
if (BaseMath_ReadCallback(self) == -1)
|
||||
return NULL;
|
||||
|
||||
if((self->col_size < 3) || (self->row_size < 3)) {
|
||||
if ((self->col_size < 3) || (self->row_size < 3)) {
|
||||
PyErr_SetString(PyExc_TypeError,
|
||||
"Matrix.to_3x3(): inappropriate matrix size");
|
||||
return NULL;
|
||||
@@ -879,10 +879,10 @@ PyDoc_STRVAR(Matrix_to_translation_doc,
|
||||
);
|
||||
static PyObject *Matrix_to_translation(MatrixObject *self)
|
||||
{
|
||||
if(BaseMath_ReadCallback(self) == -1)
|
||||
if (BaseMath_ReadCallback(self) == -1)
|
||||
return NULL;
|
||||
|
||||
if((self->col_size < 3) || self->row_size < 4){
|
||||
if ((self->col_size < 3) || self->row_size < 4) {
|
||||
PyErr_SetString(PyExc_TypeError,
|
||||
"Matrix.to_translation(): "
|
||||
"inappropriate matrix size");
|
||||
@@ -908,11 +908,11 @@ static PyObject *Matrix_to_scale(MatrixObject *self)
|
||||
float mat[3][3];
|
||||
float size[3];
|
||||
|
||||
if(BaseMath_ReadCallback(self) == -1)
|
||||
if (BaseMath_ReadCallback(self) == -1)
|
||||
return NULL;
|
||||
|
||||
/*must be 3-4 cols, 3-4 rows, square matrix*/
|
||||
if((self->col_size < 3) || (self->row_size < 3)) {
|
||||
if ((self->col_size < 3) || (self->row_size < 3)) {
|
||||
PyErr_SetString(PyExc_TypeError,
|
||||
"Matrix.to_scale(): "
|
||||
"inappropriate matrix size, 3x3 minimum size");
|
||||
@@ -945,10 +945,10 @@ static PyObject *Matrix_invert(MatrixObject *self)
|
||||
float mat[16] = {0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f,
|
||||
0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 1.0f};
|
||||
|
||||
if(BaseMath_ReadCallback(self) == -1)
|
||||
if (BaseMath_ReadCallback(self) == -1)
|
||||
return NULL;
|
||||
|
||||
if(self->row_size != self->col_size){
|
||||
if (self->row_size != self->col_size) {
|
||||
PyErr_SetString(PyExc_TypeError,
|
||||
"Matrix.invert(ed): "
|
||||
"only square matrices are supported");
|
||||
@@ -958,25 +958,25 @@ static PyObject *Matrix_invert(MatrixObject *self)
|
||||
/*calculate the determinant*/
|
||||
det = matrix_determinant_internal(self);
|
||||
|
||||
if(det != 0) {
|
||||
if (det != 0) {
|
||||
/*calculate the classical adjoint*/
|
||||
if(self->row_size == 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->row_size == 3) {
|
||||
} else if (self->row_size == 3) {
|
||||
adjoint_m3_m3((float (*)[3]) mat,(float (*)[3])self->contigPtr);
|
||||
} else if(self->row_size == 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->row_size * self->col_size); x++) {
|
||||
for (x = 0; x < (self->row_size * self->col_size); x++) {
|
||||
mat[x] /= det;
|
||||
}
|
||||
/*set values*/
|
||||
for(x = 0; x < self->row_size; x++) {
|
||||
for(y = 0; y < self->col_size; y++) {
|
||||
for (x = 0; x < self->row_size; x++) {
|
||||
for (y = 0; y < self->col_size; y++) {
|
||||
self->matrix[x][y] = mat[z];
|
||||
z++;
|
||||
}
|
||||
@@ -1024,13 +1024,13 @@ static PyObject *Matrix_rotate(MatrixObject *self, PyObject *value)
|
||||
{
|
||||
float self_rmat[3][3], other_rmat[3][3], rmat[3][3];
|
||||
|
||||
if(BaseMath_ReadCallback(self) == -1)
|
||||
if (BaseMath_ReadCallback(self) == -1)
|
||||
return NULL;
|
||||
|
||||
if(mathutils_any_to_rotmat(other_rmat, value, "matrix.rotate(value)") == -1)
|
||||
if (mathutils_any_to_rotmat(other_rmat, value, "matrix.rotate(value)") == -1)
|
||||
return NULL;
|
||||
|
||||
if(self->col_size != 3 || self->row_size != 3) {
|
||||
if (self->col_size != 3 || self->row_size != 3) {
|
||||
PyErr_SetString(PyExc_TypeError,
|
||||
"Matrix.rotate(): "
|
||||
"must have 3x3 dimensions");
|
||||
@@ -1063,14 +1063,14 @@ static PyObject *Matrix_decompose(MatrixObject *self)
|
||||
float quat[4];
|
||||
float size[3];
|
||||
|
||||
if(self->col_size != 4 || self->row_size != 4) {
|
||||
if (self->col_size != 4 || self->row_size != 4) {
|
||||
PyErr_SetString(PyExc_TypeError,
|
||||
"Matrix.decompose(): "
|
||||
"inappropriate matrix size - expects 4x4 matrix");
|
||||
return NULL;
|
||||
}
|
||||
|
||||
if(BaseMath_ReadCallback(self) == -1)
|
||||
if (BaseMath_ReadCallback(self) == -1)
|
||||
return NULL;
|
||||
|
||||
mat4_to_loc_rot_size(loc, rot, size, (float (*)[4])self->contigPtr);
|
||||
@@ -1103,21 +1103,21 @@ static PyObject *Matrix_lerp(MatrixObject *self, PyObject *args)
|
||||
MatrixObject *mat2 = NULL;
|
||||
float fac, mat[MATRIX_MAX_DIM*MATRIX_MAX_DIM];
|
||||
|
||||
if(!PyArg_ParseTuple(args, "O!f:lerp", &matrix_Type, &mat2, &fac))
|
||||
if (!PyArg_ParseTuple(args, "O!f:lerp", &matrix_Type, &mat2, &fac))
|
||||
return NULL;
|
||||
|
||||
if(self->row_size != mat2->row_size || self->col_size != mat2->col_size) {
|
||||
if (self->row_size != mat2->row_size || self->col_size != mat2->col_size) {
|
||||
PyErr_SetString(PyExc_ValueError,
|
||||
"Matrix.lerp(): "
|
||||
"expects both matrix objects of the same dimensions");
|
||||
return NULL;
|
||||
}
|
||||
|
||||
if(BaseMath_ReadCallback(self) == -1 || BaseMath_ReadCallback(mat2) == -1)
|
||||
if (BaseMath_ReadCallback(self) == -1 || BaseMath_ReadCallback(mat2) == -1)
|
||||
return NULL;
|
||||
|
||||
/* TODO, different sized matrix */
|
||||
if(self->row_size==4 && self->col_size==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->row_size==3 && self->col_size==3) {
|
||||
@@ -1146,10 +1146,10 @@ PyDoc_STRVAR(Matrix_determinant_doc,
|
||||
);
|
||||
static PyObject *Matrix_determinant(MatrixObject *self)
|
||||
{
|
||||
if(BaseMath_ReadCallback(self) == -1)
|
||||
if (BaseMath_ReadCallback(self) == -1)
|
||||
return NULL;
|
||||
|
||||
if(self->row_size != self->col_size){
|
||||
if (self->row_size != self->col_size) {
|
||||
PyErr_SetString(PyExc_TypeError,
|
||||
"Matrix.determinant(): "
|
||||
"only square matrices are supported");
|
||||
@@ -1170,21 +1170,21 @@ static PyObject *Matrix_transpose(MatrixObject *self)
|
||||
{
|
||||
float t = 0.0f;
|
||||
|
||||
if(BaseMath_ReadCallback(self) == -1)
|
||||
if (BaseMath_ReadCallback(self) == -1)
|
||||
return NULL;
|
||||
|
||||
if(self->row_size != self->col_size){
|
||||
if (self->row_size != self->col_size) {
|
||||
PyErr_SetString(PyExc_TypeError,
|
||||
"Matrix.transpose(d): "
|
||||
"only square matrices are supported");
|
||||
return NULL;
|
||||
}
|
||||
|
||||
if(self->row_size == 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->row_size == 3) {
|
||||
} else if (self->row_size == 3) {
|
||||
transpose_m3((float (*)[3])self->contigPtr);
|
||||
}
|
||||
else {
|
||||
@@ -1221,7 +1221,7 @@ static PyObject *Matrix_zero(MatrixObject *self)
|
||||
{
|
||||
fill_vn(self->contigPtr, self->row_size * self->col_size, 0.0f);
|
||||
|
||||
if(BaseMath_WriteCallback(self) == -1)
|
||||
if (BaseMath_WriteCallback(self) == -1)
|
||||
return NULL;
|
||||
|
||||
Py_RETURN_NONE;
|
||||
@@ -1239,29 +1239,29 @@ PyDoc_STRVAR(Matrix_identity_doc,
|
||||
);
|
||||
static PyObject *Matrix_identity(MatrixObject *self)
|
||||
{
|
||||
if(BaseMath_ReadCallback(self) == -1)
|
||||
if (BaseMath_ReadCallback(self) == -1)
|
||||
return NULL;
|
||||
|
||||
if(self->row_size != self->col_size){
|
||||
if (self->row_size != self->col_size) {
|
||||
PyErr_SetString(PyExc_TypeError,
|
||||
"Matrix.identity(): "
|
||||
"only square matrices are supported");
|
||||
return NULL;
|
||||
}
|
||||
|
||||
if(self->row_size == 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->row_size == 3) {
|
||||
} else if (self->row_size == 3) {
|
||||
unit_m3((float (*)[3])self->contigPtr);
|
||||
}
|
||||
else {
|
||||
unit_m4((float (*)[4])self->contigPtr);
|
||||
}
|
||||
|
||||
if(BaseMath_WriteCallback(self) == -1)
|
||||
if (BaseMath_WriteCallback(self) == -1)
|
||||
return NULL;
|
||||
|
||||
Py_RETURN_NONE;
|
||||
@@ -1278,7 +1278,7 @@ PyDoc_STRVAR(Matrix_copy_doc,
|
||||
);
|
||||
static PyObject *Matrix_copy(MatrixObject *self)
|
||||
{
|
||||
if(BaseMath_ReadCallback(self) == -1)
|
||||
if (BaseMath_ReadCallback(self) == -1)
|
||||
return NULL;
|
||||
|
||||
return (PyObject*)newMatrixObject((float (*))self->contigPtr, self->row_size, self->col_size, Py_NEW, Py_TYPE(self));
|
||||
@@ -1291,12 +1291,12 @@ static PyObject *Matrix_repr(MatrixObject *self)
|
||||
int x, y;
|
||||
PyObject *rows[MATRIX_MAX_DIM]= {NULL};
|
||||
|
||||
if(BaseMath_ReadCallback(self) == -1)
|
||||
if (BaseMath_ReadCallback(self) == -1)
|
||||
return NULL;
|
||||
|
||||
for(x = 0; x < self->row_size; x++){
|
||||
for (x = 0; x < self->row_size; x++) {
|
||||
rows[x]= PyTuple_New(self->col_size);
|
||||
for(y = 0; y < self->col_size; y++) {
|
||||
for (y = 0; y < self->col_size; y++) {
|
||||
PyTuple_SET_ITEM(rows[x], y, PyFloat_FromDouble(self->matrix[x][y]));
|
||||
}
|
||||
}
|
||||
@@ -1327,7 +1327,7 @@ static PyObject* Matrix_richcmpr(PyObject *a, PyObject *b, int op)
|
||||
MatrixObject *matA= (MatrixObject*)a;
|
||||
MatrixObject *matB= (MatrixObject*)b;
|
||||
|
||||
if(BaseMath_ReadCallback(matA) == -1 || BaseMath_ReadCallback(matB) == -1)
|
||||
if (BaseMath_ReadCallback(matA) == -1 || BaseMath_ReadCallback(matB) == -1)
|
||||
return NULL;
|
||||
|
||||
ok= ( (matA->col_size == matB->col_size) &&
|
||||
@@ -1369,10 +1369,10 @@ static int Matrix_len(MatrixObject *self)
|
||||
the wrapped vector gives direct access to the matrix data*/
|
||||
static PyObject *Matrix_item(MatrixObject *self, int i)
|
||||
{
|
||||
if(BaseMath_ReadCallback(self) == -1)
|
||||
if (BaseMath_ReadCallback(self) == -1)
|
||||
return NULL;
|
||||
|
||||
if(i < 0 || i >= self->row_size) {
|
||||
if (i < 0 || i >= self->row_size) {
|
||||
PyErr_SetString(PyExc_IndexError,
|
||||
"matrix[attribute]: "
|
||||
"array index out of range");
|
||||
@@ -1386,16 +1386,16 @@ static PyObject *Matrix_item(MatrixObject *self, int i)
|
||||
static int Matrix_ass_item(MatrixObject *self, int i, PyObject *value)
|
||||
{
|
||||
float vec[4];
|
||||
if(BaseMath_ReadCallback(self) == -1)
|
||||
if (BaseMath_ReadCallback(self) == -1)
|
||||
return -1;
|
||||
|
||||
if(i >= self->row_size || i < 0){
|
||||
if (i >= self->row_size || i < 0) {
|
||||
PyErr_SetString(PyExc_IndexError,
|
||||
"matrix[attribute] = x: bad column");
|
||||
return -1;
|
||||
}
|
||||
|
||||
if(mathutils_array_parse(vec, self->col_size, self->col_size, 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;
|
||||
}
|
||||
|
||||
@@ -1413,7 +1413,7 @@ static PyObject *Matrix_slice(MatrixObject *self, int begin, int end)
|
||||
PyObject *tuple;
|
||||
int count;
|
||||
|
||||
if(BaseMath_ReadCallback(self) == -1)
|
||||
if (BaseMath_ReadCallback(self) == -1)
|
||||
return NULL;
|
||||
|
||||
CLAMP(begin, 0, self->row_size);
|
||||
@@ -1421,7 +1421,7 @@ static PyObject *Matrix_slice(MatrixObject *self, int begin, int end)
|
||||
begin= MIN2(begin, end);
|
||||
|
||||
tuple= PyTuple_New(end - begin);
|
||||
for(count= begin; count < end; count++) {
|
||||
for (count= begin; count < end; count++) {
|
||||
PyTuple_SET_ITEM(tuple, count - begin,
|
||||
newVectorObject_cb((PyObject *)self, self->col_size, mathutils_matrix_vector_cb_index, count));
|
||||
|
||||
@@ -1435,7 +1435,7 @@ static int Matrix_ass_slice(MatrixObject *self, int begin, int end, PyObject *va
|
||||
{
|
||||
PyObject *value_fast= NULL;
|
||||
|
||||
if(BaseMath_ReadCallback(self) == -1)
|
||||
if (BaseMath_ReadCallback(self) == -1)
|
||||
return -1;
|
||||
|
||||
CLAMP(begin, 0, self->row_size);
|
||||
@@ -1443,7 +1443,7 @@ static int Matrix_ass_slice(MatrixObject *self, int begin, int end, PyObject *va
|
||||
begin = MIN2(begin, end);
|
||||
|
||||
/* non list/tuple cases */
|
||||
if(!(value_fast=PySequence_Fast(value, "matrix[begin:end] = value"))) {
|
||||
if (!(value_fast=PySequence_Fast(value, "matrix[begin:end] = value"))) {
|
||||
/* PySequence_Fast sets the error */
|
||||
return -1;
|
||||
}
|
||||
@@ -1452,7 +1452,7 @@ static int Matrix_ass_slice(MatrixObject *self, int begin, int end, PyObject *va
|
||||
int i;
|
||||
float mat[16];
|
||||
|
||||
if(PySequence_Fast_GET_SIZE(value_fast) != size) {
|
||||
if (PySequence_Fast_GET_SIZE(value_fast) != size) {
|
||||
Py_DECREF(value_fast);
|
||||
PyErr_SetString(PyExc_ValueError,
|
||||
"matrix[begin:end] = []: "
|
||||
@@ -1465,7 +1465,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->col_size], self->col_size, self->col_size, 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;
|
||||
}
|
||||
}
|
||||
@@ -1489,17 +1489,17 @@ static PyObject *Matrix_add(PyObject *m1, PyObject *m2)
|
||||
mat1 = (MatrixObject*)m1;
|
||||
mat2 = (MatrixObject*)m2;
|
||||
|
||||
if(!MatrixObject_Check(m1) || !MatrixObject_Check(m2)) {
|
||||
if (!MatrixObject_Check(m1) || !MatrixObject_Check(m2)) {
|
||||
PyErr_SetString(PyExc_TypeError,
|
||||
"Matrix addition: "
|
||||
"arguments not valid for this operation");
|
||||
return NULL;
|
||||
}
|
||||
|
||||
if(BaseMath_ReadCallback(mat1) == -1 || BaseMath_ReadCallback(mat2) == -1)
|
||||
if (BaseMath_ReadCallback(mat1) == -1 || BaseMath_ReadCallback(mat2) == -1)
|
||||
return NULL;
|
||||
|
||||
if(mat1->row_size != mat2->row_size || mat1->col_size != mat2->col_size){
|
||||
if (mat1->row_size != mat2->row_size || mat1->col_size != mat2->col_size) {
|
||||
PyErr_SetString(PyExc_TypeError,
|
||||
"Matrix addition: "
|
||||
"matrices must have the same dimensions for this operation");
|
||||
@@ -1520,17 +1520,17 @@ static PyObject *Matrix_sub(PyObject *m1, PyObject *m2)
|
||||
mat1 = (MatrixObject*)m1;
|
||||
mat2 = (MatrixObject*)m2;
|
||||
|
||||
if(!MatrixObject_Check(m1) || !MatrixObject_Check(m2)) {
|
||||
if (!MatrixObject_Check(m1) || !MatrixObject_Check(m2)) {
|
||||
PyErr_SetString(PyExc_TypeError,
|
||||
"Matrix addition: "
|
||||
"arguments not valid for this operation");
|
||||
return NULL;
|
||||
}
|
||||
|
||||
if(BaseMath_ReadCallback(mat1) == -1 || BaseMath_ReadCallback(mat2) == -1)
|
||||
if (BaseMath_ReadCallback(mat1) == -1 || BaseMath_ReadCallback(mat2) == -1)
|
||||
return NULL;
|
||||
|
||||
if(mat1->row_size != mat2->row_size || mat1->col_size != mat2->col_size){
|
||||
if (mat1->row_size != mat2->row_size || mat1->col_size != mat2->col_size) {
|
||||
PyErr_SetString(PyExc_TypeError,
|
||||
"Matrix addition: "
|
||||
"matrices must have the same dimensions for this operation");
|
||||
@@ -1556,18 +1556,18 @@ static PyObject *Matrix_mul(PyObject *m1, PyObject *m2)
|
||||
|
||||
MatrixObject *mat1 = NULL, *mat2 = NULL;
|
||||
|
||||
if(MatrixObject_Check(m1)) {
|
||||
if (MatrixObject_Check(m1)) {
|
||||
mat1 = (MatrixObject*)m1;
|
||||
if(BaseMath_ReadCallback(mat1) == -1)
|
||||
if (BaseMath_ReadCallback(mat1) == -1)
|
||||
return NULL;
|
||||
}
|
||||
if(MatrixObject_Check(m2)) {
|
||||
if (MatrixObject_Check(m2)) {
|
||||
mat2 = (MatrixObject*)m2;
|
||||
if(BaseMath_ReadCallback(mat2) == -1)
|
||||
if (BaseMath_ReadCallback(mat2) == -1)
|
||||
return NULL;
|
||||
}
|
||||
|
||||
if(mat1 && mat2) {
|
||||
if (mat1 && mat2) {
|
||||
/*MATRIX * MATRIX*/
|
||||
float mat[16]= {0.0f, 0.0f, 0.0f, 0.0f,
|
||||
0.0f, 0.0f, 0.0f, 0.0f,
|
||||
@@ -1576,9 +1576,9 @@ static PyObject *Matrix_mul(PyObject *m1, PyObject *m2)
|
||||
double dot = 0.0f;
|
||||
int x, y, 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++) {
|
||||
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->col_size) + y)] = (float)dot;
|
||||
@@ -1588,20 +1588,20 @@ static PyObject *Matrix_mul(PyObject *m1, PyObject *m2)
|
||||
|
||||
return newMatrixObject(mat, mat2->row_size, mat1->col_size, Py_NEW, Py_TYPE(mat1));
|
||||
}
|
||||
else if(mat2) {
|
||||
else if (mat2) {
|
||||
/*FLOAT/INT * MATRIX */
|
||||
if (((scalar= PyFloat_AsDouble(m1)) == -1.0f && PyErr_Occurred())==0) {
|
||||
return matrix_mul_float(mat2, scalar);
|
||||
}
|
||||
}
|
||||
else if(mat1) {
|
||||
else if (mat1) {
|
||||
/*VEC * MATRIX */
|
||||
if(VectorObject_Check(m2)) {
|
||||
if (VectorObject_Check(m2)) {
|
||||
VectorObject *vec2= (VectorObject *)m2;
|
||||
float tvec[4];
|
||||
if(BaseMath_ReadCallback(vec2) == -1)
|
||||
if (BaseMath_ReadCallback(vec2) == -1)
|
||||
return NULL;
|
||||
if(column_vector_multiplication(tvec, vec2, mat1) == -1) {
|
||||
if (column_vector_multiplication(tvec, vec2, mat1) == -1) {
|
||||
return NULL;
|
||||
}
|
||||
|
||||
@@ -1624,7 +1624,7 @@ static PyObject *Matrix_mul(PyObject *m1, PyObject *m2)
|
||||
}
|
||||
static PyObject* Matrix_inv(MatrixObject *self)
|
||||
{
|
||||
if(BaseMath_ReadCallback(self) == -1)
|
||||
if (BaseMath_ReadCallback(self) == -1)
|
||||
return NULL;
|
||||
|
||||
return Matrix_invert(self);
|
||||
@@ -1771,11 +1771,11 @@ static PyObject *Matrix_median_scale_get(MatrixObject *self, void *UNUSED(closur
|
||||
{
|
||||
float mat[3][3];
|
||||
|
||||
if(BaseMath_ReadCallback(self) == -1)
|
||||
if (BaseMath_ReadCallback(self) == -1)
|
||||
return NULL;
|
||||
|
||||
/*must be 3-4 cols, 3-4 rows, square matrix*/
|
||||
if((self->col_size < 3) || (self->row_size < 3)) {
|
||||
if ((self->col_size < 3) || (self->row_size < 3)) {
|
||||
PyErr_SetString(PyExc_AttributeError,
|
||||
"Matrix.median_scale: "
|
||||
"inappropriate matrix size, 3x3 minimum");
|
||||
@@ -1789,13 +1789,13 @@ static PyObject *Matrix_median_scale_get(MatrixObject *self, void *UNUSED(closur
|
||||
|
||||
static PyObject *Matrix_is_negative_get(MatrixObject *self, void *UNUSED(closure))
|
||||
{
|
||||
if(BaseMath_ReadCallback(self) == -1)
|
||||
if (BaseMath_ReadCallback(self) == -1)
|
||||
return NULL;
|
||||
|
||||
/*must be 3-4 cols, 3-4 rows, square matrix*/
|
||||
if(self->col_size == 4 && self->row_size == 4)
|
||||
if (self->col_size == 4 && self->row_size == 4)
|
||||
return PyBool_FromLong(is_negative_m4((float (*)[4])self->contigPtr));
|
||||
else if(self->col_size == 3 && self->row_size == 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,
|
||||
@@ -1807,13 +1807,13 @@ static PyObject *Matrix_is_negative_get(MatrixObject *self, void *UNUSED(closure
|
||||
|
||||
static PyObject *Matrix_is_orthogonal_get(MatrixObject *self, void *UNUSED(closure))
|
||||
{
|
||||
if(BaseMath_ReadCallback(self) == -1)
|
||||
if (BaseMath_ReadCallback(self) == -1)
|
||||
return NULL;
|
||||
|
||||
/*must be 3-4 cols, 3-4 rows, square matrix*/
|
||||
if(self->col_size == 4 && self->row_size == 4)
|
||||
if (self->col_size == 4 && self->row_size == 4)
|
||||
return PyBool_FromLong(is_orthogonal_m4((float (*)[4])self->contigPtr));
|
||||
else if(self->col_size == 3 && self->row_size == 3)
|
||||
else if (self->col_size == 3 && self->row_size == 3)
|
||||
return PyBool_FromLong(is_orthogonal_m3((float (*)[3])self->contigPtr));
|
||||
else {
|
||||
PyErr_SetString(PyExc_AttributeError,
|
||||
@@ -1953,7 +1953,7 @@ PyObject *newMatrixObject(float *mat, const unsigned short rowSize, const unsign
|
||||
int x, row, col;
|
||||
|
||||
/*matrix objects can be any 2-4row x 2-4col matrix*/
|
||||
if(rowSize < 2 || rowSize > 4 || colSize < 2 || colSize > 4) {
|
||||
if (rowSize < 2 || rowSize > 4 || colSize < 2 || colSize > 4) {
|
||||
PyErr_SetString(PyExc_RuntimeError,
|
||||
"Matrix(): "
|
||||
"row and column sizes must be between 2 and 4");
|
||||
@@ -1963,7 +1963,7 @@ PyObject *newMatrixObject(float *mat, const unsigned short rowSize, const unsign
|
||||
self= base_type ? (MatrixObject *)base_type->tp_alloc(base_type, 0) :
|
||||
(MatrixObject *)PyObject_GC_New(MatrixObject, &matrix_Type);
|
||||
|
||||
if(self) {
|
||||
if (self) {
|
||||
self->row_size = rowSize;
|
||||
self->col_size = colSize;
|
||||
|
||||
@@ -1971,30 +1971,30 @@ PyObject *newMatrixObject(float *mat, const unsigned short rowSize, const unsign
|
||||
self->cb_user= NULL;
|
||||
self->cb_type= self->cb_subtype= 0;
|
||||
|
||||
if(type == Py_WRAP){
|
||||
if (type == Py_WRAP) {
|
||||
self->contigPtr = mat;
|
||||
/*pointer array points to contigous memory*/
|
||||
for(x = 0; x < rowSize; x++) {
|
||||
for (x = 0; x < rowSize; x++) {
|
||||
self->matrix[x] = self->contigPtr + (x * colSize);
|
||||
}
|
||||
self->wrapped = Py_WRAP;
|
||||
}
|
||||
else if (type == Py_NEW){
|
||||
else if (type == Py_NEW) {
|
||||
self->contigPtr = PyMem_Malloc(rowSize * colSize * sizeof(float));
|
||||
if(self->contigPtr == NULL) { /*allocation failure*/
|
||||
if (self->contigPtr == NULL) { /*allocation failure*/
|
||||
PyErr_SetString(PyExc_MemoryError,
|
||||
"Matrix(): "
|
||||
"problem allocating pointer space");
|
||||
return NULL;
|
||||
}
|
||||
/*pointer array points to contigous memory*/
|
||||
for(x = 0; x < rowSize; x++) {
|
||||
for (x = 0; x < rowSize; x++) {
|
||||
self->matrix[x] = self->contigPtr + (x * colSize);
|
||||
}
|
||||
/*parse*/
|
||||
if(mat) { /*if a float array passed*/
|
||||
for(row = 0; row < rowSize; row++) {
|
||||
for(col = 0; col < colSize; col++) {
|
||||
if (mat) { /*if a float array passed*/
|
||||
for (row = 0; row < rowSize; row++) {
|
||||
for (col = 0; col < colSize; col++) {
|
||||
self->matrix[row][col] = mat[(row * colSize) + col];
|
||||
}
|
||||
}
|
||||
@@ -2016,7 +2016,7 @@ PyObject *newMatrixObject(float *mat, const unsigned short rowSize, const unsign
|
||||
PyObject *newMatrixObject_cb(PyObject *cb_user, int rowSize, int colSize, int cb_type, int cb_subtype)
|
||||
{
|
||||
MatrixObject *self= (MatrixObject *)newMatrixObject(NULL, rowSize, colSize, Py_NEW, NULL);
|
||||
if(self) {
|
||||
if (self) {
|
||||
Py_INCREF(cb_user);
|
||||
self->cb_user= cb_user;
|
||||
self->cb_type= (unsigned char)cb_type;
|
||||
|
||||
@@ -53,13 +53,13 @@ static PyObject *Quaternion_to_tuple_ext(QuaternionObject *self, int ndigits)
|
||||
|
||||
ret= PyTuple_New(QUAT_SIZE);
|
||||
|
||||
if(ndigits >= 0) {
|
||||
for(i= 0; i < QUAT_SIZE; i++) {
|
||||
if (ndigits >= 0) {
|
||||
for (i= 0; i < QUAT_SIZE; i++) {
|
||||
PyTuple_SET_ITEM(ret, i, PyFloat_FromDouble(double_round((double)self->quat[i], ndigits)));
|
||||
}
|
||||
}
|
||||
else {
|
||||
for(i= 0; i < QUAT_SIZE; i++) {
|
||||
for (i= 0; i < QUAT_SIZE; i++) {
|
||||
PyTuple_SET_ITEM(ret, i, PyFloat_FromDouble(self->quat[i]));
|
||||
}
|
||||
}
|
||||
@@ -90,34 +90,34 @@ static PyObject *Quaternion_to_euler(QuaternionObject *self, PyObject *args)
|
||||
short order= EULER_ORDER_XYZ;
|
||||
EulerObject *eul_compat = NULL;
|
||||
|
||||
if(!PyArg_ParseTuple(args, "|sO!:to_euler", &order_str, &euler_Type, &eul_compat))
|
||||
if (!PyArg_ParseTuple(args, "|sO!:to_euler", &order_str, &euler_Type, &eul_compat))
|
||||
return NULL;
|
||||
|
||||
if(BaseMath_ReadCallback(self) == -1)
|
||||
if (BaseMath_ReadCallback(self) == -1)
|
||||
return NULL;
|
||||
|
||||
if(order_str) {
|
||||
if (order_str) {
|
||||
order= euler_order_from_string(order_str, "Matrix.to_euler()");
|
||||
|
||||
if(order == -1)
|
||||
if (order == -1)
|
||||
return NULL;
|
||||
}
|
||||
|
||||
normalize_qt_qt(tquat, self->quat);
|
||||
|
||||
if(eul_compat) {
|
||||
if (eul_compat) {
|
||||
float mat[3][3];
|
||||
|
||||
if(BaseMath_ReadCallback(eul_compat) == -1)
|
||||
if (BaseMath_ReadCallback(eul_compat) == -1)
|
||||
return NULL;
|
||||
|
||||
quat_to_mat3(mat, tquat);
|
||||
|
||||
if(order == EULER_ORDER_XYZ) mat3_to_compatible_eul(eul, eul_compat->eul, mat);
|
||||
if (order == EULER_ORDER_XYZ) mat3_to_compatible_eul(eul, eul_compat->eul, mat);
|
||||
else mat3_to_compatible_eulO(eul, eul_compat->eul, order, mat);
|
||||
}
|
||||
else {
|
||||
if(order == EULER_ORDER_XYZ) quat_to_eul(eul, tquat);
|
||||
if (order == EULER_ORDER_XYZ) quat_to_eul(eul, tquat);
|
||||
else quat_to_eulO(eul, order, tquat);
|
||||
}
|
||||
|
||||
@@ -136,7 +136,7 @@ static PyObject *Quaternion_to_matrix(QuaternionObject *self)
|
||||
{
|
||||
float mat[9]; /* all values are set */
|
||||
|
||||
if(BaseMath_ReadCallback(self) == -1)
|
||||
if (BaseMath_ReadCallback(self) == -1)
|
||||
return NULL;
|
||||
|
||||
quat_to_mat3((float (*)[3])mat, self->quat);
|
||||
@@ -158,10 +158,10 @@ static PyObject *Quaternion_cross(QuaternionObject *self, PyObject *value)
|
||||
{
|
||||
float quat[QUAT_SIZE], tquat[QUAT_SIZE];
|
||||
|
||||
if(BaseMath_ReadCallback(self) == -1)
|
||||
if (BaseMath_ReadCallback(self) == -1)
|
||||
return NULL;
|
||||
|
||||
if(mathutils_array_parse(tquat, QUAT_SIZE, QUAT_SIZE, value, "Quaternion.cross(other), invalid 'other' arg") == -1)
|
||||
if (mathutils_array_parse(tquat, QUAT_SIZE, QUAT_SIZE, value, "Quaternion.cross(other), invalid 'other' arg") == -1)
|
||||
return NULL;
|
||||
|
||||
mul_qt_qtqt(quat, self->quat, tquat);
|
||||
@@ -183,10 +183,10 @@ static PyObject *Quaternion_dot(QuaternionObject *self, PyObject *value)
|
||||
{
|
||||
float tquat[QUAT_SIZE];
|
||||
|
||||
if(BaseMath_ReadCallback(self) == -1)
|
||||
if (BaseMath_ReadCallback(self) == -1)
|
||||
return NULL;
|
||||
|
||||
if(mathutils_array_parse(tquat, QUAT_SIZE, QUAT_SIZE, value, "Quaternion.dot(other), invalid 'other' arg") == -1)
|
||||
if (mathutils_array_parse(tquat, QUAT_SIZE, QUAT_SIZE, value, "Quaternion.dot(other), invalid 'other' arg") == -1)
|
||||
return NULL;
|
||||
|
||||
return PyFloat_FromDouble(dot_qtqt(self->quat, tquat));
|
||||
@@ -206,10 +206,10 @@ static PyObject *Quaternion_rotation_difference(QuaternionObject *self, PyObject
|
||||
{
|
||||
float tquat[QUAT_SIZE], quat[QUAT_SIZE];
|
||||
|
||||
if(BaseMath_ReadCallback(self) == -1)
|
||||
if (BaseMath_ReadCallback(self) == -1)
|
||||
return NULL;
|
||||
|
||||
if(mathutils_array_parse(tquat, QUAT_SIZE, QUAT_SIZE, value, "Quaternion.difference(other), invalid 'other' arg") == -1)
|
||||
if (mathutils_array_parse(tquat, QUAT_SIZE, QUAT_SIZE, value, "Quaternion.difference(other), invalid 'other' arg") == -1)
|
||||
return NULL;
|
||||
|
||||
rotation_between_quats_to_quat(quat, self->quat, tquat);
|
||||
@@ -234,20 +234,20 @@ static PyObject *Quaternion_slerp(QuaternionObject *self, PyObject *args)
|
||||
PyObject *value;
|
||||
float tquat[QUAT_SIZE], quat[QUAT_SIZE], fac;
|
||||
|
||||
if(!PyArg_ParseTuple(args, "Of:slerp", &value, &fac)) {
|
||||
if (!PyArg_ParseTuple(args, "Of:slerp", &value, &fac)) {
|
||||
PyErr_SetString(PyExc_TypeError,
|
||||
"quat.slerp(): "
|
||||
"expected Quaternion types and float");
|
||||
return NULL;
|
||||
}
|
||||
|
||||
if(BaseMath_ReadCallback(self) == -1)
|
||||
if (BaseMath_ReadCallback(self) == -1)
|
||||
return NULL;
|
||||
|
||||
if(mathutils_array_parse(tquat, QUAT_SIZE, QUAT_SIZE, value, "Quaternion.slerp(other), invalid 'other' arg") == -1)
|
||||
if (mathutils_array_parse(tquat, QUAT_SIZE, QUAT_SIZE, value, "Quaternion.slerp(other), invalid 'other' arg") == -1)
|
||||
return NULL;
|
||||
|
||||
if(fac > 1.0f || fac < 0.0f) {
|
||||
if (fac > 1.0f || fac < 0.0f) {
|
||||
PyErr_SetString(PyExc_ValueError,
|
||||
"quat.slerp(): "
|
||||
"interpolation factor must be between 0.0 and 1.0");
|
||||
@@ -272,10 +272,10 @@ static PyObject *Quaternion_rotate(QuaternionObject *self, PyObject *value)
|
||||
float self_rmat[3][3], other_rmat[3][3], rmat[3][3];
|
||||
float tquat[4], length;
|
||||
|
||||
if(BaseMath_ReadCallback(self) == -1)
|
||||
if (BaseMath_ReadCallback(self) == -1)
|
||||
return NULL;
|
||||
|
||||
if(mathutils_any_to_rotmat(other_rmat, value, "Quaternion.rotate(value)") == -1)
|
||||
if (mathutils_any_to_rotmat(other_rmat, value, "Quaternion.rotate(value)") == -1)
|
||||
return NULL;
|
||||
|
||||
length= normalize_qt_qt(tquat, self->quat);
|
||||
@@ -298,7 +298,7 @@ PyDoc_STRVAR(Quaternion_normalize_doc,
|
||||
);
|
||||
static PyObject *Quaternion_normalize(QuaternionObject *self)
|
||||
{
|
||||
if(BaseMath_ReadCallback(self) == -1)
|
||||
if (BaseMath_ReadCallback(self) == -1)
|
||||
return NULL;
|
||||
|
||||
normalize_qt(self->quat);
|
||||
@@ -327,7 +327,7 @@ PyDoc_STRVAR(Quaternion_invert_doc,
|
||||
);
|
||||
static PyObject *Quaternion_invert(QuaternionObject *self)
|
||||
{
|
||||
if(BaseMath_ReadCallback(self) == -1)
|
||||
if (BaseMath_ReadCallback(self) == -1)
|
||||
return NULL;
|
||||
|
||||
invert_qt(self->quat);
|
||||
@@ -359,7 +359,7 @@ PyDoc_STRVAR(Quaternion_identity_doc,
|
||||
);
|
||||
static PyObject *Quaternion_identity(QuaternionObject *self)
|
||||
{
|
||||
if(BaseMath_ReadCallback(self) == -1)
|
||||
if (BaseMath_ReadCallback(self) == -1)
|
||||
return NULL;
|
||||
|
||||
unit_qt(self->quat);
|
||||
@@ -378,7 +378,7 @@ PyDoc_STRVAR(Quaternion_negate_doc,
|
||||
);
|
||||
static PyObject *Quaternion_negate(QuaternionObject *self)
|
||||
{
|
||||
if(BaseMath_ReadCallback(self) == -1)
|
||||
if (BaseMath_ReadCallback(self) == -1)
|
||||
return NULL;
|
||||
|
||||
mul_qt_fl(self->quat, -1.0f);
|
||||
@@ -394,7 +394,7 @@ PyDoc_STRVAR(Quaternion_conjugate_doc,
|
||||
);
|
||||
static PyObject *Quaternion_conjugate(QuaternionObject *self)
|
||||
{
|
||||
if(BaseMath_ReadCallback(self) == -1)
|
||||
if (BaseMath_ReadCallback(self) == -1)
|
||||
return NULL;
|
||||
|
||||
conjugate_qt(self->quat);
|
||||
@@ -429,7 +429,7 @@ PyDoc_STRVAR(Quaternion_copy_doc,
|
||||
);
|
||||
static PyObject *Quaternion_copy(QuaternionObject *self)
|
||||
{
|
||||
if(BaseMath_ReadCallback(self) == -1)
|
||||
if (BaseMath_ReadCallback(self) == -1)
|
||||
return NULL;
|
||||
|
||||
return newQuaternionObject(self->quat, Py_NEW, Py_TYPE(self));
|
||||
@@ -441,7 +441,7 @@ static PyObject *Quaternion_repr(QuaternionObject *self)
|
||||
{
|
||||
PyObject *ret, *tuple;
|
||||
|
||||
if(BaseMath_ReadCallback(self) == -1)
|
||||
if (BaseMath_ReadCallback(self) == -1)
|
||||
return NULL;
|
||||
|
||||
tuple= Quaternion_to_tuple_ext(self, -1);
|
||||
@@ -461,7 +461,7 @@ static PyObject* Quaternion_richcmpr(PyObject *a, PyObject *b, int op)
|
||||
QuaternionObject *quatA= (QuaternionObject *)a;
|
||||
QuaternionObject *quatB= (QuaternionObject *)b;
|
||||
|
||||
if(BaseMath_ReadCallback(quatA) == -1 || BaseMath_ReadCallback(quatB) == -1)
|
||||
if (BaseMath_ReadCallback(quatA) == -1 || BaseMath_ReadCallback(quatB) == -1)
|
||||
return NULL;
|
||||
|
||||
ok= (EXPP_VectorsAreEqual(quatA->quat, quatB->quat, QUAT_SIZE, 1)) ? 0 : -1;
|
||||
@@ -499,16 +499,16 @@ static int Quaternion_len(QuaternionObject *UNUSED(self))
|
||||
//sequence accessor (get)
|
||||
static PyObject *Quaternion_item(QuaternionObject *self, int i)
|
||||
{
|
||||
if(i<0) i= QUAT_SIZE-i;
|
||||
if (i<0) i= QUAT_SIZE-i;
|
||||
|
||||
if(i < 0 || i >= QUAT_SIZE) {
|
||||
if (i < 0 || i >= QUAT_SIZE) {
|
||||
PyErr_SetString(PyExc_IndexError,
|
||||
"quaternion[attribute]: "
|
||||
"array index out of range");
|
||||
return NULL;
|
||||
}
|
||||
|
||||
if(BaseMath_ReadIndexCallback(self, i) == -1)
|
||||
if (BaseMath_ReadIndexCallback(self, i) == -1)
|
||||
return NULL;
|
||||
|
||||
return PyFloat_FromDouble(self->quat[i]);
|
||||
@@ -519,16 +519,16 @@ static PyObject *Quaternion_item(QuaternionObject *self, int i)
|
||||
static int Quaternion_ass_item(QuaternionObject *self, int i, PyObject *ob)
|
||||
{
|
||||
float scalar= (float)PyFloat_AsDouble(ob);
|
||||
if(scalar==-1.0f && PyErr_Occurred()) { /* parsed item not a number */
|
||||
if (scalar==-1.0f && PyErr_Occurred()) { /* parsed item not a number */
|
||||
PyErr_SetString(PyExc_TypeError,
|
||||
"quaternion[index] = x: "
|
||||
"index argument not a number");
|
||||
return -1;
|
||||
}
|
||||
|
||||
if(i<0) i= QUAT_SIZE-i;
|
||||
if (i<0) i= QUAT_SIZE-i;
|
||||
|
||||
if(i < 0 || i >= QUAT_SIZE){
|
||||
if (i < 0 || i >= QUAT_SIZE) {
|
||||
PyErr_SetString(PyExc_IndexError,
|
||||
"quaternion[attribute] = x: "
|
||||
"array assignment index out of range");
|
||||
@@ -536,7 +536,7 @@ static int Quaternion_ass_item(QuaternionObject *self, int i, PyObject *ob)
|
||||
}
|
||||
self->quat[i] = scalar;
|
||||
|
||||
if(BaseMath_WriteIndexCallback(self, i) == -1)
|
||||
if (BaseMath_WriteIndexCallback(self, i) == -1)
|
||||
return -1;
|
||||
|
||||
return 0;
|
||||
@@ -548,7 +548,7 @@ static PyObject *Quaternion_slice(QuaternionObject *self, int begin, int end)
|
||||
PyObject *tuple;
|
||||
int count;
|
||||
|
||||
if(BaseMath_ReadCallback(self) == -1)
|
||||
if (BaseMath_ReadCallback(self) == -1)
|
||||
return NULL;
|
||||
|
||||
CLAMP(begin, 0, QUAT_SIZE);
|
||||
@@ -557,7 +557,7 @@ static PyObject *Quaternion_slice(QuaternionObject *self, int begin, int end)
|
||||
begin= MIN2(begin, end);
|
||||
|
||||
tuple= PyTuple_New(end - begin);
|
||||
for(count= begin; count < end; count++) {
|
||||
for (count= begin; count < end; count++) {
|
||||
PyTuple_SET_ITEM(tuple, count - begin, PyFloat_FromDouble(self->quat[count]));
|
||||
}
|
||||
|
||||
@@ -570,7 +570,7 @@ static int Quaternion_ass_slice(QuaternionObject *self, int begin, int end, PyOb
|
||||
int i, size;
|
||||
float quat[QUAT_SIZE];
|
||||
|
||||
if(BaseMath_ReadCallback(self) == -1)
|
||||
if (BaseMath_ReadCallback(self) == -1)
|
||||
return -1;
|
||||
|
||||
CLAMP(begin, 0, QUAT_SIZE);
|
||||
@@ -578,10 +578,10 @@ static int Quaternion_ass_slice(QuaternionObject *self, int begin, int end, PyOb
|
||||
CLAMP(end, 0, QUAT_SIZE);
|
||||
begin = MIN2(begin, end);
|
||||
|
||||
if((size=mathutils_array_parse(quat, 0, QUAT_SIZE, seq, "mathutils.Quaternion[begin:end] = []")) == -1)
|
||||
if ((size=mathutils_array_parse(quat, 0, QUAT_SIZE, seq, "mathutils.Quaternion[begin:end] = []")) == -1)
|
||||
return -1;
|
||||
|
||||
if(size != (end - begin)){
|
||||
if (size != (end - begin)) {
|
||||
PyErr_SetString(PyExc_ValueError,
|
||||
"quaternion[begin:end] = []: "
|
||||
"size mismatch in slice assignment");
|
||||
@@ -589,7 +589,7 @@ static int Quaternion_ass_slice(QuaternionObject *self, int begin, int end, PyOb
|
||||
}
|
||||
|
||||
/* parsed well - now set in vector */
|
||||
for(i= 0; i < size; i++)
|
||||
for (i= 0; i < size; i++)
|
||||
self->quat[begin + i] = quat[i];
|
||||
|
||||
(void)BaseMath_WriteCallback(self);
|
||||
@@ -674,7 +674,7 @@ static PyObject *Quaternion_add(PyObject *q1, PyObject *q2)
|
||||
float quat[QUAT_SIZE];
|
||||
QuaternionObject *quat1 = NULL, *quat2 = NULL;
|
||||
|
||||
if(!QuaternionObject_Check(q1) || !QuaternionObject_Check(q2)) {
|
||||
if (!QuaternionObject_Check(q1) || !QuaternionObject_Check(q2)) {
|
||||
PyErr_SetString(PyExc_TypeError,
|
||||
"Quaternion addition: "
|
||||
"arguments not valid for this operation");
|
||||
@@ -683,7 +683,7 @@ static PyObject *Quaternion_add(PyObject *q1, PyObject *q2)
|
||||
quat1 = (QuaternionObject*)q1;
|
||||
quat2 = (QuaternionObject*)q2;
|
||||
|
||||
if(BaseMath_ReadCallback(quat1) == -1 || BaseMath_ReadCallback(quat2) == -1)
|
||||
if (BaseMath_ReadCallback(quat1) == -1 || BaseMath_ReadCallback(quat2) == -1)
|
||||
return NULL;
|
||||
|
||||
add_qt_qtqt(quat, quat1->quat, quat2->quat, 1.0f);
|
||||
@@ -697,7 +697,7 @@ static PyObject *Quaternion_sub(PyObject *q1, PyObject *q2)
|
||||
float quat[QUAT_SIZE];
|
||||
QuaternionObject *quat1 = NULL, *quat2 = NULL;
|
||||
|
||||
if(!QuaternionObject_Check(q1) || !QuaternionObject_Check(q2)) {
|
||||
if (!QuaternionObject_Check(q1) || !QuaternionObject_Check(q2)) {
|
||||
PyErr_SetString(PyExc_TypeError,
|
||||
"Quaternion addition: "
|
||||
"arguments not valid for this operation");
|
||||
@@ -707,10 +707,10 @@ static PyObject *Quaternion_sub(PyObject *q1, PyObject *q2)
|
||||
quat1 = (QuaternionObject*)q1;
|
||||
quat2 = (QuaternionObject*)q2;
|
||||
|
||||
if(BaseMath_ReadCallback(quat1) == -1 || BaseMath_ReadCallback(quat2) == -1)
|
||||
if (BaseMath_ReadCallback(quat1) == -1 || BaseMath_ReadCallback(quat2) == -1)
|
||||
return NULL;
|
||||
|
||||
for(x = 0; x < QUAT_SIZE; x++) {
|
||||
for (x = 0; x < QUAT_SIZE; x++) {
|
||||
quat[x] = quat1->quat[x] - quat2->quat[x];
|
||||
}
|
||||
|
||||
@@ -732,24 +732,24 @@ static PyObject *Quaternion_mul(PyObject *q1, PyObject *q2)
|
||||
float quat[QUAT_SIZE], scalar;
|
||||
QuaternionObject *quat1 = NULL, *quat2 = NULL;
|
||||
|
||||
if(QuaternionObject_Check(q1)) {
|
||||
if (QuaternionObject_Check(q1)) {
|
||||
quat1 = (QuaternionObject*)q1;
|
||||
if(BaseMath_ReadCallback(quat1) == -1)
|
||||
if (BaseMath_ReadCallback(quat1) == -1)
|
||||
return NULL;
|
||||
}
|
||||
if(QuaternionObject_Check(q2)) {
|
||||
if (QuaternionObject_Check(q2)) {
|
||||
quat2 = (QuaternionObject*)q2;
|
||||
if(BaseMath_ReadCallback(quat2) == -1)
|
||||
if (BaseMath_ReadCallback(quat2) == -1)
|
||||
return NULL;
|
||||
}
|
||||
|
||||
if(quat1 && quat2) { /* QUAT*QUAT (cross product) */
|
||||
if (quat1 && quat2) { /* QUAT*QUAT (cross product) */
|
||||
mul_qt_qtqt(quat, quat1->quat, quat2->quat);
|
||||
return newQuaternionObject(quat, Py_NEW, Py_TYPE(q1));
|
||||
}
|
||||
/* the only case this can happen (for a supported type is "FLOAT*QUAT") */
|
||||
else if(quat2) { /* FLOAT*QUAT */
|
||||
if(((scalar= PyFloat_AsDouble(q1)) == -1.0f && PyErr_Occurred())==0) {
|
||||
else if (quat2) { /* FLOAT*QUAT */
|
||||
if (((scalar= PyFloat_AsDouble(q1)) == -1.0f && PyErr_Occurred())==0) {
|
||||
return quat_mul_float(quat2, scalar);
|
||||
}
|
||||
}
|
||||
@@ -759,14 +759,14 @@ static PyObject *Quaternion_mul(PyObject *q1, PyObject *q2)
|
||||
VectorObject *vec2 = (VectorObject *)q2;
|
||||
float tvec[3];
|
||||
|
||||
if(vec2->size != 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) {
|
||||
if (BaseMath_ReadCallback(vec2) == -1) {
|
||||
return NULL;
|
||||
}
|
||||
|
||||
@@ -776,7 +776,7 @@ static PyObject *Quaternion_mul(PyObject *q1, PyObject *q2)
|
||||
return newVectorObject(tvec, 3, Py_NEW, Py_TYPE(vec2));
|
||||
}
|
||||
/* QUAT * FLOAT */
|
||||
else if((((scalar= PyFloat_AsDouble(q2)) == -1.0f && PyErr_Occurred())==0)) {
|
||||
else if ((((scalar= PyFloat_AsDouble(q2)) == -1.0f && PyErr_Occurred())==0)) {
|
||||
return quat_mul_float(quat1, scalar);
|
||||
}
|
||||
}
|
||||
@@ -797,7 +797,7 @@ static PyObject *Quaternion_neg(QuaternionObject *self)
|
||||
{
|
||||
float tquat[QUAT_SIZE];
|
||||
|
||||
if(BaseMath_ReadCallback(self) == -1)
|
||||
if (BaseMath_ReadCallback(self) == -1)
|
||||
return NULL;
|
||||
|
||||
negate_v4_v4(tquat, self->quat);
|
||||
@@ -874,7 +874,7 @@ static int Quaternion_setAxis(QuaternionObject *self, PyObject *value, void *typ
|
||||
|
||||
static PyObject *Quaternion_getMagnitude(QuaternionObject *self, void *UNUSED(closure))
|
||||
{
|
||||
if(BaseMath_ReadCallback(self) == -1)
|
||||
if (BaseMath_ReadCallback(self) == -1)
|
||||
return NULL;
|
||||
|
||||
return PyFloat_FromDouble(sqrt(dot_qtqt(self->quat, self->quat)));
|
||||
@@ -884,7 +884,7 @@ static PyObject *Quaternion_getAngle(QuaternionObject *self, void *UNUSED(closur
|
||||
{
|
||||
float tquat[4];
|
||||
|
||||
if(BaseMath_ReadCallback(self) == -1)
|
||||
if (BaseMath_ReadCallback(self) == -1)
|
||||
return NULL;
|
||||
|
||||
normalize_qt_qt(tquat, self->quat);
|
||||
@@ -899,7 +899,7 @@ static int Quaternion_setAngle(QuaternionObject *self, PyObject *value, void *UN
|
||||
float axis[3], angle_dummy;
|
||||
double angle;
|
||||
|
||||
if(BaseMath_ReadCallback(self) == -1)
|
||||
if (BaseMath_ReadCallback(self) == -1)
|
||||
return -1;
|
||||
|
||||
len= normalize_qt_qt(tquat, self->quat);
|
||||
@@ -907,7 +907,7 @@ static int Quaternion_setAngle(QuaternionObject *self, PyObject *value, void *UN
|
||||
|
||||
angle= PyFloat_AsDouble(value);
|
||||
|
||||
if(angle==-1.0 && PyErr_Occurred()) { /* parsed item not a number */
|
||||
if (angle==-1.0 && PyErr_Occurred()) { /* parsed item not a number */
|
||||
PyErr_SetString(PyExc_TypeError,
|
||||
"Quaternion.angle = value: float expected");
|
||||
return -1;
|
||||
@@ -916,7 +916,7 @@ static int Quaternion_setAngle(QuaternionObject *self, PyObject *value, void *UN
|
||||
angle= angle_wrap_rad(angle);
|
||||
|
||||
/* If the axis of rotation is 0,0,0 set it to 1,0,0 - for zero-degree rotations */
|
||||
if( EXPP_FloatsAreEqual(axis[0], 0.0f, 10) &&
|
||||
if ( EXPP_FloatsAreEqual(axis[0], 0.0f, 10) &&
|
||||
EXPP_FloatsAreEqual(axis[1], 0.0f, 10) &&
|
||||
EXPP_FloatsAreEqual(axis[2], 0.0f, 10)
|
||||
) {
|
||||
@@ -926,7 +926,7 @@ static int Quaternion_setAngle(QuaternionObject *self, PyObject *value, void *UN
|
||||
axis_angle_to_quat(self->quat, axis, angle);
|
||||
mul_qt_fl(self->quat, len);
|
||||
|
||||
if(BaseMath_WriteCallback(self) == -1)
|
||||
if (BaseMath_WriteCallback(self) == -1)
|
||||
return -1;
|
||||
|
||||
return 0;
|
||||
@@ -939,14 +939,14 @@ static PyObject *Quaternion_getAxisVec(QuaternionObject *self, void *UNUSED(clos
|
||||
float axis[3];
|
||||
float angle;
|
||||
|
||||
if(BaseMath_ReadCallback(self) == -1)
|
||||
if (BaseMath_ReadCallback(self) == -1)
|
||||
return NULL;
|
||||
|
||||
normalize_qt_qt(tquat, self->quat);
|
||||
quat_to_axis_angle(axis, &angle, tquat);
|
||||
|
||||
/* If the axis of rotation is 0,0,0 set it to 1,0,0 - for zero-degree rotations */
|
||||
if( EXPP_FloatsAreEqual(axis[0], 0.0f, 10) &&
|
||||
if ( EXPP_FloatsAreEqual(axis[0], 0.0f, 10) &&
|
||||
EXPP_FloatsAreEqual(axis[1], 0.0f, 10) &&
|
||||
EXPP_FloatsAreEqual(axis[2], 0.0f, 10)
|
||||
) {
|
||||
@@ -964,7 +964,7 @@ static int Quaternion_setAxisVec(QuaternionObject *self, PyObject *value, void *
|
||||
float axis[3];
|
||||
float angle;
|
||||
|
||||
if(BaseMath_ReadCallback(self) == -1)
|
||||
if (BaseMath_ReadCallback(self) == -1)
|
||||
return -1;
|
||||
|
||||
len= normalize_qt_qt(tquat, self->quat);
|
||||
@@ -976,7 +976,7 @@ static int Quaternion_setAxisVec(QuaternionObject *self, PyObject *value, void *
|
||||
axis_angle_to_quat(self->quat, axis, angle);
|
||||
mul_qt_fl(self->quat, len);
|
||||
|
||||
if(BaseMath_WriteCallback(self) == -1)
|
||||
if (BaseMath_WriteCallback(self) == -1)
|
||||
return -1;
|
||||
|
||||
return 0;
|
||||
@@ -989,14 +989,14 @@ static PyObject *Quaternion_new(PyTypeObject *type, PyObject *args, PyObject *kw
|
||||
double angle = 0.0f;
|
||||
float quat[QUAT_SIZE]= {0.0f, 0.0f, 0.0f, 0.0f};
|
||||
|
||||
if(kwds && PyDict_Size(kwds)) {
|
||||
if (kwds && PyDict_Size(kwds)) {
|
||||
PyErr_SetString(PyExc_TypeError,
|
||||
"mathutils.Quaternion(): "
|
||||
"takes no keyword args");
|
||||
return NULL;
|
||||
}
|
||||
|
||||
if(!PyArg_ParseTuple(args, "|Od:mathutils.Quaternion", &seq, &angle))
|
||||
if (!PyArg_ParseTuple(args, "|Od:mathutils.Quaternion", &seq, &angle))
|
||||
return NULL;
|
||||
|
||||
switch(PyTuple_GET_SIZE(args)) {
|
||||
@@ -1021,7 +1021,7 @@ static PyObject *quat__apply_to_copy(PyNoArgsFunction quat_func, QuaternionObjec
|
||||
{
|
||||
PyObject *ret= Quaternion_copy(self);
|
||||
PyObject *ret_dummy= quat_func(ret);
|
||||
if(ret_dummy) {
|
||||
if (ret_dummy) {
|
||||
Py_DECREF(ret_dummy);
|
||||
return (PyObject *)ret;
|
||||
}
|
||||
@@ -1144,18 +1144,18 @@ PyObject *newQuaternionObject(float *quat, int type, PyTypeObject *base_type)
|
||||
self= base_type ? (QuaternionObject *)base_type->tp_alloc(base_type, 0) :
|
||||
(QuaternionObject *)PyObject_GC_New(QuaternionObject, &quaternion_Type);
|
||||
|
||||
if(self) {
|
||||
if (self) {
|
||||
/* init callbacks as NULL */
|
||||
self->cb_user= NULL;
|
||||
self->cb_type= self->cb_subtype= 0;
|
||||
|
||||
if(type == Py_WRAP){
|
||||
if (type == Py_WRAP) {
|
||||
self->quat = quat;
|
||||
self->wrapped = Py_WRAP;
|
||||
}
|
||||
else if (type == Py_NEW){
|
||||
else if (type == Py_NEW) {
|
||||
self->quat = PyMem_Malloc(QUAT_SIZE * sizeof(float));
|
||||
if(!quat) { //new empty
|
||||
if (!quat) { //new empty
|
||||
unit_qt(self->quat);
|
||||
}
|
||||
else {
|
||||
@@ -1173,7 +1173,7 @@ PyObject *newQuaternionObject(float *quat, int type, PyTypeObject *base_type)
|
||||
PyObject *newQuaternionObject_cb(PyObject *cb_user, int cb_type, int cb_subtype)
|
||||
{
|
||||
QuaternionObject *self= (QuaternionObject *)newQuaternionObject(NULL, Py_NEW, NULL);
|
||||
if(self) {
|
||||
if (self) {
|
||||
Py_INCREF(cb_user);
|
||||
self->cb_user= cb_user;
|
||||
self->cb_type= (unsigned char)cb_type;
|
||||
|
||||
@@ -123,11 +123,11 @@ static PyObject *Vector_normalize(VectorObject *self)
|
||||
if(BaseMath_ReadCallback(self) == -1)
|
||||
return NULL;
|
||||
|
||||
for(i = 0; i < self->size; i++) {
|
||||
for (i = 0; i < self->size; i++) {
|
||||
norm += self->vec[i] * self->vec[i];
|
||||
}
|
||||
norm = (float) sqrt(norm);
|
||||
for(i = 0; i < self->size; i++) {
|
||||
for (i = 0; i < self->size; i++) {
|
||||
self->vec[i] /= norm;
|
||||
}
|
||||
|
||||
@@ -251,11 +251,11 @@ static PyObject *Vector_resize_4d(VectorObject *self)
|
||||
return NULL;
|
||||
}
|
||||
|
||||
if(self->size == 2){
|
||||
if(self->size == 2) {
|
||||
self->vec[2] = 0.0f;
|
||||
self->vec[3] = 1.0f;
|
||||
}
|
||||
else if(self->size == 3){
|
||||
else if(self->size == 3) {
|
||||
self->vec[3] = 1.0f;
|
||||
}
|
||||
self->size = 4;
|
||||
@@ -332,12 +332,12 @@ static PyObject *Vector_to_tuple_ext(VectorObject *self, int ndigits)
|
||||
ret= PyTuple_New(self->size);
|
||||
|
||||
if(ndigits >= 0) {
|
||||
for(i = 0; i < self->size; i++) {
|
||||
for (i = 0; i < self->size; i++) {
|
||||
PyTuple_SET_ITEM(ret, i, PyFloat_FromDouble(double_round((double)self->vec[i], ndigits)));
|
||||
}
|
||||
}
|
||||
else {
|
||||
for(i = 0; i < self->size; i++) {
|
||||
for (i = 0; i < self->size; i++) {
|
||||
PyTuple_SET_ITEM(ret, i, PyFloat_FromDouble(self->vec[i]));
|
||||
}
|
||||
}
|
||||
@@ -581,7 +581,7 @@ static PyObject *Vector_dot(VectorObject *self, PyObject *value)
|
||||
if(mathutils_array_parse(tvec, self->size, self->size, value, "Vector.dot(other), invalid 'other' arg") == -1)
|
||||
return NULL;
|
||||
|
||||
for(x = 0; x < self->size; x++) {
|
||||
for (x = 0; x < self->size; x++) {
|
||||
dot += (double)(self->vec[x] * tvec[x]);
|
||||
}
|
||||
|
||||
@@ -621,11 +621,11 @@ static PyObject *Vector_angle(VectorObject *self, PyObject *args)
|
||||
if(mathutils_array_parse(tvec, size, size, value, "Vector.angle(other), invalid 'other' arg") == -1)
|
||||
return NULL;
|
||||
|
||||
for(x = 0; x < size; x++) {
|
||||
for (x = 0; x < size; x++) {
|
||||
test_v1 += (double)(self->vec[x] * self->vec[x]);
|
||||
test_v2 += (double)(tvec[x] * tvec[x]);
|
||||
}
|
||||
if (!test_v1 || !test_v2){
|
||||
if (!test_v1 || !test_v2) {
|
||||
/* avoid exception */
|
||||
if(fallback) {
|
||||
Py_INCREF(fallback);
|
||||
@@ -640,7 +640,7 @@ static PyObject *Vector_angle(VectorObject *self, PyObject *args)
|
||||
}
|
||||
|
||||
//dot product
|
||||
for(x = 0; x < self->size; x++) {
|
||||
for (x = 0; x < self->size; x++) {
|
||||
dot += (double)(self->vec[x] * tvec[x]);
|
||||
}
|
||||
dot /= (sqrt(test_v1) * sqrt(test_v2));
|
||||
@@ -714,13 +714,13 @@ static PyObject *Vector_project(VectorObject *self, PyObject *value)
|
||||
return NULL;
|
||||
|
||||
//get dot products
|
||||
for(x = 0; x < size; x++) {
|
||||
for (x = 0; x < size; x++) {
|
||||
dot += (double)(self->vec[x] * tvec[x]);
|
||||
dot2 += (double)(tvec[x] * tvec[x]);
|
||||
}
|
||||
//projection
|
||||
dot /= dot2;
|
||||
for(x = 0; x < size; x++) {
|
||||
for (x = 0; x < size; x++) {
|
||||
vec[x] = (float)dot * tvec[x];
|
||||
}
|
||||
return newVectorObject(vec, size, Py_NEW, Py_TYPE(self));
|
||||
@@ -757,7 +757,7 @@ static PyObject *Vector_lerp(VectorObject *self, PyObject *args)
|
||||
|
||||
ifac= 1.0f - fac;
|
||||
|
||||
for(x = 0; x < size; x++) {
|
||||
for (x = 0; x < size; x++) {
|
||||
vec[x] = (ifac * self->vec[x]) + (fac * tvec[x]);
|
||||
}
|
||||
return newVectorObject(vec, size, Py_NEW, Py_TYPE(self));
|
||||
@@ -872,7 +872,7 @@ static int vector_ass_item_internal(VectorObject *self, int i, PyObject *value,
|
||||
|
||||
if(i<0) i= self->size-i;
|
||||
|
||||
if(i < 0 || i >= self->size){
|
||||
if(i < 0 || i >= self->size) {
|
||||
if(is_attr) {
|
||||
PyErr_Format(PyExc_AttributeError,
|
||||
"Vector.%c = x: unavailable on %dd vector",
|
||||
@@ -912,7 +912,7 @@ static PyObject *Vector_slice(VectorObject *self, int begin, int end)
|
||||
begin= MIN2(begin, end);
|
||||
|
||||
tuple= PyTuple_New(end - begin);
|
||||
for(count = begin; count < end; count++) {
|
||||
for (count = begin; count < end; count++) {
|
||||
PyTuple_SET_ITEM(tuple, count - begin, PyFloat_FromDouble(self->vec[count]));
|
||||
}
|
||||
|
||||
@@ -936,7 +936,7 @@ static int Vector_ass_slice(VectorObject *self, int begin, int end, PyObject *se
|
||||
return -1;
|
||||
|
||||
/*parsed well - now set in vector*/
|
||||
for(y = 0; y < size; y++){
|
||||
for (y = 0; y < size; y++) {
|
||||
self->vec[begin + y] = vec[y];
|
||||
}
|
||||
|
||||
@@ -1088,7 +1088,7 @@ int column_vector_multiplication(float rvec[MAX_DIMENSIONS], VectorObject* vec,
|
||||
double dot = 0.0f;
|
||||
int x, y, z = 0;
|
||||
|
||||
if(mat->row_size != vec->size){
|
||||
if(mat->row_size != vec->size) {
|
||||
if(mat->row_size == 4 && vec->size == 3) {
|
||||
vec_cpy[3] = 1.0f;
|
||||
}
|
||||
@@ -1105,8 +1105,8 @@ int column_vector_multiplication(float rvec[MAX_DIMENSIONS], VectorObject* vec,
|
||||
|
||||
rvec[3] = 1.0f;
|
||||
|
||||
for(x = 0; x < mat->col_size; x++) {
|
||||
for(y = 0; y < mat->row_size; y++) {
|
||||
for (x = 0; x < mat->col_size; x++) {
|
||||
for (y = 0; y < mat->row_size; y++) {
|
||||
dot += (double)(mat->matrix[y][x] * vec_cpy[y]);
|
||||
}
|
||||
rvec[z++] = (float)dot;
|
||||
@@ -1153,7 +1153,7 @@ static PyObject *Vector_mul(PyObject *v1, PyObject *v2)
|
||||
}
|
||||
|
||||
/*dot product*/
|
||||
for(i = 0; i < vec1->size; i++) {
|
||||
for (i = 0; i < vec1->size; i++) {
|
||||
dot += (double)(vec1->vec[i] * vec2->vec[i]);
|
||||
}
|
||||
return PyFloat_FromDouble(dot);
|
||||
@@ -1325,7 +1325,7 @@ static PyObject *Vector_div(PyObject *v1, PyObject *v2)
|
||||
return NULL;
|
||||
}
|
||||
|
||||
for(i = 0; i < vec1->size; i++) {
|
||||
for (i = 0; i < vec1->size; i++) {
|
||||
vec[i] = vec1->vec[i] / scalar;
|
||||
}
|
||||
return newVectorObject(vec, vec1->size, Py_NEW, Py_TYPE(v1));
|
||||
@@ -1354,7 +1354,7 @@ static PyObject *Vector_idiv(PyObject *v1, PyObject *v2)
|
||||
"divide by zero error");
|
||||
return NULL;
|
||||
}
|
||||
for(i = 0; i < vec1->size; i++) {
|
||||
for (i = 0; i < vec1->size; i++) {
|
||||
vec1->vec[i] /= scalar;
|
||||
}
|
||||
|
||||
@@ -1383,7 +1383,7 @@ static double vec_magnitude_nosqrt(float *data, int size)
|
||||
double dot = 0.0f;
|
||||
int i;
|
||||
|
||||
for(i=0; i<size; i++){
|
||||
for (i=0; i<size; i++) {
|
||||
dot += (double)data[i];
|
||||
}
|
||||
/*return (double)sqrt(dot);*/
|
||||
@@ -1403,8 +1403,8 @@ static PyObject* Vector_richcmpr(PyObject *objectA, PyObject *objectB, int compa
|
||||
double epsilon = .000001f;
|
||||
double lenA, lenB;
|
||||
|
||||
if (!VectorObject_Check(objectA) || !VectorObject_Check(objectB)){
|
||||
if (comparison_type == Py_NE){
|
||||
if (!VectorObject_Check(objectA) || !VectorObject_Check(objectB)) {
|
||||
if (comparison_type == Py_NE) {
|
||||
Py_RETURN_TRUE;
|
||||
}
|
||||
else {
|
||||
@@ -1417,8 +1417,8 @@ static PyObject* Vector_richcmpr(PyObject *objectA, PyObject *objectB, int compa
|
||||
if(BaseMath_ReadCallback(vecA) == -1 || BaseMath_ReadCallback(vecB) == -1)
|
||||
return NULL;
|
||||
|
||||
if (vecA->size != vecB->size){
|
||||
if (comparison_type == Py_NE){
|
||||
if (vecA->size != vecB->size) {
|
||||
if (comparison_type == Py_NE) {
|
||||
Py_RETURN_TRUE;
|
||||
}
|
||||
else {
|
||||
@@ -1426,18 +1426,18 @@ static PyObject* Vector_richcmpr(PyObject *objectA, PyObject *objectB, int compa
|
||||
}
|
||||
}
|
||||
|
||||
switch (comparison_type){
|
||||
switch (comparison_type) {
|
||||
case Py_LT:
|
||||
lenA = vec_magnitude_nosqrt(vecA->vec, vecA->size);
|
||||
lenB = vec_magnitude_nosqrt(vecB->vec, vecB->size);
|
||||
if(lenA < lenB){
|
||||
if(lenA < lenB) {
|
||||
result = 1;
|
||||
}
|
||||
break;
|
||||
case Py_LE:
|
||||
lenA = vec_magnitude_nosqrt(vecA->vec, vecA->size);
|
||||
lenB = vec_magnitude_nosqrt(vecB->vec, vecB->size);
|
||||
if(lenA < lenB){
|
||||
if(lenA < lenB) {
|
||||
result = 1;
|
||||
}
|
||||
else {
|
||||
@@ -1453,14 +1453,14 @@ static PyObject* Vector_richcmpr(PyObject *objectA, PyObject *objectB, int compa
|
||||
case Py_GT:
|
||||
lenA = vec_magnitude_nosqrt(vecA->vec, vecA->size);
|
||||
lenB = vec_magnitude_nosqrt(vecB->vec, vecB->size);
|
||||
if(lenA > lenB){
|
||||
if(lenA > lenB) {
|
||||
result = 1;
|
||||
}
|
||||
break;
|
||||
case Py_GE:
|
||||
lenA = vec_magnitude_nosqrt(vecA->vec, vecA->size);
|
||||
lenB = vec_magnitude_nosqrt(vecB->vec, vecB->size);
|
||||
if(lenA > lenB){
|
||||
if(lenA > lenB) {
|
||||
result = 1;
|
||||
}
|
||||
else {
|
||||
@@ -1471,7 +1471,7 @@ static PyObject* Vector_richcmpr(PyObject *objectA, PyObject *objectB, int compa
|
||||
printf("The result of the comparison could not be evaluated");
|
||||
break;
|
||||
}
|
||||
if (result == 1){
|
||||
if (result == 1) {
|
||||
Py_RETURN_TRUE;
|
||||
}
|
||||
else {
|
||||
@@ -1631,7 +1631,7 @@ static PyObject *Vector_getLength(VectorObject *self, void *UNUSED(closure))
|
||||
if(BaseMath_ReadCallback(self) == -1)
|
||||
return NULL;
|
||||
|
||||
for(i = 0; i < self->size; i++){
|
||||
for (i = 0; i < self->size; i++) {
|
||||
dot += (double)(self->vec[i] * self->vec[i]);
|
||||
}
|
||||
return PyFloat_FromDouble(sqrt(dot));
|
||||
@@ -1661,7 +1661,7 @@ static int Vector_setLength(VectorObject *self, PyObject *value)
|
||||
return 0;
|
||||
}
|
||||
|
||||
for(i = 0; i < self->size; i++){
|
||||
for (i = 0; i < self->size; i++) {
|
||||
dot += (double)(self->vec[i] * self->vec[i]);
|
||||
}
|
||||
|
||||
@@ -1675,7 +1675,7 @@ static int Vector_setLength(VectorObject *self, PyObject *value)
|
||||
|
||||
dot= dot/param;
|
||||
|
||||
for(i = 0; i < self->size; i++){
|
||||
for (i = 0; i < self->size; i++) {
|
||||
self->vec[i]= self->vec[i] / (float)dot;
|
||||
}
|
||||
|
||||
@@ -1693,7 +1693,7 @@ static PyObject *Vector_getLengthSquared(VectorObject *self, void *UNUSED(closur
|
||||
if(BaseMath_ReadCallback(self) == -1)
|
||||
return NULL;
|
||||
|
||||
for(i = 0; i < self->size; i++){
|
||||
for (i = 0; i < self->size; i++) {
|
||||
dot += (double)(self->vec[i] * self->vec[i]);
|
||||
}
|
||||
return PyFloat_FromDouble(dot);
|
||||
@@ -1778,7 +1778,7 @@ static int Vector_setSwizzle(VectorObject *self, PyObject *value, void *closure)
|
||||
|
||||
if (((scalarVal=PyFloat_AsDouble(value)) == -1 && PyErr_Occurred())==0) {
|
||||
int i;
|
||||
for(i=0; i < MAX_DIMENSIONS; i++)
|
||||
for (i=0; i < MAX_DIMENSIONS; i++)
|
||||
vec_assign[i]= scalarVal;
|
||||
|
||||
size_from= axis_from;
|
||||
@@ -2219,8 +2219,8 @@ static int row_vector_multiplication(float rvec[MAX_DIMENSIONS], VectorObject *v
|
||||
double dot = 0.0f;
|
||||
int x, y, z= 0, vec_size= vec->size;
|
||||
|
||||
if(mat->col_size != vec_size){
|
||||
if(mat->col_size == 4 && vec_size != 3){
|
||||
if(mat->col_size != vec_size) {
|
||||
if(mat->col_size == 4 && vec_size != 3) {
|
||||
PyErr_SetString(PyExc_ValueError,
|
||||
"vector * matrix: matrix column size "
|
||||
"and the vector size must be the same");
|
||||
@@ -2235,11 +2235,11 @@ static int row_vector_multiplication(float rvec[MAX_DIMENSIONS], VectorObject *v
|
||||
return -1;
|
||||
|
||||
memcpy(vec_cpy, vec->vec, vec_size * sizeof(float));
|
||||
printf("asasas\n");
|
||||
|
||||
rvec[3] = 1.0f;
|
||||
//muliplication
|
||||
for(x = 0; x < mat->row_size; x++) {
|
||||
for(y = 0; y < mat->col_size; y++) {
|
||||
for (x = 0; x < mat->row_size; x++) {
|
||||
for (y = 0; y < mat->col_size; y++) {
|
||||
dot += mat->matrix[x][y] * vec_cpy[y];
|
||||
}
|
||||
rvec[z++] = (float)dot;
|
||||
|
||||
@@ -86,16 +86,16 @@ static PyObject *M_Geometry_intersect_ray_tri(PyObject *UNUSED(self), PyObject*
|
||||
float det, inv_det, u, v, t;
|
||||
int clip= 1;
|
||||
|
||||
if(!PyArg_ParseTuple(args, "O!O!O!O!O!|i:intersect_ray_tri", &vector_Type, &vec1, &vector_Type, &vec2, &vector_Type, &vec3, &vector_Type, &ray, &vector_Type, &ray_off , &clip)) {
|
||||
if (!PyArg_ParseTuple(args, "O!O!O!O!O!|i:intersect_ray_tri", &vector_Type, &vec1, &vector_Type, &vec2, &vector_Type, &vec3, &vector_Type, &ray, &vector_Type, &ray_off , &clip)) {
|
||||
return NULL;
|
||||
}
|
||||
if(vec1->size != 3 || vec2->size != 3 || vec3->size != 3 || ray->size != 3 || ray_off->size != 3) {
|
||||
if (vec1->size != 3 || vec2->size != 3 || vec3->size != 3 || ray->size != 3 || ray_off->size != 3) {
|
||||
PyErr_SetString(PyExc_ValueError,
|
||||
"only 3D vectors for all parameters");
|
||||
return NULL;
|
||||
}
|
||||
|
||||
if(BaseMath_ReadCallback(vec1) == -1 || BaseMath_ReadCallback(vec2) == -1 || BaseMath_ReadCallback(vec3) == -1 || BaseMath_ReadCallback(ray) == -1 || BaseMath_ReadCallback(ray_off) == -1)
|
||||
if (BaseMath_ReadCallback(vec1) == -1 || BaseMath_ReadCallback(vec2) == -1 || BaseMath_ReadCallback(vec3) == -1 || BaseMath_ReadCallback(ray) == -1 || BaseMath_ReadCallback(ray_off) == -1)
|
||||
return NULL;
|
||||
|
||||
VECCOPY(v1, vec1->vec);
|
||||
@@ -174,19 +174,19 @@ static PyObject *M_Geometry_intersect_line_line(PyObject *UNUSED(self), PyObject
|
||||
VectorObject *vec1, *vec2, *vec3, *vec4;
|
||||
float v1[3], v2[3], v3[3], v4[3], i1[3], i2[3];
|
||||
|
||||
if(!PyArg_ParseTuple(args, "O!O!O!O!:intersect_line_line", &vector_Type, &vec1, &vector_Type, &vec2, &vector_Type, &vec3, &vector_Type, &vec4)) {
|
||||
if (!PyArg_ParseTuple(args, "O!O!O!O!:intersect_line_line", &vector_Type, &vec1, &vector_Type, &vec2, &vector_Type, &vec3, &vector_Type, &vec4)) {
|
||||
return NULL;
|
||||
}
|
||||
if(vec1->size != vec2->size || vec1->size != vec3->size || vec3->size != vec2->size) {
|
||||
if (vec1->size != vec2->size || vec1->size != vec3->size || vec3->size != vec2->size) {
|
||||
PyErr_SetString(PyExc_ValueError,
|
||||
"vectors must be of the same size");
|
||||
return NULL;
|
||||
}
|
||||
|
||||
if(BaseMath_ReadCallback(vec1) == -1 || BaseMath_ReadCallback(vec2) == -1 || BaseMath_ReadCallback(vec3) == -1 || BaseMath_ReadCallback(vec4) == -1)
|
||||
if (BaseMath_ReadCallback(vec1) == -1 || BaseMath_ReadCallback(vec2) == -1 || BaseMath_ReadCallback(vec3) == -1 || BaseMath_ReadCallback(vec4) == -1)
|
||||
return NULL;
|
||||
|
||||
if(vec1->size == 3 || vec1->size == 2) {
|
||||
if (vec1->size == 3 || vec1->size == 2) {
|
||||
int result;
|
||||
|
||||
if (vec1->size == 3) {
|
||||
@@ -257,42 +257,42 @@ static PyObject *M_Geometry_normal(PyObject *UNUSED(self), PyObject* args)
|
||||
VectorObject *vec1, *vec2, *vec3, *vec4;
|
||||
float n[3];
|
||||
|
||||
if(PyTuple_GET_SIZE(args) == 3) {
|
||||
if(!PyArg_ParseTuple(args, "O!O!O!:normal", &vector_Type, &vec1, &vector_Type, &vec2, &vector_Type, &vec3)) {
|
||||
if (PyTuple_GET_SIZE(args) == 3) {
|
||||
if (!PyArg_ParseTuple(args, "O!O!O!:normal", &vector_Type, &vec1, &vector_Type, &vec2, &vector_Type, &vec3)) {
|
||||
return NULL;
|
||||
}
|
||||
if(vec1->size != vec2->size || vec1->size != vec3->size) {
|
||||
if (vec1->size != vec2->size || vec1->size != vec3->size) {
|
||||
PyErr_SetString(PyExc_ValueError,
|
||||
"vectors must be of the same size");
|
||||
return NULL;
|
||||
}
|
||||
if(vec1->size < 3) {
|
||||
if (vec1->size < 3) {
|
||||
PyErr_SetString(PyExc_ValueError,
|
||||
"2D vectors unsupported");
|
||||
return NULL;
|
||||
}
|
||||
|
||||
if(BaseMath_ReadCallback(vec1) == -1 || BaseMath_ReadCallback(vec2) == -1 || BaseMath_ReadCallback(vec3) == -1)
|
||||
if (BaseMath_ReadCallback(vec1) == -1 || BaseMath_ReadCallback(vec2) == -1 || BaseMath_ReadCallback(vec3) == -1)
|
||||
return NULL;
|
||||
|
||||
normal_tri_v3(n, vec1->vec, vec2->vec, vec3->vec);
|
||||
}
|
||||
else {
|
||||
if(!PyArg_ParseTuple(args, "O!O!O!O!:normal", &vector_Type, &vec1, &vector_Type, &vec2, &vector_Type, &vec3, &vector_Type, &vec4)) {
|
||||
if (!PyArg_ParseTuple(args, "O!O!O!O!:normal", &vector_Type, &vec1, &vector_Type, &vec2, &vector_Type, &vec3, &vector_Type, &vec4)) {
|
||||
return NULL;
|
||||
}
|
||||
if(vec1->size != vec2->size || vec1->size != vec3->size || vec1->size != vec4->size) {
|
||||
if (vec1->size != vec2->size || vec1->size != vec3->size || vec1->size != vec4->size) {
|
||||
PyErr_SetString(PyExc_ValueError,
|
||||
"vectors must be of the same size");
|
||||
return NULL;
|
||||
}
|
||||
if(vec1->size < 3) {
|
||||
if (vec1->size < 3) {
|
||||
PyErr_SetString(PyExc_ValueError,
|
||||
"2D vectors unsupported");
|
||||
return NULL;
|
||||
}
|
||||
|
||||
if(BaseMath_ReadCallback(vec1) == -1 || BaseMath_ReadCallback(vec2) == -1 || BaseMath_ReadCallback(vec3) == -1 || BaseMath_ReadCallback(vec4) == -1)
|
||||
if (BaseMath_ReadCallback(vec1) == -1 || BaseMath_ReadCallback(vec2) == -1 || BaseMath_ReadCallback(vec3) == -1 || BaseMath_ReadCallback(vec4) == -1)
|
||||
return NULL;
|
||||
|
||||
normal_quad_v3(n, vec1->vec, vec2->vec, vec3->vec, vec4->vec);
|
||||
@@ -320,17 +320,17 @@ static PyObject *M_Geometry_area_tri(PyObject *UNUSED(self), PyObject* args)
|
||||
{
|
||||
VectorObject *vec1, *vec2, *vec3;
|
||||
|
||||
if(!PyArg_ParseTuple(args, "O!O!O!:area_tri", &vector_Type, &vec1, &vector_Type, &vec2, &vector_Type, &vec3)) {
|
||||
if (!PyArg_ParseTuple(args, "O!O!O!:area_tri", &vector_Type, &vec1, &vector_Type, &vec2, &vector_Type, &vec3)) {
|
||||
return NULL;
|
||||
}
|
||||
|
||||
if(vec1->size != vec2->size || vec1->size != vec3->size) {
|
||||
if (vec1->size != vec2->size || vec1->size != vec3->size) {
|
||||
PyErr_SetString(PyExc_ValueError,
|
||||
"vectors must be of the same size");
|
||||
return NULL;
|
||||
}
|
||||
|
||||
if(BaseMath_ReadCallback(vec1) == -1 || BaseMath_ReadCallback(vec2) == -1 || BaseMath_ReadCallback(vec3) == -1)
|
||||
if (BaseMath_ReadCallback(vec1) == -1 || BaseMath_ReadCallback(vec2) == -1 || BaseMath_ReadCallback(vec3) == -1)
|
||||
return NULL;
|
||||
|
||||
if (vec1->size == 3) {
|
||||
@@ -367,7 +367,7 @@ static PyObject *M_Geometry_intersect_line_line_2d(PyObject *UNUSED(self), PyObj
|
||||
{
|
||||
VectorObject *line_a1, *line_a2, *line_b1, *line_b2;
|
||||
float vi[2];
|
||||
if(!PyArg_ParseTuple(args, "O!O!O!O!:intersect_line_line_2d",
|
||||
if (!PyArg_ParseTuple(args, "O!O!O!O!:intersect_line_line_2d",
|
||||
&vector_Type, &line_a1,
|
||||
&vector_Type, &line_a2,
|
||||
&vector_Type, &line_b1,
|
||||
@@ -376,10 +376,10 @@ static PyObject *M_Geometry_intersect_line_line_2d(PyObject *UNUSED(self), PyObj
|
||||
return NULL;
|
||||
}
|
||||
|
||||
if(BaseMath_ReadCallback(line_a1) == -1 || BaseMath_ReadCallback(line_a2) == -1 || BaseMath_ReadCallback(line_b1) == -1 || BaseMath_ReadCallback(line_b2) == -1)
|
||||
if (BaseMath_ReadCallback(line_a1) == -1 || BaseMath_ReadCallback(line_a2) == -1 || BaseMath_ReadCallback(line_b1) == -1 || BaseMath_ReadCallback(line_b2) == -1)
|
||||
return NULL;
|
||||
|
||||
if(isect_seg_seg_v2_point(line_a1->vec, line_a2->vec, line_b1->vec, line_b2->vec, vi) == 1) {
|
||||
if (isect_seg_seg_v2_point(line_a1->vec, line_a2->vec, line_b1->vec, line_b2->vec, vi) == 1) {
|
||||
return newVectorObject(vi, 2, Py_NEW, NULL);
|
||||
}
|
||||
else {
|
||||
@@ -411,7 +411,7 @@ static PyObject *M_Geometry_intersect_line_plane(PyObject *UNUSED(self), PyObjec
|
||||
VectorObject *line_a, *line_b, *plane_co, *plane_no;
|
||||
int no_flip= 0;
|
||||
float isect[3];
|
||||
if(!PyArg_ParseTuple(args, "O!O!O!O!|i:intersect_line_plane",
|
||||
if (!PyArg_ParseTuple(args, "O!O!O!O!|i:intersect_line_plane",
|
||||
&vector_Type, &line_a,
|
||||
&vector_Type, &line_b,
|
||||
&vector_Type, &plane_co,
|
||||
@@ -421,7 +421,7 @@ static PyObject *M_Geometry_intersect_line_plane(PyObject *UNUSED(self), PyObjec
|
||||
return NULL;
|
||||
}
|
||||
|
||||
if( BaseMath_ReadCallback(line_a) == -1 ||
|
||||
if ( BaseMath_ReadCallback(line_a) == -1 ||
|
||||
BaseMath_ReadCallback(line_b) == -1 ||
|
||||
BaseMath_ReadCallback(plane_co) == -1 ||
|
||||
BaseMath_ReadCallback(plane_no) == -1
|
||||
@@ -429,14 +429,14 @@ static PyObject *M_Geometry_intersect_line_plane(PyObject *UNUSED(self), PyObjec
|
||||
return NULL;
|
||||
}
|
||||
|
||||
if(ELEM4(2, line_a->size, line_b->size, plane_co->size, plane_no->size)) {
|
||||
if (ELEM4(2, line_a->size, line_b->size, plane_co->size, plane_no->size)) {
|
||||
PyErr_SetString(PyExc_ValueError,
|
||||
"geometry.intersect_line_plane(...): "
|
||||
" can't use 2D Vectors");
|
||||
return NULL;
|
||||
}
|
||||
|
||||
if(isect_line_plane_v3(isect, line_a->vec, line_b->vec, plane_co->vec, plane_no->vec, no_flip) == 1) {
|
||||
if (isect_line_plane_v3(isect, line_a->vec, line_b->vec, plane_co->vec, plane_no->vec, no_flip) == 1) {
|
||||
return newVectorObject(isect, 3, Py_NEW, NULL);
|
||||
}
|
||||
else {
|
||||
@@ -471,7 +471,7 @@ static PyObject *M_Geometry_intersect_line_sphere(PyObject *UNUSED(self), PyObje
|
||||
float isect_a[3];
|
||||
float isect_b[3];
|
||||
|
||||
if(!PyArg_ParseTuple(args, "O!O!O!f|i:intersect_line_sphere",
|
||||
if (!PyArg_ParseTuple(args, "O!O!O!f|i:intersect_line_sphere",
|
||||
&vector_Type, &line_a,
|
||||
&vector_Type, &line_b,
|
||||
&vector_Type, &sphere_co,
|
||||
@@ -480,14 +480,14 @@ static PyObject *M_Geometry_intersect_line_sphere(PyObject *UNUSED(self), PyObje
|
||||
return NULL;
|
||||
}
|
||||
|
||||
if( BaseMath_ReadCallback(line_a) == -1 ||
|
||||
if ( BaseMath_ReadCallback(line_a) == -1 ||
|
||||
BaseMath_ReadCallback(line_b) == -1 ||
|
||||
BaseMath_ReadCallback(sphere_co) == -1
|
||||
) {
|
||||
return NULL;
|
||||
}
|
||||
|
||||
if(ELEM3(2, line_a->size, line_b->size, sphere_co->size)) {
|
||||
if (ELEM3(2, line_a->size, line_b->size, sphere_co->size)) {
|
||||
PyErr_SetString(PyExc_ValueError,
|
||||
"geometry.intersect_line_sphere(...): "
|
||||
" can't use 2D Vectors");
|
||||
@@ -502,22 +502,22 @@ static PyObject *M_Geometry_intersect_line_sphere(PyObject *UNUSED(self), PyObje
|
||||
|
||||
switch(isect_line_sphere_v3(line_a->vec, line_b->vec, sphere_co->vec, sphere_radius, isect_a, isect_b)) {
|
||||
case 1:
|
||||
if(!(!clip || (((lambda= line_point_factor_v3(isect_a, line_a->vec, line_b->vec)) >= 0.0f) && (lambda <= 1.0f)))) use_a= FALSE;
|
||||
if (!(!clip || (((lambda= line_point_factor_v3(isect_a, line_a->vec, line_b->vec)) >= 0.0f) && (lambda <= 1.0f)))) use_a= FALSE;
|
||||
use_b= FALSE;
|
||||
break;
|
||||
case 2:
|
||||
if(!(!clip || (((lambda= line_point_factor_v3(isect_a, line_a->vec, line_b->vec)) >= 0.0f) && (lambda <= 1.0f)))) use_a= FALSE;
|
||||
if(!(!clip || (((lambda= line_point_factor_v3(isect_b, line_a->vec, line_b->vec)) >= 0.0f) && (lambda <= 1.0f)))) use_b= FALSE;
|
||||
if (!(!clip || (((lambda= line_point_factor_v3(isect_a, line_a->vec, line_b->vec)) >= 0.0f) && (lambda <= 1.0f)))) use_a= FALSE;
|
||||
if (!(!clip || (((lambda= line_point_factor_v3(isect_b, line_a->vec, line_b->vec)) >= 0.0f) && (lambda <= 1.0f)))) use_b= FALSE;
|
||||
break;
|
||||
default:
|
||||
use_a= FALSE;
|
||||
use_b= FALSE;
|
||||
}
|
||||
|
||||
if(use_a) { PyTuple_SET_ITEM(ret, 0, newVectorObject(isect_a, 3, Py_NEW, NULL)); }
|
||||
if (use_a) { PyTuple_SET_ITEM(ret, 0, newVectorObject(isect_a, 3, Py_NEW, NULL)); }
|
||||
else { PyTuple_SET_ITEM(ret, 0, Py_None); Py_INCREF(Py_None); }
|
||||
|
||||
if(use_b) { PyTuple_SET_ITEM(ret, 1, newVectorObject(isect_b, 3, Py_NEW, NULL)); }
|
||||
if (use_b) { PyTuple_SET_ITEM(ret, 1, newVectorObject(isect_b, 3, Py_NEW, NULL)); }
|
||||
else { PyTuple_SET_ITEM(ret, 1, Py_None); Py_INCREF(Py_None); }
|
||||
|
||||
return ret;
|
||||
@@ -551,7 +551,7 @@ static PyObject *M_Geometry_intersect_line_sphere_2d(PyObject *UNUSED(self), PyO
|
||||
float isect_a[3];
|
||||
float isect_b[3];
|
||||
|
||||
if(!PyArg_ParseTuple(args, "O!O!O!f|i:intersect_line_sphere_2d",
|
||||
if (!PyArg_ParseTuple(args, "O!O!O!f|i:intersect_line_sphere_2d",
|
||||
&vector_Type, &line_a,
|
||||
&vector_Type, &line_b,
|
||||
&vector_Type, &sphere_co,
|
||||
@@ -560,7 +560,7 @@ static PyObject *M_Geometry_intersect_line_sphere_2d(PyObject *UNUSED(self), PyO
|
||||
return NULL;
|
||||
}
|
||||
|
||||
if( BaseMath_ReadCallback(line_a) == -1 ||
|
||||
if ( BaseMath_ReadCallback(line_a) == -1 ||
|
||||
BaseMath_ReadCallback(line_b) == -1 ||
|
||||
BaseMath_ReadCallback(sphere_co) == -1
|
||||
) {
|
||||
@@ -575,22 +575,22 @@ static PyObject *M_Geometry_intersect_line_sphere_2d(PyObject *UNUSED(self), PyO
|
||||
|
||||
switch(isect_line_sphere_v2(line_a->vec, line_b->vec, sphere_co->vec, sphere_radius, isect_a, isect_b)) {
|
||||
case 1:
|
||||
if(!(!clip || (((lambda= line_point_factor_v2(isect_a, line_a->vec, line_b->vec)) >= 0.0f) && (lambda <= 1.0f)))) use_a= FALSE;
|
||||
if (!(!clip || (((lambda= line_point_factor_v2(isect_a, line_a->vec, line_b->vec)) >= 0.0f) && (lambda <= 1.0f)))) use_a= FALSE;
|
||||
use_b= FALSE;
|
||||
break;
|
||||
case 2:
|
||||
if(!(!clip || (((lambda= line_point_factor_v2(isect_a, line_a->vec, line_b->vec)) >= 0.0f) && (lambda <= 1.0f)))) use_a= FALSE;
|
||||
if(!(!clip || (((lambda= line_point_factor_v2(isect_b, line_a->vec, line_b->vec)) >= 0.0f) && (lambda <= 1.0f)))) use_b= FALSE;
|
||||
if (!(!clip || (((lambda= line_point_factor_v2(isect_a, line_a->vec, line_b->vec)) >= 0.0f) && (lambda <= 1.0f)))) use_a= FALSE;
|
||||
if (!(!clip || (((lambda= line_point_factor_v2(isect_b, line_a->vec, line_b->vec)) >= 0.0f) && (lambda <= 1.0f)))) use_b= FALSE;
|
||||
break;
|
||||
default:
|
||||
use_a= FALSE;
|
||||
use_b= FALSE;
|
||||
}
|
||||
|
||||
if(use_a) { PyTuple_SET_ITEM(ret, 0, newVectorObject(isect_a, 2, Py_NEW, NULL)); }
|
||||
if (use_a) { PyTuple_SET_ITEM(ret, 0, newVectorObject(isect_a, 2, Py_NEW, NULL)); }
|
||||
else { PyTuple_SET_ITEM(ret, 0, Py_None); Py_INCREF(Py_None); }
|
||||
|
||||
if(use_b) { PyTuple_SET_ITEM(ret, 1, newVectorObject(isect_b, 2, Py_NEW, NULL)); }
|
||||
if (use_b) { PyTuple_SET_ITEM(ret, 1, newVectorObject(isect_b, 2, Py_NEW, NULL)); }
|
||||
else { PyTuple_SET_ITEM(ret, 1, Py_None); Py_INCREF(Py_None); }
|
||||
|
||||
return ret;
|
||||
@@ -617,7 +617,7 @@ static PyObject *M_Geometry_intersect_point_line(PyObject *UNUSED(self), PyObjec
|
||||
float lambda;
|
||||
PyObject *ret;
|
||||
|
||||
if(!PyArg_ParseTuple(args, "O!O!O!:intersect_point_line",
|
||||
if (!PyArg_ParseTuple(args, "O!O!O!:intersect_point_line",
|
||||
&vector_Type, &pt,
|
||||
&vector_Type, &line_1,
|
||||
&vector_Type, &line_2)
|
||||
@@ -625,7 +625,7 @@ static PyObject *M_Geometry_intersect_point_line(PyObject *UNUSED(self), PyObjec
|
||||
return NULL;
|
||||
}
|
||||
|
||||
if(BaseMath_ReadCallback(pt) == -1 || BaseMath_ReadCallback(line_1) == -1 || BaseMath_ReadCallback(line_2) == -1)
|
||||
if (BaseMath_ReadCallback(pt) == -1 || BaseMath_ReadCallback(line_1) == -1 || BaseMath_ReadCallback(line_2) == -1)
|
||||
return NULL;
|
||||
|
||||
/* accept 2d verts */
|
||||
@@ -666,7 +666,7 @@ static PyObject *M_Geometry_intersect_point_tri_2d(PyObject *UNUSED(self), PyObj
|
||||
{
|
||||
VectorObject *pt_vec, *tri_p1, *tri_p2, *tri_p3;
|
||||
|
||||
if(!PyArg_ParseTuple(args, "O!O!O!O!:intersect_point_tri_2d",
|
||||
if (!PyArg_ParseTuple(args, "O!O!O!O!:intersect_point_tri_2d",
|
||||
&vector_Type, &pt_vec,
|
||||
&vector_Type, &tri_p1,
|
||||
&vector_Type, &tri_p2,
|
||||
@@ -675,7 +675,7 @@ static PyObject *M_Geometry_intersect_point_tri_2d(PyObject *UNUSED(self), PyObj
|
||||
return NULL;
|
||||
}
|
||||
|
||||
if(BaseMath_ReadCallback(pt_vec) == -1 || BaseMath_ReadCallback(tri_p1) == -1 || BaseMath_ReadCallback(tri_p2) == -1 || BaseMath_ReadCallback(tri_p3) == -1)
|
||||
if (BaseMath_ReadCallback(pt_vec) == -1 || BaseMath_ReadCallback(tri_p1) == -1 || BaseMath_ReadCallback(tri_p2) == -1 || BaseMath_ReadCallback(tri_p3) == -1)
|
||||
return NULL;
|
||||
|
||||
return PyLong_FromLong(isect_point_tri_v2(pt_vec->vec, tri_p1->vec, tri_p2->vec, tri_p3->vec));
|
||||
@@ -702,7 +702,7 @@ static PyObject *M_Geometry_intersect_point_quad_2d(PyObject *UNUSED(self), PyOb
|
||||
{
|
||||
VectorObject *pt_vec, *quad_p1, *quad_p2, *quad_p3, *quad_p4;
|
||||
|
||||
if(!PyArg_ParseTuple(args, "O!O!O!O!O!:intersect_point_quad_2d",
|
||||
if (!PyArg_ParseTuple(args, "O!O!O!O!O!:intersect_point_quad_2d",
|
||||
&vector_Type, &pt_vec,
|
||||
&vector_Type, &quad_p1,
|
||||
&vector_Type, &quad_p2,
|
||||
@@ -712,7 +712,7 @@ static PyObject *M_Geometry_intersect_point_quad_2d(PyObject *UNUSED(self), PyOb
|
||||
return NULL;
|
||||
}
|
||||
|
||||
if(BaseMath_ReadCallback(pt_vec) == -1 || BaseMath_ReadCallback(quad_p1) == -1 || BaseMath_ReadCallback(quad_p2) == -1 || BaseMath_ReadCallback(quad_p3) == -1 || BaseMath_ReadCallback(quad_p4) == -1)
|
||||
if (BaseMath_ReadCallback(pt_vec) == -1 || BaseMath_ReadCallback(quad_p1) == -1 || BaseMath_ReadCallback(quad_p2) == -1 || BaseMath_ReadCallback(quad_p3) == -1 || BaseMath_ReadCallback(quad_p4) == -1)
|
||||
return NULL;
|
||||
|
||||
return PyLong_FromLong(isect_point_quad_v2(pt_vec->vec, quad_p1->vec, quad_p2->vec, quad_p3->vec, quad_p4->vec));
|
||||
@@ -747,7 +747,7 @@ static PyObject *M_Geometry_barycentric_transform(PyObject *UNUSED(self), PyObje
|
||||
VectorObject *vec_t1_src, *vec_t2_src, *vec_t3_src;
|
||||
float vec[3];
|
||||
|
||||
if(!PyArg_ParseTuple(args, "O!O!O!O!O!O!O!:barycentric_transform",
|
||||
if (!PyArg_ParseTuple(args, "O!O!O!O!O!O!O!:barycentric_transform",
|
||||
&vector_Type, &vec_pt,
|
||||
&vector_Type, &vec_t1_src,
|
||||
&vector_Type, &vec_t2_src,
|
||||
@@ -759,7 +759,7 @@ static PyObject *M_Geometry_barycentric_transform(PyObject *UNUSED(self), PyObje
|
||||
return NULL;
|
||||
}
|
||||
|
||||
if( vec_pt->size != 3 ||
|
||||
if ( vec_pt->size != 3 ||
|
||||
vec_t1_src->size != 3 ||
|
||||
vec_t2_src->size != 3 ||
|
||||
vec_t3_src->size != 3 ||
|
||||
@@ -814,7 +814,7 @@ static PyObject *M_Geometry_interpolate_bezier(PyObject *UNUSED(self), PyObject*
|
||||
float h2[4]= {0.0, 0.0, 0.0, 0.0};
|
||||
|
||||
|
||||
if(!PyArg_ParseTuple(args, "O!O!O!O!i:interpolate_bezier",
|
||||
if (!PyArg_ParseTuple(args, "O!O!O!O!i:interpolate_bezier",
|
||||
&vector_Type, &vec_k1,
|
||||
&vector_Type, &vec_h1,
|
||||
&vector_Type, &vec_h2,
|
||||
@@ -823,30 +823,30 @@ static PyObject *M_Geometry_interpolate_bezier(PyObject *UNUSED(self), PyObject*
|
||||
return NULL;
|
||||
}
|
||||
|
||||
if(resolu <= 1) {
|
||||
if (resolu <= 1) {
|
||||
PyErr_SetString(PyExc_ValueError,
|
||||
"resolution must be 2 or over");
|
||||
return NULL;
|
||||
}
|
||||
|
||||
if(BaseMath_ReadCallback(vec_k1) == -1 || BaseMath_ReadCallback(vec_h1) == -1 || BaseMath_ReadCallback(vec_k2) == -1 || BaseMath_ReadCallback(vec_h2) == -1)
|
||||
if (BaseMath_ReadCallback(vec_k1) == -1 || BaseMath_ReadCallback(vec_h1) == -1 || BaseMath_ReadCallback(vec_k2) == -1 || BaseMath_ReadCallback(vec_h2) == -1)
|
||||
return NULL;
|
||||
|
||||
dims= MAX4(vec_k1->size, vec_h1->size, vec_h2->size, vec_k2->size);
|
||||
|
||||
for(i=0; i < vec_k1->size; i++) k1[i]= vec_k1->vec[i];
|
||||
for(i=0; i < vec_h1->size; i++) h1[i]= vec_h1->vec[i];
|
||||
for(i=0; i < vec_k2->size; i++) k2[i]= vec_k2->vec[i];
|
||||
for(i=0; i < vec_h2->size; i++) h2[i]= vec_h2->vec[i];
|
||||
for (i=0; i < vec_k1->size; i++) k1[i]= vec_k1->vec[i];
|
||||
for (i=0; i < vec_h1->size; i++) h1[i]= vec_h1->vec[i];
|
||||
for (i=0; i < vec_k2->size; i++) k2[i]= vec_k2->vec[i];
|
||||
for (i=0; i < vec_h2->size; i++) h2[i]= vec_h2->vec[i];
|
||||
|
||||
coord_array= MEM_callocN(dims * (resolu) * sizeof(float), "interpolate_bezier");
|
||||
for(i=0; i<dims; i++) {
|
||||
for (i=0; i<dims; i++) {
|
||||
forward_diff_bezier(k1[i], h1[i], h2[i], k2[i], coord_array+i, resolu-1, sizeof(float)*dims);
|
||||
}
|
||||
|
||||
list= PyList_New(resolu);
|
||||
fp= coord_array;
|
||||
for(i=0; i<resolu; i++, fp= fp+dims) {
|
||||
for (i=0; i<resolu; i++, fp= fp+dims) {
|
||||
PyList_SET_ITEM(list, i, newVectorObject(fp, dims, Py_NEW, NULL));
|
||||
}
|
||||
MEM_freeN(coord_array);
|
||||
@@ -875,7 +875,7 @@ static PyObject *M_Geometry_tesselate_polygon(PyObject *UNUSED(self), PyObject *
|
||||
float *fp; /*pointer to the array of malloced dl->verts to set the points from the vectors */
|
||||
int index, *dl_face, totpoints=0;
|
||||
|
||||
if(!PySequence_Check(polyLineSeq)) {
|
||||
if (!PySequence_Check(polyLineSeq)) {
|
||||
PyErr_SetString(PyExc_TypeError,
|
||||
"expected a sequence of poly lines");
|
||||
return NULL;
|
||||
@@ -883,7 +883,7 @@ static PyObject *M_Geometry_tesselate_polygon(PyObject *UNUSED(self), PyObject *
|
||||
|
||||
len_polylines= PySequence_Size(polyLineSeq);
|
||||
|
||||
for(i= 0; i < len_polylines; ++i) {
|
||||
for (i= 0; i < len_polylines; ++i) {
|
||||
polyLine= PySequence_GetItem(polyLineSeq, i);
|
||||
if (!PySequence_Check(polyLine)) {
|
||||
freedisplist(&dispbase);
|
||||
@@ -914,16 +914,16 @@ static PyObject *M_Geometry_tesselate_polygon(PyObject *UNUSED(self), PyObject *
|
||||
dl->verts= fp= MEM_callocN(sizeof(float)*3*len_polypoints, "dl verts");
|
||||
dl->index= MEM_callocN(sizeof(int)*3*len_polypoints, "dl index");
|
||||
|
||||
for(index= 0; index<len_polypoints; ++index, fp+=3) {
|
||||
for (index= 0; index<len_polypoints; ++index, fp+=3) {
|
||||
polyVec= PySequence_GetItem(polyLine, index);
|
||||
if(VectorObject_Check(polyVec)) {
|
||||
if (VectorObject_Check(polyVec)) {
|
||||
|
||||
if(BaseMath_ReadCallback((VectorObject *)polyVec) == -1)
|
||||
if (BaseMath_ReadCallback((VectorObject *)polyVec) == -1)
|
||||
ls_error= 1;
|
||||
|
||||
fp[0]= ((VectorObject *)polyVec)->vec[0];
|
||||
fp[1]= ((VectorObject *)polyVec)->vec[1];
|
||||
if(((VectorObject *)polyVec)->size > 2)
|
||||
if (((VectorObject *)polyVec)->size > 2)
|
||||
fp[2]= ((VectorObject *)polyVec)->vec[2];
|
||||
else
|
||||
fp[2]= 0.0f; /* if its a 2d vector then set the z to be zero */
|
||||
@@ -939,7 +939,7 @@ static PyObject *M_Geometry_tesselate_polygon(PyObject *UNUSED(self), PyObject *
|
||||
Py_DECREF(polyLine);
|
||||
}
|
||||
|
||||
if(ls_error) {
|
||||
if (ls_error) {
|
||||
freedisplist(&dispbase); /* possible some dl was allocated */
|
||||
PyErr_SetString(PyExc_TypeError,
|
||||
"A point in one of the polylines "
|
||||
@@ -955,7 +955,7 @@ static PyObject *M_Geometry_tesselate_polygon(PyObject *UNUSED(self), PyObject *
|
||||
dl= dispbase.first;
|
||||
|
||||
tri_list= PyList_New(dl->parts);
|
||||
if(!tri_list) {
|
||||
if (!tri_list) {
|
||||
freedisplist(&dispbase);
|
||||
PyErr_SetString(PyExc_RuntimeError,
|
||||
"failed to make a new list");
|
||||
@@ -964,7 +964,7 @@ static PyObject *M_Geometry_tesselate_polygon(PyObject *UNUSED(self), PyObject *
|
||||
|
||||
index= 0;
|
||||
dl_face= dl->index;
|
||||
while(index < dl->parts) {
|
||||
while (index < dl->parts) {
|
||||
PyList_SET_ITEM(tri_list, index, Py_BuildValue("iii", dl_face[0], dl_face[1], dl_face[2]));
|
||||
dl_face+= 3;
|
||||
index++;
|
||||
@@ -989,7 +989,7 @@ static int boxPack_FromPyObject(PyObject *value, boxPack **boxarray)
|
||||
|
||||
|
||||
/* Error checking must already be done */
|
||||
if(!PyList_Check(value)) {
|
||||
if (!PyList_Check(value)) {
|
||||
PyErr_SetString(PyExc_TypeError,
|
||||
"can only back a list of [x, y, w, h]");
|
||||
return -1;
|
||||
@@ -1000,9 +1000,9 @@ static int boxPack_FromPyObject(PyObject *value, boxPack **boxarray)
|
||||
(*boxarray)= MEM_mallocN(len*sizeof(boxPack), "boxPack box");
|
||||
|
||||
|
||||
for(i= 0; i < len; i++) {
|
||||
for (i= 0; i < len; i++) {
|
||||
list_item= PyList_GET_ITEM(value, i);
|
||||
if(!PyList_Check(list_item) || PyList_GET_SIZE(list_item) < 4) {
|
||||
if (!PyList_Check(list_item) || PyList_GET_SIZE(list_item) < 4) {
|
||||
MEM_freeN(*boxarray);
|
||||
PyErr_SetString(PyExc_TypeError,
|
||||
"can only pack a list of [x, y, w, h]");
|
||||
@@ -1040,7 +1040,7 @@ static void boxPack_ToPyObject(PyObject *value, boxPack **boxarray)
|
||||
|
||||
len= PyList_GET_SIZE(value);
|
||||
|
||||
for(i= 0; i < len; i++) {
|
||||
for (i= 0; i < len; i++) {
|
||||
box= (*boxarray)+i;
|
||||
list_item= PyList_GET_ITEM(value, box->index);
|
||||
PyList_SET_ITEM(list_item, 0, PyFloat_FromDouble(box->x));
|
||||
@@ -1066,7 +1066,7 @@ static PyObject *M_Geometry_box_pack_2d(PyObject *UNUSED(self), PyObject *boxlis
|
||||
|
||||
PyObject *ret;
|
||||
|
||||
if(!PyList_Check(boxlist)) {
|
||||
if (!PyList_Check(boxlist)) {
|
||||
PyErr_SetString(PyExc_TypeError,
|
||||
"expected a list of boxes [[x, y, w, h], ... ]");
|
||||
return NULL;
|
||||
@@ -1075,7 +1075,7 @@ static PyObject *M_Geometry_box_pack_2d(PyObject *UNUSED(self), PyObject *boxlis
|
||||
len= PyList_GET_SIZE(boxlist);
|
||||
if (len) {
|
||||
boxPack *boxarray= NULL;
|
||||
if(boxPack_FromPyObject(boxlist, &boxarray) == -1) {
|
||||
if (boxPack_FromPyObject(boxlist, &boxarray) == -1) {
|
||||
return NULL; /* exception set */
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user