refactoring

This commit is contained in:
MadWasp79 2020-06-23 16:32:47 +03:00
parent 45852fc5ba
commit f67b1b347a
2 changed files with 49 additions and 37 deletions

View file

@ -286,8 +286,6 @@ public class BinaryMapRouteReaderAdapter {
if (i > 0) { if (i > 0) {
intValue = Integer.parseInt(v.substring(0, i)); 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<Integer> trafficSignalsDir = new TIntObjectHashMap<Integer>(); TIntObjectHashMap<Integer> trafficSignalsDir = new TIntObjectHashMap<Integer>();
List<Integer> trafficSignalsTags = new ArrayList<>(); List<Integer> trafficSignalsTags = new ArrayList<>();
int directionForward = -1;
int directionBackward = -1;
int directionTrafficSignalsForward = -1;
int directionTrafficSignalsBackward = -1;
int nameTypeRule = -1; int nameTypeRule = -1;
int refTypeRule = -1; int refTypeRule = -1;
int destinationTypeRule = -1; int destinationTypeRule = -1;
@ -357,14 +360,20 @@ public class BinaryMapRouteReaderAdapter {
destinationTypeRule = id; destinationTypeRule = id;
} else if (tags.equals("destination:ref") || tags.equals("destination:ref:forward") || tags.equals("destination:ref:backward")) { } else if (tags.equals("destination:ref") || tags.equals("destination:ref:forward") || tags.equals("destination:ref:backward")) {
destinationRefTypeRule = id; 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"))){ } else if (tags.equals("highway") && (val.equals("traffic_signals") || val.equals("stop") || val.equals("give_way"))){
trafficSignalsTags.add(id); 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,10 +382,13 @@ public class BinaryMapRouteReaderAdapter {
} }
public int getTrafficSignalDirection(int ruleId) { public int getTrafficSignalDirection(int ruleId) {
if (trafficSignalsDir.get(ruleId) != null) { if (ruleId == directionForward || ruleId == directionTrafficSignalsForward) {
return trafficSignalsDir.get(ruleId); return 1;
} else if (ruleId == directionBackward || ruleId == directionTrafficSignalsBackward) {
return -1;
} else {
return 0;
} }
return 0;
} }
public void completeRouteEncodingRules() { public void completeRouteEncodingRules() {

View file

@ -373,31 +373,31 @@ public class GeneralRouter implements VehicleRouter {
@Override @Override
public float defineRoutingObstacle(RouteDataObject road, int point, boolean dir) { public float defineRoutingObstacle(RouteDataObject road, int point, boolean dir) {
int[] pointTypes = road.getPointTypes(point); int[] pointTypes = road.getPointTypes(point);
// if (pointTypes != null) { if (pointTypes != null) {
// filteredRules.clear(); filteredRules.clear();
// for (int i = 0; i < pointTypes.length; i++) { for (int i = 0; i < pointTypes.length; i++) {
// foundDirRule = false; foundDirRule = false;
// if (road.region.isTrafficSignalsRule(pointTypes[i])) { if (road.region.isTrafficSignalsRule(pointTypes[i])) {
// for (int rid : pointTypes) { for (int rid : pointTypes) {
// if (rid != pointTypes[i]) { if (rid != pointTypes[i]) {
// int trafficSignalDir = road.region.getTrafficSignalDirection(rid); int trafficSignalDir = road.region.getTrafficSignalDirection(rid);
// if (trafficSignalDir != 0) { if (trafficSignalDir != 0) {
// if ((dir && trafficSignalDir > 0) || (!dir && trafficSignalDir < 0)) { if ((dir && trafficSignalDir > 0) || (!dir && trafficSignalDir < 0)) {
// filteredRules.add(pointTypes[i]); filteredRules.add(pointTypes[i]);
// } }
// foundDirRule = true; foundDirRule = true;
// } }
// } }
// } }
// if (!foundDirRule) { if (!foundDirRule) {
// filteredRules.add(pointTypes[i]); filteredRules.add(pointTypes[i]);
// } }
// } else if (road.region.getTrafficSignalDirection(pointTypes[i]) == 0){ } else if (road.region.getTrafficSignalDirection(pointTypes[i]) == 0) {
// filteredRules.add(pointTypes[i]); filteredRules.add(pointTypes[i]);
// } }
// } }
// pointTypes = filteredRules.size() > 0 ? filteredRules.toArray() : null; pointTypes = filteredRules.size() > 0 ? filteredRules.toArray() : null;
// } }
if(pointTypes != null) { if(pointTypes != null) {
Float obst = getCache(RouteDataObjectAttribute.ROUTING_OBSTACLES, road.region, pointTypes); Float obst = getCache(RouteDataObjectAttribute.ROUTING_OBSTACLES, road.region, pointTypes);
if(obst == null) { if(obst == null) {