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
11 import nl.tudelft.simulation.dsol.animation.Locatable;
12 import nl.tudelft.simulation.language.Throw;
13 import nl.tudelft.simulation.language.d3.DirectedPoint;
14
15 /**
16 * Location along a waterway.
17 * <p>
18 * Copyright (c) 2013-2018 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 */
31 public class WaterwayLocation implements Locatable, Serializable
32 {
33 /** */
34 private static final long serialVersionUID = 20161106L;
35
36 /** the waterway. */
37 private final Waterway waterway;
38
39 /** position along the waterway, in the direction of the design line. */
40 private final Length position;
41
42 /** cached location. */
43 private final DirectedPoint location;
44
45 /**
46 * @param waterway the waterway
47 * @param position position along the waterway, in the direction of the design line
48 */
49 public WaterwayLocation(final Waterway waterway, final Length position)
50 {
51 Throw.whenNull(waterway, "waterway cannot be null");
52 Throw.whenNull(position, "position cannot be null");
53 this.waterway = waterway;
54 this.position = position;
55 this.location = waterway.getDesignLine().getLocationExtended(position);
56 }
57
58 /**
59 * @return waterway the waterway
60 */
61 public final Waterway getWaterway()
62 {
63 return this.waterway;
64 }
65
66 /**
67 * @return position position along the waterway, in the direction of the design line
68 */
69 public final Length getPosition()
70 {
71 return this.position;
72 }
73
74 /** {@inheritDoc} */
75 @Override
76 public final DirectedPoint getLocation()
77 {
78 return this.location;
79 }
80
81 /** {@inheritDoc} */
82 @Override
83 public final Bounds getBounds()
84 {
85 return new BoundingSphere();
86 }
87
88 /** {@inheritDoc} */
89 @Override
90 public final String toString()
91 {
92 return this.waterway + "(" + this.getPosition().getInUnit(LengthUnit.KILOMETER) + ")";
93 }
94
95 /**
96 * @return short route info
97 */
98 public final String toShortString()
99 {
100 return String.format("%1$s(%2$4.2f)", this.waterway.getId(), this.getPosition().getInUnit(LengthUnit.KILOMETER));
101 }
102 }