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