From c8e8b9d421797a66df94a8fed05ca19f837a9734 Mon Sep 17 00:00:00 2001 From: "Phyks (Lucas Verney)" Date: Sat, 29 Jun 2019 14:42:28 +0200 Subject: [PATCH] Fix an incorrect handling of default nogo behavior for lines or polygons. Fix #154 --- .../java/btools/router/RoutingContext.java | 30 ++++++++++++------- 1 file changed, 19 insertions(+), 11 deletions(-) diff --git a/brouter-core/src/main/java/btools/router/RoutingContext.java b/brouter-core/src/main/java/btools/router/RoutingContext.java index 1e0b27d..be0fe55 100644 --- a/brouter-core/src/main/java/btools/router/RoutingContext.java +++ b/brouter-core/src/main/java/btools/router/RoutingContext.java @@ -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; + } } } }