added distance check for dynamic range
This commit is contained in:
parent
a6ba70a786
commit
2f4c125bf5
4 changed files with 49 additions and 31 deletions
|
|
@ -17,6 +17,9 @@ import btools.codec.WaypointMatcher;
|
|||
import btools.expressions.BExpressionContextWay;
|
||||
|
||||
public final class NodesCache {
|
||||
|
||||
private int MAX_DYNAMIC_CATCHES = 20; // used with RoutingEngiine MAX_DYNAMIC_RANGE = 60000m
|
||||
|
||||
private File segmentDir;
|
||||
private File secondarySegmentsDir = null;
|
||||
|
||||
|
|
@ -287,11 +290,11 @@ public final class NodesCache {
|
|||
waypointMatcher = new WaypointMatcherImpl(unmatchedWaypoints, maxDistance, islandNodePairs);
|
||||
for (MatchedWaypoint mwp : unmatchedWaypoints) {
|
||||
int cellsize = 12500;
|
||||
preloadPosition(mwp.waypoint, cellsize, 1);
|
||||
preloadPosition(mwp.waypoint, cellsize, 1, false);
|
||||
// get a second chance
|
||||
if (mwp.crosspoint == null || mwp.radius > Math.abs(maxDistance)) {
|
||||
cellsize = 1000000 / 32;
|
||||
preloadPosition(mwp.waypoint, cellsize, maxDistance < 0 ? 15 : 2);
|
||||
preloadPosition(mwp.waypoint, cellsize, maxDistance < 0 ? MAX_DYNAMIC_CATCHES : 2, maxDistance < 0);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -318,19 +321,24 @@ public final class NodesCache {
|
|||
return true;
|
||||
}
|
||||
|
||||
private void preloadPosition(OsmNode n, int d, int scale) {
|
||||
private void preloadPosition(OsmNode n, int d, int maxscale, boolean bUseDynamicRange) {
|
||||
first_file_access_failed = false;
|
||||
first_file_access_name = null;
|
||||
loadSegmentFor(n.ilon, n.ilat);
|
||||
if (first_file_access_failed) {
|
||||
throw new IllegalArgumentException("datafile " + first_file_access_name + " not found");
|
||||
}
|
||||
for (int idxLat = -scale; idxLat <= scale; idxLat++)
|
||||
for (int idxLon = -scale; idxLon <= scale; idxLon++) {
|
||||
if (idxLon != 0 || idxLat != 0) {
|
||||
loadSegmentFor(n.ilon + d * idxLon, n.ilat + d * idxLat);
|
||||
int scale = 1;
|
||||
while (scale < maxscale) {
|
||||
for (int idxLat = -scale; idxLat <= scale; idxLat++)
|
||||
for (int idxLon = -scale; idxLon <= scale; idxLon++) {
|
||||
if (idxLon != 0 || idxLat != 0) {
|
||||
loadSegmentFor(n.ilon + d * idxLon, n.ilat + d * idxLat);
|
||||
}
|
||||
}
|
||||
}
|
||||
if (bUseDynamicRange && waypointMatcher.hasMatch(n.ilon, n.ilat)) break;
|
||||
scale++;
|
||||
}
|
||||
}
|
||||
|
||||
private OsmFile fileForSegment(int lonDegree, int latDegree) throws Exception {
|
||||
|
|
|
|||
|
|
@ -41,13 +41,13 @@ public final class WaypointMatcherImpl implements WaypointMatcher {
|
|||
MatchedWaypoint last = null;
|
||||
this.maxDistance = maxDistance;
|
||||
if (maxDistance < 0.) {
|
||||
this.maxDistance = -1;
|
||||
this.maxDistance *= -1;
|
||||
maxDistance *= -1;
|
||||
useDynamicRange = true;
|
||||
}
|
||||
|
||||
for (MatchedWaypoint mwp : waypoints) {
|
||||
mwp.radius = useDynamicRange ? mwp.radius != maxDistance ? mwp.radius : -1 : maxDistance;
|
||||
mwp.radius = maxDistance;
|
||||
if (last != null && mwp.directionToNext == -1) {
|
||||
last.directionToNext = CheapAngleMeter.getDirection(last.waypoint.ilon, last.waypoint.ilat, mwp.waypoint.ilon, mwp.waypoint.ilat);
|
||||
}
|
||||
|
|
@ -116,7 +116,7 @@ public final class WaypointMatcherImpl implements WaypointMatcher {
|
|||
double r22 = x2 * x2 + y2 * y2;
|
||||
double radius = Math.abs(r12 < r22 ? y1 * dx - x1 * dy : y2 * dx - x2 * dy) / d;
|
||||
|
||||
if (radius < mwp.radius || (this.maxDistance == -1d)) {
|
||||
if (radius < mwp.radius) {
|
||||
double s1 = x1 * dx + y1 * dy;
|
||||
double s2 = x2 * dx + y2 * dy;
|
||||
|
||||
|
|
@ -127,7 +127,7 @@ public final class WaypointMatcherImpl implements WaypointMatcher {
|
|||
if (s2 > 0.) {
|
||||
radius = Math.sqrt(s1 < s2 ? r12 : r22);
|
||||
|
||||
if (radius > mwp.radius && mwp.radius != -1) {
|
||||
if (radius > mwp.radius) {
|
||||
continue;
|
||||
}
|
||||
}
|
||||
|
|
@ -239,6 +239,17 @@ public final class WaypointMatcherImpl implements WaypointMatcher {
|
|||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean hasMatch(int lon, int lat) {
|
||||
for (MatchedWaypoint mwp : waypoints) {
|
||||
if (mwp.waypoint.ilon == lon && mwp.waypoint.ilat == lat &&
|
||||
(mwp.radius < this.maxDistance || mwp.crosspoint != null)) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
// check limit of list size (avoid long runs)
|
||||
void updateWayList(List<MatchedWaypoint> ways, MatchedWaypoint mw) {
|
||||
ways.add(mw);
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue