getEstimatedPosition now returns null if no relevant fix is found

This commit is contained in:
Axel Uhl committed 2012-01-02 15:52:04 +01:00
1 parent 5b7855338f
commit 34b5f5c38b
2 files changed
+14 -6

No files matched your search

@@ -64,7 +64,7 @@ public class DynamicGPSFixMovingTrackImpl<ItemType> extends DynamicTrackImpl<Ite
last = next;
}
}
SpeedWithBearing avgSpeed = new KnotSpeedWithBearingImpl(knotSum / count, bearingCluster.getAverage());
SpeedWithBearing avgSpeed = count == 0 ? null : new KnotSpeedWithBearingImpl(knotSum / count, bearingCluster.getAverage());
return avgSpeed;
}
@@ -324,7 +324,7 @@ public class GPSFixTrackImpl<ItemType, FixType extends GPSFix> extends TrackImpl
last = next;
}
}
SpeedWithBearing avgSpeed = new KnotSpeedWithBearingImpl(knotSum / count, bearingCluster.getAverage());
SpeedWithBearing avgSpeed = count == 0 ? null : new KnotSpeedWithBearingImpl(knotSum / count, bearingCluster.getAverage());
return avgSpeed;
}
@@ -420,12 +420,20 @@ public class GPSFixTrackImpl<ItemType, FixType extends GPSFix> extends TrackImpl
@Override
public boolean hasDirectionChange(TimePoint at, double minimumDegreeDifference) {
boolean result = false;
TimePoint start = new MillisecondsTimePoint(at.asMillis()-getMillisecondsOverWhichToAverageSpeed());
TimePoint end = new MillisecondsTimePoint(at.asMillis()+getMillisecondsOverWhichToAverageSpeed());
Bearing bearingAtStart = getEstimatedSpeed(start).getBearing();
Bearing bearingAtEnd = getEstimatedSpeed(end).getBearing();
// TODO also need to analyze the (smoothened) directions in between; example: two tacks within averaging interval
return Math.abs(bearingAtStart.getDifferenceTo(bearingAtEnd).getDegrees()) > minimumDegreeDifference;
SpeedWithBearing estimatedSpeedAtStart = getEstimatedSpeed(start);
if (estimatedSpeedAtStart != null) {
Bearing bearingAtStart = estimatedSpeedAtStart.getBearing();
SpeedWithBearing estimatedSpeedAtEnd = getEstimatedSpeed(end);
if (estimatedSpeedAtEnd != null) {
Bearing bearingAtEnd = estimatedSpeedAtEnd.getBearing();
// TODO also need to analyze the (smoothened) directions in between; example: two tacks within averaging interval
result = Math.abs(bearingAtStart.getDifferenceTo(bearingAtEnd).getDegrees()) > minimumDegreeDifference;
}
}
return result;
}
}