From 92d757825d5bc1a4fd790e689ed901cfa882f4d9 Mon Sep 17 00:00:00 2001 From: Joshua Pelletier Date: Sun, 25 Jan 2015 14:06:38 -0800 Subject: [PATCH 1/3] Test `xy2d`. --- t/xy/2dto1d.t.js | 24 +++++++++++++++++++++--- 1 file changed, 21 insertions(+), 3 deletions(-) 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 }) From 543954caafe669034aa19c01e71fe6bb28d38902 Mon Sep 17 00:00:00 2001 From: Joshua Pelletier Date: Sun, 25 Jan 2015 14:10:27 -0800 Subject: [PATCH 2/3] Replace height variable with level. --- index.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/index.js b/index.js index ad07548..52a6cda 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 From 603a8019f7672989e2301eacc888a1a1e72dd6ac Mon Sep 17 00:00:00 2001 From: Joshua Pelletier Date: Mon, 26 Jan 2015 08:25:22 -0800 Subject: [PATCH 3/3] Correct equality in `rotate2d`. --- index.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/index.js b/index.js index 52a6cda..b3186f3 100644 --- a/index.js +++ b/index.js @@ -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 }