1 package org.opentrafficsim.base.geometry;
2
3 import org.djutils.draw.Drawable2d;
4 import org.djutils.draw.bounds.Bounds;
5 import org.djutils.draw.line.Polygon2d;
6 import org.djutils.draw.point.Point2d;
7
8
9
10
11
12
13
14
15
16
17 public interface OtsBounds2d extends Bounds<OtsBounds2d, Point2d, Drawable2d>
18 {
19
20
21 static Point2d CENTER = new Point2d(0.0, 0.0);
22
23
24 @Override
25 default double getMinX()
26 {
27 return asPolygon().getBounds().getMinX();
28 }
29
30
31 @Override
32 default double getMaxX()
33 {
34 return asPolygon().getBounds().getMaxX();
35 }
36
37
38 @Override
39 default double getMinY()
40 {
41 return asPolygon().getBounds().getMinY();
42 }
43
44
45 @Override
46 default double getMaxY()
47 {
48 return asPolygon().getBounds().getMaxY();
49 }
50
51
52 @Override
53 default Point2d midPoint()
54 {
55 return CENTER;
56 }
57
58
59 @Override
60 default boolean contains(final Point2d point) throws NullPointerException
61 {
62
63 return asPolygon().contains(point);
64 }
65
66
67 @Override
68 default boolean covers(final Point2d point) throws NullPointerException
69 {
70 boolean contians = contains(point);
71 if (contians)
72 {
73 return true;
74 }
75 return asPolygon().closestPointOnPolyLine(point).distance(point) == 0.0;
76 }
77
78
79 @Override
80 default boolean covers(final Drawable2d drawable) throws NullPointerException
81 {
82 return contains(drawable);
83 }
84
85
86 @Override
87 default boolean contains(final Drawable2d drawable) throws NullPointerException
88 {
89
90 return asPolygon().contains(drawable.getBounds());
91 }
92
93
94 @Override
95 default boolean disjoint(final Drawable2d drawable) throws NullPointerException
96 {
97 return !asPolygon().intersects(new Polygon2d(drawable.getPointList()));
98 }
99
100
101 @Override
102 default boolean intersects(final OtsBounds2d otherBounds)
103 {
104 throw new UnsupportedOperationException("Intersects between bounds is not supported.");
105 }
106
107
108 @Override
109 default OtsBounds2d intersection(final OtsBounds2d otherBounds)
110 {
111 throw new UnsupportedOperationException("Intersection between bounds is not supported.");
112 }
113
114
115
116
117
118 Polygon2d asPolygon();
119
120
121
122
123
124
125
126
127 default double signedDistance(final Point2d point)
128 {
129 double dist = asPolygon().closestPointOnPolyLine(point).distance(point);
130 return contains(point) ? -dist : dist;
131 }
132
133 }