From f67b1b347a26bffd00f758019c98d420265fe097 Mon Sep 17 00:00:00 2001 From: MadWasp79 Date: Tue, 23 Jun 2020 16:32:47 +0300 Subject: [PATCH] refactoring --- .../binary/BinaryMapRouteReaderAdapter.java | 36 ++++++++----- .../java/net/osmand/router/GeneralRouter.java | 50 +++++++++---------- 2 files changed, 49 insertions(+), 37 deletions(-) diff --git a/OsmAnd-java/src/main/java/net/osmand/binary/BinaryMapRouteReaderAdapter.java b/OsmAnd-java/src/main/java/net/osmand/binary/BinaryMapRouteReaderAdapter.java index 3336dae1f6..a397b548e8 100644 --- a/OsmAnd-java/src/main/java/net/osmand/binary/BinaryMapRouteReaderAdapter.java +++ b/OsmAnd-java/src/main/java/net/osmand/binary/BinaryMapRouteReaderAdapter.java @@ -286,8 +286,6 @@ public class BinaryMapRouteReaderAdapter { if (i > 0) { intValue = Integer.parseInt(v.substring(0, i)); } - } else if (t.endsWith("direction") && v != null) { - type = TRAFFIC_SIGNALS; } } } @@ -301,6 +299,11 @@ public class BinaryMapRouteReaderAdapter { TIntObjectHashMap trafficSignalsDir = new TIntObjectHashMap(); List trafficSignalsTags = new ArrayList<>(); + int directionForward = -1; + int directionBackward = -1; + int directionTrafficSignalsForward = -1; + int directionTrafficSignalsBackward = -1; + int nameTypeRule = -1; int refTypeRule = -1; int destinationTypeRule = -1; @@ -357,14 +360,20 @@ public class BinaryMapRouteReaderAdapter { destinationTypeRule = id; } else if (tags.equals("destination:ref") || tags.equals("destination:ref:forward") || tags.equals("destination:ref:backward")) { destinationRefTypeRule = id; - } else if (tags.endsWith("direction")) { - if (val.equals("forward")) { - trafficSignalsDir.put(id, 1); - } else if (val.equals("backward")) { - trafficSignalsDir.put(id, -1); - } } else if (tags.equals("highway") && (val.equals("traffic_signals") || val.equals("stop") || val.equals("give_way"))){ trafficSignalsTags.add(id); + } else if (tags.equals("traffic_signals:direction")){ + if (val.equals("forward")) { + directionTrafficSignalsForward = id; + } else if (val.equals("backward")) { + directionTrafficSignalsBackward = id; + } + } else if (tags.equals("direction")) { + if (val.equals("forward")) { + directionForward = id; + } else if (val.equals("backward")) { + directionBackward = id; + } } } @@ -373,12 +382,15 @@ public class BinaryMapRouteReaderAdapter { } public int getTrafficSignalDirection(int ruleId) { - if (trafficSignalsDir.get(ruleId) != null) { - return trafficSignalsDir.get(ruleId); + if (ruleId == directionForward || ruleId == directionTrafficSignalsForward) { + return 1; + } else if (ruleId == directionBackward || ruleId == directionTrafficSignalsBackward) { + return -1; + } else { + return 0; } - return 0; } - + public void completeRouteEncodingRules() { for(int i = 0; i < routeEncodingRules.size(); i++) { RouteTypeRule rtr = routeEncodingRules.get(i); diff --git a/OsmAnd-java/src/main/java/net/osmand/router/GeneralRouter.java b/OsmAnd-java/src/main/java/net/osmand/router/GeneralRouter.java index 51e5ae79fb..d65ec8f8ee 100644 --- a/OsmAnd-java/src/main/java/net/osmand/router/GeneralRouter.java +++ b/OsmAnd-java/src/main/java/net/osmand/router/GeneralRouter.java @@ -373,31 +373,31 @@ public class GeneralRouter implements VehicleRouter { @Override public float defineRoutingObstacle(RouteDataObject road, int point, boolean dir) { int[] pointTypes = road.getPointTypes(point); -// if (pointTypes != null) { -// filteredRules.clear(); -// for (int i = 0; i < pointTypes.length; i++) { -// foundDirRule = false; -// if (road.region.isTrafficSignalsRule(pointTypes[i])) { -// for (int rid : pointTypes) { -// if (rid != pointTypes[i]) { -// int trafficSignalDir = road.region.getTrafficSignalDirection(rid); -// if (trafficSignalDir != 0) { -// if ((dir && trafficSignalDir > 0) || (!dir && trafficSignalDir < 0)) { -// filteredRules.add(pointTypes[i]); -// } -// foundDirRule = true; -// } -// } -// } -// if (!foundDirRule) { -// filteredRules.add(pointTypes[i]); -// } -// } else if (road.region.getTrafficSignalDirection(pointTypes[i]) == 0){ -// filteredRules.add(pointTypes[i]); -// } -// } -// pointTypes = filteredRules.size() > 0 ? filteredRules.toArray() : null; -// } + if (pointTypes != null) { + filteredRules.clear(); + for (int i = 0; i < pointTypes.length; i++) { + foundDirRule = false; + if (road.region.isTrafficSignalsRule(pointTypes[i])) { + for (int rid : pointTypes) { + if (rid != pointTypes[i]) { + int trafficSignalDir = road.region.getTrafficSignalDirection(rid); + if (trafficSignalDir != 0) { + if ((dir && trafficSignalDir > 0) || (!dir && trafficSignalDir < 0)) { + filteredRules.add(pointTypes[i]); + } + foundDirRule = true; + } + } + } + if (!foundDirRule) { + filteredRules.add(pointTypes[i]); + } + } else if (road.region.getTrafficSignalDirection(pointTypes[i]) == 0) { + filteredRules.add(pointTypes[i]); + } + } + pointTypes = filteredRules.size() > 0 ? filteredRules.toArray() : null; + } if(pointTypes != null) { Float obst = getCache(RouteDataObjectAttribute.ROUTING_OBSTACLES, road.region, pointTypes); if(obst == null) {