diff --git a/doc/release_notes.qbk b/doc/release_notes.qbk index ca0631212..db47c8c68 100644 --- a/doc/release_notes.qbk +++ b/doc/release_notes.qbk @@ -36,6 +36,7 @@ * [@https://github.com/boostorg/geometry/issues/363 363] Missing includes in geometry/index/parameters.hpp * [@https://github.com/boostorg/geometry/issues/364 364] within(Linear, Areal) compilation error when arguments use different point types +* [@https://github.com/boostorg/geometry/issues/370 370] Buffer Seg Faults with Ring as Input [*Solved tickets] diff --git a/include/boost/geometry/algorithms/detail/buffer/buffer_inserter.hpp b/include/boost/geometry/algorithms/detail/buffer/buffer_inserter.hpp index ce55a2bfb..029053dda 100644 --- a/include/boost/geometry/algorithms/detail/buffer/buffer_inserter.hpp +++ b/include/boost/geometry/algorithms/detail/buffer/buffer_inserter.hpp @@ -453,13 +453,14 @@ struct buffer_inserter } }; - +// Not a specialization, but called from specializations of ring and of polygon. +// Calling code starts/finishes ring before/after apply template < typename RingInput, typename RingOutput > -struct buffer_inserter +struct buffer_inserter_ring { typedef typename point_type::type output_point_type; @@ -570,6 +571,43 @@ struct buffer_inserter }; +template +< + typename RingInput, + typename RingOutput +> +struct buffer_inserter +{ + template + < + typename Collection, + typename DistanceStrategy, + typename SideStrategy, + typename JoinStrategy, + typename EndStrategy, + typename PointStrategy, + typename RobustPolicy + > + static inline strategy::buffer::result_code apply(RingInput const& ring, + Collection& collection, + DistanceStrategy const& distance, + SideStrategy const& side_strategy, + JoinStrategy const& join_strategy, + EndStrategy const& end_strategy, + PointStrategy const& point_strategy, + RobustPolicy const& robust_policy) + { + collection.start_new_ring(); + strategy::buffer::result_code const code + = buffer_inserter_ring::apply(ring, + collection, distance, + side_strategy, join_strategy, end_strategy, point_strategy, + robust_policy); + collection.finish_ring(code); + return code; + } +}; + template < typename Linestring, @@ -713,7 +751,7 @@ private: typedef typename ring_type::type input_ring_type; typedef typename ring_type::type output_ring_type; - typedef buffer_inserter policy; + typedef buffer_inserter_ring policy; template diff --git a/test/algorithms/buffer/Jamfile.v2 b/test/algorithms/buffer/Jamfile.v2 index 521e5b4a1..0aede196c 100644 --- a/test/algorithms/buffer/Jamfile.v2 +++ b/test/algorithms/buffer/Jamfile.v2 @@ -18,6 +18,7 @@ test-suite boost-geometry-algorithms-buffer [ run buffer_with_strategies.cpp : : : BOOST_GEOMETRY_TEST_ONLY_ONE_TYPE : algorithms_buffer_with_strategies ] [ run buffer_point.cpp : : : BOOST_GEOMETRY_TEST_ONLY_ONE_TYPE : algorithms_buffer_point ] [ run buffer_linestring.cpp : : : BOOST_GEOMETRY_TEST_ONLY_ONE_TYPE : algorithms_buffer_linestring ] + [ run buffer_ring.cpp : : : BOOST_GEOMETRY_TEST_ONLY_ONE_TYPE : algorithms_buffer_ring ] [ run buffer_polygon.cpp : : : BOOST_GEOMETRY_TEST_ONLY_ONE_TYPE : algorithms_buffer_polygon ] [ run buffer_multi_point.cpp : : : BOOST_GEOMETRY_TEST_ONLY_ONE_TYPE : algorithms_buffer_multi_point ] [ run buffer_multi_linestring.cpp : : : BOOST_GEOMETRY_TEST_ONLY_ONE_TYPE : algorithms_buffer_multi_linestring ] diff --git a/test/algorithms/buffer/buffer_ring.cpp b/test/algorithms/buffer/buffer_ring.cpp new file mode 100644 index 000000000..0930554c6 --- /dev/null +++ b/test/algorithms/buffer/buffer_ring.cpp @@ -0,0 +1,44 @@ +// Boost.Geometry (aka GGL, Generic Geometry Library) +// Unit Test + +// Copyright (c) 2017 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 + +// Short test verifying behavior of explicit ring_type (polygon without holes) +// The test buffer_polygon.cpp contains all other tests, also for rings. + +static std::string const concave_simplex = "POLYGON ((0 0,3 5,3 3,5 3,0 0))"; + +template +void test_all() +{ + typedef bg::model::ring ring_type; + typedef bg::model::polygon polygon_type; + + bg::strategy::buffer::join_miter join_miter(10.0); + bg::strategy::buffer::join_round join_round(100); + bg::strategy::buffer::end_flat end_flat; + + test_one("concave_simplex", concave_simplex, join_round, end_flat, 14.5616, 0.5); + test_one("concave_simplex", concave_simplex, join_miter, end_flat, 16.3861, 0.5); + + test_one("concave_simplex", concave_simplex, join_round, end_flat, 0.777987, -0.5); + test_one("concave_simplex", concave_simplex, join_miter, end_flat, 0.724208, -0.5); +} + + +int test_main(int, char* []) +{ + test_all >(); +#if ! defined(BOOST_GEOMETRY_TEST_ONLY_ONE_TYPE) + test_all >(); + test_all >(); + test_all >(); +#endif + return 0; +}