X-Git-Url: http://gitweb.fperrin.net/?p=GpsPrune.git;a=blobdiff_plain;f=src%2Ftim%2Fprune%2Ffunction%2Fsew%2FCandidateSorter.java;fp=src%2Ftim%2Fprune%2Ffunction%2Fsew%2FCandidateSorter.java;h=6736f32879c3fef52c101c35977f060c61579032;hp=0000000000000000000000000000000000000000;hb=ce6f2161b8596f7018d6a76bff79bc9e571f35fd;hpb=2d8cb72e84d5cc1089ce77baf1e34ea3ea2f8465 diff --git a/src/tim/prune/function/sew/CandidateSorter.java b/src/tim/prune/function/sew/CandidateSorter.java new file mode 100644 index 0000000..6736f32 --- /dev/null +++ b/src/tim/prune/function/sew/CandidateSorter.java @@ -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 +{ + /** + * 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(); + } +}