Skip to main content

Splines project on a good path

Posted by pepe on February 26, 2008 at 10:43 PM PST

Splines project is my latest contribution to oss.
It is aimed at helping people use, display and edit splines without too much hassle.

The main entity of the project is Curve, which is a list of CurseSection objects. Three types of sections can be added at the moment, but the system can accept new implementations anytime (you can already add yours).
Actually implemented CurveSection types are:

    • linear: a direct interpolation between previous section and current
      cubic: a cubic spline interpolation between previous section and current
      quadratic: a quadratic spline interpolation between previous section and current
  • Taken from the webstart Demo, here is how i created the Curve:

    Curve = new Curve( new LinearSection( 0, 0 ) ) );
    curve.addSection( new LinearSection( 1.0, 5.0 ) );
    curve.addSection( new QuadraticSection( 3.0, 4.0, 2, 4 ) );
    curve.addSection( new CubicSection( 6., 2., 4, 5, 5, 0 ) );

    Cannot be easier.

    and here is how i displayed the curve:

    this.curveViewControl.setCurve( curve )

    Once again, cannot be easier.

    Curve and its sections can be listened for modification, curve can be serialized (listeners will not) and the whole is easy to use and fits in a very small single jar.
    Sections can be replaced by others, and section objects can be modified externally. Library is totally threadsafe and a curve or its sections can be used and modified from multiple threads without collisions.

    Plans for the future are to enhance the swing component to enable pluggable editors for curves, pluggable renderers, and before all more complete refreshing after edit.

    Related Topics >>


    Curves are 2D in the sense that one X has one and only one Y while GeneralPath is ... a path, so it can be multidimensionnal. To get a path in the way generalpath does, you would combine two Curve object, one for each ordinate. This is actually much better than what GeneralPath does for many reasons:
    • you can set different key points by ordinates
      editing curve parameters (slope, ...) is done independently too
  • Those are essential in animation.
    I hear you thinking that i would too combine two GeneralPath and achieve the same effect. That's somewhat true but GeneralPath does not limit you to 2D curves while Splines project does.
    Following reasons were no-go.

    Curves are not static. GeneralPath is. (not static in the keyword way, immutable.)
    If you need to modify a GeneralPath, you need to create a new one. Any operation on GeneralPath like moving a point, changing a section type is simply impossible. Achieving this so people can at least edit the path interactively is a mess.

    No velocity. Animations are not monotonic, they accelerate, slow down, ....

    GeneralPath only allows two dimensional curves. If you want 3D curves, you're half there.. or not.
    While you have to combine three Curve to obtain that, you have to combine 1,5 GeneralPath. Messier imho. (The splines project will include utilities to handle Curve tuples at a later time)

    There are some other (more specialized) points that greatens capabilities of Splines project over GeneralPath but i will stop there as i think it is enough already.
    I hope i was clear in my explanations. If not, please drop a word.

    I'm curious, how does this differ from what you can do with java.awt.geom.GeneralPath? Just the listening bits, or something more?