fix: always use GPSCoordinate.hasAltitude to check if altitude value is valid

Altitude is a floating point value that supports NaN so it is too easy to use the wrong comparison operation.
This commit is contained in:
Thomas Kuehne
2026-04-03 16:40:55 +00:00
parent 3cd5ae847b
commit de1c74f223
3 changed files with 4 additions and 4 deletions
@@ -72,7 +72,7 @@ public class DefaultWorkoutCharts {
}
// Elevation
if (point.getLocation() != null && point.getLocation().getAltitude() != GPSCoordinate.UNKNOWN_ALTITUDE) {
if (point.getLocation() != null && point.getLocation().hasAltitude()) {
elevationDataPoints.add(new Entry(tsShorten, (float) point.getLocation().getAltitude()));
if (point.getLocation().getAltitude() != 0) {
// Some devices provide all points at zero
@@ -130,7 +130,7 @@ public class BangleJSWorkoutParser implements ActivitySummaryParser, ActivityTra
if (p.getSteps() > 0) {
accStride.add(distanceDiff / p.getSteps());
}
if (p.getLocation() != null && p.getLocation().getAltitude() != GPSCoordinate.UNKNOWN_ALTITUDE) {
if (p.getLocation() != null && p.getLocation().hasAltitude()) {
accAltitude.add(p.getLocation().getAltitude());
}
totalTime += timeDiff;
@@ -126,9 +126,9 @@ public class GPSCoordinate implements Parcelable {
}
public double getAltitudeDifference(GPSCoordinate source) {
if (this.getAltitude() == UNKNOWN_ALTITUDE)
if (!hasAltitude())
return 0;
if (source.getAltitude() == UNKNOWN_ALTITUDE)
if (!source.hasAltitude())
return 0;
return this.getAltitude() - source.getAltitude();
}