further prepared smoothening by introducing getInternalFixes as the "smoothener" and having

all other smoothening APIs rely on it
This commit is contained in:
Axel Uhl committed 2011-07-14 18:16:55 +02:00
1 parent f22c6fda80
commit fefe4edf94
5 files changed
+50 -11

No files matched your search

@@ -93,16 +93,16 @@ public class TrackTest {
assertTrue(millis > lastMillis);
TimePoint inBetweenTimePoint = new MillisecondsTimePoint((millis+lastMillis)/2);
assertEquals(lastFix, track.getLastRawFixBefore(inBetweenTimePoint));
assertEquals(lastFix, track.getLastFixAtOrBefore(inBetweenTimePoint));
assertEquals(fix, track.getFirstFixAfter(inBetweenTimePoint));
assertEquals(lastFix, track.getLastRawFixAtOrBefore(inBetweenTimePoint));
assertEquals(fix, track.getFirstRawFixAfter(inBetweenTimePoint));
assertEquals(fix, track.getFirstRawFixAtOrAfter(inBetweenTimePoint));
assertEquals(lastFix, track.getLastFixAtOrBefore(lastFix.getTimePoint()));
assertEquals(fix, track.getFirstRawFixAtOrAfter(fix.getTimePoint()));
assertEquals(lastFix, track.getLastRawFixBefore(fix.getTimePoint()));
assertEquals(fix, track.getLastFixAtOrBefore(fix.getTimePoint()));
assertEquals(fix, track.getFirstFixAfter(lastFix.getTimePoint()));
assertEquals(fix, track.getLastRawFixAtOrBefore(fix.getTimePoint()));
assertEquals(fix, track.getFirstRawFixAfter(lastFix.getTimePoint()));
assertEquals(lastFix, track.getFirstRawFixAtOrAfter(lastFix.getTimePoint()));
}
lastMillis = millis;
@@ -22,10 +22,16 @@ public interface Track<FixType extends Timed> {
FixType getLastFixAtOrBefore(TimePoint timePoint);
FixType getLastRawFixAtOrBefore(TimePoint timePoint);
FixType getFirstFixAtOrAfter(TimePoint timePoint);
FixType getFirstRawFixAtOrAfter(TimePoint timePoint);
FixType getLastRawFixBefore(TimePoint timePoint);
FixType getFirstRawFixAfter(TimePoint timePoint);
FixType getFirstFixAfter(TimePoint timePoint);
/**
@@ -125,4 +125,10 @@ public class DynamicGPSFixMovingTrackImpl<ItemType> extends DynamicTrackImpl<Ite
return new KilometersPerHourSpeedImpl(sumInKMH/count);
}
@Override
protected NavigableSet<GPSFixMoving> getInternalFixes() {
// TODO perform even better smoothening than GPSFixTrackImpl because here we additionally have the speeds/bearings on the fixes as a hint
return super.getInternalFixes();
}
}
@@ -54,7 +54,7 @@ public class GPSFixTrackImpl<ItemType, FixType extends GPSFix> extends TrackImpl
@Override
public Position getEstimatedPosition(TimePoint timePoint, boolean extrapolate) {
FixType lastFixAtOrBefore = getLastFixAtOrBefore(timePoint);
FixType firstFixAtOrAfter = getFirstRawFixAtOrAfter(timePoint);
FixType firstFixAtOrAfter = getFirstFixAtOrAfter(timePoint);
if (lastFixAtOrBefore != null && lastFixAtOrBefore == firstFixAtOrAfter) {
return lastFixAtOrBefore.getPosition(); // exact match; how unlikely is that?
} else {
@@ -210,4 +210,13 @@ public class GPSFixTrackImpl<ItemType, FixType extends GPSFix> extends TrackImpl
return millisecondsOverWhichToAverage;
}
/**
* Smoothens the track based on a max-speed assumption.
*/
@Override
protected NavigableSet<FixType> getInternalFixes() {
// TODO implement getInternalFixes with a smart smoothening algorithm
return super.getInternalFixes();
}
}
@@ -39,23 +39,23 @@ public abstract class TrackImpl<FixType extends Timed> implements Track<FixType>
}
/**
* @return the smoothened fixes
* @return the smoothened fixes; this implementation simply delegates to {@link #getFixes()} because for only
* {@link Timed} fixes we can't know how to smoothen anything. Subclasses that constrain the
* <code>FixType</code> may provide smoothening implementations.
*/
protected NavigableSet<FixType> getInternalFixes() {
// TODO smoothen the track before returning it, or construct a smoothening "view" onto it
@SuppressWarnings("unchecked")
NavigableSet<FixType> result = (NavigableSet<FixType>) fixes;
return result;
}
/**
* Iterates the fixes with outliers getting skipped, in the order of their time points
* Iterates the fixes with outliers getting skipped, in the order of their time points.
* Relies on {@link #getInternalFixes()} to smoothen the track.
*/
@SuppressWarnings("unchecked")
@Override
public Iterable<FixType> getFixes() {
// TODO skip outliers in iterable returned
return (Iterable<FixType>) Collections.unmodifiableSet(fixes);
return (Iterable<FixType>) Collections.unmodifiableSet(getInternalFixes());
}
/**
@@ -70,6 +70,12 @@ public abstract class TrackImpl<FixType extends Timed> implements Track<FixType>
@SuppressWarnings("unchecked")
@Override
public FixType getLastFixAtOrBefore(TimePoint timePoint) {
return (FixType) getInternalFixes().floor((FixType) new DummyTimed(timePoint));
}
@SuppressWarnings("unchecked")
@Override
public FixType getLastRawFixAtOrBefore(TimePoint timePoint) {
return (FixType) fixes.floor(new DummyTimed(timePoint));
}
@@ -79,6 +85,12 @@ public abstract class TrackImpl<FixType extends Timed> implements Track<FixType>
return (FixType) fixes.ceiling(new DummyTimed(timePoint));
}
@SuppressWarnings("unchecked")
@Override
public FixType getFirstFixAtOrAfter(TimePoint timePoint) {
return (FixType) getInternalFixes().ceiling((FixType) new DummyTimed(timePoint));
}
@SuppressWarnings("unchecked")
@Override
public FixType getLastRawFixBefore(TimePoint timePoint) {
@@ -88,6 +100,12 @@ public abstract class TrackImpl<FixType extends Timed> implements Track<FixType>
@SuppressWarnings("unchecked")
@Override
public FixType getFirstFixAfter(TimePoint timePoint) {
return (FixType) getInternalFixes().higher((FixType) new DummyTimed(timePoint));
}
@SuppressWarnings("unchecked")
@Override
public FixType getFirstRawFixAfter(TimePoint timePoint) {
return (FixType) fixes.higher(new DummyTimed(timePoint));
}