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 =
52 rt.getDirection().isPlus() ? rt.getStartDistance().neg() : rt.getLane().getLength().plus(rt.getStartDistance());
53 position = position.lt0() ? Length.ZERO : position;
54 try
55 {
56 return rt.getLane().getCenterLine().getLocation(position);
57 }
58 catch (OTSGeometryException exception)
59 {
60 throw new RuntimeException("Unable to return location.", exception);
61 }
62 }
63
64
65 @Override
66 public Bounds getBounds() throws RemoteException
67 {
68 Point3d p1 = new Point3d(-1000000, -1000000, 0.0);
69 Point3d p2 = new Point3d(1000000, 1000000, 0.0);
70 return new Bounds(p1, p2);
71 }
72
73
74
75
76 public final RollingLaneStructure getRollingLaneStructure()
77 {
78 return this.rollingLaneStructure;
79 }
80
81
82
83
84 public final GTU getGtu()
85 {
86 return this.gtu;
87 }
88
89 }