LinkPosition.java

  1. package org.opentrafficsim.core.network;

  2. import java.io.Serializable;

  3. import org.djunits.unit.LengthUnit;
  4. import org.djunits.value.vdouble.scalar.Length;

  5. /**
  6.  * Class that stores a link combined with a position on that link.
  7.  * <p>
  8.  * Copyright (c) 2013-2024 Delft University of Technology, PO Box 5, 2600 AA, Delft, the Netherlands. All rights reserved. <br>
  9.  * BSD-style license. See <a href="https://opentrafficsim.org/docs/license.html">OpenTrafficSim License</a>.
  10.  * </p>
  11.  * @author <a href="https://github.com/averbraeck">Alexander Verbraeck</a>
  12.  * @author <a href="https://github.com/peter-knoppers">Peter Knoppers</a>
  13.  * @author <a href="https://github.com/wjschakel">Wouter Schakel</a>
  14.  * @param link the link
  15.  * @param fractionalLongitudinalPosition fractional position
  16.  */
  17. public record LinkPosition(Link link, double fractionalLongitudinalPosition) implements Serializable
  18. {
  19.     /** */
  20.     private static final long serialVersionUID = 20181022L;

  21.     /**
  22.      * Create a link combined with a position on that link.
  23.      * @param link the link
  24.      * @param position position
  25.      */
  26.     public LinkPosition(final Link link, final Length position)
  27.     {
  28.         this(link, position.si / link.getLength().si);
  29.     }

  30.     /**
  31.      * Return the length of the link.
  32.      * @return the length of the link
  33.      */
  34.     public Length getLinkLength()
  35.     {
  36.         return this.link.getLength();
  37.     }

  38.     /**
  39.      * Return the position on the link as a Length.
  40.      * @return position as a length on this link.
  41.      */
  42.     public final Length getLongitudinalPosition()
  43.     {
  44.         return new Length(this.link.getLength().getSI() * fractionalLongitudinalPosition(), LengthUnit.METER);
  45.     }
  46. }