cds-astro / cds-healpix-java

The CDS HEALPix library in Java
BSD 3-Clause "New" or "Revised" License
9 stars 9 forks source link

HealpixNestedFast.hash and negative longitudes #9

Closed mbtaylor closed 4 years ago

mbtaylor commented 4 years ago

Hi @fxpineau . The behaviour of the HashComputer.hash() method for HealpixNested and HealpixNestedFast seems to differ when lonRad<0, though the documentation says

lonRad ... must support reasonably large positive and negative values

Here is a test:

import cds.healpix.Healpix;
public class MbtTest {
    public static void checkHash( int depth, double lon, double lat ) {
        long h0 = Healpix.getNested( depth ).hash( lon, lat );
        long h1 = Healpix.getNestedFast( depth ).hash( lon, lat );
        System.out.println( "(" + lon + "," + lat + "):\t-> " 
                          + h0 + "\t" + h1 + "\t"
                          + ( h0 == h1 ? "" : "!!!" ) );
    }
    public static void main( String[] args ) {
        int depth = 3; 
        for ( int ilon = 1; ilon >= -1; ilon-- ) {
            for ( int ilat = 1; ilat >= -1; ilat-- ) {
                checkHash( depth, 0.5 * ilon, 0.5 * ilat );
            }
        }
    }
}

which gives me

(0.5,0.5):      -> 33   33
(0.5,0.0):      -> 278  278
(0.5,-0.5):     -> 557  557
(0.0,0.5):      -> 316  316
(0.0,0.0):      -> 304  304
(0.0,-0.5):     -> 259  259
(-0.5,0.5):     -> 210  33      !!!
(-0.5,0.0):     -> 297  278     !!!
(-0.5,-0.5):    -> 734  557     !!!
fxpineau commented 4 years ago

You are right: lonRad<0 was not taken into account in HealpixNestedFast.hash(). Should now be solved (so I close the issue).