X-Git-Url: http://gitweb.fperrin.net/?p=GpsPrune.git;a=blobdiff_plain;f=src%2Ftim%2Fprune%2Fcorrelate%2FPointMediaPair.java;fp=src%2Ftim%2Fprune%2Fcorrelate%2FPointMediaPair.java;h=7e4b6de2a7ede28ba355d5d102bac68c358dd7b7;hp=0000000000000000000000000000000000000000;hb=ce6f2161b8596f7018d6a76bff79bc9e571f35fd;hpb=2d8cb72e84d5cc1089ce77baf1e34ea3ea2f8465 diff --git a/src/tim/prune/correlate/PointMediaPair.java b/src/tim/prune/correlate/PointMediaPair.java new file mode 100644 index 0000000..7e4b6de --- /dev/null +++ b/src/tim/prune/correlate/PointMediaPair.java @@ -0,0 +1,125 @@ +package tim.prune.correlate; + +import tim.prune.data.DataPoint; +import tim.prune.data.MediaObject; + +/** + * Class to hold a pair of points used to hold the result of correlation + */ +public class PointMediaPair +{ + private MediaObject _media = null; + private DataPoint _pointBefore = null; + private DataPoint _pointAfter = null; + private long _secondsBefore = 1L; + private long _secondsAfter = -1L; + + + /** + * Constructor + * @param inMedia media object + */ + public PointMediaPair(MediaObject inMedia) { + _media = inMedia; + } + + /** + * Add a point to the pair + * @param inPoint data point + * @param inSeconds number of seconds time difference, positive means point later + */ + public void addPoint(DataPoint inPoint, long inSeconds) + { + // Check if point is closest point before + if (inSeconds <= 0) + { + // point stamp is before media stamp + if (inSeconds > _secondsBefore || _secondsBefore > 0L) + { + // point stamp is nearer to media + _pointBefore = inPoint; + _secondsBefore = inSeconds; + } + } + // Check if point is closest point after + if (inSeconds >= 0) + { + // point stamp is after media stamp + if (inSeconds < _secondsAfter || _secondsAfter < 0L) + { + // point stamp is nearer to media + _pointAfter = inPoint; + _secondsAfter = inSeconds; + } + } + } + + + /** + * @return Media object + */ + public MediaObject getMedia() { + return _media; + } + + /** + * @return the closest point before the media + */ + public DataPoint getPointBefore() { + return _pointBefore; + } + + /** + * @return number of seconds between media and subsequent point + */ + public long getSecondsBefore() { + return _secondsBefore; + } + + /** + * @return the closest point after the media + */ + public DataPoint getPointAfter() { + return _pointAfter; + } + + /** + * @return number of seconds between previous point and media + */ + public long getSecondsAfter() { + return _secondsAfter; + } + + /** + * @return true if both points found + */ + public boolean isValid() { + return getPointBefore() != null && getPointAfter() != null; + } + + /** + * @return the fraction of the distance along the interpolated line + */ + public double getFraction() + { + if (_secondsAfter == 0L) return 0.0; + return (-_secondsBefore * 1.0 / (-_secondsBefore + _secondsAfter)); + } + + /** + * @return the number of seconds to the nearest point + */ + public long getMinSeconds() { + return Math.min(_secondsAfter, -_secondsBefore); + } + + /** + * @return angle from media to nearest point in radians + */ + public double getMinRadians() + { + double totalRadians = DataPoint.calculateRadiansBetween(_pointBefore, _pointAfter); + double frac = getFraction(); + return totalRadians * Math.min(frac, 1-frac); + } +}