From ece229983fdc73bc4feb7dde606be604b628df3f Mon Sep 17 00:00:00 2001 From: Adam Wulkiewicz Date: Sat, 6 Dec 2014 19:34:56 +0100 Subject: [PATCH] [algorithms] Add iterations counter to vincenty_inverse for robustness. --- .../geometry/algorithms/detail/vincenty_inverse.hpp | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/include/boost/geometry/algorithms/detail/vincenty_inverse.hpp b/include/boost/geometry/algorithms/detail/vincenty_inverse.hpp index d016d0695..6ff4baf0b 100644 --- a/include/boost/geometry/algorithms/detail/vincenty_inverse.hpp +++ b/include/boost/geometry/algorithms/detail/vincenty_inverse.hpp @@ -25,6 +25,11 @@ #include +#ifndef BOOST_GEOMETRY_DETAIL_VINCENTY_MAX_STEPS +#define BOOST_GEOMETRY_DETAIL_VINCENTY_MAX_STEPS 1000 +#endif + + namespace boost { namespace geometry { namespace detail { @@ -103,6 +108,8 @@ public: CT previous_lambda; + int counter = 0; // robustness + do { previous_lambda = lambda; // (13) @@ -119,8 +126,11 @@ public: lambda = L + (c1 - C) * flattening * sin_alpha * (sigma + C * sin_sigma * ( cos2_sigma_m + C * cos_sigma * (-c1 + c2 * math::sqr(cos2_sigma_m)))); // (11) + ++counter; // robustness + } while ( geometry::math::abs(previous_lambda - lambda) > c_e_12 - && geometry::math::abs(lambda) < pi ); + && geometry::math::abs(lambda) < pi + && counter < BOOST_GEOMETRY_DETAIL_VINCENTY_MAX_STEPS ); // robustness } inline CT distance() const