File: DuplicatesMethod.java

package info (click to toggle)
gpsprune 26.1-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 5,824 kB
  • sloc: java: 52,154; sh: 25; makefile: 21; python: 15
file content (52 lines) | stat: -rw-r--r-- 1,650 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
package tim.prune.function.compress.methods;

import tim.prune.data.DataPoint;
import tim.prune.data.MarkingData;
import tim.prune.data.Track;
import tim.prune.function.compress.CompressionMethodType;
import tim.prune.function.compress.TrackDetails;

public class DuplicatesMethod extends ParameterlessMethod
{
	/** Number of points before this one to consider as duplicates */
	private static final int NUM_POINTS_TO_BACKTRACK = 20;

	public int compress(Track inTrack, TrackDetails inDetails, MarkingData inMarkings)
	{
		int numPoints = inTrack.getNumPoints();
		int numDeleted = 0;
		// Loop over all points looking for duplicates
		for (int i=1; i<numPoints; i++)
		{
			// Don't delete points which are already marked as deleted, or the first point in a segment
			if (inMarkings.isPointMarkedForDeletion(i) || inDetails.isSegmentStart(i)) {
				continue;
			}
			DataPoint currPoint = inTrack.getPoint(i);
			// Don't delete any photo points or audio points
			if (currPoint.hasMedia()) {
				continue;
			}
			// loop over last few points before this one
			final int startIdx = Math.max(0, i - NUM_POINTS_TO_BACKTRACK);
			for (int j = startIdx; j<i; j++)
			{
				if (!inMarkings.isPointMarkedForDeletion(j) && currPoint.isDuplicate(inTrack.getPoint(j)))
				{
					inMarkings.markPointForDeletion(i);
					numDeleted++;
					break;
				}
			}
		}
		return numDeleted;
	}

	public CompressionMethodType getType() {
		return CompressionMethodType.DUPLICATES;
	}

	static boolean recogniseString(String inString) {
		return recogniseString(inString, CompressionMethodType.DUPLICATES);
	}
}