From 056468be1b8bec728e03051a1b6107ed5ab17ce9 Mon Sep 17 00:00:00 2001 From: max-klaus Date: Tue, 17 Mar 2020 21:16:49 +0300 Subject: [PATCH] Fix segment indexes --- .../java/net/osmand/router/RouteSegmentResult.java | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/OsmAnd-java/src/main/java/net/osmand/router/RouteSegmentResult.java b/OsmAnd-java/src/main/java/net/osmand/router/RouteSegmentResult.java index a3dbe38056..9a521548b0 100644 --- a/OsmAnd-java/src/main/java/net/osmand/router/RouteSegmentResult.java +++ b/OsmAnd-java/src/main/java/net/osmand/router/RouteSegmentResult.java @@ -54,7 +54,7 @@ public class RouteSegmentResult implements StringExternalizable if (object.pointTypes != null) { int start = Math.min(startPointIndex, endPointIndex); int end = Math.max(startPointIndex, endPointIndex); - for (int i = start; i <= end; i++) { + for (int i = start; i <= end && i < object.pointTypes.length; i++) { int[] types = object.pointTypes[i]; if (types != null) { collectRules(rules, segmentRules, types); @@ -97,17 +97,17 @@ public class RouteSegmentResult implements StringExternalizable RouteTypeRule segmentRule = null; String tag = rule.getTag(); if (tag.equals("osmand_ele_start")) { - if (object.heightDistanceArray != null && object.heightDistanceArray.length > startPointIndex * 2) { + if (object.heightDistanceArray != null && object.heightDistanceArray.length > startPointIndex * 2 + 1) { float h = object.heightDistanceArray[startPointIndex * 2 + 1]; segmentRule = new RouteTypeRule(tag, String.valueOf(Math.round(h))); } } else if (tag.equals("osmand_ele_end")) { - if (object.heightDistanceArray != null && object.heightDistanceArray.length > endPointIndex * 2) { + if (object.heightDistanceArray != null && object.heightDistanceArray.length > endPointIndex * 2 + 1) { float h = object.heightDistanceArray[endPointIndex * 2 + 1]; segmentRule = new RouteTypeRule(tag, String.valueOf(Math.round(h))); } } - if (segmentRule != null && !segmentRules.containsKey(rule)) { + if (segmentRule != null) { segmentRules.put(rule, segmentRule); } else if (!rules.containsKey(rule)) { rules.put(rule, rules.size()); @@ -213,7 +213,10 @@ public class RouteSegmentResult implements StringExternalizable } bundle.putLong("id", object.id); bundle.putArray("types", convertTypes(object.types, rules, segmentRules)); - bundle.putArray("pointTypes", convertTypes(Arrays.copyOfRange(object.pointTypes, startPointIndex, endPointIndex + 1), rules, segmentRules)); + int start = Math.min(startPointIndex, endPointIndex); + int end = Math.max(startPointIndex, endPointIndex); + bundle.putArray("pointTypes", convertTypes(Arrays.copyOfRange(object.pointTypes, start, + Math.min(end + 1, object.pointTypes.length)), rules, segmentRules)); bundle.putArray("names", convertNameIds(object.nameIds, rules)); }