Fix an incorrect handling of default nogo behavior for lines or polygons.

Fix #154
This commit is contained in:
Phyks (Lucas Verney) 2019-06-29 14:42:28 +02:00
parent fc97754c90
commit c8e8b9d421

View file

@ -347,22 +347,30 @@ public final class RoutingContext
}
if ( nogo.isNogo )
{
if (Double.isNaN(nogo.nogoWeight))
{
// Nogo is default nogo (ignore completely)
if (!(nogo instanceof OsmNogoPolygon)) { // nogo is a circle
if (Double.isNaN(nogo.nogoWeight)) {
// default nogo behaviour (ignore completely)
nogoCost = -1;
}
else if (!(nogo instanceof OsmNogoPolygon)) {
// nogo is a circle, compute distance within the circle
nogoCost = nogo.distanceWithinRadius(lon1, lat1, lon2, lat2, d) * nogo.nogoWeight;
} else {
// nogo weight, compute distance within the circle
nogoCost = nogo.distanceWithinRadius(lon1, lat1, lon2, lat2, d) * nogo.nogoWeight;
}
}
else if (((OsmNogoPolygon)nogo).intersects(lon1, lat1, lon2, lat2))
{
// nogo is a polygon, compute distance within the polygon
if (((OsmNogoPolygon)nogo).isClosed) {
nogoCost = ((OsmNogoPolygon)nogo).distanceWithinPolygon(lon1, lat1, lon2, lat2) * nogo.nogoWeight;
// nogo is a polyline/polygon, we have to check there is indeed
// an intersection in this case (radius check is not enough).
if (Double.isNaN(nogo.nogoWeight)) {
// default nogo behaviour (ignore completely)
nogoCost = -1;
} else {
nogoCost = nogo.nogoWeight;
if (((OsmNogoPolygon)nogo).isClosed) {
// compute distance within the polygon
nogoCost = ((OsmNogoPolygon)nogo).distanceWithinPolygon(lon1, lat1, lon2, lat2) * nogo.nogoWeight;
} else {
// for a polyline, just add a constant penalty
nogoCost = nogo.nogoWeight;
}
}
}
}