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-2023 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://tudelft.nl/staff/p.knoppers-1">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 double; 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 Length; the distance that needs to be stored.
42 */
43 public HeadwayDistance(final Length distance)
44 {
45 this.distance = distance;
46 }
47
48 /** {@inheritDoc} */
49 @Override
50 public final String getId()
51 {
52 return "DISTANCE";
53 }
54
55 /** {@inheritDoc} */
56 @Override
57 public final Length getLength()
58 {
59 return null;
60 }
61
62 /** {@inheritDoc} */
63 @Override
64 public final Speed getSpeed()
65 {
66 return Speed.ZERO;
67 }
68
69 /** {@inheritDoc} */
70 @Override
71 public final Length getDistance()
72 {
73 return this.distance;
74 }
75
76 /** {@inheritDoc} */
77 @Override
78 public final ObjectType getObjectType()
79 {
80 return ObjectType.DISTANCEONLY;
81 }
82
83 /** {@inheritDoc} */
84 @Override
85 public final Acceleration getAcceleration()
86 {
87 return Acceleration.ZERO;
88 }
89
90 /** {@inheritDoc} */
91 @Override
92 public final Length getOverlapFront()
93 {
94 return null;
95 }
96
97 /** {@inheritDoc} */
98 @Override
99 public final Length getOverlapRear()
100 {
101 return null;
102 }
103
104 /** {@inheritDoc} */
105 @Override
106 public final Length getOverlap()
107 {
108 return null;
109 }
110
111 /** {@inheritDoc} */
112 @Override
113 public final boolean isAhead()
114 {
115 return this.distance.ge0();
116 }
117
118 /** {@inheritDoc} */
119 @Override
120 public final boolean isBehind()
121 {
122 return this.distance.lt0();
123 }
124
125 /** {@inheritDoc} */
126 @Override
127 public final boolean isParallel()
128 {
129 return false;
130 }
131
132 /** {@inheritDoc} */
133 @Override
134 public final String toString()
135 {
136 return "HeadwayDistance [distance=" + this.distance + "]";
137 }
138
139 }