Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ function convert2dPointToDistance (p, height) { // :: Int -> Int -> Int -> Int
d += level * level * ((3 * xbit) ^ ybit)
// rotate so that we'll be in sync with the next
// region.
p = p.rotate2d(height, xbit, ybit)
p = p.rotate2d(level, xbit, ybit)
}

return d
Expand Down Expand Up @@ -165,8 +165,8 @@ function convertDistanceTo3dPoint (distance, height) { // Int -> Int -> [Int, In

// Rotate the coordinate plane and (x,y)
function rotate2d (n, x, y, xbit, ybit) { // :: Int -> Int -> Int -> Int -> Int -> [Int, Int]
if (ybit === 0 ) {
if (xbit === 1) {
if (ybit == 0 ) {
if (xbit == 1) {
x = n - 1 - x
y = n - 1 - y
}
Expand Down
24 changes: 21 additions & 3 deletions t/xy/2dto1d.t.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,25 @@
#!/usr/bin/env node

require('proof')(1, function (equal) {
var hilbert = require('../..')

equal(hilbert.xy2d(16, 2, 2), 8)
var hilbert = require('../..')
equal(hilbert.xy2d(16, 2, 2), 8)
//equal(5, 8)
//hilbert.xy2d(0, 4, 2)
console.log("x: 0, y: 1, length: ", hilbert.xy2d(0, 1, 2)) // 1
console.log("x: 1, y: 1, length: ", hilbert.xy2d(1, 1, 2)) // 2
console.log("x: 1, y: 0, length: ", hilbert.xy2d(1, 0, 2)) // 3
console.log("x: 0, y: 2, length: ", hilbert.xy2d(0, 2, 2)) // 4
console.log("x: 0, y: 3, length: ", hilbert.xy2d(0, 3, 2)) // 5
console.log("x: 1, y: 3, length: ", hilbert.xy2d(1, 3, 2)) // 6
console.log("x: 1, y: 2, length: ", hilbert.xy2d(1, 2, 2)) // 7
console.log("x: 2, y: 2, length: ", hilbert.xy2d(2, 2, 2)) // 8
console.log("x: 2, y: 3, length: ", hilbert.xy2d(2, 3, 2)) // 9
console.log("x: 3, y: 3, length: ", hilbert.xy2d(3, 3, 2)) // 10
console.log("x: 3, y: 2, length: ", hilbert.xy2d(3, 2, 2)) // 11
console.log("x: 3, y: 1, length: ", hilbert.xy2d(3, 1, 2)) // 14
console.log("x: 2, y: 1, length: ", hilbert.xy2d(2, 1, 2)) // 13
console.log("x: 2, y: 0, length: ", hilbert.xy2d(2, 0, 2)) // 12
console.log("x: 3, y: 0, length: ", hilbert.xy2d(3, 0, 2)) // 15
hilbert.xy2d(3, 1, 2) // should be 12 showing up as 14
hilbert.xy2d(2, 0, 2) // should be 12 showing up as 14
})