From 5510e2659ceac94352efb4de6cddc5bc9671f7ce Mon Sep 17 00:00:00 2001 From: Thomas Fischer <thomas.fischer@ufz.de> Date: Mon, 12 May 2014 10:55:19 +0200 Subject: [PATCH] [GeoLib::Polyline] Compute values only when needed. --- GeoLib/Polyline.cpp | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/GeoLib/Polyline.cpp b/GeoLib/Polyline.cpp index 0b7c369315f..651130652d7 100644 --- a/GeoLib/Polyline.cpp +++ b/GeoLib/Polyline.cpp @@ -383,17 +383,18 @@ double Polyline::getDistanceAlongPolyline(const GeoLib::Point& pnt, const double bool found = false; // loop over all line segments of the polyline for (size_t k = 0; k < this->getNumberOfPoints() - 1; k++) { - double act_length_of_ply(this->getLength(k)); - double seg_length (getLength(k+1)-getLength(k)); - double lower_lambda (- epsilon_radius / seg_length); - double upper_lambda (1 + epsilon_radius / seg_length); - // is the orthogonal projection of the j-th node to the // line g(lambda) = _ply->getPoint(k) + lambda * (_ply->getPoint(k+1) - _ply->getPoint(k)) // at the k-th line segment of the polyline, i.e. 0 <= lambda <= 1? if (MathLib::calcProjPntToLineAndDists(pnt.getCoords(), (this->getPoint(k))->getCoords(), (this->getPoint(k + 1))->getCoords(), lambda, dist) <= epsilon_radius) { + + double act_length_of_ply(this->getLength(k)); + double seg_length (getLength(k+1)-getLength(k)); + double lower_lambda (- epsilon_radius / seg_length); + double upper_lambda (1 + epsilon_radius / seg_length); + if (lower_lambda <= lambda && lambda <= upper_lambda) { found = true; dist = act_length_of_ply + dist; -- GitLab