View Javadoc
1   package org.opentrafficsim.water.network;
2   
3   import java.io.Serializable;
4   
5   import javax.media.j3d.BoundingSphere;
6   import javax.media.j3d.Bounds;
7   
8   import org.djunits.unit.LengthUnit;
9   import org.djunits.value.vdouble.scalar.Length;
10  import org.djutils.exceptions.Throw;
11  
12  import nl.tudelft.simulation.dsol.animation.Locatable;
13  import nl.tudelft.simulation.language.d3.DirectedPoint;
14  
15  /**
16   * Location along a waterway.
17   * <p>
18   * Copyright (c) 2013-2019 Delft University of Technology, PO Box 5, 2600 AA, Delft, the Netherlands. All rights reserved. <br>
19   * BSD-style license. See <a href="http://opentrafficsim.org/docs/current/license.html">OpenTrafficSim License</a>.
20   * </p>
21   * <p>
22   * Based on software from the IDVV project, which is Copyright (c) 2013 Rijkswaterstaat - Dienst Water, Verkeer en Leefomgeving
23   * and licensed without restrictions to Delft University of Technology, including the right to sub-license sources and derived
24   * products to third parties.
25   * </p>
26   * $LastChangedDate: 2015-07-24 02:58:59 +0200 (Fri, 24 Jul 2015) $, @version $Revision: 1147 $, by $Author: averbraeck $,
27   * initial version Nov 6, 2016 <br>
28   * @author <a href="http://www.tbm.tudelft.nl/averbraeck">Alexander Verbraeck</a>
29   */
30  public class WaterwayLocation implements Locatable, Serializable
31  {
32      /** */
33      private static final long serialVersionUID = 20161106L;
34  
35      /** the waterway. */
36      private final Waterway waterway;
37  
38      /** position along the waterway, in the direction of the design line. */
39      private final Length position;
40  
41      /** cached location. */
42      private final DirectedPoint location;
43  
44      /**
45       * @param waterway Waterway; the waterway
46       * @param position Length; position along the waterway, in the direction of the design line
47       */
48      public WaterwayLocation(final Waterway waterway, final Length position)
49      {
50          Throw.whenNull(waterway, "waterway cannot be null");
51          Throw.whenNull(position, "position cannot be null");
52          this.waterway = waterway;
53          this.position = position;
54          this.location = waterway.getDesignLine().getLocationExtended(position);
55      }
56  
57      /**
58       * @return waterway the waterway
59       */
60      public final Waterway getWaterway()
61      {
62          return this.waterway;
63      }
64  
65      /**
66       * @return position position along the waterway, in the direction of the design line
67       */
68      public final Length getPosition()
69      {
70          return this.position;
71      }
72  
73      /** {@inheritDoc} */
74      @Override
75      public final DirectedPoint getLocation()
76      {
77          return this.location;
78      }
79  
80      /** {@inheritDoc} */
81      @Override
82      public final Bounds getBounds()
83      {
84          return new BoundingSphere();
85      }
86  
87      /** {@inheritDoc} */
88      @Override
89      public final String toString()
90      {
91          return this.waterway + "(" + this.getPosition().getInUnit(LengthUnit.KILOMETER) + ")";
92      }
93  
94      /**
95       * @return short route info
96       */
97      public final String toShortString()
98      {
99          return String.format("%1$s(%2$4.2f)", this.waterway.getId(), this.getPosition().getInUnit(LengthUnit.KILOMETER));
100     }
101 }