From c091fb6cc0b23864cf6aa9f1163e7ac7dae59ab6 Mon Sep 17 00:00:00 2001 From: max-klaus Date: Thu, 3 Dec 2020 18:15:16 +0300 Subject: [PATCH] Fix saving straight lines while planning route --- .../MeasurementEditingContext.java | 26 +++++++++---------- 1 file changed, 12 insertions(+), 14 deletions(-) diff --git a/OsmAnd/src/net/osmand/plus/measurementtool/MeasurementEditingContext.java b/OsmAnd/src/net/osmand/plus/measurementtool/MeasurementEditingContext.java index 3563ab77a6..6c3411b004 100644 --- a/OsmAnd/src/net/osmand/plus/measurementtool/MeasurementEditingContext.java +++ b/OsmAnd/src/net/osmand/plus/measurementtool/MeasurementEditingContext.java @@ -281,24 +281,23 @@ public class MeasurementEditingContext { } public boolean isApproximationNeeded() { - boolean hasDefaultPoints = false; + boolean hasDefaultPointsOnly = false; boolean newData = isNewData(); if (!newData) { List points = getPoints(); - WptPt prevPoint = null; + hasDefaultPointsOnly = true; for (WptPt point : points) { - if (!point.hasProfile() && (prevPoint == null || !prevPoint.hasProfile())) { - hasDefaultPoints = true; + if (point.hasProfile()) { + hasDefaultPointsOnly = false; break; } - prevPoint = point; } } - return !newData && hasDefaultPoints && getPoints().size() > 2; + return !newData && hasDefaultPointsOnly && getPoints().size() > 2; } public boolean isSelectionNeedApproximation() { - boolean hasDefaultPoints = false; + boolean hasDefaultPointsOnly = false; boolean newData = isNewData(); if (!newData && selectedPointPosition != -1) { WptPt selectedPoint = getPoints().get(selectedPointPosition); @@ -309,18 +308,17 @@ public class MeasurementEditingContext { points = segment.points; } } - WptPt prevPoint = null; - if (points != null) { + if (!Algorithms.isEmpty(points)) { + hasDefaultPointsOnly = true; for (WptPt point : points) { - if (!point.hasProfile() && (prevPoint == null || !prevPoint.hasProfile())) { - hasDefaultPoints = true; + if (point.hasProfile()) { + hasDefaultPointsOnly = false; break; } - prevPoint = point; } } } - return !newData && hasDefaultPoints && getPoints().size() > 2; + return !newData && hasDefaultPointsOnly && getPoints().size() > 2; } public void clearSnappedToRoadPoints() { @@ -625,7 +623,7 @@ public class MeasurementEditingContext { WptPt startPoint = points.get(i); WptPt endPoint = points.get(i + 1); Pair pair = new Pair<>(startPoint, endPoint); - if (roadSegmentData.get(pair) == null && startPoint.hasProfile()) { + if (roadSegmentData.get(pair) == null && (startPoint.hasProfile() || hasRoute())) { res.add(pair); } }