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