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