Fix #1349
This commit is contained in:
parent
45b0a8a75f
commit
1dd4b4b576
2 changed files with 24 additions and 5 deletions
|
@ -142,16 +142,16 @@ public class GPXUtilities {
|
|||
public List<WptPt> points = new ArrayList<WptPt>();
|
||||
|
||||
public List<GPXTrackAnalysis> splitByDistance(double meters) {
|
||||
return split(getDistanceMetric(), meters);
|
||||
return split(getDistanceMetric(), getTimeSplit(), meters);
|
||||
}
|
||||
|
||||
public List<GPXTrackAnalysis> splitByTime(int seconds) {
|
||||
return split(getTimeSplit(), seconds);
|
||||
return split(getTimeSplit(), getDistanceMetric(), seconds);
|
||||
}
|
||||
|
||||
private List<GPXTrackAnalysis> split(SplitMetric metric, double metricLimit) {
|
||||
private List<GPXTrackAnalysis> split(SplitMetric metric, SplitMetric secondaryMetric, double metricLimit) {
|
||||
List<SplitSegment> splitSegments = new ArrayList<GPXUtilities.SplitSegment>();
|
||||
splitSegment(metric, metricLimit, splitSegments, this);
|
||||
splitSegment(metric, secondaryMetric, metricLimit, splitSegments, this);
|
||||
return convert(splitSegments);
|
||||
}
|
||||
|
||||
|
@ -193,6 +193,7 @@ public class GPXUtilities {
|
|||
public int wptPoints = 0;
|
||||
|
||||
public double metricEnd;
|
||||
public double secondaryMetricEnd;
|
||||
public WptPt locationStart;
|
||||
public WptPt locationEnd;
|
||||
|
||||
|
@ -242,6 +243,7 @@ public class GPXUtilities {
|
|||
channelThres = channelThresMin;
|
||||
|
||||
metricEnd += s.metricEnd;
|
||||
secondaryMetricEnd += s.secondaryMetricEnd;
|
||||
points += numberOfPoints;
|
||||
for (int j = 0; j < numberOfPoints; j++) {
|
||||
WptPt point = s.get(j);
|
||||
|
@ -390,6 +392,7 @@ public class GPXUtilities {
|
|||
double endCoeff = 0;
|
||||
int endPointInd;
|
||||
double metricEnd;
|
||||
double secondaryMetricEnd;
|
||||
|
||||
public SplitSegment(TrkSegment s) {
|
||||
startPointInd = 0;
|
||||
|
@ -497,9 +500,11 @@ public class GPXUtilities {
|
|||
|
||||
}
|
||||
|
||||
private static void splitSegment(SplitMetric metric, double metricLimit, List<SplitSegment> splitSegments,
|
||||
private static void splitSegment(SplitMetric metric, SplitMetric secondaryMetric,
|
||||
double metricLimit, List<SplitSegment> splitSegments,
|
||||
TrkSegment segment) {
|
||||
double currentMetricEnd = metricLimit;
|
||||
double secondaryMetricEnd = 0;
|
||||
SplitSegment sp = new SplitSegment(segment, 0, 0);
|
||||
double total = 0;
|
||||
WptPt prev = null ;
|
||||
|
@ -507,11 +512,13 @@ public class GPXUtilities {
|
|||
WptPt point = segment.points.get(k);
|
||||
if (k > 0) {
|
||||
double currentSegment = metric.metric(prev, point);
|
||||
secondaryMetricEnd += secondaryMetric.metric(prev, point);
|
||||
while (total + currentSegment > currentMetricEnd) {
|
||||
double p = currentMetricEnd - total;
|
||||
double cf = (p / currentSegment);
|
||||
sp.setLastPoint(k - 1, cf);
|
||||
sp.metricEnd = currentMetricEnd;
|
||||
sp.secondaryMetricEnd = secondaryMetricEnd;
|
||||
splitSegments.add(sp);
|
||||
|
||||
sp = new SplitSegment(segment, k - 1, cf);
|
||||
|
@ -525,6 +532,7 @@ public class GPXUtilities {
|
|||
if (segment.points.size() > 0
|
||||
&& !(sp.endPointInd == segment.points.size() - 1 && sp.startCoeff == 1)) {
|
||||
sp.metricEnd = total;
|
||||
sp.secondaryMetricEnd = secondaryMetricEnd;
|
||||
sp.setLastPoint(segment.points.size() - 2, 1);
|
||||
splitSegments.add(sp);
|
||||
}
|
||||
|
|
|
@ -180,7 +180,9 @@ public class GpxSelectionHelper {
|
|||
item.group = group;
|
||||
if(split) {
|
||||
item.splitMetric = analysis.metricEnd;
|
||||
item.secondarySplitMetric = analysis.secondaryMetricEnd;
|
||||
item.splitName = formatSplitName(analysis.metricEnd, group, app);
|
||||
item.splitName += " ("+formatSecondarySplitName(analysis.secondaryMetricEnd, group, app) +") ";
|
||||
}
|
||||
|
||||
item.description = GpxUiHelper.getDescription(app, analysis, true);
|
||||
|
@ -234,6 +236,14 @@ public class GpxSelectionHelper {
|
|||
}
|
||||
}
|
||||
}
|
||||
|
||||
private static String formatSecondarySplitName(double metricEnd, GpxDisplayGroup group, OsmandApplication app) {
|
||||
if (group.isSplitDistance()) {
|
||||
return Algorithms.formatDuration((int) metricEnd);
|
||||
} else {
|
||||
return OsmAndFormatter.getFormattedDistance((float) metricEnd, app);
|
||||
}
|
||||
}
|
||||
|
||||
private static String formatSplitName(double metricEnd, GpxDisplayGroup group, OsmandApplication app) {
|
||||
if (group.isSplitDistance()) {
|
||||
|
@ -607,6 +617,7 @@ public class GpxSelectionHelper {
|
|||
public WptPt locationStart;
|
||||
public WptPt locationEnd;
|
||||
public double splitMetric = -1;
|
||||
public double secondarySplitMetric = -1;
|
||||
public String splitName;
|
||||
public String name;
|
||||
public String description;
|
||||
|
|
Loading…
Reference in a new issue