+
+ /**
+ * Find the index of the point furthest away from the start and end points
+ * @param inStartIndex start index of segment to check
+ * @param inEndIndex end index of segment to check
+ * @return index of furthest point, or -1 if none found
+ */
+ private int getFurthestPointIndex(int inStartIndex, int inEndIndex)
+ {
+ int furthestIndex = -1;
+ if (inStartIndex >= 0 && inEndIndex > inStartIndex)
+ {
+ final DataPoint startPoint = _track.getPoint(inStartIndex);
+ double maxDist = 0.0;
+ // Loop over points between start and end
+ for (int i=inStartIndex+1; i<inEndIndex; i++)
+ {
+ DataPoint p = _track.getPoint(i);
+ if (!p.isWaypoint())
+ {
+ double distFromStart = DataPoint.calculateRadiansBetween(startPoint, p);
+ if (distFromStart > maxDist)
+ {
+ furthestIndex = i;
+ maxDist = distFromStart;
+ }
+ }
+ }
+ }
+ return furthestIndex;
+ }