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