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.DirectedPoint2d;
7 import org.djutils.event.LocalEventProducer;
8 import org.djutils.exceptions.Throw;
9 import org.opentrafficsim.base.geometry.OtsShape;
10 import org.opentrafficsim.core.network.NetworkException;
11
12
13
14
15
16
17
18
19
20
21
22 public class StaticObject extends LocalEventProducer implements LocatedObject
23 {
24
25 private final String id;
26
27
28 private final Polygon2d relativeContour;
29
30
31 private final Polygon2d absoluteContour;
32
33
34 private final DirectedPoint2d location;
35
36
37 private final Length height;
38
39
40
41
42
43
44
45
46 protected StaticObject(final String id, final DirectedPoint2d location, final Polygon2d absoluteContour,
47 final Length height)
48 {
49 Throw.whenNull(id, "id");
50 Throw.whenNull(location, "location");
51 Throw.whenNull(absoluteContour, "absoluteContour");
52 Throw.whenNull(height, "height");
53
54 this.id = id;
55 this.location = location;
56 this.relativeContour = new Polygon2d(OtsShape.toRelativeTransform(location).transform(absoluteContour.iterator()));
57 this.absoluteContour = absoluteContour;
58 this.height = height;
59 }
60
61
62
63
64
65 @SuppressWarnings("checkstyle:designforextension")
66 protected void init() throws NetworkException
67 {
68
69
70
71
72 }
73
74
75
76
77
78
79
80
81
82 public static StaticObject create(final String id, final Polygon2d geometry, final Length height) throws NetworkException
83 {
84 DirectedPoint2d point = new DirectedPoint2d(geometry.getAbsoluteBounds().midPoint(), 0.0);
85 StaticObject staticObject = new StaticObject(id, point, geometry, height);
86 staticObject.init();
87 return staticObject;
88 }
89
90
91
92
93
94
95
96
97 public static StaticObject create(final String id, final Polygon2d geometry) throws NetworkException
98 {
99 return create(id, geometry, Length.ZERO);
100 }
101
102 @Override
103 public Polygon2d getAbsoluteContour()
104 {
105 return this.absoluteContour;
106 }
107
108 @Override
109 public Polygon2d getRelativeContour()
110 {
111 return this.relativeContour;
112 }
113
114 @Override
115 public final Length getHeight()
116 {
117 return this.height;
118 }
119
120 @Override
121 public final String getId()
122 {
123 return this.id;
124 }
125
126 @Override
127 @SuppressWarnings("checkstyle:designforextension")
128 public String getFullId()
129 {
130 return this.id;
131 }
132
133 @Override
134 @SuppressWarnings("checkstyle:designforextension")
135 public DirectedPoint2d getLocation()
136 {
137 return this.location;
138 }
139
140 @Override
141 @SuppressWarnings("checkstyle:designforextension")
142 public Bounds2d getRelativeBounds()
143 {
144 return this.relativeContour.getAbsoluteBounds();
145 }
146
147 @Override
148 @SuppressWarnings("checkstyle:designforextension")
149 public String toString()
150 {
151 return "StaticObject [contour=" + getAbsoluteContour() + ", height=" + this.height + "]";
152 }
153
154 }