From 613fed62e7611f44013b93750c8e25e773155969 Mon Sep 17 00:00:00 2001 From: MadWasp79 Date: Tue, 23 Jun 2020 15:55:46 +0300 Subject: [PATCH] refactoring --- .../java/net/osmand/router/GeneralRouter.java | 64 +++++++++---------- .../java/net/osmand/router/VehicleRouter.java | 5 -- 2 files changed, 30 insertions(+), 39 deletions(-) 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 bf77ed698d..51e5ae79fb 100644 --- a/OsmAnd-java/src/main/java/net/osmand/router/GeneralRouter.java +++ b/OsmAnd-java/src/main/java/net/osmand/router/GeneralRouter.java @@ -355,7 +355,7 @@ public class GeneralRouter implements VehicleRouter { @Override public float defineObstacle(RouteDataObject road, int point, boolean dir) { - int[] pointTypes = filterRulesByDirection(road.getPointTypes(point), dir, road); + int[] pointTypes = road.getPointTypes(point); if(pointTypes != null) { Float obst = getCache(RouteDataObjectAttribute.OBSTACLES, road.region, pointTypes); if(obst == null) { @@ -367,9 +367,37 @@ public class GeneralRouter implements VehicleRouter { return 0; } + boolean foundDirRule = false; + TIntArrayList filteredRules = new TIntArrayList(); + @Override public float defineRoutingObstacle(RouteDataObject road, int point, boolean dir) { - int[] pointTypes = filterRulesByDirection(road.getPointTypes(point), dir, road); + 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) { Float obst = getCache(RouteDataObjectAttribute.ROUTING_OBSTACLES, road.region, pointTypes); if(obst == null) { @@ -381,38 +409,6 @@ public class GeneralRouter implements VehicleRouter { return 0; } - @Override - public int[] filterRulesByDirection(int[] pointRules, boolean direction, RouteDataObject route) { - if (pointRules != null) { - TIntArrayList filteredRules = new TIntArrayList(); - boolean foundDirRule = false; - for (int i = 0; i < pointRules.length; i++) { - foundDirRule = false; - if (route.region.isTrafficSignalsRule(pointRules[i])) { - for (int rid : pointRules) { - if (rid != pointRules[i]) { - //possible error if we have two different directions on one point? - int trafficSignalDir = route.region.getTrafficSignalDirection(rid); - if (trafficSignalDir != 0) { - if ((direction && trafficSignalDir > 0) || (!direction && trafficSignalDir < 0)) { - filteredRules.add(pointRules[i]); - } - foundDirRule = true; - } - } - } - if (!foundDirRule) { - filteredRules.add(pointRules[i]); - } - } else if (route.region.getTrafficSignalDirection(pointRules[i]) == 0){ - filteredRules.add(pointRules[i]); - } - } - return filteredRules.size() > 0 ? filteredRules.toArray() : null; - } - return pointRules; - } - @Override public double defineHeightObstacle(RouteDataObject road, short startIndex, short endIndex) { if(!heightObstacles) { diff --git a/OsmAnd-java/src/main/java/net/osmand/router/VehicleRouter.java b/OsmAnd-java/src/main/java/net/osmand/router/VehicleRouter.java index 6047e5f561..e8757b1486 100644 --- a/OsmAnd-java/src/main/java/net/osmand/router/VehicleRouter.java +++ b/OsmAnd-java/src/main/java/net/osmand/router/VehicleRouter.java @@ -47,11 +47,6 @@ public interface VehicleRouter { */ public float defineRoutingSpeed(RouteDataObject road); - /** - * Define if rule should be applied based on movement direction; - */ - public int[] filterRulesByDirection(int[] pointRules, boolean direction, RouteDataObject road); - /** * return real speed in m/s for vehicle for specified road */