cds-astro / cds-healpix-java

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

ConeComputer ArrayIndexOutOfBoundsException #12

Closed mbtaylor closed 4 years ago

mbtaylor commented 4 years ago

If I run this:

        Healpix.getNested( 6 )
               .newConeComputer( 0.9886484667476922 )
               .overlappingCells( 4.646003386280478, -0.41602905223485265 );

I get

java.lang.ArrayIndexOutOfBoundsException: 1020
        at cds.healpix.NestedSmallCellApproxedMethod.buildMocRecursively(NestedSmallCellApproxedMethod.java:230)

Is my cone too big?

fxpineau commented 4 years ago

The problem was due to a too small estimate of the number of cells in the output MOC.
If Java were supporting collections on primitives, I would have used an ArrayList using the estimate as initial capacity.
So far, I simplify the estimate and take a more conservative value.
I promise that if you encounter again a problem, I will make the effort to implement a grow-able object. So I close this issue for the time being.

mbtaylor commented 4 years ago

Thanks. If you do decide to use a growable object, I have primitive list implementations at https://github.com/Starlink/starjava/blob/master/util/src/main/uk/ac/starlink/util/LongList.java etc which you're welcome to pinch if you like (I don't suggest making a dependency on my library, just cut'n'paste the code as required).