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) {
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>();
List<Integer> 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,11 +382,14 @@ 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;
}
}
public void completeRouteEncodingRules() {
for(int i = 0; i < routeEncodingRules.size(); i++) {

View file

@ -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) {