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



commit 64010566f790187d8dda2820983f7891a541f16e
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 ad35b8a..99b3dfd 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]