[Bf-python] Re: Python Ipocurve/CurNurb module changes

Stephen Swaney sswaney at centurytel.net
Sat Jun 25 21:19:04 CEST 2005


On Sat, Jun 25, 2005 at 11:32:52AM -0700, Ken Hughes wrote:
> Stephen Swaney wrote:
> >The thing we are wrapping here is an array contained inside a blender
> >object, not an independent object.  If we were doing a clean
> >implementation, I would agree completely.
> 
> I'm about to start pulling out my code and starting to think about your
> way.  Can you define "changed too radically"?  Only thing I can think
> of is a BezTriple sees its index is greater than the curve's list length.

That is essentially it.

> [Aside #1: Again, in defense of my approach (as in "elaborate on
> implementation") it disadvantages are it has a speed penalty when points
> are added or removed from the curve (but only then), and it incurs extra
> storage (unused pointers).  Advantage is no segfaults.]

Principle #1: We do not want to change blender's curve data structs
and all the code that manipulates them.

Principle #2: A curve holds a pointer to a chunk of allocated memory -
the control points.  This should be the only copy of that data.

Principle #3: segfaults are bad.

Given the above, I think the best way to wrap control points is for a
control point to contain a reference to the curve it belongs to and
the index of that point in the curve's array of control points.  The
control point wrapper then becomes essentially an alias for curve[i].

Accessing a curve via operator [] ( or thru the iterator interface )
is straightforward.  Holding a reference to a control point by doing
something like 

a = curve[2] 
a = [1,2,3,1] 

is straightforward *until* you start deleteing or inserting points
into the curve.  Once you modify the underlying curve, all bets are
off unless your control point index still lies within the curve.

-- 
Stephen Swaney			
sswaney at centurytel.net





More information about the Bf-python mailing list