public double calculateElevationBasedOnTwoPoints(double lat, double lon, double lat0,
                                                     double lon0, double ele0, double lat1, double lon1, double ele1) {
        double dlat0 = lat0 - lat;
        double dlon0 = lon0 - lon;
        double dlat1 = lat1 - lat;
        double dlon1 = lon1 - lon;
        double l0 = Math.sqrt(dlon0 * dlon0 + dlat0 * dlat0);
        double l1 = Math.sqrt(dlon1 * dlon1 + dlat1 * dlat1);
        double l = l0 + l1;
        if (l < EPSILON) {
            // If points are too close to each other, return elevation of the
            // point which is closer;
            return l0 <= l1 ? ele0 : ele1;
        } else {
            // Otherwise do linear interpolation
            return round2(ele0 + (ele1 - ele0) * l0 / l);
        }
    }
@Test
    public void calculatesElevationOnTwoPoints() {
        assertEquals(15, elevationInterpolator.calculateElevationBasedOnTwoPoints(0, 0, -10, -10,
                10, 10, 10, 20), PRECISION);
        assertEquals(15, elevationInterpolator.calculateElevationBasedOnTwoPoints(-10, 10, -10, -10,
                10, 10, 10, 20), PRECISION);
        assertEquals(15, elevationInterpolator.calculateElevationBasedOnTwoPoints(-5, 5, -10, -10,
                10, 10, 10, 20), PRECISION);
        assertEquals(19, elevationInterpolator.calculateElevationBasedOnTwoPoints(8, 8, -10, -10,
                10, 10, 10, 20), PRECISION);
        assertEquals(10, elevationInterpolator.calculateElevationBasedOnTwoPoints(0, 0,
                -ElevationInterpolator.EPSILON / 3, 0, 10,
                ElevationInterpolator.EPSILON / 2, 0, 20), PRECISION);
        assertEquals(20, elevationInterpolator.calculateElevationBasedOnTwoPoints(0, 0,
                -ElevationInterpolator.EPSILON / 2, 0, 10,
                ElevationInterpolator.EPSILON / 3, 0, 20), PRECISION);
        assertEquals(10, elevationInterpolator.calculateElevationBasedOnTwoPoints(0, 0, 0, 0, 10, 0,
                0, 20), PRECISION);
    }