// Boost.Geometry (aka GGL, Generic Geometry Library) // Copyright (c) 2007-2012 Barend Gehrels, Amsterdam, the Netherlands. // Copyright (c) 2008-2012 Bruno Lalande, Paris, France. // Copyright (c) 2009-2012 Mateusz Loskot, London, UK. // Parts of Boost.Geometry are redesigned from Geodan's Geographic Library // (geolib/GGL), copyright (c) 1995-2010 Geodan, 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) #ifndef BOOST_GEOMETRY_ALGORITHMS_BUFFER_HPP #define BOOST_GEOMETRY_ALGORITHMS_BUFFER_HPP #include #include #include #include #include #include #include #include namespace boost { namespace geometry { #ifndef DOXYGEN_NO_DETAIL namespace detail { namespace buffer { template struct box_loop { typedef typename coordinate_type::type coordinate_type; static inline void apply(BoxIn const& box_in, T const& distance, BoxOut& box_out) { coordinate_type d = distance; set(box_out, get(box_in) + d); box_loop::apply(box_in, distance, box_out); } }; template struct box_loop { static inline void apply(BoxIn const&, T const&, BoxOut&) {} }; // Extends a box with the same amount in all directions template inline void buffer_box(BoxIn const& box_in, T const& distance, BoxOut& box_out) { assert_dimension_equal(); static const std::size_t N = dimension::value; box_loop::apply(box_in, -distance, box_out); box_loop::apply(box_in, distance, box_out); } }} // namespace detail::buffer #endif // DOXYGEN_NO_DETAIL #ifndef DOXYGEN_NO_DISPATCH namespace dispatch { template struct buffer {}; template struct buffer { static inline void apply(BoxIn const& box_in, T const& distance, T const& , BoxIn& box_out) { detail::buffer::buffer_box(box_in, distance, box_out); } }; // Many things to do. Point is easy, other geometries require self intersections // For point, note that it should output as a polygon (like the rest). Buffers // of a set of geometries are often lateron combined using a "dissolve" operation. // Two points close to each other get a combined kidney shaped buffer then. } // namespace dispatch #endif // DOXYGEN_NO_DISPATCH /*! \brief \brief_calc{buffer} \ingroup buffer \details \details_calc{buffer, \det_buffer}. \tparam Input \tparam_geometry \tparam Output \tparam_geometry \tparam Distance \tparam_numeric \param geometry_in \param_geometry \param geometry_out \param_geometry \param distance The distance to be used for the buffer \param chord_length (optional) The length of the chord's in the generated arcs around points or bends \note Currently only implemented for box, the trivial case, but still useful \qbk{[include reference/algorithms/buffer.qbk]} */ template inline void buffer(Input const& geometry_in, Output& geometry_out, Distance const& distance, Distance const& chord_length = -1) { concept::check(); concept::check(); dispatch::buffer < typename tag::type, typename tag::type, Input, Distance, Output >::apply(geometry_in, distance, chord_length, geometry_out); } /*! \brief \brief_calc{buffer} \ingroup buffer \details \details_calc{return_buffer, \det_buffer}. \details_return{buffer}. \tparam Input \tparam_geometry \tparam Output \tparam_geometry \tparam Distance \tparam_numeric \param geometry \param_geometry \param distance The distance to be used for the buffer \param chord_length (optional) The length of the chord's in the generated arcs around points or bends \return \return_calc{buffer} */ template Output return_buffer(Input const& geometry, T const& distance, T const& chord_length = -1) { concept::check(); concept::check(); Output geometry_out; dispatch::buffer < typename tag::type, typename tag::type, Input, T, Output >::apply(geometry, distance, chord_length, geometry_out); return geometry_out; } }} // namespace boost::geometry #endif // BOOST_GEOMETRY_ALGORITHMS_BUFFER_HPP