* Added a generic helper function for parsing PyObject arguments as N-dimensional float array.

* Local helpers were replaced with the generic one.  This also fixed a memory leak in the setter
function StrokeVertex_point_set.

* Made minor code style changes.
This commit is contained in:
2013-02-04 00:23:37 +00:00
parent 7f8a17118b
commit 3c064f4553
4 changed files with 42 additions and 46 deletions

View File

@@ -601,6 +601,25 @@ Vec3r * Vec3r_ptr_from_PyTuple( PyObject* obj ) {
return new Vec3r(x,y,z);
}
// helper for argument parsing
int float_array_from_PyObject(PyObject *obj, float *v, int n)
{
if (VectorObject_Check(obj) && ((VectorObject *)obj)->size == n) {
for (int i = 0; i < n; i++)
v[i] = ((VectorObject *)obj)->vec[i];
} else if (PyList_Check(obj) && PyList_Size(obj) == n) {
for (int i = 0; i < n; i++)
v[i] = PyFloat_AsDouble(PyList_GetItem(obj, i));
} else if (PyTuple_Check(obj) && PyTuple_Size(obj) == n) {
for (int i = 0; i < n; i++)
v[i] = PyFloat_AsDouble(PyTuple_GetItem(obj, i));
} else {
return 0;
}
return 1;
}
///////////////////////////////////////////////////////////////////////////////////////////