CoordinateUtils { public static int findMinDepthIndex(double[] depths, double from) { int first = Arrays.binarySearch(depths, from); if (first < 0) { first = -1 - first; if (first != 0 && (Math.floor(from * 100) - Math.floor(100 * depths[first - 1])) <= 1) { first--; } } if (first == depths.length) { first = -1; } return first; }  static double getLongitudeM180P180(double longitude); static List<Range> createRange(int minj, int maxj, int mini, int maxi); static int findCoordElementBounded(CoordinateAxis1D axis, double pos, int lastIndex); static List<Range> getRangesFromLatLonRect(GridCoordSys gcs, LatLonRect rect); static double getMinOrMaxLon(double lon1, double lon2, boolean wantMin); static MinMax computeMinMax(MinMax ref, MinMax work); static MAMath.MinMax computeLatMinMax(MAMath.MinMax minMaxYValue2D, CoordinateAxis2D latAxis, int minj, int mini, int maxj, int maxi); static MAMath.MinMax computeLonMinMax(MAMath.MinMax minMaxXValue2D,
                                                 CoordinateAxis2D lonAxis,
                                                 int minj,
                                                 int mini,
                                                 int maxj,
                                                 int maxi,
                                                 double minx,
                                                 double maxx); static MinMax computeMinMaxX(Projection dataProjection, LatLonRect rect); static MinMax computeMinMaxY(Projection dataProjection, LatLonRect rect); static MinMax[] computeMinMaxXY(Projection dataProjection, LatLonRect rect); static void checkXYAxis(CoordinateAxis xaxis, CoordinateAxis yaxis, GridCoordSys gcs); static double checkLon(double lon, double refXMin); static boolean isInside(double lat, double lon, MinMax minMaxX, MinMax minMaxY); static void removeEmptyYXRanges(List<List<Range>> listRanges); static boolean hasEmptyYXRanges(List<List<Range>> listRanges); static List<Range> createEmptyYXRanges(); static boolean hasRange(List<Range> ranges); static boolean hasRange(Range range); static void getRangeValues(GridCoordSys gcs, Range rangeLat, Range rangeLon, double[] rangeValueLat, double[] rangeValueLon); static MAMath.MinMax getMinMaxValueForAxis(CoordinateAxis axis); static double getMinValueForAxis(CoordinateAxis axis); static double getMaxValueForAxis(CoordinateAxis axis); static String getMinValForAxisAsString(CoordinateAxis axis); static String getMaxValForAxisAsString(CoordinateAxis axis); static int findMinDepthIndex(double[] depths, double from); static int findMaxDepthIndex(double[] depths, double to);  }
@Test public void testFindMinDepthIndex() { double[] depths = { 0.18234, 0.235, 0.24, 0.245, 1.1 }; assertTrue(CoordinateUtils.findMinDepthIndex(depths, 0.15) == 0); assertTrue(CoordinateUtils.findMinDepthIndex(depths, 0.18234) == 0); assertTrue(CoordinateUtils.findMinDepthIndex(depths, 0.24) == 2); assertTrue(CoordinateUtils.findMinDepthIndex(depths, 0.2401) == 2); assertTrue(CoordinateUtils.findMinDepthIndex(depths, 0.239) == 1); assertTrue(CoordinateUtils.findMinDepthIndex(depths, 2) == -1); assertTrue(CoordinateUtils.findMinDepthIndex(depths, 0.24275) == 2); }