View Javadoc
1   package org.opentrafficsim.water.network;
2   
3   import java.io.Serializable;
4   import java.rmi.RemoteException;
5   
6   import javax.media.j3d.BoundingSphere;
7   import javax.media.j3d.Bounds;
8   
9   import org.djunits.value.vdouble.scalar.Length;
10  import org.opentrafficsim.core.geometry.OTSGeometryException;
11  
12  import nl.tudelft.simulation.dsol.animation.Locatable;
13  import nl.tudelft.simulation.language.Throw;
14  import nl.tudelft.simulation.language.d3.DirectedPoint;
15  
16  /**
17   * <p>
18   * Copyright (c) 2013-2016 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   * $LastChangedDate: 2015-07-24 02:58:59 +0200 (Fri, 24 Jul 2015) $, @version $Revision: 1147 $, by $Author: averbraeck $,
22   * initial version Nov 6, 2016 <br>
23   * @author <a href="http://www.tbm.tudelft.nl/averbraeck">Alexander Verbraeck</a>
24   */
25  public class WaterwayLocation implements Locatable, Serializable
26  {
27      /** */
28      private static final long serialVersionUID = 20161106L;
29  
30      /** the waterway. */
31      private final Waterway waterway;
32  
33      /** position along the waterway, in the direction of the design line. */
34      private final Length position;
35  
36      /** cached location. */
37      private final DirectedPoint location;
38  
39      /**
40       * @param waterway the waterway
41       * @param position position along the waterway, in the direction of the design line
42       * @throws OTSGeometryException in case the position is less than zero, or more than the length of the waterway.
43       */
44      public WaterwayLocation(final Waterway waterway, final Length position) throws OTSGeometryException
45      {
46          Throw.whenNull(waterway, "waterway cannot be null");
47          Throw.whenNull(position, "position cannot be null");
48          this.waterway = waterway;
49          this.position = position;
50          this.location = waterway.getDesignLine().getLocation(position);
51      }
52  
53      /**
54       * @return waterway the waterway
55       */
56      public final Waterway getWaterway()
57      {
58          return this.waterway;
59      }
60  
61      /**
62       * @return position position along the waterway, in the direction of the design line
63       */
64      public final Length getPosition()
65      {
66          return this.position;
67      }
68  
69      /** {@inheritDoc} */
70      @Override
71      public final DirectedPoint getLocation() throws RemoteException
72      {
73          return this.location;
74      }
75  
76      /** {@inheritDoc} */
77      @Override
78      public final Bounds getBounds() throws RemoteException
79      {
80          return new BoundingSphere();
81      }
82  
83  }