Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
42 changes: 24 additions & 18 deletions app/position/providers/internalpositionprovider.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -173,45 +173,51 @@ void InternalPositionProvider::parsePositionUpdate( const QGeoPositionInfo &posi
positionDataHasChanged = true;
}

const bool hasSpeedInfo = localPosition.hasAttribute( QGeoPositionInfo::GroundSpeed );
if ( hasSpeedInfo && !qgsDoubleNear( localPosition.attribute( QGeoPositionInfo::GroundSpeed ), mLastPosition.speed ) )
const double newSpeed = localPosition.hasAttribute( QGeoPositionInfo::GroundSpeed ) ?
localPosition.attribute( QGeoPositionInfo::GroundSpeed ) * 3.6 : std::numeric_limits<double>::quiet_NaN(); // convert from m/s to km/h
if ( !qgsDoubleNear( newSpeed, mLastPosition.speed ) )

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If both of these will be NaN, thats always false no? I think qgsDoubleNear won't ever return true if it is comparing NaN values. So it goes through even when it shouldn't and forces positionDataHasChanged to true. The attributes stay missing though and this stays like that on every consecutive update right? Is that intended? Same applies to other if statements bellow

{
mLastPosition.speed = localPosition.attribute( QGeoPositionInfo::GroundSpeed ) * 3.6; // convert from m/s to km/h
mLastPosition.speed = newSpeed;
positionDataHasChanged = true;
}

const bool hasVerticalSpeedInfo = localPosition.hasAttribute( QGeoPositionInfo::VerticalSpeed );
if ( hasVerticalSpeedInfo && !qgsDoubleNear( localPosition.attribute( QGeoPositionInfo::VerticalSpeed ), mLastPosition.verticalSpeed ) )
const double newVerticalSpeed = localPosition.hasAttribute( QGeoPositionInfo::VerticalSpeed ) ?
localPosition.attribute( QGeoPositionInfo::VerticalSpeed ) * 3.6 : std::numeric_limits<double>::quiet_NaN(); // convert from m/s to km/h
if ( !qgsDoubleNear( newVerticalSpeed, mLastPosition.verticalSpeed ) )
{
mLastPosition.verticalSpeed = localPosition.attribute( QGeoPositionInfo::VerticalSpeed ) * 3.6; // convert from m/s to km/h
mLastPosition.verticalSpeed = newVerticalSpeed;
positionDataHasChanged = true;
}

const bool hasDirectionInfo = localPosition.hasAttribute( QGeoPositionInfo::Direction );
if ( hasDirectionInfo && !qgsDoubleNear( localPosition.attribute( QGeoPositionInfo::Direction ), mLastPosition.direction ) )
const double newDirection = localPosition.hasAttribute( QGeoPositionInfo::Direction ) ?
localPosition.attribute( QGeoPositionInfo::Direction ) : std::numeric_limits<double>::quiet_NaN();
if ( !qgsDoubleNear( newDirection, mLastPosition.direction ) )
{
mLastPosition.direction = localPosition.attribute( QGeoPositionInfo::Direction );
mLastPosition.direction = newDirection;
positionDataHasChanged = true;
}

const bool hasMagneticVariation = localPosition.hasAttribute( QGeoPositionInfo::MagneticVariation );
if ( hasMagneticVariation && !qgsDoubleNear( localPosition.attribute( QGeoPositionInfo::MagneticVariation ), mLastPosition.magneticVariation ) )
const double newMagneticVariation = localPosition.hasAttribute( QGeoPositionInfo::MagneticVariation ) ?
localPosition.attribute( QGeoPositionInfo::MagneticVariation ) : -1;
if ( !qgsDoubleNear( newMagneticVariation, mLastPosition.magneticVariation ) )
{
mLastPosition.magneticVariation = localPosition.attribute( QGeoPositionInfo::MagneticVariation );
mLastPosition.magneticVariation = newMagneticVariation;
positionDataHasChanged = true;
}

const bool hasHacc = localPosition.hasAttribute( QGeoPositionInfo::HorizontalAccuracy );
if ( hasHacc && !qgsDoubleNear( localPosition.attribute( QGeoPositionInfo::HorizontalAccuracy ), mLastPosition.hacc ) )
const double newHorizontalAccuracy = localPosition.hasAttribute( QGeoPositionInfo::HorizontalAccuracy ) ?
localPosition.attribute( QGeoPositionInfo::HorizontalAccuracy ) : std::numeric_limits<double>::quiet_NaN();;

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The double semicolon might be a typo. Same on line 217

if ( !qgsDoubleNear( newHorizontalAccuracy, mLastPosition.hacc ) )
{
mLastPosition.hacc = localPosition.attribute( QGeoPositionInfo::HorizontalAccuracy );
mLastPosition.hacc = newHorizontalAccuracy;
positionDataHasChanged = true;
}

const bool hasVacc = localPosition.hasAttribute( QGeoPositionInfo::VerticalAccuracy );
if ( hasVacc && !qgsDoubleNear( localPosition.attribute( QGeoPositionInfo::VerticalAccuracy ), mLastPosition.vacc ) )
const double newVerticalAccuracy = localPosition.hasAttribute( QGeoPositionInfo::VerticalAccuracy ) ?
localPosition.attribute( QGeoPositionInfo::VerticalAccuracy ) : std::numeric_limits<double>::quiet_NaN();;
if ( !qgsDoubleNear( newVerticalAccuracy, mLastPosition.vacc ) )
{
mLastPosition.vacc = localPosition.attribute( QGeoPositionInfo::VerticalAccuracy );
mLastPosition.vacc = newVerticalAccuracy;
positionDataHasChanged = true;
}

Expand Down
Loading