[libgweather/wip/hadess/serialisation-fix-stable: 10/13] GWeatherLocation: Fix distance for loc1 == loc2



commit 432e0af809ed589c9edf0e58ac546e0342d54099
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 6e28c4d..6ddb1c0 100644
--- a/libgweather/gweather-location.c
+++ b/libgweather/gweather-location.c
@@ -698,6 +698,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]