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
15
16
17
18
19
20
21
22
23
24
25
26
27
28 public class WaterwayLocation implements Locatable, Serializable
29 {
30
31 private static final long serialVersionUID = 20161106L;
32
33
34 private final Waterway waterway;
35
36
37 private final Length position;
38
39
40 private final DirectedPoint location;
41
42
43
44
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
57
58 public final Waterway getWaterway()
59 {
60 return this.waterway;
61 }
62
63
64
65
66 public final Length getPosition()
67 {
68 return this.position;
69 }
70
71
72 @Override
73 public final DirectedPoint getLocation()
74 {
75 return this.location;
76 }
77
78
79 @Override
80 public final Bounds getBounds()
81 {
82 return new Bounds();
83 }
84
85
86 @Override
87 public final String toString()
88 {
89 return this.waterway + "(" + this.getPosition().getInUnit(LengthUnit.KILOMETER) + ")";
90 }
91
92
93
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 }