[libgweather/wip/hadess/serialisation-fix: 8/17] GWeatherLocation: Fix distance for loc1 == loc2
- From: Bastien Nocera <hadess src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [libgweather/wip/hadess/serialisation-fix: 8/17] GWeatherLocation: Fix distance for loc1 == loc2
- Date: Wed, 10 Oct 2018 12:50:06 +0000 (UTC)
commit ae0d4d1cab2d2f80fd5390a1a3f551a59081b40c
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]