View Javadoc
1   package org.opentrafficsim.road.gtu.lane.perception.headway;
2   
3   import org.djunits.unit.LengthUnit;
4   import org.djunits.value.vdouble.scalar.Acceleration;
5   import org.djunits.value.vdouble.scalar.Length;
6   import org.djunits.value.vdouble.scalar.Speed;
7   
8   /**
9    * Container for a reference to information about a headway with just a distance, without any further information about the
10   * object; it assumes a speed of 0 at the headway, so it also good to store information about a lane drop. The reason for
11   * storing a speed of zero at the end of a maximum headway is that we did not check the conditions beyond that point. A GTU or
12   * lane drop could be right behind the last point we checked.
13   * <p>
14   * Copyright (c) 2013-2018 Delft University of Technology, PO Box 5, 2600 AA, Delft, the Netherlands. All rights reserved. <br>
15   * BSD-style license. See <a href="http://opentrafficsim.org/docs/license.html">OpenTrafficSim License</a>.
16   * <p>
17   * @version $Revision: 1368 $, $LastChangedDate: 2015-09-02 00:20:20 +0200 (Wed, 02 Sep 2015) $, by $Author: averbraeck $,
18   *          initial version 11 feb. 2015 <br>
19   * @author <a href="http://www.tbm.tudelft.nl/averbraeck">Alexander Verbraeck</a>
20   * @author <a href="http://www.tudelft.nl/pknoppers">Peter Knoppers</a>
21   */
22  public class HeadwayDistance implements Headway
23  {
24      /** */
25      private static final long serialVersionUID = 20160410L;
26  
27      /** the distance of the headway. */
28      private final Length distance;
29  
30      /**
31       * Construct a new Headway information object with just a distance, without any further information about the object; it
32       * assumes a speed of 0 at the headway, so it also good to store information about a lane drop.
33       * @param distance the distance that needs to be stored.
34       */
35      public HeadwayDistance(final double distance)
36      {
37          this(new Length(distance, LengthUnit.SI));
38      }
39  
40      /**
41       * Construct a new Headway information object with just a distance, without any further information about the object; it
42       * assumes a speed of 0 at the headway, so it also good to store information about a lane drop.
43       * @param distance the distance that needs to be stored.
44       */
45      public HeadwayDistance(final Length distance)
46      {
47          this.distance = distance;
48      }
49  
50      /** {@inheritDoc} */
51      @Override
52      public final String getId()
53      {
54          return "DISTANCE";
55      }
56  
57      /** {@inheritDoc} */
58      @Override
59      public final Length getLength()
60      {
61          return null;
62      }
63  
64      /** {@inheritDoc} */
65      @Override
66      public final Speed getSpeed()
67      {
68          return Speed.ZERO;
69      }
70  
71      /** {@inheritDoc} */
72      @Override
73      public final Length getDistance()
74      {
75          return this.distance;
76      }
77  
78      /** {@inheritDoc} */
79      @Override
80      public final ObjectType getObjectType()
81      {
82          return ObjectType.DISTANCEONLY;
83      }
84  
85      /** {@inheritDoc} */
86      @Override
87      public final Acceleration getAcceleration()
88      {
89          return Acceleration.ZERO;
90      }
91  
92      /** {@inheritDoc} */
93      @Override
94      public final Length getOverlapFront()
95      {
96          return null;
97      }
98  
99      /** {@inheritDoc} */
100     @Override
101     public final Length getOverlapRear()
102     {
103         return null;
104     }
105 
106     /** {@inheritDoc} */
107     @Override
108     public final Length getOverlap()
109     {
110         return null;
111     }
112 
113     /** {@inheritDoc} */
114     @Override
115     public final boolean isAhead()
116     {
117         return this.distance.ge0();
118     }
119 
120     /** {@inheritDoc} */
121     @Override
122     public final boolean isBehind()
123     {
124         return this.distance.lt0();
125     }
126 
127     /** {@inheritDoc} */
128     @Override
129     public final boolean isParallel()
130     {
131         return false;
132     }
133 
134     /** {@inheritDoc} */
135     @Override
136     public final String toString()
137     {
138         return "HeadwayDistance [distance=" + this.distance + "]";
139     }
140 
141 }