Skip to content

Commit b48acc3

Browse files
committed
add test cases for covered_by(), within()
Signed-off-by: mitukou1109 <mitukou1109@gmail.com>
1 parent 8f7811e commit b48acc3

File tree

1 file changed

+76
-0
lines changed

1 file changed

+76
-0
lines changed

common/autoware_universe_utils/test/src/geometry/test_alt_geometry.cpp

+76
Original file line numberDiff line numberDiff line change
@@ -130,6 +130,8 @@ TEST(alt_geometry, coveredBy)
130130
using autoware::universe_utils::covered_by;
131131
using autoware::universe_utils::alt::ConvexPolygon2d;
132132
using autoware::universe_utils::alt::Point2d;
133+
using autoware::universe_utils::alt::PointList2d;
134+
using autoware::universe_utils::alt::Polygon2d;
133135

134136
{ // The point is within the polygon
135137
const Point2d point = {0.0, 0.0};
@@ -163,6 +165,42 @@ TEST(alt_geometry, coveredBy)
163165

164166
EXPECT_TRUE(result);
165167
}
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+
}
166204
}
167205

168206
TEST(alt_geometry, disjoint)
@@ -679,6 +717,8 @@ TEST(alt_geometry, within)
679717
using autoware::universe_utils::within;
680718
using autoware::universe_utils::alt::ConvexPolygon2d;
681719
using autoware::universe_utils::alt::Point2d;
720+
using autoware::universe_utils::alt::PointList2d;
721+
using autoware::universe_utils::alt::Polygon2d;
682722

683723
{ // The point is within the polygon
684724
const Point2d point = {0.0, 0.0};
@@ -713,6 +753,42 @@ TEST(alt_geometry, within)
713753
EXPECT_FALSE(result);
714754
}
715755

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+
716792
{ // One polygon is within the other
717793
const Point2d p1 = {1.0, 1.0};
718794
const Point2d p2 = {1.0, -1.0};

0 commit comments

Comments
 (0)