fix NP when position not mapped
This commit is contained in:
parent
db0c372941
commit
0dc200f983
3 changed files with 43 additions and 16 deletions
|
@ -166,6 +166,11 @@ public class RoutingEngine extends Thread
|
||||||
long endTime = System.currentTimeMillis();
|
long endTime = System.currentTimeMillis();
|
||||||
logInfo( "execution time = " + (endTime-startTime)/1000. + " seconds" );
|
logInfo( "execution time = " + (endTime-startTime)/1000. + " seconds" );
|
||||||
}
|
}
|
||||||
|
catch( IllegalArgumentException e)
|
||||||
|
{
|
||||||
|
errorMessage = e.getMessage();
|
||||||
|
logInfo( "Exception (linksProcessed=" + linksProcessed + ": " + errorMessage );
|
||||||
|
}
|
||||||
catch( Exception e)
|
catch( Exception e)
|
||||||
{
|
{
|
||||||
errorMessage = e instanceof IllegalArgumentException ? e.getMessage() : e.toString();
|
errorMessage = e instanceof IllegalArgumentException ? e.getMessage() : e.toString();
|
||||||
|
|
|
@ -83,7 +83,8 @@ final class OsmFile
|
||||||
{
|
{
|
||||||
long sum = 0;
|
long sum = 0;
|
||||||
ghost = true;
|
ghost = true;
|
||||||
for( int i=0; i< microCaches.length; i++ )
|
int nc = microCaches == null ? 0 : microCaches.length;
|
||||||
|
for( int i=0; i< nc; i++ )
|
||||||
{
|
{
|
||||||
MicroCache mc = microCaches[i];
|
MicroCache mc = microCaches[i];
|
||||||
if ( mc == null ) continue;
|
if ( mc == null ) continue;
|
||||||
|
@ -102,7 +103,8 @@ final class OsmFile
|
||||||
|
|
||||||
void cleanAll()
|
void cleanAll()
|
||||||
{
|
{
|
||||||
for( int i=0; i< microCaches.length; i++ )
|
int nc = microCaches == null ? 0 : microCaches.length;
|
||||||
|
for( int i=0; i< nc; i++ )
|
||||||
{
|
{
|
||||||
MicroCache mc = microCaches[i];
|
MicroCache mc = microCaches[i];
|
||||||
if ( mc == null ) continue;
|
if ( mc == null ) continue;
|
||||||
|
|
|
@ -12,28 +12,52 @@ import btools.mapaccess.*;
|
||||||
|
|
||||||
public class RouterTest
|
public class RouterTest
|
||||||
{
|
{
|
||||||
|
private File workingDir;
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void routerTest() throws Exception
|
public void routerTest() throws Exception
|
||||||
{
|
{
|
||||||
URL resulturl = this.getClass().getResource( "/testtrack0.gpx" );
|
URL resulturl = this.getClass().getResource( "/testtrack0.gpx" );
|
||||||
Assert.assertTrue( "reference result not found: ", resulturl != null );
|
Assert.assertTrue( "reference result not found: ", resulturl != null );
|
||||||
File resultfile = new File(resulturl.getFile());
|
File resultfile = new File(resulturl.getFile());
|
||||||
File workingDir = resultfile.getParentFile();
|
workingDir = resultfile.getParentFile();
|
||||||
|
|
||||||
|
String msg;
|
||||||
|
|
||||||
|
// first test: route within dreiech test-map crossing tile border
|
||||||
|
|
||||||
|
msg = calcRoute( 8.720897, 50.002515, 8.723658, 49.997510, "testtrack" );
|
||||||
|
|
||||||
|
// error message from router?
|
||||||
|
Assert.assertTrue( "routing failed: " + msg, msg == null );
|
||||||
|
|
||||||
|
// if the track didn't change, we expect the first alternative also
|
||||||
|
File a1 = new File( workingDir, "testtrack1.gpx" );
|
||||||
|
Assert.assertTrue( "result content missmatch", a1.exists() );
|
||||||
|
|
||||||
|
// second test: to-point far off
|
||||||
|
|
||||||
|
msg = calcRoute( 8.720897, 50.002515, 16.723658, 49.997510, "notrack" );
|
||||||
|
|
||||||
|
Assert.assertTrue( msg, msg != null && msg.indexOf( "not mapped" ) >= 0 );
|
||||||
|
}
|
||||||
|
|
||||||
|
private String calcRoute( double flon, double flat, double tlon, double tlat, String trackname ) throws Exception
|
||||||
|
{
|
||||||
String wd = workingDir.getAbsolutePath();
|
String wd = workingDir.getAbsolutePath();
|
||||||
|
|
||||||
List<OsmNodeNamed> wplist = new ArrayList<OsmNodeNamed>();
|
List<OsmNodeNamed> wplist = new ArrayList<OsmNodeNamed>();
|
||||||
OsmNodeNamed n;
|
OsmNodeNamed n;
|
||||||
n = new OsmNodeNamed();
|
n = new OsmNodeNamed();
|
||||||
n.name = "from";
|
n.name = "from";
|
||||||
n.ilon = 180000000 + 8720897;
|
n.ilon = 180000000 + (int)(flon*1000000 + 0.5);
|
||||||
n.ilat = 90000000 + 50002515;
|
n.ilat = 90000000 + (int)(flat*1000000 + 0.5);
|
||||||
wplist.add( n );
|
wplist.add( n );
|
||||||
|
|
||||||
n = new OsmNodeNamed();
|
n = new OsmNodeNamed();
|
||||||
n.name = "to";
|
n.name = "to";
|
||||||
n.ilon = 180000000 + 8723658;
|
n.ilon = 180000000 + (int)(tlon*1000000 + 0.5);
|
||||||
n.ilat = 90000000 + 49997510;
|
n.ilat = 90000000 + (int)(tlat*1000000 + 0.5);
|
||||||
wplist.add( n );
|
wplist.add( n );
|
||||||
|
|
||||||
RoutingContext rctx = new RoutingContext();
|
RoutingContext rctx = new RoutingContext();
|
||||||
|
@ -41,16 +65,12 @@ public class RouterTest
|
||||||
// c.setAlternativeIdx( 1 );
|
// c.setAlternativeIdx( 1 );
|
||||||
|
|
||||||
RoutingEngine re = new RoutingEngine(
|
RoutingEngine re = new RoutingEngine(
|
||||||
wd + "/testtrack",
|
wd + "/" + trackname,
|
||||||
wd + "/testlog",
|
wd + "/" + trackname,
|
||||||
wd + "/../../../brouter-map-creator/target/test-classes/tmp/segments", wplist, rctx );
|
wd + "/../../../brouter-map-creator/target/test-classes/tmp/segments", wplist, rctx );
|
||||||
re.doRun( 0 );
|
re.doRun( 0 );
|
||||||
|
|
||||||
// error message from router?
|
return re.getErrorMessage();
|
||||||
Assert.assertTrue( "routing failed: " + re.getErrorMessage(), re.getErrorMessage() == null );
|
}
|
||||||
|
|
||||||
// if the track didn't change, we expect the first alternative also
|
|
||||||
File a1 = new File( workingDir, "testtrack1.gpx" );
|
|
||||||
Assert.assertTrue( "result content missmatch", a1.exists() );
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue