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-2024 Delft University of Technology, PO Box 5, 2600 AA, Delft, the Netherlands. All rights reserved. <br>
15   * BSD-style license. See <a href="https://opentrafficsim.org/docs/license.html">OpenTrafficSim License</a>.
16   * </p>
17   * @author <a href="https://github.com/averbraeck">Alexander Verbraeck</a>
18   * @author <a href="https://github.com/peter-knoppers">Peter Knoppers</a>
19   */
20  public class HeadwayDistance implements Headway
21  {
22      /** */
23      private static final long serialVersionUID = 20160410L;
24  
25      /** the distance of the headway. */
26      private final Length distance;
27  
28      /**
29       * Construct a new Headway information object with just a distance, without any further information about the object; it
30       * assumes a speed of 0 at the headway, so it also good to store information about a lane drop.
31       * @param distance the distance that needs to be stored.
32       */
33      public HeadwayDistance(final double distance)
34      {
35          this(new Length(distance, LengthUnit.SI));
36      }
37  
38      /**
39       * Construct a new Headway information object with just a distance, without any further information about the object; it
40       * assumes a speed of 0 at the headway, so it also good to store information about a lane drop.
41       * @param distance the distance that needs to be stored.
42       */
43      public HeadwayDistance(final Length distance)
44      {
45          this.distance = distance;
46      }
47  
48      @Override
49      public final String getId()
50      {
51          return "DISTANCE";
52      }
53  
54      @Override
55      public final Length getLength()
56      {
57          return null;
58      }
59  
60      @Override
61      public final Speed getSpeed()
62      {
63          return Speed.ZERO;
64      }
65  
66      @Override
67      public final Length getDistance()
68      {
69          return this.distance;
70      }
71  
72      @Override
73      public final ObjectType getObjectType()
74      {
75          return ObjectType.DISTANCEONLY;
76      }
77  
78      @Override
79      public final Acceleration getAcceleration()
80      {
81          return Acceleration.ZERO;
82      }
83  
84      @Override
85      public final Length getOverlapFront()
86      {
87          return null;
88      }
89  
90      @Override
91      public final Length getOverlapRear()
92      {
93          return null;
94      }
95  
96      @Override
97      public final Length getOverlap()
98      {
99          return null;
100     }
101 
102     @Override
103     public final boolean isAhead()
104     {
105         return this.distance.ge0();
106     }
107 
108     @Override
109     public final boolean isBehind()
110     {
111         return this.distance.lt0();
112     }
113 
114     @Override
115     public final boolean isParallel()
116     {
117         return false;
118     }
119 
120     @Override
121     public final String toString()
122     {
123         return "HeadwayDistance [distance=" + this.distance + "]";
124     }
125 
126 }