class CoordinateUtils {

    public static int findMinDepthIndex(double[] depths, double from) {
        int first = Arrays.binarySearch(depths, from);
        if (first < 0) {
            // Extract insertion point
            first = -1 - first;
            // Check at 1 cm for rounding tolerance
            if (first != 0 && (Math.floor(from * 100) - Math.floor(100 * depths[first - 1])) <= 1) {
                first--;
            }
        }
        if (first == depths.length) {
            first = -1;
        }
        return first;
    }

}

class CoordinateUtilsTest {

    @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);

    }

}