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://github.com/peter-knoppers">Peter Knoppers</a>
17 * @author <a href="https://github.com/wjschakel">Wouter Schakel</a>
18 * @param dx positive x is in the normal direction of movement.
19 * @param dy positive y is left compared to the normal direction of movement (seen from the top).
20 * @param dz positive z is up.
21 * @param 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 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://github.com/peter-knoppers">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 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 @Override
99 public final String toString()
100 {
101 return this.name;
102 }
103
104 @Override
105 @SuppressWarnings("checkstyle:designforextension")
106 public int hashCode()
107 {
108 return this.hash;
109 }
110
111 @Override
112 @SuppressWarnings({"checkstyle:designforextension", "checkstyle:needbraces"})
113 public boolean equals(final Object obj)
114 {
115 if (this == obj)
116 return true;
117 if (obj == null)
118 return false;
119 if (getClass() != obj.getClass())
120 return false;
121 Type other = (Type) obj;
122 if (this.name == null)
123 {
124 if (other.name != null)
125 return false;
126 }
127 else if (!this.name.equals(other.name))
128 return false;
129 return true;
130 }
131
132 }
133
134 }