diff --git a/brouter-core/src/main/java/btools/router/RoutingEngine.java b/brouter-core/src/main/java/btools/router/RoutingEngine.java index 596dc75..58e7e3e 100644 --- a/brouter-core/src/main/java/btools/router/RoutingEngine.java +++ b/brouter-core/src/main/java/btools/router/RoutingEngine.java @@ -292,16 +292,16 @@ public class RoutingEngine extends Thread { private OsmTrack tryFindTrack(OsmTrack[] refTracks, OsmTrack[] lastTracks) { OsmTrack totaltrack = new OsmTrack(); int nUnmatched = waypoints.size(); + boolean hasDirectRouting = false; - if (hasInfo()) { - for (OsmNodeNamed wp : waypoints) { - logInfo("wp=" + wp); - } + for (OsmNodeNamed wp : waypoints) { + if (hasInfo()) logInfo("wp=" + wp + (wp.direct ? " direct" : "")); + if (wp.direct) hasDirectRouting = true; } // check for a track for that target OsmTrack nearbyTrack = null; - if (lastTracks[waypoints.size() - 2] == null) { + if (!hasDirectRouting && lastTracks[waypoints.size() - 2] == null) { StringBuilder debugInfo = hasInfo() ? new StringBuilder() : null; nearbyTrack = OsmTrack.readBinary(routingContext.rawTrackPath, waypoints.get(waypoints.size() - 1), routingContext.getNogoChecksums(), routingContext.profileTimestamp, debugInfo); if (nearbyTrack != null) { @@ -314,13 +314,13 @@ public class RoutingEngine extends Thread { } } - if (matchedWaypoints == null) // could exist from the previous alternative level - { + if (matchedWaypoints == null) { // could exist from the previous alternative level matchedWaypoints = new ArrayList(); for (int i = 0; i < nUnmatched; i++) { MatchedWaypoint mwp = new MatchedWaypoint(); mwp.waypoint = waypoints.get(i); mwp.name = waypoints.get(i).name; + mwp.direct = waypoints.get(i).direct; matchedWaypoints.add(mwp); } matchWaypointsToNodes(matchedWaypoints); @@ -330,6 +330,7 @@ public class RoutingEngine extends Thread { airDistanceCostFactor = 0.; for (int i = 0; i < matchedWaypoints.size() - 1; i++) { nodeLimit = MAXNODES_ISLAND_CHECK; + if (matchedWaypoints.get(i).direct) continue; if (routingContext.inverseRouting) { OsmTrack seg = findTrack("start-island-check", matchedWaypoints.get(i), matchedWaypoints.get(i + 1), null, null, false); if (seg == null && nodeLimit > 0) { @@ -383,10 +384,7 @@ public class RoutingEngine extends Thread { private OsmTrack searchTrack(MatchedWaypoint startWp, MatchedWaypoint endWp, OsmTrack nearbyTrack, OsmTrack refTrack) { // remove nogos with waypoints inside try { - List wpts2 = new ArrayList(); - wpts2.add(startWp.waypoint); - wpts2.add(endWp.waypoint); - boolean calcBeeline = routingContext.allInOneNogo(wpts2); + boolean calcBeeline = startWp.direct; if (!calcBeeline) return searchRoutedTrack(startWp, endWp, nearbyTrack, refTrack); diff --git a/brouter-mapaccess/src/main/java/btools/mapaccess/NodesCache.java b/brouter-mapaccess/src/main/java/btools/mapaccess/NodesCache.java index cef46b0..ab89a68 100644 --- a/brouter-mapaccess/src/main/java/btools/mapaccess/NodesCache.java +++ b/brouter-mapaccess/src/main/java/btools/mapaccess/NodesCache.java @@ -290,9 +290,20 @@ public final class NodesCache { if (first_file_access_failed) { throw new IllegalArgumentException("datafile " + first_file_access_name + " not found"); } - for (MatchedWaypoint mwp : unmatchedWaypoints) { + int len = unmatchedWaypoints.size(); + for (int i = 0; i < len; i++) { + MatchedWaypoint mwp = unmatchedWaypoints.get(i); if (mwp.crosspoint == null) { - throw new IllegalArgumentException(mwp.name + "-position not mapped in existing datafile"); + if (unmatchedWaypoints.size() > 1 && i == unmatchedWaypoints.size()-1 && unmatchedWaypoints.get(i-1).direct) { + mwp.crosspoint = new OsmNode(mwp.waypoint.ilon, mwp.waypoint.ilat); + mwp.direct = true; + } else { + throw new IllegalArgumentException(mwp.name + "-position not mapped in existing datafile"); + } + } + if (unmatchedWaypoints.size() > 1 && i == unmatchedWaypoints.size()-1 && unmatchedWaypoints.get(i-1).direct) { + mwp.crosspoint = new OsmNode(mwp.waypoint.ilon, mwp.waypoint.ilat); + mwp.direct = true; } } } diff --git a/brouter-mapaccess/src/main/java/btools/mapaccess/OsmNode.java b/brouter-mapaccess/src/main/java/btools/mapaccess/OsmNode.java index 446b873..35e9f88 100644 --- a/brouter-mapaccess/src/main/java/btools/mapaccess/OsmNode.java +++ b/brouter-mapaccess/src/main/java/btools/mapaccess/OsmNode.java @@ -25,7 +25,7 @@ public class OsmNode extends OsmLink implements OsmPos { /** * The elevation */ - public short selev; + public short selev = Short.MIN_VALUE; /** * The node-tags, if any diff --git a/brouter-mapaccess/src/main/java/btools/mapaccess/WaypointMatcherImpl.java b/brouter-mapaccess/src/main/java/btools/mapaccess/WaypointMatcherImpl.java index 11618da..1e917f8 100644 --- a/brouter-mapaccess/src/main/java/btools/mapaccess/WaypointMatcherImpl.java +++ b/brouter-mapaccess/src/main/java/btools/mapaccess/WaypointMatcherImpl.java @@ -46,7 +46,24 @@ public final class WaypointMatcherImpl implements WaypointMatcher { if (d == 0.) return; - for (MatchedWaypoint mwp : waypoints) { + int len = waypoints.size(); + for (int i = 0; i < len; i++) { + MatchedWaypoint mwp = waypoints.get(i); + + if (mwp.direct && + (i == 0 || + waypoints.get(i - 1).direct) + ) { + if (mwp.crosspoint == null) { + mwp.crosspoint = new OsmNode(); + mwp.crosspoint.ilon = mwp.waypoint.ilon; + mwp.crosspoint.ilat = mwp.waypoint.ilat; + mwp.hasUpdate = true; + anyUpdate = true; + } + continue; + } + OsmNode wp = mwp.waypoint; double x1 = (lon1 - wp.ilon) * dlon2m;