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