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