@@ -130,6 +130,8 @@ TEST(alt_geometry, coveredBy)
130
130
using autoware::universe_utils::covered_by;
131
131
using autoware::universe_utils::alt::ConvexPolygon2d;
132
132
using autoware::universe_utils::alt::Point2d;
133
+ using autoware::universe_utils::alt::PointList2d;
134
+ using autoware::universe_utils::alt::Polygon2d;
133
135
134
136
{ // The point is within the polygon
135
137
const Point2d point = {0.0 , 0.0 };
@@ -163,6 +165,42 @@ TEST(alt_geometry, coveredBy)
163
165
164
166
EXPECT_TRUE (result);
165
167
}
168
+
169
+ { // The point is within the concave polygon
170
+ PointList2d outer;
171
+ outer.push_back ({1.0 , 1.0 });
172
+ outer.push_back ({1.0 , -1.0 });
173
+ outer.push_back ({0.0 , -0.5 });
174
+ outer.push_back ({-1.0 , -1.0 });
175
+ outer.push_back ({-1.0 , 1.0 });
176
+ outer.push_back ({0.0 , 0.5 });
177
+
178
+ const Point2d point = {0.0 , 0.0 };
179
+
180
+ const auto result = covered_by (point, Polygon2d::create (outer, {}).value ());
181
+
182
+ EXPECT_TRUE (result);
183
+ }
184
+
185
+ { // The point is on the edge of the hole of the polygon
186
+ PointList2d outer;
187
+ outer.push_back ({0.0 , 0.0 });
188
+ outer.push_back ({0.0 , 2.0 });
189
+ outer.push_back ({2.0 , 2.0 });
190
+ outer.push_back ({2.0 , 0.0 });
191
+
192
+ PointList2d inner;
193
+ inner.push_back ({0.5 , 0.5 });
194
+ inner.push_back ({0.5 , 1.5 });
195
+ inner.push_back ({1.5 , 1.5 });
196
+ inner.push_back ({1.5 , 0.5 });
197
+
198
+ const Point2d point = {0.5 , 1.0 };
199
+
200
+ const auto result = covered_by (point, Polygon2d::create (outer, {inner}).value ());
201
+
202
+ EXPECT_TRUE (result);
203
+ }
166
204
}
167
205
168
206
TEST (alt_geometry, disjoint)
@@ -679,6 +717,8 @@ TEST(alt_geometry, within)
679
717
using autoware::universe_utils::within;
680
718
using autoware::universe_utils::alt::ConvexPolygon2d;
681
719
using autoware::universe_utils::alt::Point2d;
720
+ using autoware::universe_utils::alt::PointList2d;
721
+ using autoware::universe_utils::alt::Polygon2d;
682
722
683
723
{ // The point is within the polygon
684
724
const Point2d point = {0.0 , 0.0 };
@@ -713,6 +753,42 @@ TEST(alt_geometry, within)
713
753
EXPECT_FALSE (result);
714
754
}
715
755
756
+ { // The point is within the concave polygon
757
+ PointList2d outer;
758
+ outer.push_back ({1.0 , 1.0 });
759
+ outer.push_back ({1.0 , -1.0 });
760
+ outer.push_back ({0.0 , -0.5 });
761
+ outer.push_back ({-1.0 , -1.0 });
762
+ outer.push_back ({-1.0 , 1.0 });
763
+ outer.push_back ({0.0 , 0.5 });
764
+
765
+ const Point2d point = {0.0 , 0.0 };
766
+
767
+ const auto result = within (point, Polygon2d::create (outer, {}).value ());
768
+
769
+ EXPECT_TRUE (result);
770
+ }
771
+
772
+ { // The point is on the edge of the hole of the polygon
773
+ PointList2d outer;
774
+ outer.push_back ({0.0 , 0.0 });
775
+ outer.push_back ({0.0 , 2.0 });
776
+ outer.push_back ({2.0 , 2.0 });
777
+ outer.push_back ({2.0 , 0.0 });
778
+
779
+ PointList2d inner;
780
+ inner.push_back ({0.5 , 0.5 });
781
+ inner.push_back ({0.5 , 1.5 });
782
+ inner.push_back ({1.5 , 1.5 });
783
+ inner.push_back ({1.5 , 0.5 });
784
+
785
+ const Point2d point = {0.5 , 1.0 };
786
+
787
+ const auto result = within (point, Polygon2d::create (outer, {inner}).value ());
788
+
789
+ EXPECT_FALSE (result);
790
+ }
791
+
716
792
{ // One polygon is within the other
717
793
const Point2d p1 = {1.0 , 1.0 };
718
794
const Point2d p2 = {1.0 , -1.0 };
0 commit comments