jonatkins / s2-geometry-javascript

Porting Google's S2 Geometry Library to Javascript
31 stars 17 forks source link

How to apply hilbert curve? #8

Closed coolaj86 closed 8 years ago

coolaj86 commented 8 years ago

Do you know if it's possible to apply a hilbert curve without converting the cell to a 64-bit ID and back?

I'm able to return neighbors and I have some code for the hilbert curve and I'm trying to figure out how to adapt it so that I can add next() and prev() functions to a cell, but it appears to need and integer as initial.

I see you mention combine face,position to get the cell id L16, but I'm not sure which function that refers to and there's no variable called position, except in pointToHilbertQuadList L161 & L256, but I'm not clear on how to use that to get next and prev.

Can you help me with this at all? I'd be willing to pay for consulting.

coolaj86 commented 8 years ago

Well, if I ignore wrapping here's a cheap way to do it:

var current = parseInt(quad.join(''), 4);
var next = current + 1;
var prev = current - 1;

// nextQuad = next.toString(2).split('');