]> gitweb.fperrin.net Git - GpsPrune.git/blobdiff - src/tim/prune/function/sew/CandidateSorter.java
Moved source into separate src directory due to popular request
[GpsPrune.git] / src / tim / prune / function / sew / CandidateSorter.java
diff --git a/src/tim/prune/function/sew/CandidateSorter.java b/src/tim/prune/function/sew/CandidateSorter.java
new file mode 100644 (file)
index 0000000..6736f32
--- /dev/null
@@ -0,0 +1,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();
+       }
+}