From 49b490e353ebf6d9fd0722f0ef913a1c544ec533 Mon Sep 17 00:00:00 2001 From: Alan Gutierrez Date: Sun, 14 Sep 2014 12:14:03 -0400 Subject: [PATCH 01/99] Upgrade Proof to 0.0.47. Closes #16. --- package.json | 2 +- release.md | 1 + 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/package.json b/package.json index 949bcf4..a20965f 100644 --- a/package.json +++ b/package.json @@ -22,7 +22,7 @@ }], "devDependencies": { - "proof": "0.0.44" + "proof": "0.0.47" }, "licenses": [{ diff --git a/release.md b/release.md index e2bdcf9..1e06264 100644 --- a/release.md +++ b/release.md @@ -1,5 +1,6 @@ ### Issue by Issue + * Upgrade Proof to 0.0.47. #16. * Upgrade Proof to 0.0.44. #10. * Remove "url" from `package.json`. #9. * Update `LICENSE` for 2014. #8. From 1adeaa8532a1bf4290b9726fc0eb5ec8d347d68a Mon Sep 17 00:00:00 2001 From: Demarius Chrite Date: Mon, 20 Oct 2014 17:19:03 -0400 Subject: [PATCH 02/99] Diary entry. Haverkort. --- diary.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/diary.md b/diary.md index 13940c7..7aaf3bc 100644 --- a/diary.md +++ b/diary.md @@ -1 +1,3 @@ the function convertPointToDistance requires 'height' to be a power of 2. Looking into ways to rewrite that, or determine if a rewrite is necessary. + +http://www.win.tue.nl/~hermanh/stack/dagstuhl08-talk.pdf From 0f1d8b9f8301e0b7f3ff0b098ed92894d7d01ad9 Mon Sep 17 00:00:00 2001 From: Demarius Chrite Date: Tue, 21 Oct 2014 20:59:43 -0400 Subject: [PATCH 03/99] Diary entry. pseudo-code. --- diary.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/diary.md b/diary.md index 7aaf3bc..81b38d3 100644 --- a/diary.md +++ b/diary.md @@ -1,3 +1,5 @@ the function convertPointToDistance requires 'height' to be a power of 2. Looking into ways to rewrite that, or determine if a rewrite is necessary. http://www.win.tue.nl/~hermanh/stack/dagstuhl08-talk.pdf + +pseudo-code: http://www.fundza.com/algorithmic/space_filling/hilbert/basics/index.html From 08b785cf6cd5f0a1396969ddb445b6875c12f115 Mon Sep 17 00:00:00 2001 From: Demarius Chrite Date: Wed, 22 Oct 2014 10:28:03 -0400 Subject: [PATCH 04/99] Function signatures. --- index.js | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/index.js b/index.js index 359d4a6..820fe8c 100644 --- a/index.js +++ b/index.js @@ -4,7 +4,7 @@ // Accepts the height or width of a square, and the coordinates to // convert. -function convertPointToDistance (height, x, y) { +function convertPointToDistance (height, x, y) { // :: Int -> Int -> Int -> Int var xbit, ybit, level, d = 0 // For each Hilbert level, we want to add an amount to @@ -25,7 +25,8 @@ function convertPointToDistance (height, x, y) { return d } -function convertDistanceToPoint (height, distance) { +// Accepts height or width of a square and distance +function convertDistanceToPoint (height, distance) { // :: Int -> Int -> [Int, Int] var xbit, ybit, level, distance var x = 0, y = 0 @@ -45,7 +46,7 @@ function convertDistanceToPoint (height, distance) { } // Rotate the coordinate plane and (x,y) -function rotate (n, x, y, xbit, ybit) { +function rotate (n, x, y, xbit, ybit) { // :: Int -> Int -> Int -> Int -> Int -> [Int, Int] if (ybit === 0 ) { if (xbit === 1) { x = n - 1 - x From 3b0dba151692c673061e6d0f2490594d63f9715f Mon Sep 17 00:00:00 2001 From: Demarius Chrite Date: Thu, 23 Oct 2014 13:22:14 -0400 Subject: [PATCH 05/99] Change export names. --- index.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/index.js b/index.js index 820fe8c..b1437be 100644 --- a/index.js +++ b/index.js @@ -61,5 +61,5 @@ function rotate (n, x, y, xbit, ybit) { // :: Int -> Int -> Int -> Int -> Int -> return [x, y] } -exports.convertPointToDistance = convertPointToDistance -exports.convertDistanceToPoint = convertDistanceToPoint +exports.p2d = convertPointToDistance +exports.d2p = convertDistanceToPoint From 71d7405df262d421384aae9d71db628778a92690 Mon Sep 17 00:00:00 2001 From: Demarius Chrite Date: Fri, 24 Oct 2014 18:08:54 -0400 Subject: [PATCH 06/99] Fix distance-to-point calculation. --- index.js | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/index.js b/index.js index b1437be..29ad0d2 100644 --- a/index.js +++ b/index.js @@ -27,10 +27,10 @@ function convertPointToDistance (height, x, y) { // :: Int -> Int -> Int -> Int // Accepts height or width of a square and distance function convertDistanceToPoint (height, distance) { // :: Int -> Int -> [Int, Int] - var xbit, ybit, level, distance + var xbit, ybit, level var x = 0, y = 0 - for (level = 1; level < height; level *= 2) { + for (level = 1; level < height && distance > 0; level *= 2) { xbit = 1 & (distance / 2) ybit = 1 & (distance ^ xbit) @@ -39,7 +39,7 @@ function convertDistanceToPoint (height, distance) { // :: Int -> Int -> [Int, I y = temp[1] x += level * xbit y += level * xbit - distance /= 4 + distance = Math.floor(distance / 4) } return [x, y] From 30753fe7343dceb61718f407c75c13281a3562a3 Mon Sep 17 00:00:00 2001 From: Demarius Chrite Date: Sat, 25 Oct 2014 20:17:37 -0400 Subject: [PATCH 07/99] Minimum height is 2. --- index.js | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/index.js b/index.js index 29ad0d2..bad99b1 100644 --- a/index.js +++ b/index.js @@ -2,7 +2,7 @@ // Will later expand to allow `n` dimensions. -// Accepts the height or width of a square, and the coordinates to +// Accepts the height or width of a square/graph, and the coordinates to // convert. function convertPointToDistance (height, x, y) { // :: Int -> Int -> Int -> Int var xbit, ybit, level, d = 0 @@ -25,10 +25,13 @@ function convertPointToDistance (height, x, y) { // :: Int -> Int -> Int -> Int return d } -// Accepts height or width of a square and distance +// Accepts height or width of a square/graph and distance function convertDistanceToPoint (height, distance) { // :: Int -> Int -> [Int, Int] var xbit, ybit, level var x = 0, y = 0 + if (height < 2) { + height = 2 + } for (level = 1; level < height && distance > 0; level *= 2) { xbit = 1 & (distance / 2) From 446a2ba6c2769a37bf196c61b48944cd42e76a73 Mon Sep 17 00:00:00 2001 From: Demarius Chrite Date: Sun, 26 Oct 2014 21:32:03 -0400 Subject: [PATCH 08/99] Update minimum height for p2d. --- index.js | 3 +++ 1 file changed, 3 insertions(+) diff --git a/index.js b/index.js index bad99b1..eece1dd 100644 --- a/index.js +++ b/index.js @@ -6,6 +6,9 @@ // convert. function convertPointToDistance (height, x, y) { // :: Int -> Int -> Int -> Int var xbit, ybit, level, d = 0 + if (height < 2) { + height = 2 + } // For each Hilbert level, we want to add an amount to // `d` based on which region we are in From 177c79a6c71682aec87acfcd31fa02654371590d Mon Sep 17 00:00:00 2001 From: Demarius Chrite Date: Mon, 27 Oct 2014 16:44:15 -0400 Subject: [PATCH 09/99] Fix rotation calculations. --- index.js | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/index.js b/index.js index eece1dd..c61141b 100644 --- a/index.js +++ b/index.js @@ -30,17 +30,18 @@ function convertPointToDistance (height, x, y) { // :: Int -> Int -> Int -> Int // Accepts height or width of a square/graph and distance function convertDistanceToPoint (height, distance) { // :: Int -> Int -> [Int, Int] + distance = Math.floor(distance) var xbit, ybit, level var x = 0, y = 0 if (height < 2) { height = 2 } - for (level = 1; level < height && distance > 0; level *= 2) { - xbit = 1 & (distance / 2) - ybit = 1 & (distance ^ xbit) + for (level = 1; level < height || distance > 0; level *= 2) { + ybit = 1 & (distance / 2) + xbit = 1 & (ybit ^ distance) - var temp = rotate(height, x, y, xbit, ybit) + var temp = rotate(level, x, y, xbit, ybit) x = temp[0] y = temp[1] x += level * xbit From 02c8ddcb3a0e2553b0f3123140d5f199f92430d6 Mon Sep 17 00:00:00 2001 From: Demarius Chrite Date: Tue, 28 Oct 2014 22:10:22 -0400 Subject: [PATCH 10/99] Converting distance to point works. --- index.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/index.js b/index.js index c61141b..e6548dc 100644 --- a/index.js +++ b/index.js @@ -45,7 +45,7 @@ function convertDistanceToPoint (height, distance) { // :: Int -> Int -> [Int, I x = temp[0] y = temp[1] x += level * xbit - y += level * xbit + y += level * ybit distance = Math.floor(distance / 4) } From 0fe63258524d602e6081910cacc97c9a49f3e336 Mon Sep 17 00:00:00 2001 From: Demarius Chrite Date: Thu, 30 Oct 2014 22:13:52 -0400 Subject: [PATCH 11/99] Test conversion to point. --- t/xy/d2p.t.js | 7 +++++++ 1 file changed, 7 insertions(+) create mode 100755 t/xy/d2p.t.js diff --git a/t/xy/d2p.t.js b/t/xy/d2p.t.js new file mode 100755 index 0000000..222b259 --- /dev/null +++ b/t/xy/d2p.t.js @@ -0,0 +1,7 @@ +#!/usr/bin/env node + +require('proof')(2, function(assert) { + var xy = require('../../index.js') + assert(xy.d2p(2, 0), [0, 0]) + assert(xy.d2p(2, 3), [0, 1]) +}) From 40ca0de525a24187acaeb57a7138808782ac723d Mon Sep 17 00:00:00 2001 From: Demarius Chrite Date: Fri, 31 Oct 2014 18:28:19 -0400 Subject: [PATCH 12/99] Test conversion to distance. --- t/xy/p2d.t.js | 7 +++++++ 1 file changed, 7 insertions(+) create mode 100644 t/xy/p2d.t.js diff --git a/t/xy/p2d.t.js b/t/xy/p2d.t.js new file mode 100644 index 0000000..46c41e6 --- /dev/null +++ b/t/xy/p2d.t.js @@ -0,0 +1,7 @@ +#!/usr/bin/env node + +require('proof')(2, function(assert) { + var xy = require('../../index.js') + assert(xy.p2d(2, 0, 0), 0) + assert(xy.p2d(2, 0, 1), 3) +}) From 195922d90c43712fc6c12d6384706621b4251bf8 Mon Sep 17 00:00:00 2001 From: Demarius Chrite Date: Wed, 29 Oct 2014 13:42:59 -0400 Subject: [PATCH 13/99] Diary entry. 3d implementations. --- diary.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/diary.md b/diary.md index 81b38d3..b017b05 100644 --- a/diary.md +++ b/diary.md @@ -3,3 +3,5 @@ the function convertPointToDistance requires 'height' to be a power of 2. Lookin http://www.win.tue.nl/~hermanh/stack/dagstuhl08-talk.pdf pseudo-code: http://www.fundza.com/algorithmic/space_filling/hilbert/basics/index.html + +http://arxiv.org/abs/1109.2323 From d3101ab22f5d1f8802b6b7ed7531f34dd87069ad Mon Sep 17 00:00:00 2001 From: Demarius Chrite Date: Sat, 1 Nov 2014 16:21:44 -0400 Subject: [PATCH 14/99] Renaming. --- index.js | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/index.js b/index.js index e6548dc..f3130c8 100644 --- a/index.js +++ b/index.js @@ -4,7 +4,7 @@ // Accepts the height or width of a square/graph, and the coordinates to // convert. -function convertPointToDistance (height, x, y) { // :: Int -> Int -> Int -> Int +function convert2dPointToDistance (height, x, y) { // :: Int -> Int -> Int -> Int var xbit, ybit, level, d = 0 if (height < 2) { height = 2 @@ -29,7 +29,7 @@ function convertPointToDistance (height, x, y) { // :: Int -> Int -> Int -> Int } // Accepts height or width of a square/graph and distance -function convertDistanceToPoint (height, distance) { // :: Int -> Int -> [Int, Int] +function convertDistanceTo2dPoint (height, distance) { // :: Int -> Int -> [Int, Int] distance = Math.floor(distance) var xbit, ybit, level var x = 0, y = 0 @@ -53,7 +53,7 @@ function convertDistanceToPoint (height, distance) { // :: Int -> Int -> [Int, I } // Rotate the coordinate plane and (x,y) -function rotate (n, x, y, xbit, ybit) { // :: Int -> Int -> Int -> Int -> Int -> [Int, Int] +function rotate2d (n, x, y, xbit, ybit) { // :: Int -> Int -> Int -> Int -> Int -> [Int, Int] if (ybit === 0 ) { if (xbit === 1) { x = n - 1 - x @@ -68,5 +68,5 @@ function rotate (n, x, y, xbit, ybit) { // :: Int -> Int -> Int -> Int -> Int -> return [x, y] } -exports.p2d = convertPointToDistance -exports.d2p = convertDistanceToPoint +exports.p2d = convert2dPointToDistance +exports.d2p = convertDistanceTo2dPoint From 8f39a58893e304b2be00855a9aa57ec430c921b2 Mon Sep 17 00:00:00 2001 From: Demarius Chrite Date: Sun, 2 Nov 2014 19:15:54 -0400 Subject: [PATCH 15/99] Working on 3D conversions. --- index.js | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/index.js b/index.js index f3130c8..0f4ee02 100644 --- a/index.js +++ b/index.js @@ -28,6 +28,9 @@ function convert2dPointToDistance (height, x, y) { // :: Int -> Int -> Int -> In return d } +function convert3dPointToDistance (height, distance) { +} + // Accepts height or width of a square/graph and distance function convertDistanceTo2dPoint (height, distance) { // :: Int -> Int -> [Int, Int] distance = Math.floor(distance) @@ -52,6 +55,22 @@ function convertDistanceTo2dPoint (height, distance) { // :: Int -> Int -> [Int, return [x, y] } +function convertDistanceTo3dPoint (height, distance) { + distance = Math.floor(distance) + var xbit, ybit, zbit, level + if (height < 2) { + height = 2 + } + + for (level = 1; level < height || distance > 0; level *=2) { + xbit = distance & 1; + ybit = (ditance / 2) & 1; + zbit = (distance / 4) & 1; + + // do some rotations + } +} + // Rotate the coordinate plane and (x,y) function rotate2d (n, x, y, xbit, ybit) { // :: Int -> Int -> Int -> Int -> Int -> [Int, Int] if (ybit === 0 ) { From 7f9312cec4895128e61f4eba4b82d8158ccd8ee1 Mon Sep 17 00:00:00 2001 From: Demarius Chrite Date: Mon, 3 Nov 2014 20:53:13 -0400 Subject: [PATCH 16/99] Fix rotate2d() calls. --- index.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/index.js b/index.js index 0f4ee02..a705baf 100644 --- a/index.js +++ b/index.js @@ -20,7 +20,7 @@ function convert2dPointToDistance (height, x, y) { // :: Int -> Int -> Int -> In d += level * level * ((3 * xbit) ^ ybit) // rotate so that we'll be in sync with the next // region. - var temp = rotate (height, x, y, xbit, ybit) + var temp = rotate2d(height, x, y, xbit, ybit) x = temp[0] y = temp[1] } @@ -44,7 +44,7 @@ function convertDistanceTo2dPoint (height, distance) { // :: Int -> Int -> [Int, ybit = 1 & (distance / 2) xbit = 1 & (ybit ^ distance) - var temp = rotate(level, x, y, xbit, ybit) + var temp = rotate2d(level, x, y, xbit, ybit) x = temp[0] y = temp[1] x += level * xbit From 8d385ed548e262af251bb53e3fde3da2f0918cba Mon Sep 17 00:00:00 2001 From: Demarius Chrite Date: Tue, 4 Nov 2014 21:35:37 -0400 Subject: [PATCH 17/99] Implement rotate3d(). --- index.js | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/index.js b/index.js index a705baf..84b0b66 100644 --- a/index.js +++ b/index.js @@ -87,5 +87,20 @@ function rotate2d (n, x, y, xbit, ybit) { // :: Int -> Int -> Int -> Int -> Int return [x, y] } +function rotate3d(level, x, y, z) { + index = 4 * z + 2 * y + x + if (index == 0) { + return [z, x, y] + } else if (index == 1 || index == 3) { + return [y, z, x] + } else if (index == 2 || index == 6) { + return [level - x, level - y, z] + } else if (index == 5 || index == 7) { + return [y, level - z, level - x] + } else { + return [level - z, x, level - y] + } +} + exports.p2d = convert2dPointToDistance exports.d2p = convertDistanceTo2dPoint From 6fe52fe7ba012da457fea78bd6f4c7ffe06d9720 Mon Sep 17 00:00:00 2001 From: Demarius Chrite Date: Wed, 5 Nov 2014 23:14:21 -0400 Subject: [PATCH 18/99] Working on 3D. --- index.js | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/index.js b/index.js index 84b0b66..ee4faa2 100644 --- a/index.js +++ b/index.js @@ -58,6 +58,7 @@ function convertDistanceTo2dPoint (height, distance) { // :: Int -> Int -> [Int, function convertDistanceTo3dPoint (height, distance) { distance = Math.floor(distance) var xbit, ybit, zbit, level + var x = 0, y = 0, z = 0 if (height < 2) { height = 2 } @@ -67,7 +68,12 @@ function convertDistanceTo3dPoint (height, distance) { ybit = (ditance / 2) & 1; zbit = (distance / 4) & 1; - // do some rotations + var temp = rotate3d(level - 1, xbit ^ ybit, ybit ^ zbit, zbit) + x = temp[0] * level + level - 1 + y = temp[1] * level + level - 1 + z = temp[2] * level + level - 1 + + distance = Math.floor(distance / 8) } } From 5f5686d45e9baca8cb8be3bdc4c87dff6862b303 Mon Sep 17 00:00:00 2001 From: Demarius Chrite Date: Thu, 6 Nov 2014 21:27:23 -0500 Subject: [PATCH 19/99] Diary entry. axis rotation. --- diary.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/diary.md b/diary.md index b017b05..6b1bc3b 100644 --- a/diary.md +++ b/diary.md @@ -5,3 +5,5 @@ http://www.win.tue.nl/~hermanh/stack/dagstuhl08-talk.pdf pseudo-code: http://www.fundza.com/algorithmic/space_filling/hilbert/basics/index.html http://arxiv.org/abs/1109.2323 + +Axis rotation: http://www.siggraph.org/education/materials/HyperGraph/modeling/mod_tran/3drota.htm#X-Axis%20Rotation From 92a57837b4efd070a6b8cadf0fdb3c1638b595a5 Mon Sep 17 00:00:00 2001 From: Demarius Chrite Date: Fri, 7 Nov 2014 22:17:50 -0400 Subject: [PATCH 20/99] Fix function params. --- index.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/index.js b/index.js index ee4faa2..b13e647 100644 --- a/index.js +++ b/index.js @@ -28,7 +28,7 @@ function convert2dPointToDistance (height, x, y) { // :: Int -> Int -> Int -> In return d } -function convert3dPointToDistance (height, distance) { +function convert3dPointToDistance (height, x, y, z) { } // Accepts height or width of a square/graph and distance From 4d6134b7a9779292e8d9b1a83f8696106d4b4663 Mon Sep 17 00:00:00 2001 From: Demarius Chrite Date: Sat, 8 Nov 2014 23:58:19 -0500 Subject: [PATCH 21/99] Working on 3d->distance. --- index.js | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/index.js b/index.js index b13e647..ab443f0 100644 --- a/index.js +++ b/index.js @@ -29,6 +29,10 @@ function convert2dPointToDistance (height, x, y) { // :: Int -> Int -> Int -> In } function convert3dPointToDistance (height, x, y, z) { + var s = 1, level = 0, max = Math.max.apply(Math, [x, y, z]) + for (;, 2 * s <= max; s *= 2) { + level = (level + 1) % 3 + } } // Accepts height or width of a square/graph and distance From d17bdea8fd8b1110a0fa0c8ebbd7c1741dd044f7 Mon Sep 17 00:00:00 2001 From: Demarius Chrite Date: Sun, 9 Nov 2014 13:43:22 -0400 Subject: [PATCH 22/99] Parity. --- index.js | 1 + 1 file changed, 1 insertion(+) diff --git a/index.js b/index.js index ab443f0..30dd0bc 100644 --- a/index.js +++ b/index.js @@ -66,6 +66,7 @@ function convertDistanceTo3dPoint (height, distance) { if (height < 2) { height = 2 } + var parity = height % 3; for (level = 1; level < height || distance > 0; level *=2) { xbit = distance & 1; From 3aa16682f0063b955f12372739ee2bcb42e0f6da Mon Sep 17 00:00:00 2001 From: Demarius Chrite Date: Mon, 10 Nov 2014 19:02:23 -0400 Subject: [PATCH 23/99] Diary entry. parity. --- diary.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/diary.md b/diary.md index 6b1bc3b..ad79ddd 100644 --- a/diary.md +++ b/diary.md @@ -7,3 +7,5 @@ pseudo-code: http://www.fundza.com/algorithmic/space_filling/hilbert/basics/inde http://arxiv.org/abs/1109.2323 Axis rotation: http://www.siggraph.org/education/materials/HyperGraph/modeling/mod_tran/3drota.htm#X-Axis%20Rotation + +parity: http://en.wikipedia.org/wiki/Parity_%28mathematics%29 http://en.wikipedia.org/wiki/Parity_bit From ae78aa8f27ad39e7bf5d29996086f0db31e6267d Mon Sep 17 00:00:00 2001 From: Demarius Chrite Date: Tue, 11 Nov 2014 19:56:01 -0400 Subject: [PATCH 24/99] Diary entry. --- diary.md | 3 +++ 1 file changed, 3 insertions(+) diff --git a/diary.md b/diary.md index ad79ddd..66c8c8c 100644 --- a/diary.md +++ b/diary.md @@ -9,3 +9,6 @@ http://arxiv.org/abs/1109.2323 Axis rotation: http://www.siggraph.org/education/materials/HyperGraph/modeling/mod_tran/3drota.htm#X-Axis%20Rotation parity: http://en.wikipedia.org/wiki/Parity_%28mathematics%29 http://en.wikipedia.org/wiki/Parity_bit + +Want to express axis rotations internally without creating a point object. +or perhaps use one internally but return an array. From f7ab6e642cd8708fc3e2a48ea343c279bcf06217 Mon Sep 17 00:00:00 2001 From: Demarius Chrite Date: Sat, 15 Nov 2014 16:37:48 -0400 Subject: [PATCH 25/99] Function signatures. --- index.js | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/index.js b/index.js index 30dd0bc..fe68b1d 100644 --- a/index.js +++ b/index.js @@ -28,7 +28,8 @@ function convert2dPointToDistance (height, x, y) { // :: Int -> Int -> Int -> In return d } -function convert3dPointToDistance (height, x, y, z) { +// height and coordinates. +function convert3dPointToDistance (height, x, y, z) { // :: Int -> Int -> Int -> Int -> Int var s = 1, level = 0, max = Math.max.apply(Math, [x, y, z]) for (;, 2 * s <= max; s *= 2) { level = (level + 1) % 3 @@ -59,7 +60,8 @@ function convertDistanceTo2dPoint (height, distance) { // :: Int -> Int -> [Int, return [x, y] } -function convertDistanceTo3dPoint (height, distance) { +// height/width of a square/graph and distance +function convertDistanceTo3dPoint (height, distance) { // Int -> Int -> [Int, Int, Int] distance = Math.floor(distance) var xbit, ybit, zbit, level var x = 0, y = 0, z = 0 @@ -98,7 +100,8 @@ function rotate2d (n, x, y, xbit, ybit) { // :: Int -> Int -> Int -> Int -> Int return [x, y] } -function rotate3d(level, x, y, z) { +// Rotate the coordinate plane and (x,y, z) +function rotate3d(level, x, y, z) { // :: Int -> Int -> Int -> Int -> [Int, Int, Int] index = 4 * z + 2 * y + x if (index == 0) { return [z, x, y] From 3dc0ced4da37762c5ecca9bf66e73c1061f95778 Mon Sep 17 00:00:00 2001 From: Demarius Chrite Date: Sun, 16 Nov 2014 13:27:11 -0400 Subject: [PATCH 26/99] Compiles. --- index.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/index.js b/index.js index fe68b1d..08fbe7e 100644 --- a/index.js +++ b/index.js @@ -31,7 +31,7 @@ function convert2dPointToDistance (height, x, y) { // :: Int -> Int -> Int -> In // height and coordinates. function convert3dPointToDistance (height, x, y, z) { // :: Int -> Int -> Int -> Int -> Int var s = 1, level = 0, max = Math.max.apply(Math, [x, y, z]) - for (;, 2 * s <= max; s *= 2) { + for (; 2 * s <= max; s *= 2) { level = (level + 1) % 3 } } From 4b57ddf243dd849ac1e549107a04be53666c23f3 Mon Sep 17 00:00:00 2001 From: Demarius Chrite Date: Mon, 17 Nov 2014 11:34:13 -0500 Subject: [PATCH 27/99] Add point object. --- index.js | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/index.js b/index.js index 08fbe7e..359e3a5 100644 --- a/index.js +++ b/index.js @@ -1,6 +1,15 @@ // Use Hilbert curve point generation to map 2D data to 1D space and vice-versa. // Will later expand to allow `n` dimensions. +function Point(x, y, z) { + this.x = Math.round(x) || 0 + this.y = Math.round(y) || 0 + this.z = Math.round(z) || 0 + + this.array = function () { + return [this.x, this.y, this.z] + } +} // Accepts the height or width of a square/graph, and the coordinates to // convert. From 41a0fefb4932c08124da5ddc3de5707f2a83f8fe Mon Sep 17 00:00:00 2001 From: Demarius Chrite Date: Tue, 18 Nov 2014 13:47:35 -0400 Subject: [PATCH 28/99] Expand point object. --- index.js | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/index.js b/index.js index 359e3a5..4b01018 100644 --- a/index.js +++ b/index.js @@ -4,10 +4,16 @@ function Point(x, y, z) { this.x = Math.round(x) || 0 this.y = Math.round(y) || 0 - this.z = Math.round(z) || 0 + if (z) { + this.z = Math.round(z) || 0 + this.d = 3 + } else { + this.d = 2 + } this.array = function () { - return [this.x, this.y, this.z] + if (this.d == 3) { return [this.x, this.y, this.z] } + return [this.x, this.y] } } From d1a13b8c51dbbd05deb1afeeceb42042fda758f2 Mon Sep 17 00:00:00 2001 From: Demarius Chrite Date: Wed, 19 Nov 2014 22:23:59 -0400 Subject: [PATCH 29/99] 'roatateLeft()'. --- index.js | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/index.js b/index.js index 4b01018..c79fa5a 100644 --- a/index.js +++ b/index.js @@ -8,6 +8,7 @@ function Point(x, y, z) { this.z = Math.round(z) || 0 this.d = 3 } else { + this.z = null this.d = 2 } @@ -17,6 +18,13 @@ function Point(x, y, z) { } } +Point.prototype.rotateLeft = function (n) { + if (n % 3 == 0) return this + if (n % 3 == 1) return new Point(this.y, this.z, this.x) + return new Point(this.z, this.x, this.y) +} + + // Accepts the height or width of a square/graph, and the coordinates to // convert. function convert2dPointToDistance (height, x, y) { // :: Int -> Int -> Int -> Int @@ -45,7 +53,7 @@ function convert2dPointToDistance (height, x, y) { // :: Int -> Int -> Int -> In // height and coordinates. function convert3dPointToDistance (height, x, y, z) { // :: Int -> Int -> Int -> Int -> Int - var s = 1, level = 0, max = Math.max.apply(Math, [x, y, z]) + var s = 1, level = 0, max = Math.max.apply(Math, [x, y, z]), p = new Point(x, y, z) for (; 2 * s <= max; s *= 2) { level = (level + 1) % 3 } From 4ca1b6785091f4a9ab6d95d1f1ff6bbf57ca4c92 Mon Sep 17 00:00:00 2001 From: Demarius Chrite Date: Thu, 20 Nov 2014 14:53:12 -0400 Subject: [PATCH 30/99] 'rotateRight()'. --- index.js | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/index.js b/index.js index c79fa5a..d6a5bb6 100644 --- a/index.js +++ b/index.js @@ -24,6 +24,11 @@ Point.prototype.rotateLeft = function (n) { return new Point(this.z, this.x, this.y) } +Point.prototype.rotateRight = function (n) { + if (n % 3 == 0) return this + if (n % 3 == 1) return new Point(this.z, this.x, this.y) + return new Point(this.y, this.z, this.x) +} // Accepts the height or width of a square/graph, and the coordinates to // convert. From 1b15bfc5b56e3a0bce85f351d389d916de1111e4 Mon Sep 17 00:00:00 2001 From: Demarius Chrite Date: Fri, 21 Nov 2014 22:26:02 -0400 Subject: [PATCH 31/99] Switching to point object. --- index.js | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) diff --git a/index.js b/index.js index d6a5bb6..9e4caa3 100644 --- a/index.js +++ b/index.js @@ -32,7 +32,7 @@ Point.prototype.rotateRight = function (n) { // Accepts the height or width of a square/graph, and the coordinates to // convert. -function convert2dPointToDistance (height, x, y) { // :: Int -> Int -> Int -> Int +function convert2dPointToDistance (height, p) { // :: Int -> Int -> Int -> Int var xbit, ybit, level, d = 0 if (height < 2) { height = 2 @@ -42,15 +42,15 @@ function convert2dPointToDistance (height, x, y) { // :: Int -> Int -> Int -> In // `d` based on which region we are in for (level = height / 2; level > 0; level /= 2) { // Determine what region we're in - xbit = (x & level) > 0 - ybit = (y & level) > 0 + xbit = (p.x & level) > 0 + ybit = (p.y & level) > 0 // increase distance based on region d += level * level * ((3 * xbit) ^ ybit) // rotate so that we'll be in sync with the next // region. - var temp = rotate2d(height, x, y, xbit, ybit) - x = temp[0] - y = temp[1] + var temp = rotate2d(height, p.x, p.y, xbit, ybit) + p.x = temp[0] + p.y = temp[1] } return d @@ -144,5 +144,7 @@ function rotate3d(level, x, y, z) { // :: Int -> Int -> Int -> Int -> [Int, Int, } } -exports.p2d = convert2dPointToDistance +exports.p2d = function (height, x, y) { + return convert2dPointToDistance(height, new Point(x, y)) +} exports.d2p = convertDistanceTo2dPoint From 04324f8af63cc44624c8176efbfb84c37cd5ce43 Mon Sep 17 00:00:00 2001 From: Demarius Chrite Date: Sat, 22 Nov 2014 12:38:46 -0400 Subject: [PATCH 32/99] Point.n. --- index.js | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/index.js b/index.js index 9e4caa3..532b21d 100644 --- a/index.js +++ b/index.js @@ -16,6 +16,10 @@ function Point(x, y, z) { if (this.d == 3) { return [this.x, this.y, this.z] } return [this.x, this.y] } + + this.n = function () { + return 4 * this.z + 2 * this.y + this.x + } } Point.prototype.rotateLeft = function (n) { From 47a1eb5363a7adb82c107217a745204a82bdd0b0 Mon Sep 17 00:00:00 2001 From: Demarius Chrite Date: Mon, 24 Nov 2014 02:01:54 -0400 Subject: [PATCH 33/99] Diary entry. --- diary.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/diary.md b/diary.md index 66c8c8c..711eb4d 100644 --- a/diary.md +++ b/diary.md @@ -12,3 +12,5 @@ parity: http://en.wikipedia.org/wiki/Parity_%28mathematics%29 http://en.wikipedi Want to express axis rotations internally without creating a point object. or perhaps use one internally but return an array. + +move Point to own module for reuse in Voronoi diagram calculator and r-tree From 4981c2a9e73668b131762eaa0876642b0907346a Mon Sep 17 00:00:00 2001 From: Demarius Chrite Date: Tue, 25 Nov 2014 23:00:48 -0500 Subject: [PATCH 34/99] Cleanup. --- index.js | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/index.js b/index.js index 532b21d..1e842f4 100644 --- a/index.js +++ b/index.js @@ -72,7 +72,7 @@ function convert3dPointToDistance (height, x, y, z) { // :: Int -> Int -> Int -> function convertDistanceTo2dPoint (height, distance) { // :: Int -> Int -> [Int, Int] distance = Math.floor(distance) var xbit, ybit, level - var x = 0, y = 0 + var p = new Point(0, 0) if (height < 2) { height = 2 } @@ -82,14 +82,14 @@ function convertDistanceTo2dPoint (height, distance) { // :: Int -> Int -> [Int, xbit = 1 & (ybit ^ distance) var temp = rotate2d(level, x, y, xbit, ybit) - x = temp[0] - y = temp[1] - x += level * xbit - y += level * ybit + p.x = temp[0] + p.y = temp[1] + p.x += level * xbit + p.y += level * ybit distance = Math.floor(distance / 4) } - return [x, y] + return p } // height/width of a square/graph and distance From 7b01fb93b090e3be7c041fc652c3a93cdf48771a Mon Sep 17 00:00:00 2001 From: Demarius Chrite Date: Wed, 26 Nov 2014 22:59:38 -0400 Subject: [PATCH 35/99] Point.toArray(). --- index.js | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/index.js b/index.js index 1e842f4..896c3fb 100644 --- a/index.js +++ b/index.js @@ -12,11 +12,6 @@ function Point(x, y, z) { this.d = 2 } - this.array = function () { - if (this.d == 3) { return [this.x, this.y, this.z] } - return [this.x, this.y] - } - this.n = function () { return 4 * this.z + 2 * this.y + this.x } @@ -34,6 +29,11 @@ Point.prototype.rotateRight = function (n) { return new Point(this.y, this.z, this.x) } +Point.prototype.toArray = function () { + if (this.d == 3) { return [this.x, this.y, this.z] } + return [this.x, this.y] +} + // Accepts the height or width of a square/graph, and the coordinates to // convert. function convert2dPointToDistance (height, p) { // :: Int -> Int -> Int -> Int From f5fc1d4adc8dfed6e11f8d36752b0c9ff9083fab Mon Sep 17 00:00:00 2001 From: Demarius Chrite Date: Thu, 27 Nov 2014 16:23:42 -0400 Subject: [PATCH 36/99] Point.n(). --- index.js | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/index.js b/index.js index 896c3fb..a95565c 100644 --- a/index.js +++ b/index.js @@ -12,9 +12,6 @@ function Point(x, y, z) { this.d = 2 } - this.n = function () { - return 4 * this.z + 2 * this.y + this.x - } } Point.prototype.rotateLeft = function (n) { @@ -34,6 +31,10 @@ Point.prototype.toArray = function () { return [this.x, this.y] } +Point.prototype.n = function () { + return 4 * this.z + 2 * this.y + this.x +} + // Accepts the height or width of a square/graph, and the coordinates to // convert. function convert2dPointToDistance (height, p) { // :: Int -> Int -> Int -> Int From b241d57404829fe2dbf29ca0ee5288974d769732 Mon Sep 17 00:00:00 2001 From: Demarius Chrite Date: Fri, 28 Nov 2014 15:36:51 -0400 Subject: [PATCH 37/99] Point.rotateLeft(). --- index.js | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/index.js b/index.js index a95565c..42b9978 100644 --- a/index.js +++ b/index.js @@ -12,12 +12,20 @@ function Point(x, y, z) { this.d = 2 } + this.rotateLeft2d = function (n) { + if (n % 3 == 0) return this + if (n % 3 == 1) return new Point(this.y, this.z, this.x) + return new Point(this.z, this.x, this.y) + } + } Point.prototype.rotateLeft = function (n) { - if (n % 3 == 0) return this - if (n % 3 == 1) return new Point(this.y, this.z, this.x) - return new Point(this.z, this.x, this.y) + if (this.d == 2) { + return this.rotateLeft2d(n) + } + + return this.rotateLeft3d(n) } Point.prototype.rotateRight = function (n) { From 74faaca02c0eb5d242d94a60036cca4c1f609a12 Mon Sep 17 00:00:00 2001 From: Demarius Chrite Date: Sat, 29 Nov 2014 10:18:18 -0500 Subject: [PATCH 38/99] Point.rotateRight(). --- index.js | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/index.js b/index.js index 42b9978..6f0fa21 100644 --- a/index.js +++ b/index.js @@ -18,6 +18,11 @@ function Point(x, y, z) { return new Point(this.z, this.x, this.y) } + this.rotateRight2d = function (n) { + if (n % 3 == 0) return this + if (n % 3 == 1) return new Point(this.z, this.x, this.y) + return new Point(this.y, this.z, this.x) + } } Point.prototype.rotateLeft = function (n) { @@ -29,9 +34,11 @@ Point.prototype.rotateLeft = function (n) { } Point.prototype.rotateRight = function (n) { - if (n % 3 == 0) return this - if (n % 3 == 1) return new Point(this.z, this.x, this.y) - return new Point(this.y, this.z, this.x) + if (this.d == 2) { + return this.rotateRight2d(n) + } + + return this.rotateRight3d(n) } Point.prototype.toArray = function () { From efaa29cb7477a6690b48314498f456383bb7c651 Mon Sep 17 00:00:00 2001 From: Demarius Chrite Date: Sun, 30 Nov 2014 20:29:05 -0400 Subject: [PATCH 39/99] Point.mod(). --- index.js | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/index.js b/index.js index 6f0fa21..7afdbfb 100644 --- a/index.js +++ b/index.js @@ -50,6 +50,10 @@ Point.prototype.n = function () { return 4 * this.z + 2 * this.y + this.x } +Point.prototype.mod = function (n) { + return new Point(this.x % n, this.y % n, this.z % n) +} + // Accepts the height or width of a square/graph, and the coordinates to // convert. function convert2dPointToDistance (height, p) { // :: Int -> Int -> Int -> Int From c219a5cb99fa78c4ee12eede408550a980c2b842 Mon Sep 17 00:00:00 2001 From: Demarius Chrite Date: Mon, 1 Dec 2014 21:42:17 -0400 Subject: [PATCH 40/99] Fix rotation names. --- index.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/index.js b/index.js index 7afdbfb..695436c 100644 --- a/index.js +++ b/index.js @@ -12,13 +12,13 @@ function Point(x, y, z) { this.d = 2 } - this.rotateLeft2d = function (n) { + this.rotateLeft3d = function (n) { if (n % 3 == 0) return this if (n % 3 == 1) return new Point(this.y, this.z, this.x) return new Point(this.z, this.x, this.y) } - this.rotateRight2d = function (n) { + this.rotateRight3d = function (n) { if (n % 3 == 0) return this if (n % 3 == 1) return new Point(this.z, this.x, this.y) return new Point(this.y, this.z, this.x) From 307faf9e1985641c8dd7af9b5819a21c3e1d58ba Mon Sep 17 00:00:00 2001 From: Demarius Chrite Date: Wed, 3 Dec 2014 14:32:00 -0500 Subject: [PATCH 41/99] Working out rotations. --- diary.md | 2 ++ index.js | 6 ++++++ 2 files changed, 8 insertions(+) diff --git a/diary.md b/diary.md index 711eb4d..62d4072 100644 --- a/diary.md +++ b/diary.md @@ -14,3 +14,5 @@ Want to express axis rotations internally without creating a point object. or perhaps use one internally but return an array. move Point to own module for reuse in Voronoi diagram calculator and r-tree + +http://en.wikipedia.org/wiki/Rotation_matrix diff --git a/index.js b/index.js index 695436c..d2b8127 100644 --- a/index.js +++ b/index.js @@ -18,11 +18,17 @@ function Point(x, y, z) { return new Point(this.z, this.x, this.y) } + this.rotateLeft2d = function (n) { + } + this.rotateRight3d = function (n) { if (n % 3 == 0) return this if (n % 3 == 1) return new Point(this.z, this.x, this.y) return new Point(this.y, this.z, this.x) } + + this.rotateRight2d = function (n) { + } } Point.prototype.rotateLeft = function (n) { From 959f672f17a5d4e8424e3ef9e135613939df81f7 Mon Sep 17 00:00:00 2001 From: Demarius Chrite Date: Tue, 2 Dec 2014 15:32:57 -0400 Subject: [PATCH 42/99] Utilities for 3d. --- index.js | 3 +++ 1 file changed, 3 insertions(+) diff --git a/index.js b/index.js index d2b8127..14dc405 100644 --- a/index.js +++ b/index.js @@ -60,6 +60,9 @@ Point.prototype.mod = function (n) { return new Point(this.x % n, this.y % n, this.z % n) } +Point.prototype.unrotate = function (n) { +} + // Accepts the height or width of a square/graph, and the coordinates to // convert. function convert2dPointToDistance (height, p) { // :: Int -> Int -> Int -> Int From 5f3e67244423f46ac76a074c2817acfb773f371e Mon Sep 17 00:00:00 2001 From: Demarius Chrite Date: Thu, 4 Dec 2014 18:26:11 -0400 Subject: [PATCH 43/99] Changing rotations. --- index.js | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/index.js b/index.js index 14dc405..9f8d96d 100644 --- a/index.js +++ b/index.js @@ -31,9 +31,9 @@ function Point(x, y, z) { } } -Point.prototype.rotateLeft = function (n) { +Point.prototype.rotateLeft = function (n, xbit, ybit) { if (this.d == 2) { - return this.rotateLeft2d(n) + rotate2d(this.x, this.y n, xbit, ybit) } return this.rotateLeft3d(n) @@ -41,7 +41,7 @@ Point.prototype.rotateLeft = function (n) { Point.prototype.rotateRight = function (n) { if (this.d == 2) { - return this.rotateRight2d(n) + return rotate2d(this.x, this.y, n xbit, ybit) } return this.rotateRight3d(n) From df418df0d13389a62c9849376afb1b14b2fd799e Mon Sep 17 00:00:00 2001 From: Demarius Chrite Date: Fri, 5 Dec 2014 15:38:45 -0400 Subject: [PATCH 44/99] Remove 2d rotations. --- index.js | 34 ++++++---------------------------- 1 file changed, 6 insertions(+), 28 deletions(-) diff --git a/index.js b/index.js index 9f8d96d..1ebea43 100644 --- a/index.js +++ b/index.js @@ -11,40 +11,18 @@ function Point(x, y, z) { this.z = null this.d = 2 } - - this.rotateLeft3d = function (n) { - if (n % 3 == 0) return this - if (n % 3 == 1) return new Point(this.y, this.z, this.x) - return new Point(this.z, this.x, this.y) - } - - this.rotateLeft2d = function (n) { - } - - this.rotateRight3d = function (n) { - if (n % 3 == 0) return this - if (n % 3 == 1) return new Point(this.z, this.x, this.y) - return new Point(this.y, this.z, this.x) - } - - this.rotateRight2d = function (n) { - } } Point.prototype.rotateLeft = function (n, xbit, ybit) { - if (this.d == 2) { - rotate2d(this.x, this.y n, xbit, ybit) - } - - return this.rotateLeft3d(n) + if (n % 3 == 0) return this + if (n % 3 == 1) return new Point(this.y, this.z, this.x) + return new Point(this.z, this.x, this.y) } Point.prototype.rotateRight = function (n) { - if (this.d == 2) { - return rotate2d(this.x, this.y, n xbit, ybit) - } - - return this.rotateRight3d(n) + if (n % 3 == 0) return this + if (n % 3 == 1) return new Point(this.z, this.x, this.y) + return new Point(this.y, this.z, this.x) } Point.prototype.toArray = function () { From dc2eb4692830fc38ae22b24635f9edc320954995 Mon Sep 17 00:00:00 2001 From: Demarius Chrite Date: Sat, 6 Dec 2014 16:19:21 -0400 Subject: [PATCH 45/99] Use general rotate2d(). --- index.js | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/index.js b/index.js index 1ebea43..15ed236 100644 --- a/index.js +++ b/index.js @@ -13,6 +13,10 @@ function Point(x, y, z) { } } +Point.prototype.rotate2d(n, xbit, ybit) { + return rotate2d(n, this.x, this.y, xbit, ybit) +} + Point.prototype.rotateLeft = function (n, xbit, ybit) { if (n % 3 == 0) return this if (n % 3 == 1) return new Point(this.y, this.z, this.x) From a056237749b878e610038891e453851bd436b924 Mon Sep 17 00:00:00 2001 From: Demarius Chrite Date: Sun, 7 Dec 2014 22:49:04 -0400 Subject: [PATCH 46/99] Change point parameters and make rotate2d() useful. --- index.js | 19 ++++++++++++++----- 1 file changed, 14 insertions(+), 5 deletions(-) diff --git a/index.js b/index.js index 15ed236..9507082 100644 --- a/index.js +++ b/index.js @@ -2,6 +2,17 @@ // Will later expand to allow `n` dimensions. function Point(x, y, z) { + if (x instanceof Array) { + this.x = x[0] + this.y = x[1] + if (x[2]) { + this.z = x[2] + this.d = 3 + } else { + this.z = null + this.d = 2 + } + } this.x = Math.round(x) || 0 this.y = Math.round(y) || 0 if (z) { @@ -13,8 +24,8 @@ function Point(x, y, z) { } } -Point.prototype.rotate2d(n, xbit, ybit) { - return rotate2d(n, this.x, this.y, xbit, ybit) +Point.prototype.rotate2d = function (n, xbit, ybit) { + return new Point(rotate2d(n, this.x, this.y, xbit, ybit)) } Point.prototype.rotateLeft = function (n, xbit, ybit) { @@ -63,9 +74,7 @@ function convert2dPointToDistance (height, p) { // :: Int -> Int -> Int -> Int d += level * level * ((3 * xbit) ^ ybit) // rotate so that we'll be in sync with the next // region. - var temp = rotate2d(height, p.x, p.y, xbit, ybit) - p.x = temp[0] - p.y = temp[1] + p = p.rotate2d(height, p.x, p.y, xbit, ybit) } return d From 35839786ca3094fee286f02709931750686e246e Mon Sep 17 00:00:00 2001 From: Demarius Chrite Date: Mon, 8 Dec 2014 14:09:19 -0400 Subject: [PATCH 47/99] Update convertDistanceTo2dPoint(). --- index.js | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/index.js b/index.js index 9507082..3d47086 100644 --- a/index.js +++ b/index.js @@ -101,9 +101,7 @@ function convertDistanceTo2dPoint (height, distance) { // :: Int -> Int -> [Int, ybit = 1 & (distance / 2) xbit = 1 & (ybit ^ distance) - var temp = rotate2d(level, x, y, xbit, ybit) - p.x = temp[0] - p.y = temp[1] + p = p.rotate2d(level, x, y, xbit, ybit) p.x += level * xbit p.y += level * ybit distance = Math.floor(distance / 4) From fa44b805024d27126b4a14398758161846839c55 Mon Sep 17 00:00:00 2001 From: Demarius Chrite Date: Tue, 9 Dec 2014 21:58:36 -0400 Subject: [PATCH 48/99] Fix Point(). --- index.js | 17 +++++++++-------- 1 file changed, 9 insertions(+), 8 deletions(-) diff --git a/index.js b/index.js index 3d47086..5774adb 100644 --- a/index.js +++ b/index.js @@ -12,15 +12,16 @@ function Point(x, y, z) { this.z = null this.d = 2 } - } - this.x = Math.round(x) || 0 - this.y = Math.round(y) || 0 - if (z) { - this.z = Math.round(z) || 0 - this.d = 3 } else { - this.z = null - this.d = 2 + this.x = Math.round(x) || 0 + this.y = Math.round(y) || 0 + if (z) { + this.z = Math.round(z) || 0 + this.d = 3 + } else { + this.z = null + this.d = 2 + } } } From 7c7b7e145cc4c08a8bea033953ec15b33a363093 Mon Sep 17 00:00:00 2001 From: Demarius Chrite Date: Wed, 10 Dec 2014 20:23:18 -0400 Subject: [PATCH 49/99] Point.rotate3d(). --- index.js | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/index.js b/index.js index 5774adb..f4a1a2c 100644 --- a/index.js +++ b/index.js @@ -29,6 +29,10 @@ Point.prototype.rotate2d = function (n, xbit, ybit) { return new Point(rotate2d(n, this.x, this.y, xbit, ybit)) } +Point.prototype.rotate3d = function (level) { + return new Point(rotate3d(level, this.x, this.y, this.z)) +} + Point.prototype.rotateLeft = function (n, xbit, ybit) { if (n % 3 == 0) return this if (n % 3 == 1) return new Point(this.y, this.z, this.x) From 04c583a96012415abdc7d67250193df25b064c3f Mon Sep 17 00:00:00 2001 From: Demarius Chrite Date: Thu, 11 Dec 2014 10:52:43 -0400 Subject: [PATCH 50/99] Diary entry. --- diary.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/diary.md b/diary.md index 62d4072..1439a2c 100644 --- a/diary.md +++ b/diary.md @@ -16,3 +16,5 @@ or perhaps use one internally but return an array. move Point to own module for reuse in Voronoi diagram calculator and r-tree http://en.wikipedia.org/wiki/Rotation_matrix + +figure out how to keep track of rotations so we can unrotate. From 04aad2949f65cbe63331f801571faa3ccbca0f4b Mon Sep 17 00:00:00 2001 From: Demarius Chrite Date: Fri, 12 Dec 2014 14:12:46 -0400 Subject: [PATCH 51/99] Just put rotations in a {}. --- index.js | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/index.js b/index.js index f4a1a2c..fe7a258 100644 --- a/index.js +++ b/index.js @@ -23,6 +23,12 @@ function Point(x, y, z) { this.d = 2 } } + + this.rotations = { + x: 0, + y: 0, + z: 0 + } } Point.prototype.rotate2d = function (n, xbit, ybit) { From 6b0df8b18e57876d228f375ae65b0ed648599b1a Mon Sep 17 00:00:00 2001 From: Demarius Chrite Date: Sat, 13 Dec 2014 15:32:56 -0400 Subject: [PATCH 52/99] Diary entry. --- diary.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/diary.md b/diary.md index 1439a2c..74117c0 100644 --- a/diary.md +++ b/diary.md @@ -18,3 +18,5 @@ move Point to own module for reuse in Voronoi diagram calculator and r-tree http://en.wikipedia.org/wiki/Rotation_matrix figure out how to keep track of rotations so we can unrotate. + +interesting hilbert implementation. https://github.com/ryan-williams/hilbert-js From 8a92930270c1dd25c5527918174f0941e2f369b6 Mon Sep 17 00:00:00 2001 From: Demarius Chrite Date: Sun, 14 Dec 2014 19:54:02 -0400 Subject: [PATCH 53/99] Function signatures. --- index.js | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/index.js b/index.js index fe7a258..4bf39ec 100644 --- a/index.js +++ b/index.js @@ -31,36 +31,36 @@ function Point(x, y, z) { } } -Point.prototype.rotate2d = function (n, xbit, ybit) { +Point.prototype.rotate2d = function (n, xbit, ybit) { // : Int -> Int -> Int -> Point return new Point(rotate2d(n, this.x, this.y, xbit, ybit)) } -Point.prototype.rotate3d = function (level) { +Point.prototype.rotate3d = function (level) { // :: Int -> Point return new Point(rotate3d(level, this.x, this.y, this.z)) } -Point.prototype.rotateLeft = function (n, xbit, ybit) { +Point.prototype.rotateLeft = function (n, xbit, ybit) { // :: Int -> Int -> Int -> Point if (n % 3 == 0) return this if (n % 3 == 1) return new Point(this.y, this.z, this.x) return new Point(this.z, this.x, this.y) } -Point.prototype.rotateRight = function (n) { +Point.prototype.rotateRight = function (n) { // :: Int -> Point if (n % 3 == 0) return this if (n % 3 == 1) return new Point(this.z, this.x, this.y) return new Point(this.y, this.z, this.x) } -Point.prototype.toArray = function () { +Point.prototype.toArray = function () { // Int :: -> [Int, Int] if (this.d == 3) { return [this.x, this.y, this.z] } return [this.x, this.y] } -Point.prototype.n = function () { +Point.prototype.n = function () { // :: Int return 4 * this.z + 2 * this.y + this.x } -Point.prototype.mod = function (n) { +Point.prototype.mod = function (n) { // :: Int -> Point return new Point(this.x % n, this.y % n, this.z % n) } From 5a4d118208600840612b705e40cdc11745381ca9 Mon Sep 17 00:00:00 2001 From: Demarius Chrite Date: Mon, 15 Dec 2014 12:32:42 -0400 Subject: [PATCH 54/99] Change n to field, not function. --- index.js | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) diff --git a/index.js b/index.js index 4bf39ec..a0a6c99 100644 --- a/index.js +++ b/index.js @@ -7,10 +7,11 @@ function Point(x, y, z) { this.y = x[1] if (x[2]) { this.z = x[2] - this.d = 3 + this.d = 3 } else { this.z = null this.d = 2 + this.n = 4 * this.z + 2 * this.y + this.x } } else { this.x = Math.round(x) || 0 @@ -56,10 +57,6 @@ Point.prototype.toArray = function () { // Int :: -> [Int, Int] return [this.x, this.y] } -Point.prototype.n = function () { // :: Int - return 4 * this.z + 2 * this.y + this.x -} - Point.prototype.mod = function (n) { // :: Int -> Point return new Point(this.x % n, this.y % n, this.z % n) } From 60eeb532707f0c91e0408342e3cc83e4a80053f7 Mon Sep 17 00:00:00 2001 From: Demarius Chrite Date: Tue, 16 Dec 2014 17:54:03 -0400 Subject: [PATCH 55/99] Working on d->3d. --- index.js | 24 ++++++++++++++++++------ 1 file changed, 18 insertions(+), 6 deletions(-) diff --git a/index.js b/index.js index a0a6c99..883f59d 100644 --- a/index.js +++ b/index.js @@ -32,6 +32,13 @@ function Point(x, y, z) { } } +Point.prototype.rotate = function (p, n) { + if (p.n == 0) return new Point(this.z, this.x, this.y) + if (p.n == 1 || p.n == 3) return new Point(this.y, this.z, this.x) + if (p.n == 2 || p.n == 6) return new Point(n - this.x, n - this.y, this.z) + return new Point(n - this.z, this.x, n - this.y) +} + Point.prototype.rotate2d = function (n, xbit, ybit) { // : Int -> Int -> Int -> Point return new Point(rotate2d(n, this.x, this.y, xbit, ybit)) } @@ -121,12 +128,13 @@ function convertDistanceTo2dPoint (height, distance) { // :: Int -> Int -> [Int, // height/width of a square/graph and distance function convertDistanceTo3dPoint (height, distance) { // Int -> Int -> [Int, Int, Int] distance = Math.floor(distance) - var xbit, ybit, zbit, level - var x = 0, y = 0, z = 0 + var xbit, ybit, zbit, level, parity + var x = 0, y = 0, z = 0, iter = 2, log = 0, p = new Point(x, y, z) if (height < 2) { height = 2 } - var parity = height % 3; + for (parity = 1; parity < height; parity *= 2, log++) {} + parity = log % 3; for (level = 1; level < height || distance > 0; level *=2) { xbit = distance & 1; @@ -134,12 +142,16 @@ function convertDistanceTo3dPoint (height, distance) { // Int -> Int -> [Int, In zbit = (distance / 4) & 1; var temp = rotate3d(level - 1, xbit ^ ybit, ybit ^ zbit, zbit) - x = temp[0] * level + level - 1 - y = temp[1] * level + level - 1 - z = temp[2] * level + level - 1 + p.x = temp[0] * level + level - 1 + p.y = temp[1] * level + level - 1 + p.z = temp[2] * level + level - 1 distance = Math.floor(distance / 8) + level *= 2; + iter++; } + + p = p.rotateLeft(iter - parity + 1); } // Rotate the coordinate plane and (x,y) From e8f21f499aea21c6bd1cab80c3b9a0958cb66ad6 Mon Sep 17 00:00:00 2001 From: Demarius Chrite Date: Wed, 17 Dec 2014 19:31:12 -0400 Subject: [PATCH 56/99] Fix rotateLeft() params. --- index.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/index.js b/index.js index 883f59d..3080728 100644 --- a/index.js +++ b/index.js @@ -47,7 +47,7 @@ Point.prototype.rotate3d = function (level) { // :: Int -> Point return new Point(rotate3d(level, this.x, this.y, this.z)) } -Point.prototype.rotateLeft = function (n, xbit, ybit) { // :: Int -> Int -> Int -> Point +Point.prototype.rotateLeft = function (n) { // :: Int -> Point if (n % 3 == 0) return this if (n % 3 == 1) return new Point(this.y, this.z, this.x) return new Point(this.z, this.x, this.y) From 4a9dd04f8ef3b591544d37c83a1818492a12bb5a Mon Sep 17 00:00:00 2001 From: Demarius Chrite Date: Thu, 18 Dec 2014 15:21:38 -0400 Subject: [PATCH 57/99] Cleanup dist -> 3d. --- index.js | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/index.js b/index.js index 3080728..5389877 100644 --- a/index.js +++ b/index.js @@ -129,10 +129,12 @@ function convertDistanceTo2dPoint (height, distance) { // :: Int -> Int -> [Int, function convertDistanceTo3dPoint (height, distance) { // Int -> Int -> [Int, Int, Int] distance = Math.floor(distance) var xbit, ybit, zbit, level, parity - var x = 0, y = 0, z = 0, iter = 2, log = 0, p = new Point(x, y, z) + var iter = 2, log = 0, p = new Point(x, y, z) + if (height < 2) { height = 2 } + for (parity = 1; parity < height; parity *= 2, log++) {} parity = log % 3; @@ -151,7 +153,7 @@ function convertDistanceTo3dPoint (height, distance) { // Int -> Int -> [Int, In iter++; } - p = p.rotateLeft(iter - parity + 1); + return p.rotateLeft(iter - parity + 1); } // Rotate the coordinate plane and (x,y) From 8a241a3afa534afc53265263c9a6a5a776bdd364 Mon Sep 17 00:00:00 2001 From: Demarius Chrite Date: Fri, 19 Dec 2014 18:12:32 -0400 Subject: [PATCH 58/99] Comments. --- index.js | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/index.js b/index.js index 5389877..8cd3acd 100644 --- a/index.js +++ b/index.js @@ -33,6 +33,7 @@ function Point(x, y, z) { } Point.prototype.rotate = function (p, n) { + // record rotations if (p.n == 0) return new Point(this.z, this.x, this.y) if (p.n == 1 || p.n == 3) return new Point(this.y, this.z, this.x) if (p.n == 2 || p.n == 6) return new Point(n - this.x, n - this.y, this.z) @@ -97,7 +98,8 @@ function convert2dPointToDistance (height, p) { // :: Int -> Int -> Int -> Int // height and coordinates. function convert3dPointToDistance (height, x, y, z) { // :: Int -> Int -> Int -> Int -> Int - var s = 1, level = 0, max = Math.max.apply(Math, [x, y, z]), p = new Point(x, y, z) + var s = 1, level = 0, p = new Point(x, y, z) + var max = Math.max.apply(Math, p.toArray()) for (; 2 * s <= max; s *= 2) { level = (level + 1) % 3 } From 51111ea65038df695a0486eba78b9040633be484 Mon Sep 17 00:00:00 2001 From: Demarius Chrite Date: Sat, 20 Dec 2014 16:22:57 -0400 Subject: [PATCH 59/99] Commenting 'unrotate' --- index.js | 1 + 1 file changed, 1 insertion(+) diff --git a/index.js b/index.js index 8cd3acd..538e398 100644 --- a/index.js +++ b/index.js @@ -70,6 +70,7 @@ Point.prototype.mod = function (n) { // :: Int -> Point } Point.prototype.unrotate = function (n) { + // read this.rotations and undo } // Accepts the height or width of a square/graph, and the coordinates to From 8b4a49e0658c7f841ede8e6fd5a1aa9e8b8b0d73 Mon Sep 17 00:00:00 2001 From: Demarius Chrite Date: Sun, 21 Dec 2014 18:23:37 -0400 Subject: [PATCH 60/99] Scoping 3d-> dist. --- index.js | 3 +++ 1 file changed, 3 insertions(+) diff --git a/index.js b/index.js index 538e398..c8dc71b 100644 --- a/index.js +++ b/index.js @@ -104,6 +104,9 @@ function convert3dPointToDistance (height, x, y, z) { // :: Int -> Int -> Int -> for (; 2 * s <= max; s *= 2) { level = (level + 1) % 3 } + + // shuffle axes + // rotate based on parity } // Accepts height or width of a square/graph and distance From a055ae9479c812895072b8358aad732f79a46e55 Mon Sep 17 00:00:00 2001 From: Demarius Chrite Date: Mon, 22 Dec 2014 13:18:47 -0400 Subject: [PATCH 61/99] Exports. --- index.js | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/index.js b/index.js index c8dc71b..62ac9b4 100644 --- a/index.js +++ b/index.js @@ -194,7 +194,8 @@ function rotate3d(level, x, y, z) { // :: Int -> Int -> Int -> Int -> [Int, Int, } } -exports.p2d = function (height, x, y) { +exports.xy2d = function (height, x, y) { return convert2dPointToDistance(height, new Point(x, y)) } -exports.d2p = convertDistanceTo2dPoint +exports.d2xy = convertDistanceTo2dPoint +exports.d2xyz = convertDistanceTo3dPoint From 5b30ff85c6c4207107f2e5e9921bb5b42d07b336 Mon Sep 17 00:00:00 2001 From: Demarius Chrite Date: Tue, 23 Dec 2014 19:22:51 -0400 Subject: [PATCH 62/99] Add algorithm to diary. --- diary.md | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/diary.md b/diary.md index 74117c0..844f963 100644 --- a/diary.md +++ b/diary.md @@ -20,3 +20,17 @@ http://en.wikipedia.org/wiki/Rotation_matrix figure out how to keep track of rotations so we can unrotate. interesting hilbert implementation. https://github.com/ryan-williams/hilbert-js + +2D encoding algorithm: +Outline of the Method + +To encode from index to coordinates: +"Unpack" the index into a list of h D-bit ints (called "index chunks"). +h will be the number of levels of recursion (in our case the number of times to loop); from this calculate the orientation of the overall cube. +Then, for each index chunk, starting at the most- significant, +Use a modified Gray code to convert the index chunk into a D-bit "coordinate chunk" with one bit destined for each of the D coordinates; +Calculate the start and end corners for the child cube to which the indexed point belongs; +Loop to do the child cube. +Finally, +"Pack" the output coordinates by redistributing the D bits from each of h coordinate chunks into D ints, each with h bits. +Decoding is very similar, except that at each stage we Gray- decode D index bits from coordinate bits. At that point the decoder has the same information the encoder uses to calculate the orientation of the child cube for the next stage. From a23d4a15ca86e6c8e3ba7814c73ea637e6d5d31e Mon Sep 17 00:00:00 2001 From: Demarius Chrite Date: Wed, 24 Dec 2014 21:43:07 -0400 Subject: [PATCH 63/99] Diary. n-dimensional mapping. --- diary.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/diary.md b/diary.md index 844f963..c03aa4c 100644 --- a/diary.md +++ b/diary.md @@ -34,3 +34,5 @@ Loop to do the child cube. Finally, "Pack" the output coordinates by redistributing the D bits from each of h coordinate chunks into D ints, each with h bits. Decoding is very similar, except that at each stage we Gray- decode D index bits from coordinate bits. At that point the decoder has the same information the encoder uses to calculate the orientation of the child cube for the next stage. + +N-dimensional mapping. http://www.dcs.bbk.ac.uk/~jkl/pubs/JL1_00a.pdf From 02a04a41d95e2ec34b63097f01c4c443e3a982ed Mon Sep 17 00:00:00 2001 From: Demarius Chrite Date: Sat, 27 Dec 2014 15:21:38 -0400 Subject: [PATCH 64/99] Cleanup. --- index.js | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/index.js b/index.js index 62ac9b4..5c77508 100644 --- a/index.js +++ b/index.js @@ -3,10 +3,10 @@ function Point(x, y, z) { if (x instanceof Array) { - this.x = x[0] - this.y = x[1] + this.x = Math.round(x[0]) || 0 + this.y = Math.round(x[1]) || 0 if (x[2]) { - this.z = x[2] + this.z = Math.round(x[2]) || 0 this.d = 3 } else { this.z = null From bbc864987bec97f8ebe887203be7bd3af1d48af7 Mon Sep 17 00:00:00 2001 From: Demarius Chrite Date: Sun, 28 Dec 2014 22:33:12 -0400 Subject: [PATCH 65/99] Fix 'n'. --- index.js | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/index.js b/index.js index 5c77508..3b3a32e 100644 --- a/index.js +++ b/index.js @@ -8,10 +8,10 @@ function Point(x, y, z) { if (x[2]) { this.z = Math.round(x[2]) || 0 this.d = 3 + this.n = 4 * this.z + 2 * this.y + this.x } else { this.z = null this.d = 2 - this.n = 4 * this.z + 2 * this.y + this.x } } else { this.x = Math.round(x) || 0 @@ -19,6 +19,7 @@ function Point(x, y, z) { if (z) { this.z = Math.round(z) || 0 this.d = 3 + this.n = 4 * this.z + 2 * this.y + this.x } else { this.z = null this.d = 2 From db053a9af1d7bbd517adcefe721777a8ca8c164a Mon Sep 17 00:00:00 2001 From: Demarius Chrite Date: Mon, 29 Dec 2014 17:21:52 -0400 Subject: [PATCH 66/99] separate init for cleaner array handling. --- index.js | 29 ++++++++++++----------------- 1 file changed, 12 insertions(+), 17 deletions(-) diff --git a/index.js b/index.js index 3b3a32e..69dbe53 100644 --- a/index.js +++ b/index.js @@ -2,18 +2,13 @@ // Will later expand to allow `n` dimensions. function Point(x, y, z) { - if (x instanceof Array) { - this.x = Math.round(x[0]) || 0 - this.y = Math.round(x[1]) || 0 - if (x[2]) { - this.z = Math.round(x[2]) || 0 - this.d = 3 - this.n = 4 * this.z + 2 * this.y + this.x - } else { - this.z = null - this.d = 2 - } - } else { + this.rotations = { + x: 0, + y: 0, + z: 0 + } + + this.init = function (x, y, z) { this.x = Math.round(x) || 0 this.y = Math.round(y) || 0 if (z) { @@ -25,11 +20,10 @@ function Point(x, y, z) { this.d = 2 } } - - this.rotations = { - x: 0, - y: 0, - z: 0 + if (x instanceof Array) { + this.init(x[0], x[1], x[2] || null) + } else { + this.init(x, y, z) } } @@ -200,3 +194,4 @@ exports.xy2d = function (height, x, y) { } exports.d2xy = convertDistanceTo2dPoint exports.d2xyz = convertDistanceTo3dPoint +exports.point = Point From 1b462b777bf1f46c51fb38d941458fed9eef27af Mon Sep 17 00:00:00 2001 From: Demarius Chrite Date: Tue, 30 Dec 2014 15:38:45 -0400 Subject: [PATCH 67/99] Fix 'z' in array inits. --- index.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/index.js b/index.js index 69dbe53..9a2b753 100644 --- a/index.js +++ b/index.js @@ -11,7 +11,7 @@ function Point(x, y, z) { this.init = function (x, y, z) { this.x = Math.round(x) || 0 this.y = Math.round(y) || 0 - if (z) { + if (z != null) { this.z = Math.round(z) || 0 this.d = 3 this.n = 4 * this.z + 2 * this.y + this.x @@ -21,7 +21,7 @@ function Point(x, y, z) { } } if (x instanceof Array) { - this.init(x[0], x[1], x[2] || null) + this.init(x[0], x[1], x[2]) } else { this.init(x, y, z) } From 3dcfcf7ff7b00d5e82cf146eff3d85ed3896d021 Mon Sep 17 00:00:00 2001 From: Demarius Chrite Date: Wed, 31 Dec 2014 18:49:01 -0400 Subject: [PATCH 68/99] Diary. spatial indexing. --- diary.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/diary.md b/diary.md index c03aa4c..7091029 100644 --- a/diary.md +++ b/diary.md @@ -36,3 +36,5 @@ Finally, Decoding is very similar, except that at each stage we Gray- decode D index bits from coordinate bits. At that point the decoder has the same information the encoder uses to calculate the orientation of the child cube for the next stage. N-dimensional mapping. http://www.dcs.bbk.ac.uk/~jkl/pubs/JL1_00a.pdf + +more spatial indexing info. http://blog.notdot.net/2009/11/Damn-Cool-Algorithms-Spatial-indexing-with-Quadtrees-and-Hilbert-Curves From f14892b929732597a0e4ef94cd5355cb448c8823 Mon Sep 17 00:00:00 2001 From: Demarius Chrite Date: Thu, 1 Jan 2015 22:40:31 -0400 Subject: [PATCH 69/99] Exports. --- index.js | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/index.js b/index.js index 9a2b753..de3c1e8 100644 --- a/index.js +++ b/index.js @@ -193,5 +193,6 @@ exports.xy2d = function (height, x, y) { return convert2dPointToDistance(height, new Point(x, y)) } exports.d2xy = convertDistanceTo2dPoint +exports.xy2d = convert2dPointToDistance exports.d2xyz = convertDistanceTo3dPoint -exports.point = Point +exports.xyz2d = convert3dPointToDistance From fc3523e17830ef99c3b7272f46df569da485d290 Mon Sep 17 00:00:00 2001 From: Demarius Chrite Date: Fri, 2 Jan 2015 19:01:24 -0400 Subject: [PATCH 70/99] Cleanup. --- index.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/index.js b/index.js index de3c1e8..0166259 100644 --- a/index.js +++ b/index.js @@ -105,7 +105,7 @@ function convert3dPointToDistance (height, x, y, z) { // :: Int -> Int -> Int -> } // Accepts height or width of a square/graph and distance -function convertDistanceTo2dPoint (height, distance) { // :: Int -> Int -> [Int, Int] +function convertDistanceTo2dPoint (distance, height) { // :: Int -> Int -> [Int, Int] distance = Math.floor(distance) var xbit, ybit, level var p = new Point(0, 0) @@ -117,7 +117,7 @@ function convertDistanceTo2dPoint (height, distance) { // :: Int -> Int -> [Int, ybit = 1 & (distance / 2) xbit = 1 & (ybit ^ distance) - p = p.rotate2d(level, x, y, xbit, ybit) + p = p.rotate2d(level, p.x, p.y, xbit, ybit) p.x += level * xbit p.y += level * ybit distance = Math.floor(distance / 4) From 66264b0f7cf322e44e852c473d8d4c6a93e74f1d Mon Sep 17 00:00:00 2001 From: Demarius Chrite Date: Sat, 3 Jan 2015 22:07:03 -0400 Subject: [PATCH 71/99] Move optional 'height' parameter. --- index.js | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/index.js b/index.js index 0166259..42ccb75 100644 --- a/index.js +++ b/index.js @@ -70,7 +70,7 @@ Point.prototype.unrotate = function (n) { // Accepts the height or width of a square/graph, and the coordinates to // convert. -function convert2dPointToDistance (height, p) { // :: Int -> Int -> Int -> Int +function convert2dPointToDistance (p, height) { // :: Int -> Int -> Int -> Int var xbit, ybit, level, d = 0 if (height < 2) { height = 2 @@ -93,7 +93,7 @@ function convert2dPointToDistance (height, p) { // :: Int -> Int -> Int -> Int } // height and coordinates. -function convert3dPointToDistance (height, x, y, z) { // :: Int -> Int -> Int -> Int -> Int +function convert3dPointToDistance (x, y, z, height) { // :: Int -> Int -> Int -> Int -> Int var s = 1, level = 0, p = new Point(x, y, z) var max = Math.max.apply(Math, p.toArray()) for (; 2 * s <= max; s *= 2) { @@ -127,7 +127,7 @@ function convertDistanceTo2dPoint (distance, height) { // :: Int -> Int -> [Int, } // height/width of a square/graph and distance -function convertDistanceTo3dPoint (height, distance) { // Int -> Int -> [Int, Int, Int] +function convertDistanceTo3dPoint (distance, height) { // Int -> Int -> [Int, Int, Int] distance = Math.floor(distance) var xbit, ybit, zbit, level, parity var iter = 2, log = 0, p = new Point(x, y, z) @@ -189,8 +189,8 @@ function rotate3d(level, x, y, z) { // :: Int -> Int -> Int -> Int -> [Int, Int, } } -exports.xy2d = function (height, x, y) { - return convert2dPointToDistance(height, new Point(x, y)) +exports.xy2d = function (x, y, height) { + return convert2dPointToDistance(new Point(x, y), height) } exports.d2xy = convertDistanceTo2dPoint exports.xy2d = convert2dPointToDistance From 5578e6c3ddf54fe04c78a2d87e08477345803b0d Mon Sep 17 00:00:00 2001 From: Demarius Chrite Date: Sun, 4 Jan 2015 01:48:16 -0500 Subject: [PATCH 72/99] Cleanup. --- index.js | 1 - 1 file changed, 1 deletion(-) diff --git a/index.js b/index.js index 42ccb75..d334d43 100644 --- a/index.js +++ b/index.js @@ -193,6 +193,5 @@ exports.xy2d = function (x, y, height) { return convert2dPointToDistance(new Point(x, y), height) } exports.d2xy = convertDistanceTo2dPoint -exports.xy2d = convert2dPointToDistance exports.d2xyz = convertDistanceTo3dPoint exports.xyz2d = convert3dPointToDistance From 04fd8fb7fe9da24edd78c29abbd916aba54b40ea Mon Sep 17 00:00:00 2001 From: Demarius Chrite Date: Tue, 6 Jan 2015 13:55:21 -0400 Subject: [PATCH 73/99] Exports and convert to xyz2d to use Point. --- index.js | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/index.js b/index.js index d334d43..cf4bbba 100644 --- a/index.js +++ b/index.js @@ -93,8 +93,8 @@ function convert2dPointToDistance (p, height) { // :: Int -> Int -> Int -> Int } // height and coordinates. -function convert3dPointToDistance (x, y, z, height) { // :: Int -> Int -> Int -> Int -> Int - var s = 1, level = 0, p = new Point(x, y, z) +function convert3dPointToDistance (p, height) { // :: Int -> Int -> Int -> Int -> Int + var s = 1, level = 0 var max = Math.max.apply(Math, p.toArray()) for (; 2 * s <= max; s *= 2) { level = (level + 1) % 3 @@ -192,6 +192,8 @@ function rotate3d(level, x, y, z) { // :: Int -> Int -> Int -> Int -> [Int, Int, exports.xy2d = function (x, y, height) { return convert2dPointToDistance(new Point(x, y), height) } +exports.xyz2d = function(x, y, z, height) { + return convert3dPointToDistance(new Point(x, y, z), height) +} exports.d2xy = convertDistanceTo2dPoint exports.d2xyz = convertDistanceTo3dPoint -exports.xyz2d = convert3dPointToDistance From f5b107219dd53a4b80088ec93e6525a37582ad9e Mon Sep 17 00:00:00 2001 From: Demarius Chrite Date: Wed, 7 Jan 2015 16:15:38 -0400 Subject: [PATCH 74/99] Cleanup. --- index.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/index.js b/index.js index cf4bbba..d6eda1b 100644 --- a/index.js +++ b/index.js @@ -27,7 +27,7 @@ function Point(x, y, z) { } } -Point.prototype.rotate = function (p, n) { +Point.prototype.rotate = function (p, n) { // :: Point -> Int -> Point // record rotations if (p.n == 0) return new Point(this.z, this.x, this.y) if (p.n == 1 || p.n == 3) return new Point(this.y, this.z, this.x) @@ -55,7 +55,7 @@ Point.prototype.rotateRight = function (n) { // :: Int -> Point return new Point(this.y, this.z, this.x) } -Point.prototype.toArray = function () { // Int :: -> [Int, Int] +Point.prototype.toArray = function () { // :: -> [Int, Int] if (this.d == 3) { return [this.x, this.y, this.z] } return [this.x, this.y] } From 31f21497da198e4978f5b07584210be84ab62548 Mon Sep 17 00:00:00 2001 From: Demarius Chrite Date: Sun, 11 Jan 2015 22:41:51 -0400 Subject: [PATCH 75/99] Don't return Points. --- index.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/index.js b/index.js index d334d43..811c47d 100644 --- a/index.js +++ b/index.js @@ -123,7 +123,7 @@ function convertDistanceTo2dPoint (distance, height) { // :: Int -> Int -> [Int, distance = Math.floor(distance / 4) } - return p + return p.toArray() } // height/width of a square/graph and distance @@ -154,7 +154,7 @@ function convertDistanceTo3dPoint (distance, height) { // Int -> Int -> [Int, In iter++; } - return p.rotateLeft(iter - parity + 1); + return p.rotateLeft(iter - parity + 1).toArray(); } // Rotate the coordinate plane and (x,y) From 413dd84bdb366543a46c370a2fb22840e4b0ba20 Mon Sep 17 00:00:00 2001 From: Demarius Chrite Date: Mon, 12 Jan 2015 15:08:47 -0400 Subject: [PATCH 76/99] Remove old tests. --- t/xy/d2p.t.js | 7 ------- t/xy/p2d.t.js | 7 ------- 2 files changed, 14 deletions(-) delete mode 100755 t/xy/d2p.t.js delete mode 100644 t/xy/p2d.t.js diff --git a/t/xy/d2p.t.js b/t/xy/d2p.t.js deleted file mode 100755 index 222b259..0000000 --- a/t/xy/d2p.t.js +++ /dev/null @@ -1,7 +0,0 @@ -#!/usr/bin/env node - -require('proof')(2, function(assert) { - var xy = require('../../index.js') - assert(xy.d2p(2, 0), [0, 0]) - assert(xy.d2p(2, 3), [0, 1]) -}) diff --git a/t/xy/p2d.t.js b/t/xy/p2d.t.js deleted file mode 100644 index 46c41e6..0000000 --- a/t/xy/p2d.t.js +++ /dev/null @@ -1,7 +0,0 @@ -#!/usr/bin/env node - -require('proof')(2, function(assert) { - var xy = require('../../index.js') - assert(xy.p2d(2, 0, 0), 0) - assert(xy.p2d(2, 0, 1), 3) -}) From 2d77249823da0a326e695242bcd766a711ebc4d0 Mon Sep 17 00:00:00 2001 From: Demarius Chrite Date: Tue, 13 Jan 2015 19:01:11 -0400 Subject: [PATCH 77/99] Update tests. --- t/xy/1dto2d.js | 2 +- t/xy/2dto1d.js | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/t/xy/1dto2d.js b/t/xy/1dto2d.js index d9caf16..8632551 100644 --- a/t/xy/1dto2d.js +++ b/t/xy/1dto2d.js @@ -3,5 +3,5 @@ require('proof')(1, function (equal( { var hilbert = require('../..') - equal(hilbert.convertDistanceToPoint(16, 2), [1, 1]) + equal(hilbert.d2xy(16, 2), [1, 1]) } diff --git a/t/xy/2dto1d.js b/t/xy/2dto1d.js index ee53a73..5c714d6 100644 --- a/t/xy/2dto1d.js +++ b/t/xy/2dto1d.js @@ -3,5 +3,5 @@ require('proof')(1, function (equal) { var hilbert = require('../..') - equal(hilbert.convertPointToDistance(16, 2, 2,), 8) + equal(hilbert.xy2d(16, 2, 2,), 8) } From 31b2551db87ff164ff4441799634c184bccd89f8 Mon Sep 17 00:00:00 2001 From: Demarius Chrite Date: Wed, 14 Jan 2015 14:27:33 -0500 Subject: [PATCH 78/99] Update Proof. --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index a20965f..d3db414 100644 --- a/package.json +++ b/package.json @@ -22,7 +22,7 @@ }], "devDependencies": { - "proof": "0.0.47" + "proof": "*" }, "licenses": [{ From 5f7a6c0f0cfdb7e4d51047b229757a13d0441229 Mon Sep 17 00:00:00 2001 From: Demarius Chrite Date: Thu, 15 Jan 2015 23:43:51 -0400 Subject: [PATCH 79/99] Remove old test. --- t/xy/1dto2d.js | 7 ------- 1 file changed, 7 deletions(-) delete mode 100644 t/xy/1dto2d.js diff --git a/t/xy/1dto2d.js b/t/xy/1dto2d.js deleted file mode 100644 index 8632551..0000000 --- a/t/xy/1dto2d.js +++ /dev/null @@ -1,7 +0,0 @@ -#!/usr/bin/env node - -require('proof')(1, function (equal( { - var hilbert = require('../..') - - equal(hilbert.d2xy(16, 2), [1, 1]) -} From b2bec8988b5af963fae947ef5012158acc4278b2 Mon Sep 17 00:00:00 2001 From: Demarius Chrite Date: Fri, 16 Jan 2015 11:16:28 -0400 Subject: [PATCH 80/99] Test 1d -> 2D. --- t/xy/1dto2d.t.js | 7 +++++++ 1 file changed, 7 insertions(+) create mode 100644 t/xy/1dto2d.t.js diff --git a/t/xy/1dto2d.t.js b/t/xy/1dto2d.t.js new file mode 100644 index 0000000..a82a01b --- /dev/null +++ b/t/xy/1dto2d.t.js @@ -0,0 +1,7 @@ +#!/usr/bin/env node + +require('proof')(1, function (equal) { + var hilbert = require('../..') + + equal(hilbert.d2xy(16, 2), [4, 0]) +}) From 2407f23e5ebb23bd309a028e393f8932b9114d63 Mon Sep 17 00:00:00 2001 From: Demarius Chrite Date: Sat, 17 Jan 2015 18:20:47 -0400 Subject: [PATCH 81/99] Test 1D <-> 3D. --- t/xy/1dto3d.t.js | 7 +++++++ 1 file changed, 7 insertions(+) create mode 100644 t/xy/1dto3d.t.js diff --git a/t/xy/1dto3d.t.js b/t/xy/1dto3d.t.js new file mode 100644 index 0000000..fa4e2d1 --- /dev/null +++ b/t/xy/1dto3d.t.js @@ -0,0 +1,7 @@ +#!/usr/bin/env node + +require('proof')(1, function (equal) { + var hilbert = require('../..') + + equal(hilbert.convertPointToDistance(16, 2, 2), 8) +}) From 8f8bd123d68c8690ea6059abf0efc2cf4bba1ce4 Mon Sep 17 00:00:00 2001 From: Demarius Chrite Date: Sun, 18 Jan 2015 15:21:48 -0500 Subject: [PATCH 82/99] Test 2D <-> 1D. --- t/xy/2dto1d.t.js | 7 +++++++ 1 file changed, 7 insertions(+) create mode 100644 t/xy/2dto1d.t.js diff --git a/t/xy/2dto1d.t.js b/t/xy/2dto1d.t.js new file mode 100644 index 0000000..090b892 --- /dev/null +++ b/t/xy/2dto1d.t.js @@ -0,0 +1,7 @@ +#!/usr/bin/env node + +require('proof')(1, function (equal) { + var hilbert = require('../..') + + equal(hilbert.xy2d(16, 2, 2), 8) +}) From 2bccc31d00b01e62b42a5ab265f4d5526c1c9738 Mon Sep 17 00:00:00 2001 From: Demarius Chrite Date: Sun, 11 Jan 2015 22:41:51 -0400 Subject: [PATCH 83/99] Don't return Points. --- index.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/index.js b/index.js index d6eda1b..0694009 100644 --- a/index.js +++ b/index.js @@ -123,7 +123,7 @@ function convertDistanceTo2dPoint (distance, height) { // :: Int -> Int -> [Int, distance = Math.floor(distance / 4) } - return p + return p.toArray() } // height/width of a square/graph and distance @@ -154,7 +154,7 @@ function convertDistanceTo3dPoint (distance, height) { // Int -> Int -> [Int, In iter++; } - return p.rotateLeft(iter - parity + 1); + return p.rotateLeft(iter - parity + 1).toArray(); } // Rotate the coordinate plane and (x,y) From 4035fe68b8c5007dddbe7216f3843b03910e0adb Mon Sep 17 00:00:00 2001 From: Demarius Chrite Date: Mon, 12 Jan 2015 15:08:47 -0400 Subject: [PATCH 84/99] Remove old tests. --- t/xy/d2p.t.js | 7 ------- t/xy/p2d.t.js | 7 ------- 2 files changed, 14 deletions(-) delete mode 100755 t/xy/d2p.t.js delete mode 100644 t/xy/p2d.t.js diff --git a/t/xy/d2p.t.js b/t/xy/d2p.t.js deleted file mode 100755 index 222b259..0000000 --- a/t/xy/d2p.t.js +++ /dev/null @@ -1,7 +0,0 @@ -#!/usr/bin/env node - -require('proof')(2, function(assert) { - var xy = require('../../index.js') - assert(xy.d2p(2, 0), [0, 0]) - assert(xy.d2p(2, 3), [0, 1]) -}) diff --git a/t/xy/p2d.t.js b/t/xy/p2d.t.js deleted file mode 100644 index 46c41e6..0000000 --- a/t/xy/p2d.t.js +++ /dev/null @@ -1,7 +0,0 @@ -#!/usr/bin/env node - -require('proof')(2, function(assert) { - var xy = require('../../index.js') - assert(xy.p2d(2, 0, 0), 0) - assert(xy.p2d(2, 0, 1), 3) -}) From 84522e1f9518bc563b86b9f4e09d6bc44c8c7259 Mon Sep 17 00:00:00 2001 From: Demarius Chrite Date: Tue, 13 Jan 2015 19:01:11 -0400 Subject: [PATCH 85/99] Update tests. --- t/xy/1dto2d.js | 2 +- t/xy/2dto1d.js | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/t/xy/1dto2d.js b/t/xy/1dto2d.js index d9caf16..8632551 100644 --- a/t/xy/1dto2d.js +++ b/t/xy/1dto2d.js @@ -3,5 +3,5 @@ require('proof')(1, function (equal( { var hilbert = require('../..') - equal(hilbert.convertDistanceToPoint(16, 2), [1, 1]) + equal(hilbert.d2xy(16, 2), [1, 1]) } diff --git a/t/xy/2dto1d.js b/t/xy/2dto1d.js index ee53a73..5c714d6 100644 --- a/t/xy/2dto1d.js +++ b/t/xy/2dto1d.js @@ -3,5 +3,5 @@ require('proof')(1, function (equal) { var hilbert = require('../..') - equal(hilbert.convertPointToDistance(16, 2, 2,), 8) + equal(hilbert.xy2d(16, 2, 2,), 8) } From f3291825b7ae18277939433e76fefb9c4afe3058 Mon Sep 17 00:00:00 2001 From: Demarius Chrite Date: Wed, 14 Jan 2015 14:27:33 -0500 Subject: [PATCH 86/99] Update Proof. --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index a20965f..d3db414 100644 --- a/package.json +++ b/package.json @@ -22,7 +22,7 @@ }], "devDependencies": { - "proof": "0.0.47" + "proof": "*" }, "licenses": [{ From 707447feb2b2fa46683f801a68cd83133e43ca72 Mon Sep 17 00:00:00 2001 From: Demarius Chrite Date: Thu, 15 Jan 2015 23:43:51 -0400 Subject: [PATCH 87/99] Remove old test. --- t/xy/1dto2d.js | 7 ------- 1 file changed, 7 deletions(-) delete mode 100644 t/xy/1dto2d.js diff --git a/t/xy/1dto2d.js b/t/xy/1dto2d.js deleted file mode 100644 index 8632551..0000000 --- a/t/xy/1dto2d.js +++ /dev/null @@ -1,7 +0,0 @@ -#!/usr/bin/env node - -require('proof')(1, function (equal( { - var hilbert = require('../..') - - equal(hilbert.d2xy(16, 2), [1, 1]) -} From 0294cd7d61be3604b676a033cf3d7a533a9714f1 Mon Sep 17 00:00:00 2001 From: Demarius Chrite Date: Fri, 16 Jan 2015 11:16:28 -0400 Subject: [PATCH 88/99] Test 1d -> 2D. --- t/xy/1dto2d.t.js | 7 +++++++ 1 file changed, 7 insertions(+) create mode 100644 t/xy/1dto2d.t.js diff --git a/t/xy/1dto2d.t.js b/t/xy/1dto2d.t.js new file mode 100644 index 0000000..a82a01b --- /dev/null +++ b/t/xy/1dto2d.t.js @@ -0,0 +1,7 @@ +#!/usr/bin/env node + +require('proof')(1, function (equal) { + var hilbert = require('../..') + + equal(hilbert.d2xy(16, 2), [4, 0]) +}) From f6c6709f6ebf42b56e4391b03591d2d1878f93a3 Mon Sep 17 00:00:00 2001 From: Demarius Chrite Date: Sat, 17 Jan 2015 18:20:47 -0400 Subject: [PATCH 89/99] Test 1D <-> 3D. --- t/xy/1dto3d.t.js | 7 +++++++ 1 file changed, 7 insertions(+) create mode 100644 t/xy/1dto3d.t.js diff --git a/t/xy/1dto3d.t.js b/t/xy/1dto3d.t.js new file mode 100644 index 0000000..fa4e2d1 --- /dev/null +++ b/t/xy/1dto3d.t.js @@ -0,0 +1,7 @@ +#!/usr/bin/env node + +require('proof')(1, function (equal) { + var hilbert = require('../..') + + equal(hilbert.convertPointToDistance(16, 2, 2), 8) +}) From 99567be6f64379c15cc7abb51a0e22526377bf5b Mon Sep 17 00:00:00 2001 From: Demarius Chrite Date: Sun, 18 Jan 2015 15:21:48 -0500 Subject: [PATCH 90/99] Test 2D <-> 1D. --- t/xy/2dto1d.t.js | 7 +++++++ 1 file changed, 7 insertions(+) create mode 100644 t/xy/2dto1d.t.js diff --git a/t/xy/2dto1d.t.js b/t/xy/2dto1d.t.js new file mode 100644 index 0000000..090b892 --- /dev/null +++ b/t/xy/2dto1d.t.js @@ -0,0 +1,7 @@ +#!/usr/bin/env node + +require('proof')(1, function (equal) { + var hilbert = require('../..') + + equal(hilbert.xy2d(16, 2, 2), 8) +}) From 75137875b04b50d64805e0e11f414e01d9db22cb Mon Sep 17 00:00:00 2001 From: Demarius Chrite Date: Mon, 19 Jan 2015 14:13:57 -0400 Subject: [PATCH 91/99] Cleanup. --- t/xy/2dto1d.js | 7 ------- 1 file changed, 7 deletions(-) delete mode 100644 t/xy/2dto1d.js diff --git a/t/xy/2dto1d.js b/t/xy/2dto1d.js deleted file mode 100644 index 5c714d6..0000000 --- a/t/xy/2dto1d.js +++ /dev/null @@ -1,7 +0,0 @@ -#!/usr/bin/env node - -require('proof')(1, function (equal) { - var hilbert = require('../..') - - equal(hilbert.xy2d(16, 2, 2,), 8) -} From 96d916fcd5b06fef95fb693db12ec8ee85c350f8 Mon Sep 17 00:00:00 2001 From: Demarius Chrite Date: Tue, 20 Jan 2015 20:43:32 -0500 Subject: [PATCH 92/99] Fix 1d<->2d test. --- t/xy/1dto2d.t.js | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/t/xy/1dto2d.t.js b/t/xy/1dto2d.t.js index a82a01b..6a30510 100644 --- a/t/xy/1dto2d.t.js +++ b/t/xy/1dto2d.t.js @@ -1,7 +1,8 @@ #!/usr/bin/env node -require('proof')(1, function (equal) { - var hilbert = require('../..') - - equal(hilbert.d2xy(16, 2), [4, 0]) +require('proof')(2, function (equal) { + var hilbert = require('../..'), res + res = hilbert.d2xy(16, 2) + equal(res[0], 4) + equal(res[1], 0) }) From 72dc9b4c7d9796dc0786cea12f908beebf0631e6 Mon Sep 17 00:00:00 2001 From: Demarius Chrite Date: Wed, 21 Jan 2015 17:28:35 -0400 Subject: [PATCH 93/99] Fix height. --- index.js | 13 ++++--------- 1 file changed, 4 insertions(+), 9 deletions(-) diff --git a/index.js b/index.js index 0694009..9210718 100644 --- a/index.js +++ b/index.js @@ -72,9 +72,6 @@ Point.prototype.unrotate = function (n) { // convert. function convert2dPointToDistance (p, height) { // :: Int -> Int -> Int -> Int var xbit, ybit, level, d = 0 - if (height < 2) { - height = 2 - } // For each Hilbert level, we want to add an amount to // `d` based on which region we are in @@ -109,11 +106,9 @@ function convertDistanceTo2dPoint (distance, height) { // :: Int -> Int -> [Int, distance = Math.floor(distance) var xbit, ybit, level var p = new Point(0, 0) - if (height < 2) { - height = 2 - } for (level = 1; level < height || distance > 0; level *= 2) { + console.log(level) ybit = 1 & (distance / 2) xbit = 1 & (ybit ^ distance) @@ -132,9 +127,7 @@ function convertDistanceTo3dPoint (distance, height) { // Int -> Int -> [Int, In var xbit, ybit, zbit, level, parity var iter = 2, log = 0, p = new Point(x, y, z) - if (height < 2) { - height = 2 - } + height = height || 2 for (parity = 1; parity < height; parity *= 2, log++) {} parity = log % 3; @@ -190,9 +183,11 @@ function rotate3d(level, x, y, z) { // :: Int -> Int -> Int -> Int -> [Int, Int, } exports.xy2d = function (x, y, height) { + height = height || 2 return convert2dPointToDistance(new Point(x, y), height) } exports.xyz2d = function(x, y, z, height) { + height = height || 2 return convert3dPointToDistance(new Point(x, y, z), height) } exports.d2xy = convertDistanceTo2dPoint From 0b98f49a0e54ca4213327a995f468bf3db17e71b Mon Sep 17 00:00:00 2001 From: Demarius Chrite Date: Thu, 22 Jan 2015 12:20:33 -0500 Subject: [PATCH 94/99] Diary entry. --- diary.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/diary.md b/diary.md index 7091029..e4ed60f 100644 --- a/diary.md +++ b/diary.md @@ -38,3 +38,5 @@ Decoding is very similar, except that at each stage we Gray- decode D index bits N-dimensional mapping. http://www.dcs.bbk.ac.uk/~jkl/pubs/JL1_00a.pdf more spatial indexing info. http://blog.notdot.net/2009/11/Damn-Cool-Algorithms-Spatial-indexing-with-Quadtrees-and-Hilbert-Curves + +hilbert curve scheduling. http://en.wikipedia.org/wiki/Hilbert_curve_scheduling From 61ab7594df7dc2cc5ab4bbcea99ac781d816cac9 Mon Sep 17 00:00:00 2001 From: Joshua Pelletier Date: Fri, 23 Jan 2015 17:15:20 -0800 Subject: [PATCH 95/99] Implement `d2xy` function. --- index.js | 7 +++++-- t/xy/1dto2d.t.js | 46 +++++++++++++++++++++++++++++++++++++++++++--- 2 files changed, 48 insertions(+), 5 deletions(-) diff --git a/index.js b/index.js index 811c47d..7a31f5c 100644 --- a/index.js +++ b/index.js @@ -109,11 +109,14 @@ function convertDistanceTo2dPoint (distance, height) { // :: Int -> Int -> [Int, distance = Math.floor(distance) var xbit, ybit, level var p = new Point(0, 0) - if (height < 2) { + if (height <= Math.sqrt(distance)) { height = 2 + while (height <= Math.sqrt(distance)) { + height *=2 + } } - for (level = 1; level < height || distance > 0; level *= 2) { + for (level = 1; level < height; level *= 2) { ybit = 1 & (distance / 2) xbit = 1 & (ybit ^ distance) diff --git a/t/xy/1dto2d.t.js b/t/xy/1dto2d.t.js index a82a01b..aa58879 100644 --- a/t/xy/1dto2d.t.js +++ b/t/xy/1dto2d.t.js @@ -1,7 +1,47 @@ #!/usr/bin/env node -require('proof')(1, function (equal) { - var hilbert = require('../..') +require('proof')(7, function (equal) { + var hilbert = require('../..') - equal(hilbert.d2xy(16, 2), [4, 0]) + + equal(hilbert.d2xy(0, 2), [0, 0]) + equal(hilbert.d2xy(0, 3), [0, 1]) + equal(hilbert.d2xy(4, 2), [0, 2]) + equal(hilbert.d2xy(15, 2), [3, 0]) + equal(hilbert.d2xy(16, 2), [0, 4]) + equal(hilbert.d2xy(63, 2), [7, 0]) + equal(hilbert.d2xy(64, 2), [0, 8]) + + /* + console.log("0 " , hilbert.d2xy(0, 2)) + console.log("1 " , hilbert.d2xy(1, 2)) + console.log("2 " , hilbert.d2xy(2, 2)) + console.log("3 " , hilbert.d2xy(3, 2)) + console.log("4 " , hilbert.d2xy(4, 2)) + console.log("5 " , hilbert.d2xy(5, 2)) + console.log("6 " , hilbert.d2xy(6, 2)) + console.log("7 " , hilbert.d2xy(7, 2)) + console.log("8 " , hilbert.d2xy(8, 2)) + console.log("9 " , hilbert.d2xy(9, 2)) + console.log("10 " , hilbert.d2xy(10, 2)) + console.log("11 " , hilbert.d2xy(11, 2)) + console.log("12 " ,hilbert.d2xy(12, 2)) + console.log("13 " ,hilbert.d2xy(13, 2)) + console.log("14 " ,hilbert.d2xy(14, 2)) + console.log("15 " ,hilbert.d2xy(15, 2)) + console.log("16 " ,hilbert.d2xy(16, 2)) + console.log("17 " ,hilbert.d2xy(17, 2)) + console.log("18 " ,hilbert.d2xy(18, 2)) + console.log("19 " ,hilbert.d2xy(19, 2)) + console.log("20 " ,hilbert.d2xy(20, 2)) + console.log("21 " ,hilbert.d2xy(21, 2)) + console.log("22 " ,hilbert.d2xy(22, 2)) + console.log("23 " ,hilbert.d2xy(23, 2)) + console.log("24 " ,hilbert.d2xy(24, 2)) + console.log("25 " ,hilbert.d2xy(25, 2)) + console.log("26 " ,hilbert.d2xy(26, 2)) + console.log("27 " ,hilbert.d2xy(27, 2)) + console.log("28 " ,hilbert.d2xy(28, 2)) + console.log("29 " ,hilbert.d2xy(29, 2)) + */ }) From 8f6532e89ea0eb8abf40459e02718e6cdb177511 Mon Sep 17 00:00:00 2001 From: Joshua Pelletier Date: Sun, 25 Jan 2015 13:03:53 -0800 Subject: [PATCH 96/99] Exchange bit variables in 2dPoint to distance. --- index.js | 17 ++++++++++------- t/xy/1dto2d.t.js | 11 ++++------- 2 files changed, 14 insertions(+), 14 deletions(-) diff --git a/index.js b/index.js index 7a31f5c..ad07548 100644 --- a/index.js +++ b/index.js @@ -72,10 +72,13 @@ Point.prototype.unrotate = function (n) { // convert. function convert2dPointToDistance (p, height) { // :: Int -> Int -> Int -> Int var xbit, ybit, level, d = 0 - if (height < 2) { - height = 2 - } + var forHeight = p.x > p.y ? p.x : p.y + // needs some tests to make sure height is compatible + // What keeps the user from putting 54 down as the height + while (forHeight >= height) { + height *=2 + } // For each Hilbert level, we want to add an amount to // `d` based on which region we are in for (level = height / 2; level > 0; level /= 2) { @@ -86,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, p.x, p.y, xbit, ybit) + p = p.rotate2d(height, xbit, ybit) } return d @@ -117,10 +120,10 @@ function convertDistanceTo2dPoint (distance, height) { // :: Int -> Int -> [Int, } for (level = 1; level < height; level *= 2) { - ybit = 1 & (distance / 2) - xbit = 1 & (ybit ^ distance) + xbit = 1 & (distance / 2) + ybit = 1 & (xbit ^ distance) - p = p.rotate2d(level, p.x, p.y, xbit, ybit) + p = p.rotate2d(level, xbit, ybit) p.x += level * xbit p.y += level * ybit distance = Math.floor(distance / 4) diff --git a/t/xy/1dto2d.t.js b/t/xy/1dto2d.t.js index aa58879..c095812 100644 --- a/t/xy/1dto2d.t.js +++ b/t/xy/1dto2d.t.js @@ -1,18 +1,16 @@ #!/usr/bin/env node -require('proof')(7, function (equal) { +require('proof')(9, function (equal) { var hilbert = require('../..') - - equal(hilbert.d2xy(0, 2), [0, 0]) equal(hilbert.d2xy(0, 3), [0, 1]) - equal(hilbert.d2xy(4, 2), [0, 2]) + equal(hilbert.d2xy(4, 2), [2, 0]) equal(hilbert.d2xy(15, 2), [3, 0]) equal(hilbert.d2xy(16, 2), [0, 4]) equal(hilbert.d2xy(63, 2), [7, 0]) equal(hilbert.d2xy(64, 2), [0, 8]) - - /* + equal(hilbert.d2xy(1023, 2), [31, 0]) + equal(hilbert.d2xy(1024, 2), [0, 32]) console.log("0 " , hilbert.d2xy(0, 2)) console.log("1 " , hilbert.d2xy(1, 2)) console.log("2 " , hilbert.d2xy(2, 2)) @@ -43,5 +41,4 @@ require('proof')(7, function (equal) { console.log("27 " ,hilbert.d2xy(27, 2)) console.log("28 " ,hilbert.d2xy(28, 2)) console.log("29 " ,hilbert.d2xy(29, 2)) - */ }) From a76b15fcc2e4a46b814a7f873bd5096ef4d41e2e Mon Sep 17 00:00:00 2001 From: Demarius Chrite Date: Fri, 23 Jan 2015 08:34:12 -0400 Subject: [PATCH 97/99] Fix rotate2d() calls. --- index.js | 17 ++++++++--------- 1 file changed, 8 insertions(+), 9 deletions(-) diff --git a/index.js b/index.js index 9210718..53c32c4 100644 --- a/index.js +++ b/index.js @@ -75,7 +75,7 @@ function convert2dPointToDistance (p, height) { // :: Int -> Int -> Int -> Int // For each Hilbert level, we want to add an amount to // `d` based on which region we are in - for (level = height / 2; level > 0; level /= 2) { + for (level = height / 2; level > 0; level = Math.floor(level / 2)) { // Determine what region we're in xbit = (p.x & level) > 0 ybit = (p.y & level) > 0 @@ -83,7 +83,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, p.x, p.y, xbit, ybit) + p = p.rotate2d(level, xbit, ybit) } return d @@ -104,15 +104,14 @@ function convert3dPointToDistance (p, height) { // :: Int -> Int -> Int -> Int - // Accepts height or width of a square/graph and distance function convertDistanceTo2dPoint (distance, height) { // :: Int -> Int -> [Int, Int] distance = Math.floor(distance) - var xbit, ybit, level - var p = new Point(0, 0) + var xbit, ybit, level, p = new Point(0, 0) for (level = 1; level < height || distance > 0; level *= 2) { console.log(level) - ybit = 1 & (distance / 2) - xbit = 1 & (ybit ^ distance) + xbit = 1 & (distance / 2) + ybit = 1 & (distance ^ xbit) - p = p.rotate2d(level, p.x, p.y, xbit, ybit) + p = p.rotate2d(level, xbit, ybit) p.x += level * xbit p.y += level * ybit distance = Math.floor(distance / 4) @@ -152,8 +151,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 } From cbd3b7388df29be91aeb0ac52f56a4587f4024e2 Mon Sep 17 00:00:00 2001 From: Demarius Chrite Date: Sat, 24 Jan 2015 15:28:53 -0400 Subject: [PATCH 98/99] Update test. --- t/xy/2dto1d.t.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/t/xy/2dto1d.t.js b/t/xy/2dto1d.t.js index 090b892..b4ce8f8 100755 --- a/t/xy/2dto1d.t.js +++ b/t/xy/2dto1d.t.js @@ -3,5 +3,5 @@ require('proof')(1, function (equal) { var hilbert = require('../..') - equal(hilbert.xy2d(16, 2, 2), 8) + equal(hilbert.xy2d(4, 0, 2), 16) }) From a877e562bee26cdee0426b05d2c053421bc34879 Mon Sep 17 00:00:00 2001 From: Joshua Pelletier Date: Mon, 26 Jan 2015 09:14:41 -0800 Subject: [PATCH 99/99] Add test for `xy2d`. --- t/xy/2dto1d.t.js | 25 ++++++++++++++++++++++--- 1 file changed, 22 insertions(+), 3 deletions(-) mode change 100755 => 100644 t/xy/2dto1d.t.js diff --git a/t/xy/2dto1d.t.js b/t/xy/2dto1d.t.js old mode 100755 new mode 100644 index b4ce8f8..c13cd6a --- a/t/xy/2dto1d.t.js +++ b/t/xy/2dto1d.t.js @@ -1,7 +1,26 @@ #!/usr/bin/env node -require('proof')(1, function (equal) { - var hilbert = require('../..') +require('proof')(3, function (equal) { - equal(hilbert.xy2d(4, 0, 2), 16) + var hilbert = require('../..') + equal(hilbert.xy2d(1, 0, 2), 3) + equal(hilbert.xy2d(2, 0, 4), 4) + equal(hilbert.xy2d(9, 9, 4), 10) + //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)) // 12 + 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)) // 14 + console.log("x: 3, y: 0, length: ", hilbert.xy2d(3, 0, 2)) // 15 })