diff --git a/test/algorithms/buffer/multi_point_buffer.cpp b/test/algorithms/buffer/multi_point_buffer.cpp index d18f57ff6..2c917d834 100644 --- a/test/algorithms/buffer/multi_point_buffer.cpp +++ b/test/algorithms/buffer/multi_point_buffer.cpp @@ -69,141 +69,6 @@ void test_all() distance_strategy(0.54), side_strategy, point_strategy, 99); #endif } - - -} - -template -< - typename GeometryOut, - template class JoinStrategy, - template class EndStrategy, - typename Geometry -> -double test_growth(Geometry const& geometry, int n, int d, double distance) -{ - namespace bg = boost::geometry; - - typedef typename bg::coordinate_type::type coordinate_type; - typedef typename bg::point_type::type point_type; - - // extern int point_buffer_count; - std::ostringstream complete; - complete - << "point" << "_" - << "growth" << "_" - << string_from_type::name() - << "_" << "r" - << "_" << n - << "_" << d - // << "_" << point_buffer_count - ; - - //std::cout << complete.str() << std::endl; - - std::ostringstream filename; - filename << "buffer_" << complete.str() << ".svg"; - - std::ofstream svg(filename.str().c_str()); - -#ifdef BOOST_GEOMETRY_DEBUG_WITH_MAPPER - bg::svg_mapper mapper(svg, 500, 500); - - { - bg::model::box box; - bg::envelope(geometry, box); - - bg::buffer(box, box, distance * 1.01); - mapper.add(box); - } -#endif - - JoinStrategy - < - point_type, - typename bg::point_type::type - > join_strategy; - EndStrategy - < - point_type, - typename bg::point_type::type - > end_strategy; - - typedef bg::strategy::buffer::distance_symmetric distance_strategy_type; - distance_strategy_type distance_strategy(distance); - - std::vector buffered; - - typedef typename bg::rescale_policy_type::type - rescale_policy_type; - rescale_policy_type rescale_policy - = bg::get_rescale_policy(geometry); - - bg::detail::buffer::buffer_inserter(geometry, - std::back_inserter(buffered), - distance_strategy, - join_strategy, - end_strategy, - rescale_policy -#ifdef BOOST_GEOMETRY_DEBUG_WITH_MAPPER - , mapper -#endif - ); - - typename bg::default_area_result::type area = 0; - BOOST_FOREACH(GeometryOut const& polygon, buffered) - { - area += bg::area(polygon); - } - -#ifdef BOOST_GEOMETRY_DEBUG_WITH_MAPPER - // Map input geometry in green - mapper.map(geometry, "opacity:0.5;fill:rgb(0,128,0);stroke:rgb(0,128,0);stroke-width:10"); - - BOOST_FOREACH(GeometryOut const& polygon, buffered) - { - mapper.map(polygon, "opacity:0.4;fill:rgb(255,255,128);stroke:rgb(0,0,0);stroke-width:3"); - } -#endif - - return area; -} - -template -void test_growth(int n, int distance_count) -{ - srand(int(time(NULL))); - //std::cout << typeid(bg::coordinate_type

::type).name() << std::endl; - boost::timer t; - - namespace buf = bg::strategy::buffer; - typedef bg::model::polygon

polygon; - typedef bg::model::multi_point

