diff options
author | Teemu Ikonen <tpikonen@mailbox.org> | 2021-12-14 13:59:21 +0200 |
---|---|---|
committer | Teemu Ikonen <tpikonen@mailbox.org> | 2022-01-13 12:05:05 +0000 |
commit | 1db13ee5b6287d440e3cc88e067cd5a69c621cd6 (patch) | |
tree | ba1028527ff8b45a635ecec9c043dec84b3b776b | |
parent | 542b3b8e26bb17710893adfca506e49e83378ef3 (diff) |
location: Return meters from _get_distance_from, fix users
Make the unit of gclue_location_get_distance_from return value to be
meters, not km.
Meters are used everywhere else in GeoClue as a unit of distance, and it
is better to be consistent.
Fix the users of this function, mostly by removing a 1000.0 m
multiplier.
-rw-r--r-- | src/gclue-location.c | 10 | ||||
-rw-r--r-- | src/gclue-locator.c | 2 | ||||
-rw-r--r-- | src/gclue-service-client.c | 12 |
3 files changed, 12 insertions, 12 deletions
diff --git a/src/gclue-location.c b/src/gclue-location.c index 5c4fd48..b0e5e0d 100644 --- a/src/gclue-location.c +++ b/src/gclue-location.c @@ -949,8 +949,8 @@ gclue_location_set_speed_from_prev_location (GClueLocation *location, goto out; } - speed = gclue_location_get_distance_from (location, prev_location) * - 1000.0 / (timestamp - prev_timestamp); + speed = gclue_location_get_distance_from (location, prev_location) / + (timestamp - prev_timestamp); out: location->priv->speed = speed; @@ -1067,11 +1067,11 @@ gclue_location_set_heading_from_prev_location (GClueLocation *location, * @loca: a #GClueLocation * @locb: a #GClueLocation * - * Calculates the distance in km, along the curvature of the Earth, + * Calculates the distance in meters, along the curvature of the Earth, * between 2 locations. Note that altitude changes are not * taken into account. * - * Returns: a distance in km. + * Returns: a distance in meters. **/ double gclue_location_get_distance_from (GClueLocation *loca, @@ -1094,5 +1094,5 @@ gclue_location_get_distance_from (GClueLocation *loca, a = sin (dlat / 2) * sin (dlat / 2) + sin (dlon / 2) * sin (dlon / 2) * cos (lat1) * cos (lat2); c = 2 * atan2 (sqrt (a), sqrt (1-a)); - return EARTH_RADIUS_KM * c; + return 1000.0 * EARTH_RADIUS_KM * c; } diff --git a/src/gclue-locator.c b/src/gclue-locator.c index 05efeb0..46045e9 100644 --- a/src/gclue-locator.c +++ b/src/gclue-locator.c @@ -103,7 +103,7 @@ set_location (GClueLocator *locator, return; } - dist = gclue_location_get_distance_from (location, cur_location) * 1000; + dist = gclue_location_get_distance_from (location, cur_location); if (new_timestamp > cur_timestamp) { guint64 age = new_timestamp - cur_timestamp; diff --git a/src/gclue-service-client.c b/src/gclue-service-client.c index 7ab1590..e7cfd86 100644 --- a/src/gclue-service-client.c +++ b/src/gclue-service-client.c @@ -126,7 +126,7 @@ distance_below_threshold (GClueServiceClient *client, GClueServiceClientPrivate *priv = client->priv; GClueLocation *cur_location; gdouble distance; - gdouble threshold_km; + gdouble threshold; if (priv->distance_threshold == 0) return FALSE; @@ -137,11 +137,11 @@ distance_below_threshold (GClueServiceClient *client, distance = gclue_location_get_distance_from (cur_location, location); g_object_unref (cur_location); - threshold_km = priv->distance_threshold / 1000.0; - if (distance < threshold_km) { - g_debug ("Distance from previous location is %f km and " - "below threshold of %f km.", - distance, threshold_km); + threshold = priv->distance_threshold; + if (distance < threshold) { + g_debug ("Distance from previous location is %f m and " + "below threshold of %f m.", + distance, threshold); return TRUE; } |