1 package org.opentrafficsim.road.gtu.following;
2
3 import org.djunits.unit.LengthUnit;
4 import org.opentrafficsim.core.OTS_SCALAR;
5 import org.opentrafficsim.road.gtu.lane.LaneBasedGTU;
6
7 /**
8 * Container for a reference to a LaneBasedGTU and a headway.
9 * <p>
10 * Copyright (c) 2013-2015 Delft University of Technology, PO Box 5, 2600 AA, Delft, the Netherlands. All rights reserved. <br>
11 * BSD-style license. See <a href="http://opentrafficsim.org/docs/license.html">OpenTrafficSim License</a>.
12 * <p>
13 * @version $Revision: 1368 $, $LastChangedDate: 2015-09-02 00:20:20 +0200 (Wed, 02 Sep 2015) $, by $Author: averbraeck $,
14 * initial version 11 feb. 2015 <br>
15 * @author <a href="http://www.tbm.tudelft.nl/averbraeck">Alexander Verbraeck</a>
16 * @author <a href="http://www.tudelft.nl/pknoppers">Peter Knoppers</a>
17 */
18 public class HeadwayGTU implements OTS_SCALAR
19 {
20 /** the other GTU. */
21 private final LaneBasedGTU otherGTU;
22
23 /** the distance to the GTU in meters. */
24 private final double distanceSI;
25
26 /**
27 * Construct a new HeadwayGTU.
28 * @param otherGTU the other GTU
29 * @param distanceSI the distance to the other GTU in meters; if the other GTU is parallel, use distance Double.NaN
30 */
31 public HeadwayGTU(final LaneBasedGTU otherGTU, final double distanceSI)
32 {
33 this.otherGTU = otherGTU;
34 this.distanceSI = distanceSI;
35 }
36
37 /**
38 * @return the other GTU.
39 */
40 public final LaneBasedGTU getOtherGTU()
41 {
42 return this.otherGTU;
43 }
44
45 /**
46 * Retrieve the distance to the other GTU in meters.
47 * @return the distance to the other GTU in SI unit for length (meter), the value Double.NaN is used to indicate that the
48 * other GTU is parallel with the reference GTU
49 */
50 public final double getDistanceSI()
51 {
52 return this.distanceSI;
53 }
54
55 /**
56 * Retrieve the strongly typed distance to the other GTU.
57 * @return DoubleScalar.Rel<LengthUnit>; the distance to the GTU, return value null indicates that the other GTU is
58 * parallel to the reference GTU
59 */
60 public final Length.Rel getDistance()
61 {
62 if (Double.isNaN(this.distanceSI))
63 {
64 return null;
65 }
66 return new Length.Rel(this.distanceSI, LengthUnit.SI);
67 }
68
69 /** {@inheritDoc} */
70 public final String toString()
71 {
72 return String.format("Headway %s to %s", getDistance(), this.otherGTU);
73 }
74
75 }