From f740da412b0a713719fcf7a1606970f6a1df529d Mon Sep 17 00:00:00 2001 From: rahv <karsten.rink@ufz.de> Date: Tue, 3 Feb 2015 09:39:51 +0100 Subject: [PATCH] added method to check if polyline is coplanar --- GeoLib/Polyline.cpp | 20 ++++++++++++++++++++ GeoLib/Polyline.h | 3 +++ 2 files changed, 23 insertions(+) diff --git a/GeoLib/Polyline.cpp b/GeoLib/Polyline.cpp index b3a8af26b9a..000d9bce51b 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 1f5e5bf8d52..6a90c156bdd 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. -- GitLab