1   package org.opentrafficsim.animation.lane;
2   
3   import org.djunits.value.vdouble.scalar.Length;
4   import org.djutils.draw.point.OrientedPoint2d;
5   import org.opentrafficsim.base.geometry.BoundingBox;
6   import org.opentrafficsim.base.geometry.OtsBounds2d;
7   import org.opentrafficsim.base.geometry.OtsLocatable;
8   import org.opentrafficsim.core.geometry.OtsGeometryException;
9   import org.opentrafficsim.core.gtu.Gtu;
10  import org.opentrafficsim.road.gtu.lane.perception.LaneStructureRecord;
11  import org.opentrafficsim.road.gtu.lane.perception.RollingLaneStructure;
12  
13  
14  
15  
16  
17  
18  
19  
20  
21  public class LaneStructureLocatable implements OtsLocatable
22  {
23      
24      private final RollingLaneStructure rollingLaneStructure;
25  
26      
27      private final Gtu gtu;
28  
29      
30  
31  
32  
33      public LaneStructureLocatable(final RollingLaneStructure rollingLaneStructure, final Gtu gtu)
34      {
35          this.rollingLaneStructure = rollingLaneStructure;
36          this.gtu = gtu;
37      }
38  
39      
40      @Override
41      public OrientedPoint2d getLocation()
42      {
43          LaneStructureRecord rt = this.rollingLaneStructure.getRootRecord();
44          if (rt == null)
45          {
46              return this.gtu.getLocation();
47          }
48          Length position = rt.getStartDistance().neg();
49          position = position.lt0() ? Length.ZERO : position;
50          try
51          {
52              return rt.getLane().getCenterLine().getLocation(position);
53          }
54          catch (OtsGeometryException exception)
55          {
56              throw new RuntimeException("Unable to return location.", exception);
57          }
58      }
59  
60      
61      @Override
62      public OtsBounds2d getBounds()
63      {
64          return new BoundingBox(1000000, 1000000);
65      }
66  
67      
68  
69  
70      public final RollingLaneStructure getRollingLaneStructure()
71      {
72          return this.rollingLaneStructure;
73      }
74  
75      
76  
77  
78      public final Gtu getGtu()
79      {
80          return this.gtu;
81      }
82  
83  }