]> gitweb.fperrin.net Git - GpsPrune.git/blob - tim/prune/data/Checker.java
Version 10, May 2010
[GpsPrune.git] / tim / prune / data / Checker.java
1 package tim.prune.data;
2
3 /**
4  * Class to provide checking functions
5  */
6 public abstract class Checker
7 {
8
9         /**
10          * Check if a given track is doubled, so that each point is given twice,
11          * once as waypoint and again as track point
12          * @param inTrack track to check
13          * @return true if track is doubled, false otherwise
14          */
15         public static boolean isDoubledTrack(Track inTrack)
16         {
17                 // Check for empty track
18                 if (inTrack == null || inTrack.getNumPoints() < 2) {return false;}
19                 // Check for non-even number of points
20                 final int numPoints = inTrack.getNumPoints();
21                 if (numPoints % 2 == 1) {return false;}
22                 // Loop through first half of track
23                 final int halfNum = numPoints / 2;
24                 for (int i=0; i<halfNum; i++)
25                 {
26                         DataPoint firstPoint = inTrack.getPoint(i);
27                         DataPoint secondPoint = inTrack.getPoint(i + halfNum);
28                         if (!firstPoint.getLatitude().equals(secondPoint.getLatitude())
29                                 || !firstPoint.getLongitude().equals(secondPoint.getLongitude())) {
30                                 return false;
31                         }
32                 }
33                 // Passed the test, so contents must all be doubled
34                 return true;
35         }
36
37         /**
38          * Find the index of the next segment start after the given index
39          * @param inTrack track object
40          * @param inIndex current index
41          * @return index of next segment start
42          */
43         public static int getNextSegmentStart(Track inTrack, int inIndex)
44         {
45                 int i = inIndex + 1;
46                 DataPoint point = null;
47                 while ((point=inTrack.getPoint(i)) != null && !point.getSegmentStart()) {
48                         i++;
49                 }
50                 return Math.min(i, inTrack.getNumPoints()-1);
51         }
52
53         /**
54          * Find the index of the previous segment start before the given index
55          * @param inTrack track object
56          * @param inIndex current index
57          * @return index of previous segment start
58          */
59         public static int getPreviousSegmentStart(Track inTrack, int inIndex)
60         {
61                 int i = inIndex - 1;
62                 DataPoint point = null;
63                 while ((point=inTrack.getPoint(i)) != null && !point.getSegmentStart()) {
64                         i--;
65                 }
66                 return Math.max(i, 0);
67         }
68 }