diff --git a/GeoLib/Polyline.cpp b/GeoLib/Polyline.cpp index b3a8af26b9ab02e2284df84ba1c2c99891f5e156..000d9bce51b6500ec39f4f2723067b5aa557d17e 100644 --- a/GeoLib/Polyline.cpp +++ b/GeoLib/Polyline.cpp @@ -193,6 +193,26 @@ bool Polyline::isClosed() const return false; } +bool Polyline::isCoplanar() const +{ + std::size_t const n_points (_ply_pnt_ids.size()); + if (n_points > 3) + { + GeoLib::Point const& p0 (*this->getPoint(0)); + GeoLib::Point const& p1 (*this->getPoint(1)); + GeoLib::Point const& p2 (*this->getPoint(2)); + for (std::size_t i=3; i<n_points; ++i) + { + if (!GeoLib::isCoplanar(p0, p1, p2, *this->getPoint(i))) + { + ERR ("Point %d is not coplanar to the first three points of the line.", i); + return false; + } + } + } + return true; +} + bool Polyline::isPointIDInPolyline(std::size_t pnt_id) const { return std::find(_ply_pnt_ids.begin(), _ply_pnt_ids.end(), pnt_id) != _ply_pnt_ids.end(); diff --git a/GeoLib/Polyline.h b/GeoLib/Polyline.h index 1f5e5bf8d52ec36eaa22d70fa5fece01429b693e..6a90c156bddea9dd8fa9945f15a999f977aa74ec 100644 --- a/GeoLib/Polyline.h +++ b/GeoLib/Polyline.h @@ -112,6 +112,9 @@ public: /** returns true if the polyline is closed */ bool isClosed() const; + /** returns true if the polyline is coplanar */ + bool isCoplanar() const; + /** * Method tests if the given id of a point (within the vector of points the polyline is * based on) is inside the polyline.