1 package org.opentrafficsim.road.network.lane;
2
3 import java.io.Serializable;
4
5 import nl.tudelft.simulation.language.d3.DirectedPoint;
6
7 import org.djunits.value.vdouble.scalar.Length;
8 import org.opentrafficsim.core.Throw;
9 import org.opentrafficsim.core.gtu.GTUDirectionality;
10 import org.opentrafficsim.core.gtu.GTUException;
11
12
13
14
15
16
17
18
19
20
21
22 public class DirectedLanePosition implements Serializable
23 {
24
25 private static final long serialVersionUID = 20151111L;
26
27
28 private final Lane lane;
29
30
31 private final Length position;
32
33
34 private final GTUDirectionality gtuDirection;
35
36
37
38
39
40
41
42 public DirectedLanePosition(final Lane lane, final Length position, final GTUDirectionality gtuDirection)
43 throws GTUException
44 {
45 super();
46 Throw.when(lane == null, GTUException.class, "lane is null");
47 Throw.when(position == null, GTUException.class, "position is null");
48 Throw.when(gtuDirection == null, GTUException.class, "gtuDirection is null");
49 this.lane = lane;
50 this.position = position;
51 this.gtuDirection = gtuDirection;
52 }
53
54
55
56
57 public final Lane getLane()
58 {
59 return this.lane;
60 }
61
62
63
64
65 public final Length getPosition()
66 {
67 return this.position;
68 }
69
70
71
72
73 public final GTUDirectionality getGtuDirection()
74 {
75 return this.gtuDirection;
76 }
77
78
79
80
81 public DirectedPoint getLocation()
82 {
83 double fraction = this.position.si / this.lane.getParentLink().getLength().si;
84 DirectedPoint p = this.lane.getCenterLine().getLocationFractionExtended(fraction);
85 if (this.gtuDirection.equals(GTUDirectionality.DIR_PLUS))
86 {
87 return p;
88 }
89 return new DirectedPoint(p.x, p.y, p.z, p.getRotX(), p.getRotY(), p.getRotZ() + Math.PI);
90 }
91
92
93 @Override
94 public int hashCode()
95 {
96 final int prime = 31;
97 int result = 1;
98 result = prime * result + ((this.gtuDirection == null) ? 0 : this.gtuDirection.hashCode());
99 result = prime * result + ((this.lane == null) ? 0 : this.lane.hashCode());
100 result = prime * result + ((this.position == null) ? 0 : this.position.hashCode());
101 return result;
102 }
103
104
105 @Override
106 public boolean equals(final Object obj)
107 {
108 if (this == obj)
109 return true;
110 if (obj == null)
111 return false;
112 if (getClass() != obj.getClass())
113 return false;
114 DirectedLanePosition other = (DirectedLanePosition) obj;
115 if (this.gtuDirection != other.gtuDirection)
116 return false;
117 if (this.lane == null)
118 {
119 if (other.lane != null)
120 return false;
121 }
122 else if (!this.lane.equals(other.lane))
123 return false;
124 if (this.position == null)
125 {
126 if (other.position != null)
127 return false;
128 }
129 else if (!this.position.equals(other.position))
130 return false;
131 return true;
132 }
133
134
135 @Override
136 public String toString()
137 {
138 return "DirectedLanePosition [lane=" + this.lane + ", position=" + this.position + ", gtuDirection="
139 + this.gtuDirection + "]";
140 }
141
142 }