diff --git a/include/boost/geometry/extensions/algorithms/buffer/multi_buffer_inserter.hpp b/include/boost/geometry/extensions/algorithms/buffer/multi_buffer_inserter.hpp index 0edbc7534..6d59ac8cd 100644 --- a/include/boost/geometry/extensions/algorithms/buffer/multi_buffer_inserter.hpp +++ b/include/boost/geometry/extensions/algorithms/buffer/multi_buffer_inserter.hpp @@ -34,14 +34,15 @@ struct check_original } }; -}} // namespace detail::buffer -#endif // DOXYGEN_NO_DETAIL - - - -#ifndef DOXYGEN_NO_DISPATCH -namespace dispatch +template <> +struct check_original { + template + static inline int apply(Point const& point, Geometry const& geometry) + { + return 0; + } +}; template @@ -49,7 +50,7 @@ template typename Multi, typename PolygonOutput > -struct buffer_inserter +struct multi_buffer_inserter { template < @@ -60,8 +61,8 @@ struct buffer_inserter DistanceStrategy const& distance, JoinStrategy const& join_strategy) { - typedef typename ring_type::type output_ring_type; - typedef buffer_inserter + typedef typename geometry::ring_type::type output_ring_type; + typedef dispatch::buffer_inserter < typename single_tag_of < @@ -81,6 +82,34 @@ struct buffer_inserter } }; +}} // namespace detail::buffer +#endif // DOXYGEN_NO_DETAIL + + + +#ifndef DOXYGEN_NO_DISPATCH +namespace dispatch +{ + + +template +< + typename Multi, + typename PolygonOutput +> +struct buffer_inserter + : public detail::buffer::multi_buffer_inserter +{}; + +template +< + typename Multi, + typename PolygonOutput +> +struct buffer_inserter + : public detail::buffer::multi_buffer_inserter +{}; + } // namespace dispatch #endif // DOXYGEN_NO_DISPATCH diff --git a/include/boost/geometry/extensions/strategies/buffer.hpp b/include/boost/geometry/extensions/strategies/buffer.hpp index 71c00c7c8..6f3c7e4d8 100644 --- a/include/boost/geometry/extensions/strategies/buffer.hpp +++ b/include/boost/geometry/extensions/strategies/buffer.hpp @@ -152,8 +152,13 @@ template > struct join_round { +#ifdef BOOST_GEOMETRY_BUFFER_USE_MIDPOINTS inline join_round(int max_level = 4) : m_max_level(max_level) +#else + inline join_round(int steps_per_circle = 100) + : m_steps_per_circle(steps_per_circle) +#endif {} typedef typename strategy::side::services::default_strategy::type>::type side; @@ -169,9 +174,11 @@ struct join_round double >::type promoted_type; - int m_max_level; #ifdef BOOST_GEOMETRY_BUFFER_USE_MIDPOINTS + + int m_max_level; + template inline void mid_points(PointIn const& vertex, PointIn const& p1, PointIn const& p2, @@ -209,7 +216,10 @@ struct join_round mid_points(vertex, mid_point, p2, buffer_distance, range_out, level + 1); } } -#endif + +#else + + int m_steps_per_circle; template inline void generate_points(PointIn const& vertex, @@ -229,14 +239,14 @@ struct join_round promoted_type angle_diff = acos(dx1 * dx2 + dy1 * dy2); - // Default might be 100 steps for a full circle (2 pi) - promoted_type const steps_per_circle = 100.0; promoted_type two = 2.0; - int n = boost::numeric_cast(steps_per_circle * angle_diff + promoted_type steps = m_steps_per_circle; + int n = boost::numeric_cast(steps * angle_diff / (two * geometry::math::pi())); if (n > 1000) { + // TODO change this / verify this std::cout << dx1 << ", " << dy1 << " .. " << dx2 << ", " << dy2 << std::endl; std::cout << angle_diff << " -> " << n << std::endl; n = 1000; @@ -258,6 +268,7 @@ struct join_round range_out.push_back(p); } } +#endif template inline void apply(PointIn const& ip, PointIn const& vertex, diff --git a/test_extensions/algorithms/buffer/Jamfile.v2 b/test_extensions/algorithms/buffer/Jamfile.v2 index c5e6b9a3c..15b7b0e57 100644 --- a/test_extensions/algorithms/buffer/Jamfile.v2 +++ b/test_extensions/algorithms/buffer/Jamfile.v2 @@ -17,5 +17,6 @@ test-suite boost-geometry-extensions-algorithms-buffer [ run polygon_buffer.cpp ] [ run linestring_buffer.cpp ] [ run multi_polygon_buffer.cpp ] + [ run multi_linestring_buffer.cpp ] ; diff --git a/test_extensions/algorithms/buffer/buffer.sln b/test_extensions/algorithms/buffer/buffer.sln index 57ff89e45..67cdcfbd8 100644 --- a/test_extensions/algorithms/buffer/buffer.sln +++ b/test_extensions/algorithms/buffer/buffer.sln @@ -6,6 +6,8 @@ Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "linestring_buffer", "linest EndProject Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "multi_polygon_buffer", "multi_polygon_buffer.vcproj", "{1E74F110-996E-44DD-A2EC-5D3B55425903}" EndProject +Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "multi_linestring_buffer", "multi_linestring_buffer.vcproj", "{90A3DD9E-376E-4F7B-AA71-03D5598F4285}" +EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution Debug|Win32 = Debug|Win32 @@ -24,6 +26,10 @@ Global {1E74F110-996E-44DD-A2EC-5D3B55425903}.Debug|Win32.Build.0 = Debug|Win32 {1E74F110-996E-44DD-A2EC-5D3B55425903}.Release|Win32.ActiveCfg = Release|Win32 {1E74F110-996E-44DD-A2EC-5D3B55425903}.Release|Win32.Build.0 = Release|Win32 + {90A3DD9E-376E-4F7B-AA71-03D5598F4285}.Debug|Win32.ActiveCfg = Debug|Win32 + {90A3DD9E-376E-4F7B-AA71-03D5598F4285}.Debug|Win32.Build.0 = Debug|Win32 + {90A3DD9E-376E-4F7B-AA71-03D5598F4285}.Release|Win32.ActiveCfg = Release|Win32 + {90A3DD9E-376E-4F7B-AA71-03D5598F4285}.Release|Win32.Build.0 = Release|Win32 EndGlobalSection GlobalSection(SolutionProperties) = preSolution HideSolutionNode = FALSE diff --git a/test_extensions/algorithms/buffer/multi_linestring_buffer.cpp b/test_extensions/algorithms/buffer/multi_linestring_buffer.cpp new file mode 100644 index 000000000..429bd1327 --- /dev/null +++ b/test_extensions/algorithms/buffer/multi_linestring_buffer.cpp @@ -0,0 +1,48 @@ +// Boost.Geometry (aka GGL, Generic Geometry Library) +// Unit Test + +// Copyright (c) 2010-2012 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) + +//#define BOOST_GEOMETRY_DEBUG_WITH_MAPPER +//#define BOOST_GEOMETRY_DEBUG_ASSEMBLE +//#define BOOST_GEOMETRY_DEBUG_IDENTIFIER + +#include + +#include + +#include // TODO: more specific +#include +#include + + +static std::string const simplex = "MULTILINESTRING((0 0,4 5),(5 4,10 0))"; +static std::string const two_bends = "MULTILINESTRING((0 0,4 5,7 4,10 6),(1 5,5 9,8 6))"; + + +template +void test_all() +{ + namespace buf = bg::strategy::buffer; + typedef bg::model::linestring

