[libgweather/wip/hadess/serialisation-fix: 8/17] GWeatherLocation: Fix distance for loc1 == loc2



commit ff7ec97fd50d66aa0004ccedc0a41455bef1e0d9
Author: Bastien Nocera <hadess hadess net>
Date:   Tue Oct 9 18:04:45 2018 +0200

    GWeatherLocation: Fix distance for loc1 == loc2
    
    If the coordinates for the 2 sets of coordinates are exactly the same,
    the returned distance between the 2 would have been "nan" instead of
    0.0, such as for Bamboo and its airport.

 libgweather/gweather-location.c | 3 +++
 1 file changed, 3 insertions(+)
---
diff --git a/libgweather/gweather-location.c b/libgweather/gweather-location.c
index 4ca4840..03e67ee 100644
--- a/libgweather/gweather-location.c
+++ b/libgweather/gweather-location.c
@@ -727,6 +727,9 @@ location_distance (double lat1, double long1,
     /* average radius of the earth in km */
     static const double radius = 6372.795;
 
+    if (lat1 == lat2 && long1 == long2)
+        return 0.0;
+
     return acos (cos (lat1) * cos (lat2) * cos (long1 - long2) +
                 sin (lat1) * sin (lat2)) * radius;
 }


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]