
Structure for Bezier curves
Posted Tuesday, 4 March, 2008 - 19:36 by georgwaechter inHello,
in my private math library i have structures for calculating bezier curves. I think this could be useful for OpenTK too, or? Within my personal projekt i use these structures to calculate and draw bezier curves with OpenGL.
I have one structure for quadric bezier curves, one structure for cubic bezier curves and one struct for bezier curves with any count of anchor points.
georg


Comments
Re: Structure for Bezier curves
Nice, thanks :)
2) Makes sense. I'd suggest a pattern like this, though:
The main reason is that this helps keep the internal state consistent. If the user was able to say
curve.Points = null, you'd have to guard against null references every time you used the property.This still allows you to add and remove points:
What do you think?
Re: Structure for Bezier curves
In reality i anyway should check for
nullin all functions, because a line likeprivate List<Vector2> points = new List<Vector2>();is not allowed within structures. An alternative would be to switch to a class ...
1) using IEnumerable now implies, that we have to copy the specified list always ... but thats no real problem
Re: Structure for Bezier curves
No need, just make sure
pointsare always initialized in the constructor.1) True. I think it's good design to always copy though, because it avoids nasty surprises:
Re: Structure for Bezier curves
Ok i made all changes. But there is yet the theoretical chance of null-reference-exceptions, because anybody could call the default ctor of the struct, that initializes all fields to
0ornull.For that reason i added a setter for the property
Points:Additionally i made a few performance optimizations within the loops to reduce redundant calculations.
Here is the patch: http://trackplanner.de/files/BezierPatch.patch
Re: Structure for Bezier curves
Thanks, I've applied it to my working copy and it looks good, I'll play with it a bit and commit it.
Re: Structure for Bezier curves
Just a little precision about the order of the control points :
Like in OpenGL, it would be a nice addon to have the following "targets" : Normal, Texture, Color