1 package org.opentrafficsim.core.object;
2
3 import org.djunits.value.vdouble.scalar.Length;
4 import org.djutils.draw.line.PolyLine2d;
5 import org.djutils.draw.line.Polygon2d;
6 import org.djutils.draw.point.OrientedPoint2d;
7 import org.djutils.event.LocalEventProducer;
8 import org.djutils.exceptions.Throw;
9 import org.opentrafficsim.base.geometry.BoundingPolygon;
10 import org.opentrafficsim.base.geometry.OtsBounds2d;
11 import org.opentrafficsim.core.animation.Drawable;
12 import org.opentrafficsim.core.network.NetworkException;
13
14
15
16
17
18
19
20
21
22
23
24 public class StaticObject extends LocalEventProducer implements LocatedObject, Drawable
25 {
26
27 private static final long serialVersionUID = 20160400L;
28
29
30 private final String id;
31
32
33 private final PolyLine2d geometry;
34
35
36 private final OrientedPoint2d location;
37
38
39 private final OtsBounds2d bounds;
40
41
42 private final Length height;
43
44
45
46
47
48
49
50 protected StaticObject(final String id, final OrientedPoint2d location, final PolyLine2d geometry, final Length height)
51 {
52 Throw.whenNull(id, "object id cannot be null");
53 Throw.whenNull(geometry, "geometry cannot be null");
54 Throw.whenNull(height, "height cannot be null");
55
56 this.id = id;
57 this.geometry = geometry;
58 this.location = location;
59
60 this.bounds = BoundingPolygon.geometryToBounds(location, geometry);
61 this.height = height;
62 }
63
64
65
66
67
68 @SuppressWarnings("checkstyle:designforextension")
69 protected void init() throws NetworkException
70 {
71
72
73
74
75 }
76
77
78
79
80
81
82
83
84
85 public static StaticObject create(final String id, final Polygon2d geometry, final Length height) throws NetworkException
86 {
87 OrientedPoint2d point = new OrientedPoint2d(geometry.getBounds().midPoint(), 0.0);
88 StaticObject staticObject = new StaticObject(id, point, geometry, height);
89 staticObject.init();
90 return staticObject;
91 }
92
93
94
95
96
97
98
99
100 public static StaticObject create(final String id, final Polygon2d geometry) throws NetworkException
101 {
102 return create(id, geometry, Length.ZERO);
103 }
104
105
106 @Override
107 public PolyLine2d getGeometry()
108 {
109 return this.geometry;
110 }
111
112
113 @Override
114 public final Length getHeight()
115 {
116 return this.height;
117 }
118
119
120 @Override
121 public final String getId()
122 {
123 return this.id;
124 }
125
126
127 @Override
128 @SuppressWarnings("checkstyle:designforextension")
129 public String getFullId()
130 {
131 return this.id;
132 }
133
134
135 @Override
136 @SuppressWarnings("checkstyle:designforextension")
137 public OrientedPoint2d getLocation()
138 {
139 return this.location;
140 }
141
142
143 @Override
144 @SuppressWarnings("checkstyle:designforextension")
145 public OtsBounds2d getBounds()
146 {
147 return this.bounds;
148 }
149
150
151 @Override
152 @SuppressWarnings("checkstyle:designforextension")
153 public String toString()
154 {
155 return "StaticObject [geometry=" + getGeometry() + ", height=" + this.height + "]";
156 }
157
158 }