Monday, November 2, 2009

Why Blogging Is Good For Your Programming...

...about half of the time I go to post on something I've considered "done", the process of thinking about it makes me stop and rewrite it.

Case in point: I'm currently working on generating SVG output for Nubs and Polynomial, so that I can draw pretty pictures demonstrating the math. The very first thing I set out to was make sure that both classes had an equivalently called evaluate function, because that's what we'll use to drive the graphing. And that meant adding a bit of logic to the Nubs class.

I don't know if I've properly explained this before or not, but Nubs and Nurbs have two slightly different ways of evaluating them, which I've called Left and Right here. Neither approach can evaluate what you'd like to be the entire range of the curve: if the curve's range is [a, b], then Left works for [a, b), Right for (a, b]. That has all been handled ever since I got the Nubs to Polynomial code working correctly.

That means to have a fully working evaluate function, you need to be able to use a blended approach. So I decided that you should be able set $direction to Left, Right, or Reasonable. That meant I had to special case Reasonable in the KnotVector code, and come up with a function that did a reasonable thing if Reasonable was set. Here's the gist of that code:

Now that I've put these two together like this, the problem here is kind of glaring. KnotBasisDirection has three values, two of which are the only ones that make sense in the first function, and the third of which is the only one that makes sense in the second. I overloaded it like that merely so KnotBasisDirection could take Reasonable as a default value. Stupid.

So I had written that code and tested it and gone on to the next segment of code, and it wasn't until I started thinking about how to blog the code that I realized it was stupid and needed to be rewritten. Yay blogging!

Tomorrow: The corrected code.

Edited to add: I forgot to say "Perl 6" in this post, which is needed to make it show up in the Ironman feed, IME. (Well, just Perl would do, but I prefer to say Perl 6.)

No comments:

Post a Comment