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 #17

Closed mbtaylor closed 2 years ago

mbtaylor commented 2 years ago

HealpixNestedFast, but not other VerticesAndPathComputers, gets the North vertex wrong for tiles just below the northern cap when executing pathAlongCellEdge, though not when calling vertex directly. Using v0.30_1, this code:

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

public class Vert {
    public static void main( String[] args ) {
        int order = 3;
        int hash = 42;
        VerticesAndPathComputer vc1 = Healpix.getNested(order).newVerticesAndPathComputer();
        VerticesAndPathComputer vc2 = Healpix.getNestedFast(order);
        printVertexNorth(vc1, hash);
        printVertexNorth(vc2, hash);
        System.out.println();
        printVertices(vc1, hash);
        printVertices(vc2, hash);
    }
    static void printVertexNorth(VerticesAndPathComputer vc, int hash) {
        System.out.println(Arrays.toString(vc.vertex(hash, CompassPoint.Cardinal.N)));
    }
    static void printVertices(VerticesAndPathComputer vc, int hash) {
        double[][] lonlats = vc.pathAlongCellEdge(hash, CompassPoint.Cardinal.E, true, 1);
        for (int i = 0; i < 4; i++) {
            System.out.print(Arrays.toString(lonlats[i]));
        }
        System.out.println();
    }
}

gives this result:

[0.0, 0.8402225818983444]
[0.0, 0.8402225818983444]

[0.19634954084936207, 0.7297276562269663][0.09817477042468103, 0.6228265854120029][0.0, 0.7297276562269663][0.0, 0.8402225818983444]
[0.19634954084936207, 0.7297276562269663][0.09817477042468103, 0.6228265854120029][0.0, 0.7297276562269663][0.09817477042468103, 0.848062078981481]
fxpineau commented 2 years ago

Thank you @mbtaylor . I fixed several bugs in HealpixNestedFast.pathAlongCellEdge (NaN at poles, issue on cells centered at the Equatorial Region/Polar caps separation) and added a test to cross-compare with HealpixNested.pathAlongCellEdge.