Merge lp:~osomon/qtubuntu-sensors/shield-against-nans into lp:qtubuntu-sensors

Proposed by Olivier Tilloy
Status: Merged
Approved by: Loïc Minier
Approved revision: 75
Merged at revision: 74
Proposed branch: lp:~osomon/qtubuntu-sensors/shield-against-nans
Merge into: lp:qtubuntu-sensors
Diff against target: 37 lines (+12/-6)
1 file modified
plugins/position/core_geo_position_info_source.cpp (+12/-6)
To merge this branch: bzr merge lp:~osomon/qtubuntu-sensors/shield-against-nans
Reviewer Review Type Date Requested Status
Loïc Minier Approve
PS Jenkins bot continuous-integration Approve
Review via email: mp+235670@code.launchpad.net

Commit message

Shield position updates against NaN values for horizontal and vertical accuracy.

To post a comment you must log in.
Revision history for this message
PS Jenkins bot (ps-jenkins) wrote :
review: Approve (continuous-integration)
Revision history for this message
Loïc Minier (lool) wrote :

LGTM

Typo horizontal/vertical was obviously a mistake, and the nan fix is about making sure we only set the attributes which indeed are good values, so makes sense.

While at it, is it correct to set the altitude to 0 and to copy over the timestamp?

review: Approve
Revision history for this message
Olivier Tilloy (osomon) wrote :

> While at it, is it correct to set the altitude to 0 and to copy over the
> timestamp?

Setting the altitude to 0 if no value is set seems fine to me. I just checked and the constructor of QGeoCoordinate sets altitude to NaN by default, so we’d better be covered and initialize it to 0 if unknown. In any case I also updated my oxide MR (https://code.launchpad.net/~osomon/oxide/geolocation-doesnt-like-nans/+merge/235667) to shield it against invalid altitudes too (better safe than sorry).

As for the timestamp, I’m not really sure it makes sense to check for NaN for the value returned by ua_location_position_update_get_timestamp(…). I would expect the timestamp to be a mandatory value set by the location plugin. Maybe Thomas can comment on this?

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'plugins/position/core_geo_position_info_source.cpp'
2--- plugins/position/core_geo_position_info_source.cpp 2014-09-17 14:20:27 +0000
3+++ plugins/position/core_geo_position_info_source.cpp 2014-09-23 16:19:20 +0000
4@@ -18,6 +18,8 @@
5
6 #include "core_geo_position_info_source.h"
7
8+#include <cmath>
9+
10 #include <QtCore>
11
12 #include <ubuntu/application/location/service.h>
13@@ -273,14 +275,18 @@
14 lastKnownPosition.setCoordinate(coord);
15
16 if (ua_location_position_update_has_horizontal_accuracy(position))
17- lastKnownPosition.setAttribute(
18- QGeoPositionInfo::HorizontalAccuracy,
19- ua_location_position_update_get_horizontal_accuracy_in_meter(position));
20+ {
21+ double accuracy = ua_location_position_update_get_horizontal_accuracy_in_meter(position);
22+ if (!std::isnan(accuracy))
23+ lastKnownPosition.setAttribute(QGeoPositionInfo::HorizontalAccuracy, accuracy);
24+ }
25
26 if (ua_location_position_update_has_vertical_accuracy(position))
27- lastKnownPosition.setAttribute(
28- QGeoPositionInfo::HorizontalAccuracy,
29- ua_location_position_update_get_vertical_accuracy_in_meter(position));
30+ {
31+ double accuracy = ua_location_position_update_get_vertical_accuracy_in_meter(position);
32+ if (!std::isnan(accuracy))
33+ lastKnownPosition.setAttribute(QGeoPositionInfo::VerticalAccuracy, accuracy);
34+ }
35
36 lastKnownPosition.setTimestamp(
37 QDateTime::fromMSecsSinceEpoch(

Subscribers

People subscribed via source and target branches