Skip to content

Commit

Permalink
fix: access to roads where transporting hazardous materials is forbid…
Browse files Browse the repository at this point in the history
…den (#1853)
  • Loading branch information
aoles authored Oct 1, 2024
2 parents 9093cce + f48a073 commit 3f2e4fc
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 10 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ RELEASING:
### Deprecated
### Removed
### Fixed
- access to roads where transporting hazardous materials is forbidden ([#1853](https://github.com/GIScience/openrouteservice/pull/1853))
### Security

## [8.1.3] - 2024-09-13
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -130,9 +130,9 @@ public void setDestinationEdge(EdgeIteratorState edge, Graph graph, FlagEncoder

if (!destinationEdges.contains(EdgeIteratorStateHelper.getOriginalEdge(edge))) {
int vt = gsHeavyVehicles.getEdgeVehicleType(EdgeIteratorStateHelper.getOriginalEdge(edge), buffer);
boolean dstFlag = buffer[1] != 0; // ((buffer[1] >> (vehicleType >> 1)) & 1) == 1
boolean dstFlag = buffer[1] != 0;

if (((vt & vehicleType) == vehicleType) && (dstFlag))
if (isVehicleType(vt, vehicleType) && (dstFlag))
destinationEdges.add(EdgeIteratorStateHelper.getOriginalEdge(edge));
}

Expand All @@ -148,30 +148,30 @@ public boolean accept(EdgeIteratorState iter) {
int edgeId = EdgeIteratorStateHelper.getOriginalEdge(iter);

int vt = gsHeavyVehicles.getEdgeVehicleType(edgeId, buffer);
boolean dstFlag = buffer[1] != 0; // ((buffer[1] >> (vehicleType >> 1)) & 1) == 1
boolean dstFlag = buffer[1] != 0;

// if edge has some restrictions
if (vt != HeavyVehicleAttributes.UNKNOWN) {
if (mode == MODE_CLOSEST_EDGE) {
// current vehicle type is not forbidden
boolean edgeRestricted = ((vt & vehicleType) == vehicleType);
boolean edgeRestricted = isVehicleType(vt, vehicleType);
if ((edgeRestricted || dstFlag) && buffer[1] != vehicleType)
return false;
} else if (mode == MODE_DESTINATION_EDGES) {
// Here we are looking for all edges that have destination
return dstFlag && ((vt & vehicleType) == vehicleType);
return dstFlag && isVehicleType(vt, vehicleType);
} else {
// Check an edge with destination attribute
if (dstFlag) {
if ((vt & vehicleType) == vehicleType) {
if (isVehicleType(vt, vehicleType)) {
if (destinationEdges != null) {
if (!destinationEdges.contains(edgeId))
return false;
} else
return false;
} else
return false;
} else if ((vt & vehicleType) == vehicleType)
} else if (isVehicleType(vt, vehicleType))
return false;
}
} else {
Expand All @@ -180,7 +180,7 @@ public boolean accept(EdgeIteratorState iter) {
}
}

if (hasHazmat && (vt & HeavyVehicleAttributes.HAZMAT) != 0) {
if (hasHazmat && isVehicleType(vt, HeavyVehicleAttributes.HAZMAT)) {
return false;
}

Expand All @@ -201,4 +201,8 @@ public boolean accept(EdgeIteratorState iter) {
}
return true;
}

private boolean isVehicleType(int vt, int vehicleType) {
return (vt & vehicleType) == vehicleType;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -135,11 +135,11 @@ public boolean getEdgeRestrictionValues(int edgeId, double[] retValues) {

public int getEdgeVehicleType(int edgeId, byte[] buffer) {
long edgeBase = (long) edgeId * edgeEntryBytes;
orsEdges.getBytes(edgeBase + efVehicleType, buffer, 2);
orsEdges.getBytes(edgeBase + efVehicleType, buffer, 1);

int result = buffer[0];
if (result < 0)
result = (byte) (result & 0xff);
result = result & 0xFF;

return result;
}
Expand Down

0 comments on commit 3f2e4fc

Please sign in to comment.