linestring; + typedef bg::model::multi_linestring multi_linestring_type; + typedef bg::model::polygon

polygon; + + test_one("simplex", simplex, 'r', 38.2623, 1.5, 1.5); + test_one("two_bends", two_bends, 'r', 64.6217, 1.5, 1.5); + test_one("two_bends", two_bends, 'm', 65.1834, 1.5, 1.5); + test_one("two_bends_asym", two_bends, 'm', 52.3793, 1.5, 0.75); +} + + + +int test_main(int, char* []) +{ + test_all >(); + + return 0; +} diff --git a/test_extensions/algorithms/buffer/multi_linestring_buffer.vcproj b/test_extensions/algorithms/buffer/multi_linestring_buffer.vcproj new file mode 100644 index 000000000..6c29535a6 --- /dev/null +++ b/test_extensions/algorithms/buffer/multi_linestring_buffer.vcproj @@ -0,0 +1,174 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/test_extensions/algorithms/buffer/multi_polygon_buffer.vcproj b/test_extensions/algorithms/buffer/multi_polygon_buffer.vcproj index 5494a8631..ddb795e41 100644 --- a/test_extensions/algorithms/buffer/multi_polygon_buffer.vcproj +++ b/test_extensions/algorithms/buffer/multi_polygon_buffer.vcproj @@ -1,7 +1,7 @@ ::name() << "_" << join; - std::cout << complete.str() << std::endl; + //std::cout << complete.str() << std::endl; std::ostringstream filename; filename << "buffer_" << complete.str() << ".svg";