1 package tim.prune.correlate;
3 import tim.prune.data.DataPoint;
4 import tim.prune.data.MediaFile;
7 * Class to hold a pair of points used to hold the result of correlation
9 public class PointMediaPair
11 private MediaFile _media = null;
12 private DataPoint _pointBefore = null;
13 private DataPoint _pointAfter = null;
14 private long _secondsBefore = 1L;
15 private long _secondsAfter = -1L;
20 * @param inMedia media object
22 public PointMediaPair(MediaFile inMedia) {
27 * Add a point to the pair
28 * @param inPoint data point
29 * @param inSeconds number of seconds time difference, positive means point later
31 public void addPoint(DataPoint inPoint, long inSeconds)
33 // Check if point is closest point before
36 // point stamp is before media stamp
37 if (inSeconds > _secondsBefore || _secondsBefore > 0L)
39 // point stamp is nearer to media
40 _pointBefore = inPoint;
41 _secondsBefore = inSeconds;
44 // Check if point is closest point after
47 // point stamp is after media stamp
48 if (inSeconds < _secondsAfter || _secondsAfter < 0L)
50 // point stamp is nearer to media
51 _pointAfter = inPoint;
52 _secondsAfter = inSeconds;
59 * @return Media object
61 public MediaFile getMedia() {
66 * @return the closest point before the media
68 public DataPoint getPointBefore() {
73 * @return number of seconds between media and subsequent point
75 public long getSecondsBefore() {
76 return _secondsBefore;
80 * @return the closest point after the media
82 public DataPoint getPointAfter() {
87 * @return number of seconds between previous point and media
89 public long getSecondsAfter() {
94 * @return true if both points found
96 public boolean isValid() {
97 return getPointBefore() != null && getPointAfter() != null;
101 * @return the fraction of the distance along the interpolated line
103 public double getFraction()
105 if (_secondsAfter == 0L) return 0.0;
106 return (-_secondsBefore * 1.0 / (-_secondsBefore + _secondsAfter));
110 * @return the number of seconds to the nearest point
112 public long getMinSeconds() {
113 return Math.min(_secondsAfter, -_secondsBefore);
117 * @return angle from media to nearest point in radians
119 public double getMinRadians()
121 double totalRadians = DataPoint.calculateRadiansBetween(_pointBefore, _pointAfter);
122 double frac = getFraction();
123 return totalRadians * Math.min(frac, 1-frac);