File: CandidateSorter.java

package info (click to toggle)
gpsprune 17-1
  • links: PTS, VCS
  • area: main
  • in suites: jessie, jessie-kfreebsd
  • size: 3,984 kB
  • ctags: 5,218
  • sloc: java: 39,403; sh: 25; makefile: 17; python: 15
file content (29 lines) | stat: -rw-r--r-- 741 bytes parent folder | download | duplicates (5)
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
package tim.prune.function.sew;

import java.util.Comparator;

/**
 * Class to sort the candidates for segment splitting
 */
public class CandidateSorter implements Comparator<SplitPoint>
{
	/**
	 * Sort the objects by distance (greatest first)
	 */
	public int compare(SplitPoint inFirst, SplitPoint inSecond)
	{
		if (inFirst == null)  return 1;
		if (inSecond == null) return -1;
		// First, sort by distance
		final double dist1 = inFirst.getDistanceToPrevPoint();
		final double dist2 = inSecond.getDistanceToPrevPoint();
		if (dist1 > dist2) {
			return -1;
		}
		if (dist1 < dist2) {
			return 1;
		}
		// If the distances are identical, then just sort by point index
		return inFirst.getPointIndex() - inSecond.getPointIndex();
	}
}