diff --git a/GeoLib/Polyline.cpp b/GeoLib/Polyline.cpp index a24f3263d05f49fb3346c2043d550229814ef94f..ebfb4d2a8abc4c24d161c79ecef0e2d251e40966 100644 --- a/GeoLib/Polyline.cpp +++ b/GeoLib/Polyline.cpp @@ -172,7 +172,7 @@ size_t Polyline::getNumberOfPoints() const bool Polyline::isClosed() const { - if (_ply_pnt_ids.empty()) + if (_ply_pnt_ids.size() < 3) return false; if (_ply_pnt_ids.front() == _ply_pnt_ids.back()) diff --git a/Tests/GeoLib/TestPolyline.cpp b/Tests/GeoLib/TestPolyline.cpp new file mode 100644 index 0000000000000000000000000000000000000000..39990e80b5e6eb96a188b290648801861b012298 --- /dev/null +++ b/Tests/GeoLib/TestPolyline.cpp @@ -0,0 +1,53 @@ +/** + * @file TestPolyline.cpp + * @author Thomas Fischer + * @date Jan 7, 2013 + * + * @copyright + * Copyright (c) 2012, OpenGeoSys Community (http://www.opengeosys.org) + * Distributed under a Modified BSD License. + * See accompanying file LICENSE.txt or + * http://www.opengeosys.org/LICENSE.txt + */ + +#include <ctime> +#include "gtest/gtest.h" + +#include "Polyline.h" + +using namespace GeoLib; + +TEST(GeoLib, PolylineConstructorTest) +{ + std::vector<Point*> ply_pnts; + Polyline ply(ply_pnts); + + // checking properties of empty polyline + ASSERT_EQ(ply.getNumberOfPoints(), 0); + ASSERT_FALSE(ply.isClosed()); + ASSERT_FALSE(ply.isPointIDInPolyline(0)); + ASSERT_EQ(ply.getLength(0), 0.0); + + ply_pnts.push_back(new Point(0.0, 0.0, 0.0)); + ply.addPoint(0); + // checking properties of polyline with one point + ASSERT_EQ(ply.getNumberOfPoints(), 1); + ASSERT_FALSE(ply.isClosed()); + ASSERT_TRUE(ply.isPointIDInPolyline(0)); + ASSERT_EQ(ply.getLength(0), 0.0); + + ply_pnts.push_back(new Point(1.0, 0.0, 0.0)); + ply.addPoint(1); + // checking properties of polyline with two points + ASSERT_EQ(ply.getNumberOfPoints(), 2); + ASSERT_FALSE(ply.isClosed()); + ASSERT_TRUE(ply.isPointIDInPolyline(1)); + ASSERT_EQ(ply.getLength(1), 1); + + ply_pnts.push_back(new Point(0.5, 0.5, 0.0)); + ply.addPoint(2); + ASSERT_EQ(ply.getNumberOfPoints(), 3); + ASSERT_FALSE(ply.isClosed()); + ASSERT_TRUE(ply.isPointIDInPolyline(2)); + ASSERT_TRUE(fabs(ply.getLength(2) - (1.0 + sqrt(0.5))) < std::numeric_limits<double>::min()); +}