1 package org.opentrafficsim.road.network.lane;
2
3 import java.io.Serializable;
4
5 import org.djunits.value.vdouble.scalar.Length;
6 import org.djutils.exceptions.Throw;
7 import org.opentrafficsim.core.geometry.DirectedPoint;
8 import org.opentrafficsim.core.geometry.OtsLine3d;
9
10
11
12
13
14
15
16
17
18
19
20 public class LanePosition implements Serializable
21 {
22
23 private static final long serialVersionUID = 20151111L;
24
25
26 private final Lane lane;
27
28
29 private final Length position;
30
31
32
33
34
35
36 public LanePosition(final Lane lane, final Length position)
37 {
38 Throw.whenNull(lane, "lane is null");
39 Throw.whenNull(position, "position is null");
40 this.lane = lane;
41 this.position = position;
42 }
43
44
45
46
47
48 public final Lane getLane()
49 {
50 return this.lane;
51 }
52
53
54
55
56
57 public final Length getPosition()
58 {
59 return this.position;
60 }
61
62
63
64
65
66 public final DirectedPoint getLocation()
67 {
68
69 OtsLine3d centerLine = this.lane.getCenterLine();
70 double centerLineLength = centerLine.getLengthSI();
71 double fraction = this.position.si / centerLineLength;
72 return centerLine.getLocationFractionExtended(fraction);
73 }
74
75
76 @Override
77 public int hashCode()
78 {
79 final int prime = 31;
80 int result = 1;
81 result = prime * result + ((this.lane == null) ? 0 : this.lane.hashCode());
82 result = prime * result + ((this.position == null) ? 0 : this.position.hashCode());
83 return result;
84 }
85
86
87 @SuppressWarnings("checkstyle:needbraces")
88 @Override
89 public boolean equals(final Object obj)
90 {
91 if (this == obj)
92 return true;
93 if (obj == null)
94 return false;
95 if (getClass() != obj.getClass())
96 return false;
97 LanePosition other = (LanePosition) obj;
98 if (this.lane == null)
99 {
100 if (other.lane != null)
101 return false;
102 }
103 else if (!this.lane.equals(other.lane))
104 return false;
105 if (this.position == null)
106 {
107 if (other.position != null)
108 return false;
109 }
110 else if (!this.position.equals(other.position))
111 return false;
112 return true;
113 }
114
115
116 @Override
117 public final String toString()
118 {
119 return "LanePosition [lane=" + this.lane + ", position=" + this.position + "]";
120 }
121
122 }