View Javadoc
1   package org.opentrafficsim.core.network;
2   
3   import org.djunits.unit.LengthUnit;
4   import org.djunits.value.vdouble.scalar.Length;
5   import org.opentrafficsim.core.gtu.GTUDirectionality;
6   
7   /**
8    * Directed link position.
9    * <p>
10   * Copyright (c) 2013-2019 Delft University of Technology, PO Box 5, 2600 AA, Delft, the Netherlands. All rights reserved. <br>
11   * BSD-style license. See <a href="http://opentrafficsim.org/node/13">OpenTrafficSim License</a>.
12   * <p>
13   * @version $Revision$, $LastChangedDate$, by $Author$, initial version 22 okt. 2018 <br>
14   * @author <a href="http://www.tbm.tudelft.nl/averbraeck">Alexander Verbraeck</a>
15   * @author <a href="http://www.tudelft.nl/pknoppers">Peter Knoppers</a>
16   * @author <a href="http://www.transport.citg.tudelft.nl">Wouter Schakel</a>
17   */
18  public class DirectedLinkPosition extends LinkDirection
19  {
20  
21      /** */
22      private static final long serialVersionUID = 20181022L;
23  
24      /** The fractional position (between 0.0 and 1.0) of the reference point on the lane. */
25      private final double fractionalLongitudinalPosition;
26  
27      /**
28       * @param link Link; the link
29       * @param fractionalLongitudinalPosition double; fractional position
30       * @param direction GTUDirectionality; the direction on the link, with or against the design line
31       */
32      public DirectedLinkPosition(final Link link, final double fractionalLongitudinalPosition, final GTUDirectionality direction)
33      {
34          super(link, direction);
35          this.fractionalLongitudinalPosition = fractionalLongitudinalPosition;
36      }
37  
38      /**
39       * @param link Link; the link
40       * @param position Length; position
41       * @param direction GTUDirectionality; the direction on the link, with or against the design line
42       */
43      public DirectedLinkPosition(final Link link, final Length position, final GTUDirectionality direction)
44      {
45          this(link, position.si / link.getLength().si, direction);
46      }
47  
48      /**
49       * @return fractionalLongitudinalPosition.
50       */
51      public final double getFractionalLongitudinalPosition()
52      {
53          return this.fractionalLongitudinalPosition;
54      }
55  
56      /**
57       * @return position as a length as a traveled length on this link.
58       */
59      public final Length getLongitudinalPosition()
60      {
61          return new Length(getLink().getLength().getSI() * getFractionalLongitudinalPosition(), LengthUnit.METER);
62      }
63  
64      /** {@inheritDoc} */
65      @Override
66      public String toString()
67      {
68          return "DirectedLinkPosition [link=" + getLink() + ", direction=" + getDirection() + ", fractionalLongitudinalPosition="
69                  + this.fractionalLongitudinalPosition + "]";
70      }
71  
72  }