Additional code improvements: avoid unnecessary Python object allocations in Freestyle.
This commit is contained in:
@@ -512,103 +512,100 @@ Nature::EdgeNature EdgeNature_from_BPy_Nature(PyObject *obj)
|
||||
return static_cast<Nature::EdgeNature>(PyLong_AsLong(obj));
|
||||
}
|
||||
|
||||
Vec2f *Vec2f_ptr_from_PyObject(PyObject *obj)
|
||||
bool Vec2f_ptr_from_PyObject(PyObject *obj, Vec2f *vec)
|
||||
{
|
||||
Vec2f *v;
|
||||
if ((v = Vec2f_ptr_from_Vector(obj)))
|
||||
return v;
|
||||
if ((v = Vec2f_ptr_from_PyList(obj)))
|
||||
return v;
|
||||
if ((v = Vec2f_ptr_from_PyTuple(obj)))
|
||||
return v;
|
||||
return NULL;
|
||||
if (Vec2f_ptr_from_Vector(obj, vec))
|
||||
return true;
|
||||
if (Vec2f_ptr_from_PyList(obj, vec))
|
||||
return true;
|
||||
if (Vec2f_ptr_from_PyTuple(obj, vec))
|
||||
return true;
|
||||
return false;
|
||||
}
|
||||
|
||||
Vec3f *Vec3f_ptr_from_PyObject(PyObject *obj)
|
||||
bool Vec3f_ptr_from_PyObject(PyObject *obj, Vec3f *vec)
|
||||
{
|
||||
Vec3f *v;
|
||||
if ((v = Vec3f_ptr_from_Vector(obj)))
|
||||
return v;
|
||||
if ((v = Vec3f_ptr_from_Color(obj)))
|
||||
return v;
|
||||
if ((v = Vec3f_ptr_from_PyList(obj)))
|
||||
return v;
|
||||
if ((v = Vec3f_ptr_from_PyTuple(obj)))
|
||||
return v;
|
||||
return NULL;
|
||||
if (Vec3f_ptr_from_Vector(obj, vec))
|
||||
return true;
|
||||
if (Vec3f_ptr_from_Color(obj, vec))
|
||||
return true;
|
||||
if (Vec3f_ptr_from_PyList(obj, vec))
|
||||
return true;
|
||||
if (Vec3f_ptr_from_PyTuple(obj, vec))
|
||||
return true;
|
||||
return false;
|
||||
}
|
||||
|
||||
Vec3r *Vec3r_ptr_from_PyObject(PyObject *obj)
|
||||
bool Vec3r_ptr_from_PyObject(PyObject *obj, Vec3r *vec)
|
||||
{
|
||||
Vec3r *v;
|
||||
if ((v = Vec3r_ptr_from_Vector(obj)))
|
||||
return v;
|
||||
if ((v = Vec3r_ptr_from_Color(obj)))
|
||||
return v;
|
||||
if ((v = Vec3r_ptr_from_PyList(obj)))
|
||||
return v;
|
||||
if ((v = Vec3r_ptr_from_PyTuple(obj)))
|
||||
return v;
|
||||
return NULL;
|
||||
if (Vec3r_ptr_from_Vector(obj, vec))
|
||||
return true;
|
||||
if (Vec3r_ptr_from_Color(obj, vec))
|
||||
return true;
|
||||
if (Vec3r_ptr_from_PyList(obj, vec))
|
||||
return true;
|
||||
if (Vec3r_ptr_from_PyTuple(obj, vec))
|
||||
return true;
|
||||
return false;
|
||||
}
|
||||
|
||||
Vec2f *Vec2f_ptr_from_Vector(PyObject *obj)
|
||||
bool Vec2f_ptr_from_Vector(PyObject *obj, Vec2f *vec)
|
||||
{
|
||||
if (!VectorObject_Check(obj) || ((VectorObject *)obj)->size != 2)
|
||||
return NULL;
|
||||
return false;
|
||||
if (BaseMath_ReadCallback((BaseMathObject *)obj) == -1)
|
||||
return NULL;
|
||||
float x = ((VectorObject *)obj)->vec[0];
|
||||
float y = ((VectorObject *)obj)->vec[1];
|
||||
return new Vec2f(x, y);
|
||||
return false;
|
||||
vec[0] = ((VectorObject *)obj)->vec[0];
|
||||
vec[1] = ((VectorObject *)obj)->vec[1];
|
||||
return true;
|
||||
}
|
||||
|
||||
Vec3f *Vec3f_ptr_from_Vector(PyObject *obj)
|
||||
bool Vec3f_ptr_from_Vector(PyObject *obj, Vec3f *vec)
|
||||
{
|
||||
if (!VectorObject_Check(obj) || ((VectorObject *)obj)->size != 3)
|
||||
return NULL;
|
||||
return false;
|
||||
if (BaseMath_ReadCallback((BaseMathObject *)obj) == -1)
|
||||
return NULL;
|
||||
float x = ((VectorObject *)obj)->vec[0];
|
||||
float y = ((VectorObject *)obj)->vec[1];
|
||||
float z = ((VectorObject *)obj)->vec[2];
|
||||
return new Vec3f(x, y, z);
|
||||
return false;
|
||||
vec[0] = ((VectorObject *)obj)->vec[0];
|
||||
vec[1] = ((VectorObject *)obj)->vec[1];
|
||||
vec[2] = ((VectorObject *)obj)->vec[2];
|
||||
return true;
|
||||
}
|
||||
|
||||
Vec3r *Vec3r_ptr_from_Vector(PyObject *obj)
|
||||
bool Vec3r_ptr_from_Vector(PyObject *obj, Vec3r *vec)
|
||||
{
|
||||
if (!VectorObject_Check(obj) || ((VectorObject *)obj)->size != 3)
|
||||
return NULL;
|
||||
return false;
|
||||
if (BaseMath_ReadCallback((BaseMathObject *)obj) == -1)
|
||||
return NULL;
|
||||
real x = ((VectorObject *)obj)->vec[0];
|
||||
real y = ((VectorObject *)obj)->vec[1];
|
||||
real z = ((VectorObject *)obj)->vec[2];
|
||||
return new Vec3r(x, y, z);
|
||||
return false;
|
||||
vec[0] = ((VectorObject *)obj)->vec[0];
|
||||
vec[1] = ((VectorObject *)obj)->vec[1];
|
||||
vec[2] = ((VectorObject *)obj)->vec[2];
|
||||
return true;
|
||||
}
|
||||
|
||||
Vec3f *Vec3f_ptr_from_Color(PyObject *obj)
|
||||
bool Vec3f_ptr_from_Color(PyObject *obj, Vec3f *vec)
|
||||
{
|
||||
if (!ColorObject_Check(obj))
|
||||
return NULL;
|
||||
return false;
|
||||
if (BaseMath_ReadCallback((BaseMathObject *)obj) == -1)
|
||||
return NULL;
|
||||
float r = ((ColorObject *)obj)->col[0];
|
||||
float g = ((ColorObject *)obj)->col[1];
|
||||
float b = ((ColorObject *)obj)->col[2];
|
||||
return new Vec3f(r, g, b);
|
||||
return false;
|
||||
vec[0] = ((ColorObject *)obj)->col[0];
|
||||
vec[1] = ((ColorObject *)obj)->col[1];
|
||||
vec[2] = ((ColorObject *)obj)->col[2];
|
||||
return true;
|
||||
}
|
||||
|
||||
Vec3r *Vec3r_ptr_from_Color(PyObject *obj)
|
||||
bool Vec3r_ptr_from_Color(PyObject *obj, Vec3r *vec)
|
||||
{
|
||||
if (!ColorObject_Check(obj))
|
||||
return NULL;
|
||||
return false;
|
||||
if (BaseMath_ReadCallback((BaseMathObject *)obj) == -1)
|
||||
return NULL;
|
||||
real r = ((ColorObject *)obj)->col[0];
|
||||
real g = ((ColorObject *)obj)->col[1];
|
||||
real b = ((ColorObject *)obj)->col[2];
|
||||
return new Vec3r(r, g, b);
|
||||
return false;
|
||||
vec[0] = ((ColorObject *)obj)->col[0];
|
||||
vec[1] = ((ColorObject *)obj)->col[1];
|
||||
vec[2] = ((ColorObject *)obj)->col[2];
|
||||
return true;
|
||||
}
|
||||
|
||||
static int float_array_from_PyList(PyObject *obj, float *v, int n)
|
||||
@@ -623,37 +620,45 @@ static int float_array_from_PyList(PyObject *obj, float *v, int n)
|
||||
return 1;
|
||||
}
|
||||
|
||||
Vec2f *Vec2f_ptr_from_PyList(PyObject *obj)
|
||||
bool Vec2f_ptr_from_PyList(PyObject *obj, Vec2f *vec)
|
||||
{
|
||||
float v[2];
|
||||
|
||||
if (!PyList_Check(obj) || PyList_Size(obj) != 2)
|
||||
return NULL;
|
||||
return false;
|
||||
if (!float_array_from_PyList(obj, v, 2))
|
||||
return NULL;
|
||||
return new Vec2f(v[0], v[1]);
|
||||
return false;
|
||||
vec[0] = v[0];
|
||||
vec[1] = v[1];
|
||||
return true;
|
||||
}
|
||||
|
||||
Vec3f *Vec3f_ptr_from_PyList(PyObject *obj)
|
||||
bool Vec3f_ptr_from_PyList(PyObject *obj, Vec3f *vec)
|
||||
{
|
||||
float v[3];
|
||||
|
||||
if (!PyList_Check(obj) || PyList_Size(obj) != 3)
|
||||
return NULL;
|
||||
return false;
|
||||
if (!float_array_from_PyList(obj, v, 3))
|
||||
return NULL;
|
||||
return new Vec3f(v[0], v[1], v[2]);
|
||||
return false;
|
||||
vec[0] = v[0];
|
||||
vec[1] = v[1];
|
||||
vec[2] = v[2];
|
||||
return true;
|
||||
}
|
||||
|
||||
Vec3r *Vec3r_ptr_from_PyList(PyObject *obj)
|
||||
bool Vec3r_ptr_from_PyList(PyObject *obj, Vec3r *vec)
|
||||
{
|
||||
float v[3];
|
||||
|
||||
if (!PyList_Check(obj) || PyList_Size(obj) != 3)
|
||||
return NULL;
|
||||
return false;
|
||||
if (!float_array_from_PyList(obj, v, 3))
|
||||
return NULL;
|
||||
return new Vec3r(v[0], v[1], v[2]);
|
||||
return false;
|
||||
vec[0] = v[0];
|
||||
vec[1] = v[1];
|
||||
vec[2] = v[2];
|
||||
return true;
|
||||
}
|
||||
|
||||
static int float_array_from_PyTuple(PyObject *obj, float *v, int n)
|
||||
@@ -668,37 +673,45 @@ static int float_array_from_PyTuple(PyObject *obj, float *v, int n)
|
||||
return 1;
|
||||
}
|
||||
|
||||
Vec2f *Vec2f_ptr_from_PyTuple(PyObject *obj)
|
||||
bool Vec2f_ptr_from_PyTuple(PyObject *obj, Vec2f *vec)
|
||||
{
|
||||
float v[2];
|
||||
|
||||
if (!PyTuple_Check(obj) || PyTuple_Size(obj) != 2)
|
||||
return NULL;
|
||||
return false;
|
||||
if (!float_array_from_PyTuple(obj, v, 2))
|
||||
return NULL;
|
||||
return new Vec2f(v[0], v[1]);
|
||||
return false;
|
||||
vec[0] = v[0];
|
||||
vec[1] = v[1];
|
||||
return true;
|
||||
}
|
||||
|
||||
Vec3f *Vec3f_ptr_from_PyTuple(PyObject *obj)
|
||||
bool Vec3f_ptr_from_PyTuple(PyObject *obj, Vec3f *vec)
|
||||
{
|
||||
float v[3];
|
||||
|
||||
if (!PyTuple_Check(obj) || PyTuple_Size(obj) != 3)
|
||||
return NULL;
|
||||
return false;
|
||||
if (!float_array_from_PyTuple(obj, v, 3))
|
||||
return NULL;
|
||||
return new Vec3f(v[0], v[1], v[2]);
|
||||
return false;
|
||||
vec[0] = v[0];
|
||||
vec[1] = v[1];
|
||||
vec[2] = v[2];
|
||||
return true;
|
||||
}
|
||||
|
||||
Vec3r *Vec3r_ptr_from_PyTuple(PyObject *obj)
|
||||
bool Vec3r_ptr_from_PyTuple(PyObject *obj, Vec3r *vec)
|
||||
{
|
||||
float v[3];
|
||||
|
||||
if (!PyTuple_Check(obj) || PyTuple_Size(obj) != 3)
|
||||
return NULL;
|
||||
return false;
|
||||
if (!float_array_from_PyTuple(obj, v, 3))
|
||||
return NULL;
|
||||
return new Vec3r(v[0], v[1], v[2]);
|
||||
return false;
|
||||
vec[0] = v[0];
|
||||
vec[1] = v[1];
|
||||
vec[2] = v[2];
|
||||
return true;
|
||||
}
|
||||
|
||||
// helper for argument parsing
|
||||
|
||||
Reference in New Issue
Block a user