1 package org.opentrafficsim.road.network.lane;
2
3 import java.util.List;
4
5 import org.djunits.value.vdouble.scalar.Length;
6 import org.djutils.draw.line.PolyLine2d;
7 import org.djutils.exceptions.Throw;
8 import org.opentrafficsim.base.StripeElement;
9 import org.opentrafficsim.base.StripeElement.StripeLateralSync;
10 import org.opentrafficsim.base.geometry.DirectionalPolyLine;
11 import org.opentrafficsim.core.gtu.GtuType;
12 import org.opentrafficsim.core.network.LateralDirectionality;
13 import org.opentrafficsim.road.network.lane.StripeData.StripePhaseSync;
14
15
16
17
18
19
20
21
22
23
24
25
26
27 public class Stripe extends CrossSectionElement
28 {
29
30 private final StripeData data;
31
32
33 private Length dashOffset = Length.ZERO;
34
35
36 private PolyLine2d linkReferenceLine = null;
37
38
39
40
41
42
43
44
45 public Stripe(final String id, final StripeData data, final CrossSectionLink link, final CrossSectionGeometry geometry)
46 {
47 super(link, id, geometry);
48 Throw.whenNull(data, "Type may not be null.");
49 this.data = data;
50 }
51
52
53
54
55
56
57
58
59 public void addPermeability(final GtuType gtuType, final LateralDirectionality lateralDirection)
60 {
61 this.data.addPermeability(gtuType, lateralDirection);
62 }
63
64
65
66
67
68
69
70 public final boolean isPermeable(final GtuType gtuType, final LateralDirectionality lateralDirection)
71 {
72 return this.data.isPermeable(gtuType, lateralDirection);
73 }
74
75
76
77
78
79 public List<StripeElement> getElements()
80 {
81 return this.data.getElements();
82 }
83
84
85
86
87
88 public void setDashOffset(final Length dashOffset)
89 {
90 this.dashOffset = dashOffset;
91 }
92
93
94
95
96
97 public Length getDashOffset()
98 {
99 return this.dashOffset;
100 }
101
102
103
104
105
106 public void setLateralSync(final StripeLateralSync lateralSync)
107 {
108 this.data.setLateralSync(lateralSync);
109 }
110
111
112
113
114
115 public StripeLateralSync getLateralSync()
116 {
117 return this.data.getLateralSync();
118 }
119
120
121
122
123
124 public void setPhaseSync(final StripePhaseSync phaseSync)
125 {
126 this.data.setPhaseSync(phaseSync);
127 }
128
129
130
131
132
133 public StripePhaseSync getPhaseSync()
134 {
135 return this.data.getPhaseSync();
136 }
137
138
139
140
141
142 public double getPeriod()
143 {
144 return this.data.getPeriod();
145 }
146
147
148
149
150
151 public PolyLine2d getLinkReferenceLine()
152 {
153 if (this.linkReferenceLine == null)
154 {
155 PolyLine2d linkLine = getLink().getDesignLine();
156 double offsetMin0 = Double.POSITIVE_INFINITY;
157 double offsetMax0 = Double.NEGATIVE_INFINITY;
158 double offsetMin1 = Double.POSITIVE_INFINITY;
159 double offsetMax1 = Double.NEGATIVE_INFINITY;
160 for (CrossSectionElement element : getLink().getCrossSectionElementList())
161 {
162 if (element instanceof Stripe)
163 {
164 offsetMin0 = Math.min(offsetMin0, element.getOffsetAtBegin().si);
165 offsetMax0 = Math.max(offsetMax0, element.getOffsetAtBegin().si);
166 offsetMin1 = Math.min(offsetMin1, element.getOffsetAtEnd().si);
167 offsetMax1 = Math.max(offsetMax1, element.getOffsetAtEnd().si);
168 }
169 }
170 DirectionalPolyLine directionalLine = new DirectionalPolyLine(linkLine, getLink().getStartNode().getHeading(),
171 getLink().getEndNode().getHeading());
172 PolyLine2d start = directionalLine.directionalOffsetLine(.5 * (offsetMin0 + offsetMax0));
173 PolyLine2d end = directionalLine.directionalOffsetLine(.5 * (offsetMin1 + offsetMax1));
174 this.linkReferenceLine = start.transitionLine(end, (f) -> f);
175 }
176 return this.linkReferenceLine;
177 }
178
179 @Override
180 public String toString()
181 {
182 return "Stripe [id=" + this.getFullId() + "]";
183 }
184
185 }