From e9830964c415a4c6255780e5f046ccb7bcce6434 Mon Sep 17 00:00:00 2001 From: Kalev Lember Date: Tue, 10 Sep 2013 00:00:27 +0200 Subject: [PATCH 1/7] location-info: Add gclue_location_info_equal https://bugs.freedesktop.org/show_bug.cgi?id=69105 --- src/gclue-location-info.c | 27 +++++++++++++++++++++++++++ src/gclue-location-info.h | 3 +++ 2 files changed, 30 insertions(+) diff --git a/src/gclue-location-info.c b/src/gclue-location-info.c index d372acf..49ea11c 100644 --- a/src/gclue-location-info.c +++ b/src/gclue-location-info.c @@ -26,6 +26,7 @@ #include #define EARTH_RADIUS_KM 6372.795 +#define EPSILON (1e-10) /** * SECTION:gclue-location @@ -413,3 +414,29 @@ gclue_location_info_get_distance_from (GClueLocationInfo *loca, c = 2 * atan2 (sqrt (a), sqrt (1-a)); return EARTH_RADIUS_KM * c; } + +/** + * gclue_location_info_equal: + * @loca: a #GClueLocationInfo + * @locb: a #GClueLocationInfo + * + * Compares two locations for equality, returning TRUE if they are equal. + * + * Returns: TRUE if the coordinates, accuracy, and description are equal + **/ +gboolean +gclue_location_info_equal (GClueLocationInfo *loca, + GClueLocationInfo *locb) +{ + gboolean ret; + + g_return_val_if_fail (GCLUE_IS_LOCATION_INFO (loca), FALSE); + g_return_val_if_fail (GCLUE_IS_LOCATION_INFO (locb), FALSE); + + ret = fabs (loca->priv->latitude - locb->priv->latitude) < EPSILON && + fabs (loca->priv->longitude - locb->priv->longitude) < EPSILON && + fabs (loca->priv->accuracy - locb->priv->accuracy) < EPSILON && + g_strcmp0 (loca->priv->description, locb->priv->description) == 0; + + return ret; +} diff --git a/src/gclue-location-info.h b/src/gclue-location-info.h index e31266c..16e0453 100644 --- a/src/gclue-location-info.h +++ b/src/gclue-location-info.h @@ -82,6 +82,9 @@ GClueLocationInfo *gclue_location_info_new_with_description (gdouble latitud double gclue_location_info_get_distance_from (GClueLocationInfo *loca, GClueLocationInfo *locb); +gboolean gclue_location_info_equal (GClueLocationInfo *loca, + GClueLocationInfo *locb); + void gclue_location_info_set_description (GClueLocationInfo *loc, const char *description); -- 1.8.3.1