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