1 package org.opentrafficsim.core.gtu;
2
3 import java.io.Serializable;
4
5 import org.djunits.value.vdouble.scalar.Length;
6
7 /**
8 * A RelativePosition is a position on a GTU; e.g. the front, rear, position of the driver, etc. <br>
9 * A RelativePosition stores the offset of the position from the reference position of the GTU.
10 * <p>
11 * Copyright (c) 2013-2024 Delft University of Technology, PO Box 5, 2600 AA, Delft, the Netherlands. All rights reserved. <br>
12 * BSD-style license. See <a href="https://opentrafficsim.org/docs/license.html">OpenTrafficSim License</a>.
13 * <p>
14 * $LastChangedDate$, @version $Revision$, by $Author$, initial version Dec 30, 2014 <br>
15 * @author <a href="https://github.com/averbraeck">Alexander Verbraeck</a>
16 * @author <a href="https://tudelft.nl/staff/p.knoppers-1">Peter Knoppers</a>
17 * @author <a href="https://github.com/wjschakel">Wouter Schakel</a>
18 * @param dx Length; positive x is in the normal direction of movement.
19 * @param dy Length; positive y is left compared to the normal direction of movement (seen from the top).
20 * @param dz Length; positive z is up.
21 * @param type TYPE; type of relative position (FRONT, BACK, etc.).
22 */
23 public record RelativePosition(Length dx, Length dy, Length dz, Type type) implements Serializable
24 {
25
26 /** */
27 private static final long serialVersionUID = 20141231L;
28
29 /** Standard relative position type FRONT. */
30 public static final Type FRONT = new Type("FRONT");
31
32 /** Standard relative position type BACK. */
33 public static final Type REAR = new Type("REAR");
34
35 /** Standard relative position type CENTER. */
36 public static final Type CENTER = new Type("CENTER");
37
38 /** Standard relative position type REFERENCE. */
39 public static final Type REFERENCE = new Type("REFERENCE");
40
41 /** Standard relative position type DRIVER. */
42 public static final Type DRIVER = new Type("DRIVER");
43
44 /** Standard relative position type CONTOUR. There can be multiple points of type CONTOUR for one GTU. */
45 public static final Type CONTOUR = new Type("CONTOUR");
46
47 /** The reference position (always 0, 0, 0). */
48 public static final RelativePosition REFERENCE_POSITION =
49 new RelativePosition(Length.ZERO, Length.ZERO, Length.ZERO, RelativePosition.REFERENCE);
50
51 /**
52 * @param p RelativePosition; a relative position to make a deep copy of.
53 */
54 public RelativePosition(final RelativePosition p)
55 {
56 this(p.dx(), p.dy(), p.dz(), p.type());
57 }
58
59 /**
60 * The type of relative position, e.g., Front, Back, etc.
61 * <p>
62 * Copyright (c) 2013-2024 Delft University of Technology, PO Box 5, 2600 AA, Delft, the Netherlands. <br>
63 * All rights reserved. <br>
64 * BSD-style license. See <a href="https://opentrafficsim.org/docs/license.html">OpenTrafficSim License</a>.
65 * <p>
66 * $LastChangedDate$, @version $Revision$, by $Author$, initial version ec 31, 2014 <br>
67 * @author <a href="https://github.com/averbraeck">Alexander Verbraeck</a>
68 * @author <a href="https://tudelft.nl/staff/p.knoppers-1">Peter Knoppers</a>
69 */
70 public static class Type implements Serializable
71 {
72 /** */
73 private static final long serialVersionUID = 20141231L;
74
75 /** The type name. */
76 private final String name;
77
78 /** the cached hashcode. */
79 private final int hash;
80
81 /**
82 * @param name String; the type name.
83 */
84 public Type(final String name)
85 {
86 this.name = name;
87 this.hash = 31 + ((this.name == null) ? 0 : this.name.hashCode());
88 }
89
90 /**
91 * @return name.
92 */
93 public final String getName()
94 {
95 return this.name;
96 }
97
98 /** {@inheritDoc} */
99 @Override
100 public final String toString()
101 {
102 return this.name;
103 }
104
105 /** {@inheritDoc} */
106 @Override
107 @SuppressWarnings("checkstyle:designforextension")
108 public int hashCode()
109 {
110 return this.hash;
111 }
112
113 /** {@inheritDoc} */
114 @Override
115 @SuppressWarnings({"checkstyle:designforextension", "checkstyle:needbraces"})
116 public boolean equals(final Object obj)
117 {
118 if (this == obj)
119 return true;
120 if (obj == null)
121 return false;
122 if (getClass() != obj.getClass())
123 return false;
124 Type other = (Type) obj;
125 if (this.name == null)
126 {
127 if (other.name != null)
128 return false;
129 }
130 else if (!this.name.equals(other.name))
131 return false;
132 return true;
133 }
134
135 }
136
137 }