C++ hilberts curve class

TeeJay on 2004-06-09T14:53:53

On the train to guildford yesterday I managed to write a class to implement Hilberts Space Filling curve, porting it from the Perl module I have already done -- actually I just wanted a handy copy of the algorithm on which to base it as the C++ Class is pretty different.

Most of the time was spent getting used to debugging C++ and spotting silly mistakes rather than understanding OO C++.

Then I foolishly thought I might have time to do a demo using QT. No such look - all kinds of very strange errors, essentially I couldn't get anything to compile. GTK was much easier (both to compile and to understand).

I will probably just look at doing a demo with the GD library instead.

Oddly - the C++ will probably have less LoC than the perl version (excluding comments and pod) - some of that because its a Second System (and so quicker/easier to design), and some is because OOP in C++ can be more concise than perl, the C++ code is a bit clearer than the perl as it relies more on using class attributes to keep state than the equivilent code which uses more data structures (partly because data structures are much easier to deal with in Perl than C++, partly because the prototypes and earlier versions were procedural rather than OO).


LoC

jonasbn on 2004-06-09T18:24:23

I have just discussed this subject on the Copenhagen Perl Mongers mailinglist - and I would very much like to see you Perl and C++ versions if there are publically available?

Re:LoC

TeeJay on 2004-06-10T12:00:16

ok

have a look at my C++ and the perl

the perl code is more mature, but also organic while the C++ is a rewrite, so it is better done.

I think I could get the perl to be better, based on the C++ class, then the LoC would be marginally less than the C++ but the difference would be a lot smaller than I expected. I could probably optimise the C++ for LoC as well so its looking pretty even.

The key part is the constructor and the up,down, etc methods - this is the core of the class and you can see how the C++ is probably clearer and more concise even if slightly more LoC.

Hope that helps

Re:LoC

TeeJay on 2004-06-10T12:01:56

bah - messed up the perl link

perl version can be found at http://search.cpan.org/src/TEEJAY/Math-Curve-Hilbert-0.04/