[Bf-python] Vector data type

Campbell Barton cbarton at metavr.com
Tue Oct 3 19:48:03 CEST 2006


just successfully removed the need for coerced_object in the struct by 
setting the
PyTypeObject vector_Type's flag to
Py_TPFLAGS_DEFAULT | Py_TPFLAGS_CHECKTYPES

instead of just Py_TPFLAGS_DEFAULT

That way types dont need to be cast to vectors for 10 * vec to be dealt 
with by the vector math function.
(without Py_TPFLAGS_CHECKTYPES   vec*10 worked but 10*vec didnt )

Also implemented getsetatrs and in place functions +=  -=   *=  /=
These are a bit more optimal because they avoid making new pyobjects.

What do people think about changing the struct to..

typedef struct {
    PyObject_VAR_HEAD
    float *vec;                //1D array of data (alias)
    short size;
    short wrapped;            //is wrapped data?
} VectorObject;


from

typedef struct {
    PyObject_VAR_HEAD
    struct{
        float *py_data;        //python managed
        float *blend_data;    //blender managed
    }data;
    float *vec;                //1D array of data (alias)
    int size;
    int wrapped;            //is wrapped data?
} VectorObject;



More information about the Bf-python mailing list