multi_point_type; - - multi_point_type multi_point; - for (int i = 0; i < n; i++) - { - P point(rand() % 100, rand() % 100); - multi_point.push_back(point); - } - - //std::cout << bg::wkt(multi_point) << std::endl; - - double previous_area = 0; - double epsilon = 0.1; - double distance = 15.0; - for (int d = 0; d < distance_count; d++, distance += epsilon) - { - double area = test_growth(multi_point, n, d, distance); - if (area < previous_area) - { - std::cout << "Error: " << area << " < " << previous_area << std::endl - << " n=" << n << " distance=" << distance - << bg::wkt(multi_point) << std::endl; - } - previous_area = area; - } - std::cout << "n=" << n << " time=" << t.elapsed() << std::endl; } int test_main(int, char* []) @@ -211,13 +76,5 @@ int test_main(int, char* []) test_all >(); test_all >(); - -#ifdef BOOST_GEOMETRY_BUFFER_TEST_GROWTH - for (int i = 5; i <= 50; i++) - { - test_growth >(i, 20); - } -#endif - return 0; } diff --git a/test/robustness/overlay/buffer/multi_point_growth.cpp b/test/robustness/overlay/buffer/multi_point_growth.cpp new file mode 100644 index 000000000..d74a6c5f6 --- /dev/null +++ b/test/robustness/overlay/buffer/multi_point_growth.cpp @@ -0,0 +1,139 @@ +// Boost.Geometry (aka GGL, Generic Geometry Library) +// Performance Test + +// Copyright (c) 2012-2015 Barend Gehrels, Amsterdam, the Netherlands. + +// Use, modification and distribution is subject to the Boost Software License, +// Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at +// http://www.boost.org/LICENSE_1_0.txt) + +#include +#include + +#include +#include +#include + + +namespace bg = boost::geometry; + +template +< + typename GeometryOut, + typename Geometry +> +double test_growth(Geometry const& geometry, int n, int d, double distance) +{ + + typedef typename bg::coordinate_type::type coordinate_type; + typedef typename bg::point_type::type point_type; + + // extern int point_buffer_count; + std::ostringstream complete; + complete + << "point_growth" + << "_" << "r" + << "_" << n + << "_" << d + // << "_" << point_buffer_count + ; + + //std::cout << complete.str() << std::endl; + + std::ostringstream filename; + filename << "buffer_" << complete.str() << ".svg"; + + std::ofstream svg(filename.str().c_str()); + +#ifdef BOOST_GEOMETRY_DEBUG_WITH_MAPPER + bg::svg_mapper mapper(svg, 500, 500); + + { + bg::model::box box; + bg::envelope(geometry, box); + + bg::buffer(box, box, distance * 1.01); + mapper.add(box); + } +#endif + + bg::strategy::buffer::join_round join_strategy(100); + bg::strategy::buffer::end_flat end_strategy; + bg::strategy::buffer::point_circle point_strategy; + bg::strategy::buffer::side_straight side_strategy; + + typedef bg::strategy::buffer::distance_symmetric distance_strategy_type; + distance_strategy_type distance_strategy(distance); + + std::vector buffered; + + bg::buffer(geometry, buffered, + distance_strategy, side_strategy, + join_strategy, end_strategy, point_strategy); + + + typename bg::default_area_result::type area = 0; + BOOST_FOREACH(GeometryOut const& polygon, buffered) + { + area += bg::area(polygon); + } + +#ifdef BOOST_GEOMETRY_DEBUG_WITH_MAPPER + // Map input geometry in green + mapper.map(geometry, "opacity:0.5;fill:rgb(0,128,0);stroke:rgb(0,128,0);stroke-width:10"); + + BOOST_FOREACH(GeometryOut const& polygon, buffered) + { + mapper.map(polygon, "opacity:0.4;fill:rgb(255,255,128);stroke:rgb(0,0,0);stroke-width:3"); + } +#endif + + return area; +} + +template +void test_growth(int n, int distance_count) +{ + srand(int(time(NULL))); + //std::cout << typeid(bg::coordinate_type

::type).name() << std::endl; + boost::timer t; + + namespace buf = bg::strategy::buffer; + typedef bg::model::polygon

polygon; + typedef bg::model::multi_point

multi_point_type; + + multi_point_type multi_point; + for (int i = 0; i < n; i++) + { + P point(rand() % 100, rand() % 100); + multi_point.push_back(point); + } + + //std::cout << bg::wkt(multi_point) << std::endl; + + double previous_area = 0; + double epsilon = 0.1; + double distance = 15.0; + for (int d = 0; d < distance_count; d++, distance += epsilon) + { + double area = test_growth(multi_point, n, d, distance); + if (area < previous_area) + { + std::cout << "Error: " << area << " < " << previous_area << std::endl + << " n=" << n << " distance=" << distance + << bg::wkt(multi_point) << std::endl; + } + previous_area = area; + } + std::cout << "n=" << n << " time=" << t.elapsed() << std::endl; +} + +int main(int, char* []) +{ + for (int i = 5; i <= 50; i++) + { + test_growth >(i, 20); + } + + return 0; +}