Open rbedia opened 13 years ago
I've made an SVG test, with live configurable point density and recursion depth, at https://gist.github.com/3317841. This may help to visualize the issue.
(The page can be tinkered with at http://jsbin.com/oheloc/1/edit)
Indeed there's an issue with this algorithm.
I wrote a test file that creates an 16x16 table and then fills the table with the Hilbert number at that coordinate. When the algorithm is working correctly the numbers 0 through 255 will fill the space in order in the Hilbert pattern. However the test code finds a problem when it gets to 16. It jumps to 26 instead of 16. Similarly 24,18 are transposed and so are 27,19 and 25,17. This happens several other places in the grid with the same pattern. An upper left quadrant is being swapped with a lower right quadrant.
The hilbert.js file I used and the test HTML file are published at: https://gist.github.com/1090942