-
Notifications
You must be signed in to change notification settings - Fork 21
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Negative coordinates #70
Comments
Sorry, I've read your question wrongly. Coordinates are in range -2^63..2^63-1. Your use case is still useful but I'll make some guesses. If your coordinates are (x, y) then construct a hilbert index that maps (x/2+2^62, y/2+2^62) to a Hilbert index using 63 bits. When you conversely get a coordinate from the index then you multiply the ordinates by 2 and subtract 2^63 to get your original range. Then use appropriate criteria on the returned coordinates to filter them (as though you had an index of 64 bits). Does that help? |
Thanks for the answer! My use case in fact uses coordinates in range -2^63..2^63-1. What I ended up doing which I think does work is the following:
Here is the adapted code: https://gist.github.com/normen662/0d312d1424adb70f274d95bb16734aac I am not sure if that does the same as what you were suggesting. Maybe you find the angle interesting. I would certainly rather like to call your library methods instead of creating a Frankenstein out of your code. |
Oh right: The code to shift the coordinates:
|
I'm still in the dark about why don't just divide your coordinates by two before mapping to the hilbert index and the reverse when mapping hilbert index value to the coordinates. If necessary at that point you can do a further filter appropriate to your search (the nature of which I'm curious about too). |
By dividing the coordinate by two I would lose resolution, unless there is a misunderstanding on my part. I need a bijective function Maybe I am gettin wrong what you are suggesting, but by dividing them by two I would assign e.g. |
Yes but it depends on how you are using the Hilbert index. If you are using it for a proximity search for instance then you just do the refinement on the results by checking with the proximity criterion all the coordinates that correspond to the divided-by-2 result (combinations (2x, 2y), (2x +1,2y),(2x, 2y+1), (2x+1, 2y+1) in 2d for example). |
Hi David, thank you for all the suggestions! I don't think I can avoid having those 64 bits of resolution. Since my adapted code can deal with that case I will use that for the time being. Please feel free to close. |
Hi David,
I think the acceptable ranges for coordinates are
0..2^bits
(for point to Hilbert value conversions). Unfortunately, I have to deal with full java longs-2^63 ... 2^63-1
. I was thinking of preprocessing these numbers (by shifting them into the positive (adding2^63
to each) and then doing the conversion to a Hilbert value in code specifically adopted to useBigInteger
to also support higher numbers of bits (64 in my cases) at the expense of worse performance). Short question: Do you see an easier/better way to do this? Ideally I would still like to call methods in this library.(Note that I kind of can do this in a better way for 2 dimensions; however, it eludes me how to generalize that to n dimensions).
The text was updated successfully, but these errors were encountered: