]> gitweb.fperrin.net Git - GpsPrune.git/blob - tim/prune/correlate/PointPair.java
Version 4, January 2008
[GpsPrune.git] / tim / prune / correlate / PointPair.java
1 package tim.prune.correlate;
2
3 import tim.prune.data.DataPoint;
4 import tim.prune.data.Photo;
5
6 /**
7  * Class to hold a pair of points
8  * used to hold the result of correlation of a photo
9  */
10 public class PointPair
11 {
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;
17
18
19         /**
20          * Constructor
21          * @param inPhoto Photo object
22          */
23         public PointPair(Photo inPhoto)
24         {
25                 _photo = inPhoto;
26         }
27
28
29         /**
30          * Add a point to the pair
31          * @param inPoint data point
32          * @param inSeconds number of seconds time difference, positive means point later
33          */
34         public void addPoint(DataPoint inPoint, long inSeconds)
35         {
36                 // Check if point is closest point before
37                 if (inSeconds <= 0)
38                 {
39                         // point stamp is before photo stamp
40                         if (inSeconds > _secondsBefore || _secondsBefore > 0L)
41                         {
42                                 // point stamp is nearer to photo
43                                 _pointBefore = inPoint;
44                                 _secondsBefore = inSeconds;
45                         }
46                 }
47                 // Check if point is closest point after
48                 if (inSeconds >= 0)
49                 {
50                         // point stamp is after photo stamp
51                         if (inSeconds < _secondsAfter || _secondsAfter < 0L)
52                         {
53                                 // point stamp is nearer to photo
54                                 _pointAfter = inPoint;
55                                 _secondsAfter = inSeconds;
56                         }
57                 }
58         }
59
60
61         /**
62          * @return Photo object
63          */
64         public Photo getPhoto()
65         {
66                 return _photo;
67         }
68
69         /**
70          * @return the closest point before the photo
71          */
72         public DataPoint getPointBefore()
73         {
74                 return _pointBefore;
75         }
76
77         /**
78          * @return number of seconds between photo and subsequent point
79          */
80         public long getSecondsBefore()
81         {
82                 return _secondsBefore;
83         }
84
85         /**
86          * @return the closest point after the photo
87          */
88         public DataPoint getPointAfter()
89         {
90                 return _pointAfter;
91         }
92
93         /**
94          * @return number of seconds between previous point and photo
95          */
96         public long getSecondsAfter()
97         {
98                 return _secondsAfter;
99         }
100
101         /**
102          * @return true if both points found
103          */
104         public boolean isValid()
105         {
106                 return getPointBefore() != null && getPointAfter() != null;
107         }
108
109         /**
110          * @return the fraction of the distance along the interpolated line
111          */
112         public double getFraction()
113         {
114                 if (_secondsAfter == 0L) return 0.0;
115                 return (-_secondsBefore * 1.0 / (-_secondsBefore + _secondsAfter));
116         }
117
118         /**
119          * @return the number of seconds to the nearest point
120          */
121         public long getMinSeconds()
122         {
123                 return Math.min(_secondsAfter, -_secondsBefore);
124         }
125
126         /**
127          * @return angle from photo to nearest point in radians
128          */
129         public double getMinRadians()
130         {
131                 double totalRadians = DataPoint.calculateRadiansBetween(_pointBefore, _pointAfter);
132                 double frac = getFraction();
133                 return totalRadians * Math.min(frac, 1-frac);
134         }
135 }