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.pathAlongCellEdge bug? #10

Closed mbtaylor closed 4 years ago

mbtaylor commented 4 years ago

The result of VerticesAndPathComputer.pathAlongCellEdge differs in some cases between HealpixNested and HealpixNestedFast. I think HealpixNestedFast is the one getting it wrong.

Running this:

import cds.healpix.CompassPoint;
import cds.healpix.Healpix;
import cds.healpix.VerticesAndPathComputer;
import java.util.Arrays;

public class MbtTest {
    public static void checkVertices( int depth, long hash ) {
        VerticesAndPathComputer vpc0 = Healpix.getNested( depth );
        VerticesAndPathComputer vpc1 = Healpix.getNestedFast( depth );
        CompassPoint.Cardinal east = CompassPoint.Cardinal.E;
        double[][] vs0 = vpc0.pathAlongCellEdge( hash, east, true, 1 );
        double[][] vs1 = vpc1.pathAlongCellEdge( hash, east, true, 1 );
        System.out.println( depth + "\t" + hash + ": "
                          + (Arrays.deepEquals( vs0, vs1 ) ? "ok" : "NOT OK") );
    }
    public static void main( String[] args ) {
        for ( long h = 42236L; h < 42243L; h++ ) {
            checkVertices( 6, h );
        }
    }
}

gives me

6       42236: ok
6       42237: ok
6       42238: ok
6       42239: NOT OK
6       42240: ok
6       42241: ok
6       42242: ok

May or may not be related to #9.

fxpineau commented 4 years ago

I solve the issue. Even so, your code still fails. Here the results for hash 6/42239:

Left: 
4.338389854957334, -0.7436814253990303
4.3323576109988275, -0.7575925985268412
4.313456579928843, -0.7436814253990303
4.319689898685965, -0.7297276562269663
Right: 
4.338389854957334, -0.7436814253990303
4.3323576109988275, -0.7575925985268412
4.313456579928843, -0.7436814253990303
4.319689898685965, -0.7297276562269666

The difference -0.7297276562269663 != -0.7297276562269666 comes from different numerical approximations using two different algo. The difference is 3e-16 rad = 0.06 nano arcsec.

I close the issue considering that it is acceptable (feel free to re-open if you do not agree).

mbtaylor commented 4 years ago

Nano arcsec is OK! Thanks for the fix.