diff --git a/index.js b/index.js index ad07548..b3186f3 100644 --- a/index.js +++ b/index.js @@ -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 @@ -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 } diff --git a/t/xy/2dto1d.t.js b/t/xy/2dto1d.t.js index 090b892..2bbb7ea 100644 --- a/t/xy/2dto1d.t.js +++ b/t/xy/2dto1d.t.js @@ -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 })