]> gitweb.fperrin.net Git - GpsPrune.git/blob - tim/prune/function/sew/CandidateSorter.java
Version 16, February 2014
[GpsPrune.git] / tim / prune / function / sew / CandidateSorter.java
1 package tim.prune.function.sew;
2
3 import java.util.Comparator;
4
5 /**
6  * Class to sort the candidates for segment splitting
7  */
8 public class CandidateSorter implements Comparator<SplitPoint>
9 {
10         /**
11          * Sort the objects by distance (greatest first)
12          */
13         public int compare(SplitPoint inFirst, SplitPoint inSecond)
14         {
15                 if (inFirst == null)  return 1;
16                 if (inSecond == null) return -1;
17                 // First, sort by distance
18                 final double dist1 = inFirst.getDistanceToPrevPoint();
19                 final double dist2 = inSecond.getDistanceToPrevPoint();
20                 if (dist1 > dist2) {
21                         return -1;
22                 }
23                 if (dist1 < dist2) {
24                         return 1;
25                 }
26                 // If the distances are identical, then just sort by point index
27                 return inFirst.getPointIndex() - inSecond.getPointIndex();
28         }
29 }