0

I have a Javascript library to plot points on a Hilbert curve, but something's wrong with the point determination.

I've written a test page that plots 256 points on a path. While it should look like this, instead it's coming out like this:

There appears to be some discontinuity.

You can inspect the source behind the page at http://jsbin.com/oheloc/1/edit (for kicks, unlock the recursion depth and raise it higher than the points exponent to see the whole path get WAY more deformed).

What's wrong with this picture? I think it's something to do with (at least) one of the quadrant transformations being incorrect, but I can't figure out what it should be.

Stuart P. Bentley
  • 10,195
  • 10
  • 55
  • 84
  • You'd be much more likely to get help if you'd set up your code in jsbin or jsfiddle. – Pointy Aug 11 '12 at 11:27
  • I'm not sure what's wrong, but your code looks a lot like [this code on github](https://github.com/chrisdew/jshilbert). That one has an issue logged against it that sounds suspiciously similar to the bug you're seeing. – Pointy Aug 11 '12 at 12:35
  • Oh, ha ha I see you found that too :-) – Pointy Aug 11 '12 at 12:40
  • Indeed, this is my fork of that code on Github, with the code refactored to do the same (broken) thing more concisely. This bug's been around for a year, I figure it's high time to fix it. – Stuart P. Bentley Aug 11 '12 at 21:20
  • Well it's hard for me to map the way I think about the Hilbert curve over what this code does. It seems like there's a basic flaw in the way that it does the "turns" in the recursion. It works for depth 1 and 2, but starts breaking at 3. [Here](http://jsfiddle.net/Pointy/zGLKF/3/) is a fiddle done the way I understand it. Note that I stay away from floating point in that, letting the SVG renderer do the work. – Pointy Aug 11 '12 at 21:23
  • Also my jsfiddle runs *way* faster than that floating-point code. – Pointy Aug 11 '12 at 21:24
  • You know, honestly, I agree that this code is overcomplicated and inefficient. My initial plan was to figure out the mistake in their implementation and just fix that, but the more I think about it, the more I realize that things would probably be better off if I just cut out their whole objects-and-recursion approach entirely. – Stuart P. Bentley Aug 15 '12 at 06:43

0 Answers0