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.opentrafficsim.core.geometry.OTSGeometryException;
7 import org.opentrafficsim.core.network.NetworkException;
8 import org.opentrafficsim.core.network.OTSNetwork;
9
10 import nl.tudelft.simulation.dsol.simulators.SimulatorInterface;
11
12 /**
13 * <p>
14 * Copyright (c) 2013-2018 Delft University of Technology, PO Box 5, 2600 AA, Delft, the Netherlands. All rights reserved. <br>
15 * BSD-style license. See <a href="http://opentrafficsim.org/docs/license.html">OpenTrafficSim License</a>.
16 * <p>
17 * $LastChangedDate: 2015-09-03 13:38:01 +0200 (Thu, 03 Sep 2015) $, @version $Revision: 1378 $, by $Author: averbraeck $,
18 * initial version Aug 19, 2014 <br>
19 * @author <a href="http://www.tbm.tudelft.nl/averbraeck">Alexander Verbraeck</a>
20 * @author <a href="http://www.tudelft.nl/pknoppers">Peter Knoppers</a>
21 * @author <a href="http://www.citg.tudelft.nl">Guus Tamminga</a>
22 */
23 public class Shoulder extends CrossSectionElement
24 {
25 /** */
26 private static final long serialVersionUID = 20140819L;
27
28 /**
29 * @param parentLink Cross Section Link to which the element belongs.
30 * @param id String; the id of the lane. Should be unique within the parentLink.
31 * @param lateralPositionStart the lateral start position compared to the linear geometry of the Cross Section Link.
32 * @param lateralPositionEnd the lateral end position compared to the linear geometry of the Cross Section Link
33 * @param beginWidth start width, positioned <i>symmetrically around</i> the lateral start position.
34 * @param endWidth end width, positioned <i>symmetrically around</i> the lateral end position.
35 * @throws OTSGeometryException when creation of the center line or contour geometry fails
36 * @throws NetworkException when id equal to null or not unique
37 */
38 public Shoulder(final CrossSectionLink parentLink, final String id, final Length lateralPositionStart,
39 final Length lateralPositionEnd, final Length beginWidth, final Length endWidth)
40 throws OTSGeometryException, NetworkException
41 {
42 super(parentLink, id, lateralPositionStart, lateralPositionEnd, beginWidth, endWidth);
43 }
44
45 /**
46 * @param parentLink Cross Section Link to which the element belongs.
47 * @param id String; the id of the lane. Should be unique within the parentLink.
48 * @param lateralPosition the lateral start position compared to the linear geometry of the Cross Section Link.
49 * @param width the shoulder width, positioned <i>symmetrically around</i> the lateral start position.
50 * @throws OTSGeometryException when creation of the center line or contour geometry fails
51 * @throws NetworkException when id equal to null or not unique
52 */
53 public Shoulder(final CrossSectionLink parentLink, final String id, final Length lateralPosition, final Length width)
54 throws OTSGeometryException, NetworkException
55 {
56 super(parentLink, id, lateralPosition, width);
57 }
58
59 /**
60 * @param parentLink Cross Section Link to which the element belongs.
61 * @param id String; the id of the lane. Should be unique within the parentLink.
62 * @param crossSectionSlices The offsets and widths at positions along the line, relative to the design line of the parent
63 * link. If there is just one with and offset, there should just be one element in the list with Length = 0. If
64 * there are more slices, the last one should be at the length of the design line. If not, a NetworkException is
65 * thrown.
66 * @throws OTSGeometryException when creation of the center line or contour geometry fails
67 * @throws NetworkException when id equal to null or not unique
68 */
69 public Shoulder(final CrossSectionLink parentLink, final String id, final List<CrossSectionSlice> crossSectionSlices)
70 throws OTSGeometryException, NetworkException
71 {
72 super(parentLink, id, crossSectionSlices);
73 }
74
75 /**
76 * Clone a Shoulder for a new network.
77 * @param newParentLink the new link to which the clone belongs
78 * @param newSimulator the new simulator for this network
79 * @param animation whether to (re)create animation or not
80 * @param cse the element to clone from
81 * @throws NetworkException if link already exists in the network, if name of the link is not unique, or if the start node
82 * or the end node of the link are not registered in the network.
83 */
84 protected Shoulder(final CrossSectionLink newParentLink, final SimulatorInterface.TimeDoubleUnit newSimulator, final boolean animation,
85 final Shoulder cse) throws NetworkException
86 {
87 super(newParentLink, newSimulator, animation, cse);
88
89 if (animation)
90 {
91 OTSNetwork.cloneAnimation(cse, this, cse.getParentLink().getSimulator(), newSimulator);
92 }
93 }
94
95 /** {@inheritDoc} */
96 @Override
97 protected final double getZ()
98 {
99 return -0.0002;
100 }
101
102 /** {@inheritDoc} */
103 @Override
104 @SuppressWarnings("checkstyle:designforextension")
105 public String toString()
106 {
107 return String.format("Shoulder offset %.2fm..%.2fm, width %.2fm..%.2fm", getDesignLineOffsetAtBegin().getSI(),
108 getDesignLineOffsetAtEnd().getSI(), getBeginWidth().getSI(), getEndWidth().getSI());
109 }
110
111 /** {@inheritDoc} */
112 @Override
113 @SuppressWarnings("checkstyle:designforextension")
114 public Shoulder clone(final CrossSectionLink newParentLink, final SimulatorInterface.TimeDoubleUnit newSimulator,
115 final boolean animation) throws NetworkException
116 {
117 return new Shoulder(newParentLink, newSimulator, animation, this);
118 }
119
120 }