Fix saving straight lines while planning route

This commit is contained in:
max-klaus 2020-12-03 18:15:16 +03:00
parent 76be9016c2
commit c091fb6cc0

View file

@ -281,24 +281,23 @@ public class MeasurementEditingContext {
} }
public boolean isApproximationNeeded() { public boolean isApproximationNeeded() {
boolean hasDefaultPoints = false; boolean hasDefaultPointsOnly = false;
boolean newData = isNewData(); boolean newData = isNewData();
if (!newData) { if (!newData) {
List<WptPt> points = getPoints(); List<WptPt> points = getPoints();
WptPt prevPoint = null; hasDefaultPointsOnly = true;
for (WptPt point : points) { for (WptPt point : points) {
if (!point.hasProfile() && (prevPoint == null || !prevPoint.hasProfile())) { if (point.hasProfile()) {
hasDefaultPoints = true; hasDefaultPointsOnly = false;
break; break;
} }
prevPoint = point;
} }
} }
return !newData && hasDefaultPoints && getPoints().size() > 2; return !newData && hasDefaultPointsOnly && getPoints().size() > 2;
} }
public boolean isSelectionNeedApproximation() { public boolean isSelectionNeedApproximation() {
boolean hasDefaultPoints = false; boolean hasDefaultPointsOnly = false;
boolean newData = isNewData(); boolean newData = isNewData();
if (!newData && selectedPointPosition != -1) { if (!newData && selectedPointPosition != -1) {
WptPt selectedPoint = getPoints().get(selectedPointPosition); WptPt selectedPoint = getPoints().get(selectedPointPosition);
@ -309,18 +308,17 @@ public class MeasurementEditingContext {
points = segment.points; points = segment.points;
} }
} }
WptPt prevPoint = null; if (!Algorithms.isEmpty(points)) {
if (points != null) { hasDefaultPointsOnly = true;
for (WptPt point : points) { for (WptPt point : points) {
if (!point.hasProfile() && (prevPoint == null || !prevPoint.hasProfile())) { if (point.hasProfile()) {
hasDefaultPoints = true; hasDefaultPointsOnly = false;
break; break;
} }
prevPoint = point;
} }
} }
} }
return !newData && hasDefaultPoints && getPoints().size() > 2; return !newData && hasDefaultPointsOnly && getPoints().size() > 2;
} }
public void clearSnappedToRoadPoints() { public void clearSnappedToRoadPoints() {
@ -625,7 +623,7 @@ public class MeasurementEditingContext {
WptPt startPoint = points.get(i); WptPt startPoint = points.get(i);
WptPt endPoint = points.get(i + 1); WptPt endPoint = points.get(i + 1);
Pair<WptPt, WptPt> pair = new Pair<>(startPoint, endPoint); Pair<WptPt, WptPt> pair = new Pair<>(startPoint, endPoint);
if (roadSegmentData.get(pair) == null && startPoint.hasProfile()) { if (roadSegmentData.get(pair) == null && (startPoint.hasProfile() || hasRoute())) {
res.add(pair); res.add(pair);
} }
} }