diff --git a/Tests/GeoLib/TestPolygon.cpp b/Tests/GeoLib/TestPolygon.cpp index 087348f024c522943b28f41cf3ea3cb2b6709800..eeaa7b8155c8854a2c57924b481e705f3c870b2f 100644 --- a/Tests/GeoLib/TestPolygon.cpp +++ b/Tests/GeoLib/TestPolygon.cpp @@ -129,6 +129,76 @@ TEST_F(PolygonTest, isPntInPolygonCheckOuterPoints) * 0 * 0 = (0,0), 1=(-2,2), 2=(-2,4), 3=(-1,2), 4=(0,4), 5=(1,2), 6=(2,4), 7=(2,2) */ +TEST_F(PolygonTest, containsSegment) +{ + // test segment (2,6) + GeoLib::Point &a(*(const_cast<GeoLib::Point*>(_polygon->getPoint(2)))); + GeoLib::Point &b(*(const_cast<GeoLib::Point*>(_polygon->getPoint(6)))); + ASSERT_FALSE(_polygon->containsSegment(a, b)); + + // test segments of polygon + for (std::size_t k(0); k<_polygon->getNumberOfPoints()-1;k++) { + a = *(const_cast<GeoLib::Point*>(_polygon->getPoint(k))); + b = *(const_cast<GeoLib::Point*>(_polygon->getPoint(k+1))); + EXPECT_TRUE(_polygon->containsSegment(a, b)); + } + + // 01 + a = *(const_cast<GeoLib::Point*>(_polygon->getPoint(0))); + b = *(const_cast<GeoLib::Point*>(_polygon->getPoint(1))); + ASSERT_TRUE(_polygon->containsSegment(a, b)); + + // 12 + a = *(const_cast<GeoLib::Point*>(_polygon->getPoint(1))); + b = *(const_cast<GeoLib::Point*>(_polygon->getPoint(2))); + ASSERT_TRUE(_polygon->containsSegment(a, b)); + + // 23 + a = *(const_cast<GeoLib::Point*>(_polygon->getPoint(2))); + b = *(const_cast<GeoLib::Point*>(_polygon->getPoint(3))); + ASSERT_TRUE(_polygon->containsSegment(a, b)); + + // 34 + a = *(const_cast<GeoLib::Point*>(_polygon->getPoint(3))); + b = *(const_cast<GeoLib::Point*>(_polygon->getPoint(4))); + ASSERT_TRUE(_polygon->containsSegment(a, b)); + + // 45 + a = *(const_cast<GeoLib::Point*>(_polygon->getPoint(4))); + b = *(const_cast<GeoLib::Point*>(_polygon->getPoint(5))); + ASSERT_TRUE(_polygon->containsSegment(a, b)); + + // 56 + a = *(const_cast<GeoLib::Point*>(_polygon->getPoint(5))); + b = *(const_cast<GeoLib::Point*>(_polygon->getPoint(6))); + ASSERT_TRUE(_polygon->containsSegment(a, b)); + + // 67 + a = *(const_cast<GeoLib::Point*>(_polygon->getPoint(6))); + b = *(const_cast<GeoLib::Point*>(_polygon->getPoint(7))); + ASSERT_TRUE(_polygon->containsSegment(a, b)); + + // 70 + a = *(const_cast<GeoLib::Point*>(_polygon->getPoint(7))); + b = *(const_cast<GeoLib::Point*>(_polygon->getPoint(0))); + ASSERT_TRUE(_polygon->containsSegment(a, b)); + + // test segment (3,5) + a = *(const_cast<GeoLib::Point*>(_polygon->getPoint(3))); + b = *(const_cast<GeoLib::Point*>(_polygon->getPoint(5))); + ASSERT_TRUE(_polygon->containsSegment(a, b)); + + // test segment (1,7) + a = *(const_cast<GeoLib::Point*>(_polygon->getPoint(1))); + b = *(const_cast<GeoLib::Point*>(_polygon->getPoint(7))); + ASSERT_TRUE(_polygon->containsSegment(a, b)); + + // test segment (1,4) + a = *(const_cast<GeoLib::Point*>(_polygon->getPoint(1))); + b = *(const_cast<GeoLib::Point*>(_polygon->getPoint(4))); + ASSERT_FALSE(_polygon->containsSegment(a, b)); + +} TEST_F(PolygonTest, isPolylineInPolygon) {