[Bf-blender-cvs] SVN commit: /data/svn/bf-blender [19842] trunk/blender/source/blender/ python/api2_2x: needed to remove gen_utils functions from Mathutils.c
Campbell Barton
ideasman42 at gmail.com
Tue Apr 21 14:42:37 CEST 2009
Revision: 19842
http://projects.blender.org/plugins/scmsvn/viewcvs.php?view=rev&root=bf-blender&revision=19842
Author: campbellbarton
Date: 2009-04-21 14:42:37 +0200 (Tue, 21 Apr 2009)
Log Message:
-----------
needed to remove gen_utils functions from Mathutils.c
Modified Paths:
--------------
trunk/blender/source/blender/python/api2_2x/Mathutils.c
trunk/blender/source/blender/python/api2_2x/Mathutils.h
trunk/blender/source/blender/python/api2_2x/vector.c
Modified: trunk/blender/source/blender/python/api2_2x/Mathutils.c
===================================================================
--- trunk/blender/source/blender/python/api2_2x/Mathutils.c 2009-04-21 11:01:09 UTC (rev 19841)
+++ trunk/blender/source/blender/python/api2_2x/Mathutils.c 2009-04-21 12:42:37 UTC (rev 19842)
@@ -162,8 +162,8 @@
if(mat->rowSize != vec->size){
if(mat->rowSize == 4 && vec->size != 3){
- return EXPP_ReturnPyObjError(PyExc_AttributeError,
- "matrix * vector: matrix row size and vector size must be the same");
+ PyErr_SetString(PyExc_AttributeError, "matrix * vector: matrix row size and vector size must be the same");
+ return NULL;
}else{
vecCopy[3] = 1.0f;
}
@@ -197,8 +197,8 @@
if(mat->colSize != vec_size){
if(mat->rowSize == 4 && vec_size != 3){
- return EXPP_ReturnPyObjError(PyExc_AttributeError,
- "vector * matrix: matrix column size and the vector size must be the same");
+ PyErr_SetString(PyExc_AttributeError, "vector * matrix: matrix column size and the vector size must be the same");
+ return NULL;
}else{
vecCopy[3] = 1.0f;
}
@@ -267,8 +267,9 @@
}
}
- return (EXPP_ReturnPyObjError(PyExc_RuntimeError,
- "quat_rotation(internal): internal problem rotating vector/point\n"));
+ PyErr_SetString(PyExc_RuntimeError, "quat_rotation(internal): internal problem rotating vector/point\n");
+ return NULL;
+
}
//----------------------------------Mathutils.Rand() --------------------
@@ -281,14 +282,15 @@
high = 1.0;
low = 0.0;
- if(!PyArg_ParseTuple(args, "|ff", &low, &high))
- return (EXPP_ReturnPyObjError(PyExc_TypeError,
- "Mathutils.Rand(): expected nothing or optional (float, float)\n"));
+ if(!PyArg_ParseTuple(args, "|ff", &low, &high)) {
+ PyErr_SetString(PyExc_TypeError, "Mathutils.Rand(): expected nothing or optional (float, float)\n");
+ return NULL;
+ }
- if((high < low) || (high < 0 && low > 0))
- return (EXPP_ReturnPyObjError(PyExc_ValueError,
- "Mathutils.Rand(): high value should be larger than low value\n"));
-
+ if((high < low) || (high < 0 && low > 0)) {
+ PyErr_SetString(PyExc_ValueError, "Mathutils.Rand(): high value should be larger than low value\n");
+ return NULL;
+ }
//get the random number 0 - 1
drand = BLI_drand();
@@ -317,40 +319,42 @@
size = PySequence_Length(listObject);
} else { // Single argument was not a sequence
Py_XDECREF(listObject);
- return EXPP_ReturnPyObjError(PyExc_TypeError,
- "Mathutils.Vector(): 2-4 floats or ints expected (optionally in a sequence)\n");
+ PyErr_SetString(PyExc_TypeError, "Mathutils.Vector(): 2-4 floats or ints expected (optionally in a sequence)\n");
+ return NULL;
}
} else if (size == 0) {
//returns a new empty 3d vector
return newVectorObject(NULL, 3, Py_NEW);
} else {
- listObject = EXPP_incr_ret(args);
+ Py_INCREF(args);
+ listObject = args;
}
if (size<2 || size>4) { // Invalid vector size
Py_XDECREF(listObject);
- return EXPP_ReturnPyObjError(PyExc_AttributeError,
- "Mathutils.Vector(): 2-4 floats or ints expected (optionally in a sequence)\n");
+ PyErr_SetString(PyExc_AttributeError, "Mathutils.Vector(): 2-4 floats or ints expected (optionally in a sequence)\n");
+ return NULL;
}
for (i=0; i<size; i++) {
v=PySequence_GetItem(listObject, i);
if (v==NULL) { // Failed to read sequence
Py_XDECREF(listObject);
- return EXPP_ReturnPyObjError(PyExc_RuntimeError,
- "Mathutils.Vector(): 2-4 floats or ints expected (optionally in a sequence)\n");
+ PyErr_SetString(PyExc_RuntimeError, "Mathutils.Vector(): 2-4 floats or ints expected (optionally in a sequence)\n");
+ return NULL;
}
f=PyNumber_Float(v);
if(f==NULL) { // parsed item not a number
Py_DECREF(v);
Py_XDECREF(listObject);
- return EXPP_ReturnPyObjError(PyExc_TypeError,
- "Mathutils.Vector(): 2-4 floats or ints expected (optionally in a sequence)\n");
+ PyErr_SetString(PyExc_TypeError, "Mathutils.Vector(): 2-4 floats or ints expected (optionally in a sequence)\n");
+ return NULL;
}
vec[i]=(float)PyFloat_AS_DOUBLE(f);
- EXPP_decr2(f,v);
+ Py_DECREF(f);
+ Py_DECREF(v);
}
Py_DECREF(listObject);
return newVectorObject(vec, size, Py_NEW);
@@ -362,13 +366,15 @@
PyObject *vecCross = NULL;
VectorObject *vec1 = NULL, *vec2 = NULL;
- if(!PyArg_ParseTuple(args, "O!O!", &vector_Type, &vec1, &vector_Type, &vec2))
- return EXPP_ReturnPyObjError(PyExc_TypeError,
- "Mathutils.CrossVecs(): expects (2) 3D vector objects\n");
- if(vec1->size != 3 || vec2->size != 3)
- return EXPP_ReturnPyObjError(PyExc_AttributeError,
- "Mathutils.CrossVecs(): expects (2) 3D vector objects\n");
-
+ if(!PyArg_ParseTuple(args, "O!O!", &vector_Type, &vec1, &vector_Type, &vec2)) {
+ PyErr_SetString(PyExc_TypeError, "Mathutils.CrossVecs(): expects (2) 3D vector objects\n");
+ return NULL;
+ }
+
+ if(vec1->size != 3 || vec2->size != 3) {
+ PyErr_SetString(PyExc_AttributeError, "Mathutils.CrossVecs(): expects (2) 3D vector objects\n");
+ return NULL;
+ }
vecCross = newVectorObject(NULL, 3, Py_NEW);
Crossf(((VectorObject*)vecCross)->vec, vec1->vec, vec2->vec);
return vecCross;
@@ -381,12 +387,15 @@
double dot = 0.0f;
int x;
- if(!PyArg_ParseTuple(args, "O!O!", &vector_Type, &vec1, &vector_Type, &vec2))
- return EXPP_ReturnPyObjError(PyExc_TypeError,
- "Mathutils.DotVecs(): expects (2) vector objects of the same size\n");
- if(vec1->size != vec2->size)
- return EXPP_ReturnPyObjError(PyExc_AttributeError,
- "Mathutils.DotVecs(): expects (2) vector objects of the same size\n");
+ if(!PyArg_ParseTuple(args, "O!O!", &vector_Type, &vec1, &vector_Type, &vec2)) {
+ PyErr_SetString(PyExc_TypeError, "Mathutils.DotVecs(): expects (2) vector objects of the same size\n");
+ return NULL;
+ }
+
+ if(vec1->size != vec2->size) {
+ PyErr_SetString(PyExc_AttributeError, "Mathutils.DotVecs(): expects (2) vector objects of the same size\n");
+ return NULL;
+ }
for(x = 0; x < vec1->size; x++) {
dot += vec1->vec[x] * vec2->vec[x];
@@ -428,12 +437,12 @@
return PyFloat_FromDouble(angleRads * (180/ Py_PI));
AttributeError1:
- return EXPP_ReturnPyObjError(PyExc_AttributeError,
- "Mathutils.AngleBetweenVecs(): expects (2) VECTOR objects of the same size\n");
+ PyErr_SetString(PyExc_AttributeError, "Mathutils.AngleBetweenVecs(): expects (2) VECTOR objects of the same size\n");
+ return NULL;
AttributeError2:
- return EXPP_ReturnPyObjError(PyExc_AttributeError,
- "Mathutils.AngleBetweenVecs(): zero length vectors are not acceptable arguments\n");
+ PyErr_SetString(PyExc_AttributeError, "Mathutils.AngleBetweenVecs(): zero length vectors are not acceptable arguments\n");
+ return NULL;
}
//----------------------------------Mathutils.MidpointVecs() -------------
//calculates the midpoint between 2 vectors
@@ -443,12 +452,14 @@
float vec[4];
int x;
- if(!PyArg_ParseTuple(args, "O!O!", &vector_Type, &vec1, &vector_Type, &vec2))
- return EXPP_ReturnPyObjError(PyExc_TypeError,
- "Mathutils.MidpointVecs(): expects (2) vector objects of the same size\n");
- if(vec1->size != vec2->size)
- return EXPP_ReturnPyObjError(PyExc_AttributeError,
- "Mathutils.MidpointVecs(): expects (2) vector objects of the same size\n");
+ if(!PyArg_ParseTuple(args, "O!O!", &vector_Type, &vec1, &vector_Type, &vec2)) {
+ PyErr_SetString(PyExc_TypeError, "Mathutils.MidpointVecs(): expects (2) vector objects of the same size\n");
+ return NULL;
+ }
+ if(vec1->size != vec2->size) {
+ PyErr_SetString(PyExc_AttributeError, "Mathutils.MidpointVecs(): expects (2) vector objects of the same size\n");
+ return NULL;
+ }
for(x = 0; x < vec1->size; x++) {
vec[x] = 0.5f * (vec1->vec[x] + vec2->vec[x]);
@@ -464,12 +475,14 @@
double dot = 0.0f, dot2 = 0.0f;
int x, size;
- if(!PyArg_ParseTuple(args, "O!O!", &vector_Type, &vec1, &vector_Type, &vec2))
- return EXPP_ReturnPyObjError(PyExc_TypeError,
- "Mathutils.ProjectVecs(): expects (2) vector objects of the same size\n");
- if(vec1->size != vec2->size)
- return EXPP_ReturnPyObjError(PyExc_AttributeError,
- "Mathutils.ProjectVecs(): expects (2) vector objects of the same size\n");
+ if(!PyArg_ParseTuple(args, "O!O!", &vector_Type, &vec1, &vector_Type, &vec2)) {
+ PyErr_SetString(PyExc_TypeError, "Mathutils.ProjectVecs(): expects (2) vector objects of the same size\n");
+ return NULL;
+ }
+ if(vec1->size != vec2->size) {
+ PyErr_SetString(PyExc_AttributeError, "Mathutils.ProjectVecs(): expects (2) vector objects of the same size\n");
+ return NULL;
+ }
//since they are the same size...
size = vec1->size;
@@ -501,8 +514,8 @@
argSize = PySequence_Length(args);
if(argSize > 4){ //bad arg nums
- return EXPP_ReturnPyObjError(PyExc_AttributeError,
- "Mathutils.Matrix(): expects 0-4 numeric sequences of the same size\n");
+ PyErr_SetString(PyExc_AttributeError, "Mathutils.Matrix(): expects 0-4 numeric sequences of the same size\n");
+ return NULL;
} else if (argSize == 0) { //return empty 4D matrix
return (PyObject *) newMatrixObject(NULL, 4, 4, Py_NEW);
}else if (argSize == 1){
@@ -525,15 +538,15 @@
if(seqSize){ //0 at first
if(PySequence_Length(argObject) != seqSize){ //seq size not same
Py_DECREF(argObject);
- return EXPP_ReturnPyObjError(PyExc_AttributeError,
- "Mathutils.Matrix(): expects 0-4 numeric sequences of the same size\n");
+ PyErr_SetString(PyExc_AttributeError, "Mathutils.Matrix(): expects 0-4 numeric sequences of the same size\n");
+ return NULL;
}
}
seqSize = PySequence_Length(argObject);
}else{ //arg not a sequence
Py_XDECREF(argObject);
- return EXPP_ReturnPyObjError(PyExc_TypeError,
- "Mathutils.Matrix(): expects 0-4 numeric sequences of the same size\n");
+ PyErr_SetString(PyExc_TypeError, "Mathutils.Matrix(): expects 0-4 numeric sequences of the same size\n");
+ return NULL;
}
Py_DECREF(argObject);
}
@@ -542,27 +555,29 @@
for (i = 0; i < argSize; i++){
m = PySequence_GetItem(listObject, i);
if (m == NULL) { // Failed to read sequence
- return EXPP_ReturnPyObjError(PyExc_RuntimeError,
- "Mathutils.Matrix(): failed to parse arguments...\n");
+ PyErr_SetString(PyExc_RuntimeError, "Mathutils.Matrix(): failed to parse arguments...\n");
+ return NULL;
}
for (j = 0; j < seqSize; j++) {
s = PySequence_GetItem(m, j);
@@ Diff output truncated at 10240 characters. @@
More information about the Bf-blender-cvs
mailing list