123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268 |
- #ifndef BOOST_GEOMETRY_ALGORITHMS_BUFFER_HPP
- #define BOOST_GEOMETRY_ALGORITHMS_BUFFER_HPP
- #include <cstddef>
- #include <boost/numeric/conversion/cast.hpp>
- #include <boost/range/value_type.hpp>
- #include <boost/variant/apply_visitor.hpp>
- #include <boost/variant/static_visitor.hpp>
- #include <boost/variant/variant_fwd.hpp>
- #include <boost/geometry/algorithms/clear.hpp>
- #include <boost/geometry/algorithms/envelope.hpp>
- #include <boost/geometry/algorithms/is_empty.hpp>
- #include <boost/geometry/algorithms/not_implemented.hpp>
- #include <boost/geometry/arithmetic/arithmetic.hpp>
- #include <boost/geometry/geometries/concepts/check.hpp>
- #include <boost/geometry/geometries/box.hpp>
- #include <boost/geometry/util/math.hpp>
- #include <boost/geometry/algorithms/detail/buffer/buffer_box.hpp>
- #include <boost/geometry/algorithms/detail/buffer/buffer_inserter.hpp>
- namespace boost { namespace geometry
- {
- #ifndef DOXYGEN_NO_DISPATCH
- namespace dispatch
- {
- template
- <
- typename Input,
- typename Output,
- typename TagIn = typename tag<Input>::type,
- typename TagOut = typename tag<Output>::type
- >
- struct buffer: not_implemented<TagIn, TagOut>
- {};
- template <typename BoxIn, typename BoxOut>
- struct buffer<BoxIn, BoxOut, box_tag, box_tag>
- {
- template <typename Distance>
- static inline void apply(BoxIn const& box_in, Distance const& distance,
- Distance const& , BoxOut& box_out)
- {
- detail::buffer::buffer_box(box_in, distance, box_out);
- }
- };
- }
- #endif
- namespace resolve_variant {
- template <typename Geometry>
- struct buffer
- {
- template <typename Distance, typename GeometryOut>
- static inline void apply(Geometry const& geometry,
- Distance const& distance,
- Distance const& chord_length,
- GeometryOut& out)
- {
- dispatch::buffer<Geometry, GeometryOut>::apply(geometry, distance, chord_length, out);
- }
- };
- template <BOOST_VARIANT_ENUM_PARAMS(typename T)>
- struct buffer<boost::variant<BOOST_VARIANT_ENUM_PARAMS(T)> >
- {
- template <typename Distance, typename GeometryOut>
- struct visitor: boost::static_visitor<void>
- {
- Distance const& m_distance;
- Distance const& m_chord_length;
- GeometryOut& m_out;
- visitor(Distance const& distance,
- Distance const& chord_length,
- GeometryOut& out)
- : m_distance(distance),
- m_chord_length(chord_length),
- m_out(out)
- {}
- template <typename Geometry>
- void operator()(Geometry const& geometry) const
- {
- buffer<Geometry>::apply(geometry, m_distance, m_chord_length, m_out);
- }
- };
- template <typename Distance, typename GeometryOut>
- static inline void apply(
- boost::variant<BOOST_VARIANT_ENUM_PARAMS(T)> const& geometry,
- Distance const& distance,
- Distance const& chord_length,
- GeometryOut& out
- )
- {
- boost::apply_visitor(visitor<Distance, GeometryOut>(distance, chord_length, out), geometry);
- }
- };
- }
- template <typename Input, typename Output, typename Distance>
- inline void buffer(Input const& geometry_in, Output& geometry_out,
- Distance const& distance, Distance const& chord_length = -1)
- {
- concepts::check<Input const>();
- concepts::check<Output>();
- resolve_variant::buffer<Input>::apply(geometry_in, distance, chord_length, geometry_out);
- }
- template <typename Output, typename Input, typename Distance>
- Output return_buffer(Input const& geometry, Distance const& distance, Distance const& chord_length = -1)
- {
- concepts::check<Input const>();
- concepts::check<Output>();
- Output geometry_out;
- resolve_variant::buffer<Input>::apply(geometry, distance, chord_length, geometry_out);
- return geometry_out;
- }
- template
- <
- typename GeometryIn,
- typename MultiPolygon,
- typename DistanceStrategy,
- typename SideStrategy,
- typename JoinStrategy,
- typename EndStrategy,
- typename PointStrategy
- >
- inline void buffer(GeometryIn const& geometry_in,
- MultiPolygon& geometry_out,
- DistanceStrategy const& distance_strategy,
- SideStrategy const& side_strategy,
- JoinStrategy const& join_strategy,
- EndStrategy const& end_strategy,
- PointStrategy const& point_strategy)
- {
- typedef typename boost::range_value<MultiPolygon>::type polygon_type;
- concepts::check<GeometryIn const>();
- concepts::check<polygon_type>();
- typedef typename point_type<GeometryIn>::type point_type;
- typedef typename rescale_policy_type
- <
- point_type,
- typename geometry::cs_tag<point_type>::type
- >::type rescale_policy_type;
- geometry_out.clear();
- if (geometry::is_empty(geometry_in))
- {
-
- return;
- }
- model::box<point_type> box;
- geometry::envelope(geometry_in, box);
- geometry::buffer(box, box, distance_strategy.max_distance(join_strategy, end_strategy));
- typename strategies::relate::services::default_strategy
- <
- GeometryIn, GeometryIn
- >::type strategies;
- rescale_policy_type rescale_policy
- = boost::geometry::get_rescale_policy<rescale_policy_type>(
- box, strategies);
- detail::buffer::buffer_inserter<polygon_type>(geometry_in,
- range::back_inserter(geometry_out),
- distance_strategy,
- side_strategy,
- join_strategy,
- end_strategy,
- point_strategy,
- strategies,
- rescale_policy);
- }
- }}
- #endif
|