24
24
import gnu .trove .list .TIntList ;
25
25
import gnu .trove .list .array .TIntArrayList ;
26
26
27
+ import java .util .ArrayList ;
28
+ import java .util .List ;
29
+
27
30
/**
28
31
* Stores the nodes for the found path of an algorithm. It additionally needs the edgeIds to make
29
32
* edge determination faster and less complex as there could be several edges (u,v) especially for
@@ -47,7 +50,7 @@ public class Path
47
50
protected int endNode = -1 ;
48
51
private TIntList edgeIds ;
49
52
private PointList cachedPoints ;
50
- private InstructionList cachedWays ;
53
+ private List < Instruction > cachedWays ;
51
54
private double weight ;
52
55
53
56
public Path ( Graph graph , FlagEncoder encoder )
@@ -300,12 +303,12 @@ public void next( EdgeIteratorState eb, int i )
300
303
/**
301
304
* @return the cached list of ways for this path
302
305
*/
303
- public InstructionList calcInstructions ()
306
+ public List < Instruction > calcInstructions ()
304
307
{
305
308
if (cachedWays != null )
306
309
return cachedWays ;
307
310
308
- cachedWays = new InstructionList (edgeIds .size () / 4 );
311
+ cachedWays = new ArrayList < Instruction > (edgeIds .size () / 4 );
309
312
if (edgeIds .isEmpty ())
310
313
return cachedWays ;
311
314
@@ -337,6 +340,7 @@ public InstructionList calcInstructions()
337
340
double prevLon = graph .getLongitude (tmpNode );
338
341
double prevOrientation ;
339
342
double prevDist ;
343
+ long prevTime ;
340
344
341
345
@ Override
342
346
public void next ( EdgeIteratorState edgeBase , int index )
@@ -366,7 +370,8 @@ public void next( EdgeIteratorState edgeBase, int index )
366
370
{
367
371
name = edgeBase .getName ();
368
372
prevDist = calcDistance (edgeBase );
369
- cachedWays .add (InstructionList .CONTINUE_ON_STREET , name , prevDist );
373
+ prevTime = calcTime (prevDist , edgeBase .getFlags ());
374
+ cachedWays .add (new Instruction (Instruction .CONTINUE_ON_STREET , name , prevDist , prevTime , prevLat , prevLon ));
370
375
} else
371
376
{
372
377
double tmpOrientation ;
@@ -388,41 +393,46 @@ public void next( EdgeIteratorState edgeBase, int index )
388
393
String tmpName = edgeBase .getName ();
389
394
if (!name .equals (tmpName ))
390
395
{
391
- cachedWays . updateLastDistance ( prevDist );
396
+ InstructionUtil . updateLastDistanceAndTime ( cachedWays , prevDist , prevTime );
392
397
prevDist = calcDistance (edgeBase );
398
+ prevTime = calcTime (prevDist , edgeBase .getFlags ());
393
399
name = tmpName ;
394
400
double delta = Math .abs (tmpOrientation - prevOrientation );
395
401
if (delta < 0.2 )
396
402
{
397
403
// 0.2 ~= 11°
398
- cachedWays .add (InstructionList .CONTINUE_ON_STREET , name , prevDist );
404
+ cachedWays .add (new Instruction ( Instruction .CONTINUE_ON_STREET , name , prevDist , prevTime , prevLat , prevLon ) );
399
405
400
406
} else if (delta < 0.8 )
401
407
{
402
408
// 0.8 ~= 40°
403
409
if (tmpOrientation > prevOrientation )
404
- cachedWays .add (InstructionList .TURN_SLIGHT_LEFT , name , prevDist );
410
+ cachedWays .add (new Instruction ( Instruction .TURN_SLIGHT_LEFT , name , prevDist , prevTime , prevLat , prevLon ) );
405
411
else
406
- cachedWays .add (InstructionList .TURN_SLIGHT_RIGHT , name , prevDist );
412
+ cachedWays .add (new Instruction ( Instruction .TURN_SLIGHT_RIGHT , name , prevDist , prevTime , prevLat , prevLon ) );
407
413
408
414
} else if (delta < 1.8 )
409
415
{
410
416
// 1.8 ~= 103°
411
417
if (tmpOrientation > prevOrientation )
412
- cachedWays .add (InstructionList .TURN_LEFT , name , prevDist );
418
+ cachedWays .add (new Instruction ( Instruction .TURN_LEFT , name , prevDist , prevTime , prevLat , prevLon ) );
413
419
else
414
- cachedWays .add (InstructionList .TURN_RIGHT , name , prevDist );
420
+ cachedWays .add (new Instruction ( Instruction .TURN_RIGHT , name , prevDist , prevTime , prevLat , prevLon ) );
415
421
416
422
} else
417
423
{
418
424
if (tmpOrientation > prevOrientation )
419
- cachedWays .add (InstructionList .TURN_SHARP_LEFT , name , prevDist );
425
+ cachedWays .add (new Instruction ( Instruction .TURN_SHARP_LEFT , name , prevDist , prevTime , prevLat , prevLon ) );
420
426
else
421
- cachedWays .add (InstructionList .TURN_SHARP_RIGHT , name , prevDist );
427
+ cachedWays .add (new Instruction ( Instruction .TURN_SHARP_RIGHT , name , prevDist , prevTime , prevLat , prevLon ) );
422
428
423
429
}
424
430
} else
425
- prevDist += calcDistance (edgeBase );
431
+ {
432
+ double tmpDist = calcDistance (edgeBase );
433
+ prevDist += tmpDist ;
434
+ prevTime += calcTime (tmpDist , edgeBase .getFlags ());
435
+ }
426
436
}
427
437
428
438
prevLat = baseLat ;
@@ -434,7 +444,7 @@ public void next( EdgeIteratorState edgeBase, int index )
434
444
435
445
boolean lastEdgeIter = index == edgeIds .size () - 1 ;
436
446
if (lastEdgeIter )
437
- cachedWays . updateLastDistance ( prevDist );
447
+ InstructionUtil . updateLastDistanceAndTime ( cachedWays , prevDist , prevTime );
438
448
}
439
449
});
440
450
0 commit comments