From d0331aa3ebed1a28a075e00312bec9c14bfcc78b Mon Sep 17 00:00:00 2001 From: Vissarion Fysikopoulos Date: Mon, 18 Feb 2019 14:43:53 +0200 Subject: [PATCH] [algorithm] [test] Assertion for possible division with zero in line_interpolate --- include/boost/geometry/algorithms/line_interpolate_point.hpp | 3 ++- test/algorithms/line_interpolate_point.cpp | 5 +++++ 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/include/boost/geometry/algorithms/line_interpolate_point.hpp b/include/boost/geometry/algorithms/line_interpolate_point.hpp index 615f1d409..eb98aa160 100644 --- a/include/boost/geometry/algorithms/line_interpolate_point.hpp +++ b/include/boost/geometry/algorithms/line_interpolate_point.hpp @@ -108,10 +108,11 @@ struct range Distance dist = strategy.get_distance_pp_strategy().apply(*prev, *it); current_distance = prev_distance + dist; - while (current_distance >= repeated_distance ) + while (current_distance >= repeated_distance) { point_t p; Distance diff_distance = current_distance - prev_distance; + BOOST_ASSERT(diff_distance != Distance(0)); strategy.apply(start_p, *it, (repeated_distance - prev_distance)/diff_distance, p, diff --git a/test/algorithms/line_interpolate_point.cpp b/test/algorithms/line_interpolate_point.cpp index f35350c38..da595ce85 100644 --- a/test/algorithms/line_interpolate_point.cpp +++ b/test/algorithms/line_interpolate_point.cpp @@ -137,6 +137,7 @@ std::string const l1 = "LINESTRING(1 1, 2 1, 2 2, 1 2, 1 3)"; std::string const l2 = "LINESTRING(0 2, 5 2, 5 1, 20 1)"; std::string const l00 = "LINESTRING()"; std::string const l01 = "LINESTRING(1 1)"; +std::string const l02 = "LINESTRING(1 1, 1 1)"; void test_car_edge_cases() { @@ -156,6 +157,10 @@ void test_car_edge_cases() test_distance(l01, 1, "POINT(1 1)"); test_distance(l01, 1, "MULTIPOINT((1 1))"); + //linestring with two same points + test_distance(l02, 1, "POINT(1 1)"); + test_distance(l02, 1, "MULTIPOINT((1 1))"); + //empty linestring try {