1 package tim.prune.correlate;
3 import tim.prune.data.DataPoint;
4 import tim.prune.data.Photo;
7 * Class to hold a pair of points
8 * used to hold the result of correlation of a photo
10 public class PointPair
12 private Photo _photo = null;
13 private DataPoint _pointBefore = null;
14 private DataPoint _pointAfter = null;
15 private long _secondsBefore = 1L;
16 private long _secondsAfter = -1L;
21 * @param inPhoto Photo object
23 public PointPair(Photo inPhoto)
30 * Add a point to the pair
31 * @param inPoint data point
32 * @param inSeconds number of seconds time difference, positive means point later
34 public void addPoint(DataPoint inPoint, long inSeconds)
36 // Check if point is closest point before
39 // point stamp is before photo stamp
40 if (inSeconds > _secondsBefore || _secondsBefore > 0L)
42 // point stamp is nearer to photo
43 _pointBefore = inPoint;
44 _secondsBefore = inSeconds;
47 // Check if point is closest point after
50 // point stamp is after photo stamp
51 if (inSeconds < _secondsAfter || _secondsAfter < 0L)
53 // point stamp is nearer to photo
54 _pointAfter = inPoint;
55 _secondsAfter = inSeconds;
62 * @return Photo object
64 public Photo getPhoto()
70 * @return the closest point before the photo
72 public DataPoint getPointBefore()
78 * @return number of seconds between photo and subsequent point
80 public long getSecondsBefore()
82 return _secondsBefore;
86 * @return the closest point after the photo
88 public DataPoint getPointAfter()
94 * @return number of seconds between previous point and photo
96 public long getSecondsAfter()
102 * @return true if both points found
104 public boolean isValid()
106 return getPointBefore() != null && getPointAfter() != null;
110 * @return the fraction of the distance along the interpolated line
112 public double getFraction()
114 if (_secondsAfter == 0L) return 0.0;
115 return (-_secondsBefore * 1.0 / (-_secondsBefore + _secondsAfter));
119 * @return the number of seconds to the nearest point
121 public long getMinSeconds()
123 return Math.min(_secondsAfter, -_secondsBefore);
127 * @return angle from photo to nearest point in radians
129 public double getMinRadians()
131 double totalRadians = DataPoint.calculateRadiansBetween(_pointBefore, _pointAfter);
132 double frac = getFraction();
133 return totalRadians * Math.min(frac, 1-frac);