File: Checker.java

package info (click to toggle)
gpsprune 10-1
  • links: PTS, VCS
  • area: main
  • in suites: squeeze
  • size: 2,220 kB
  • ctags: 3,013
  • sloc: java: 22,662; sh: 23; makefile: 16; python: 15
file content (68 lines) | stat: -rw-r--r-- 1,934 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
package tim.prune.data;

/**
 * Class to provide checking functions
 */
public abstract class Checker
{

	/**
	 * Check if a given track is doubled, so that each point is given twice,
	 * once as waypoint and again as track point
	 * @param inTrack track to check
	 * @return true if track is doubled, false otherwise
	 */
	public static boolean isDoubledTrack(Track inTrack)
	{
		// Check for empty track
		if (inTrack == null || inTrack.getNumPoints() < 2) {return false;}
		// Check for non-even number of points
		final int numPoints = inTrack.getNumPoints();
		if (numPoints % 2 == 1) {return false;}
		// Loop through first half of track
		final int halfNum = numPoints / 2;
		for (int i=0; i<halfNum; i++)
		{
			DataPoint firstPoint = inTrack.getPoint(i);
			DataPoint secondPoint = inTrack.getPoint(i + halfNum);
			if (!firstPoint.getLatitude().equals(secondPoint.getLatitude())
				|| !firstPoint.getLongitude().equals(secondPoint.getLongitude())) {
				return false;
			}
		}
		// Passed the test, so contents must all be doubled
		return true;
	}

	/**
	 * Find the index of the next segment start after the given index
	 * @param inTrack track object
	 * @param inIndex current index
	 * @return index of next segment start
	 */
	public static int getNextSegmentStart(Track inTrack, int inIndex)
	{
		int i = inIndex + 1;
		DataPoint point = null;
		while ((point=inTrack.getPoint(i)) != null && !point.getSegmentStart()) {
			i++;
		}
		return Math.min(i, inTrack.getNumPoints()-1);
	}

	/**
	 * Find the index of the previous segment start before the given index
	 * @param inTrack track object
	 * @param inIndex current index
	 * @return index of previous segment start
	 */
	public static int getPreviousSegmentStart(Track inTrack, int inIndex)
	{
		int i = inIndex - 1;
		DataPoint point = null;
		while ((point=inTrack.getPoint(i)) != null && !point.getSegmentStart()) {
			i--;
		}
		return Math.max(i, 0);
	}
}