|
|
00001 // Boost.Geometry (aka GGL, Generic Geometry Library) 00002 // 00003 // Copyright Barend Gehrels 2007-2009, Geodan, Amsterdam, the Netherlands. 00004 // Copyright Bruno Lalande 2008, 2009 00005 // Use, modification and distribution is subject to the Boost Software License, 00006 // Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at 00007 // http://www.boost.org/LICENSE_1_0.txt) 00008 00009 #ifndef BOOST_GEOMETRY_ALGORITHMS_BUFFER_HPP 00010 #define BOOST_GEOMETRY_ALGORITHMS_BUFFER_HPP 00011 00012 #include <cstddef> 00013 00014 #include <boost/numeric/conversion/cast.hpp> 00015 00016 #include <boost/geometry/geometries/concepts/check.hpp> 00017 00018 #include <boost/geometry/arithmetic/arithmetic.hpp> 00019 00029 namespace boost { namespace geometry 00030 { 00031 00032 #ifndef DOXYGEN_NO_DETAIL 00033 namespace detail { namespace buffer { 00034 00035 template <typename BoxIn, typename BoxOut, typename T, std::size_t C, std::size_t D, std::size_t N> 00036 struct box_loop 00037 { 00038 typedef typename coordinate_type<BoxOut>::type coordinate_type; 00039 00040 static inline void apply(BoxIn const& box_in, T const& distance, BoxOut& box_out) 00041 { 00042 set<C, D>(box_out, boost::numeric_cast<coordinate_type>(get<C, D>(box_in) + distance)); 00043 box_loop<BoxIn, BoxOut, T, C, D + 1, N>::apply(box_in, distance, box_out); 00044 } 00045 }; 00046 00047 template <typename BoxIn, typename BoxOut, typename T, std::size_t C, std::size_t N> 00048 struct box_loop<BoxIn, BoxOut, T, C, N, N> 00049 { 00050 static inline void apply(BoxIn const&, T const&, BoxOut&) {} 00051 }; 00052 00053 // Extends a box with the same amount in all directions 00054 template<typename BoxIn, typename BoxOut, typename T> 00055 inline void buffer_box(BoxIn const& box_in, T const& distance, BoxOut& box_out) 00056 { 00057 assert_dimension_equal<BoxIn, BoxOut>(); 00058 00059 static const std::size_t N = dimension<BoxIn>::value; 00060 00061 box_loop<BoxIn, BoxOut, T, min_corner, 0, N>::apply(box_in, -distance, box_out); 00062 box_loop<BoxIn, BoxOut, T, max_corner, 0, N>::apply(box_in, +distance, box_out); 00063 } 00064 00065 }} // namespace detail::buffer 00066 #endif // DOXYGEN_NO_DETAIL 00067 00068 #ifndef DOXYGEN_NO_DISPATCH 00069 namespace dispatch 00070 { 00071 00072 template <typename TagIn, typename TagOut, typename Input, typename T, typename Output> 00073 struct buffer {}; 00074 00075 00076 template <typename BoxIn, typename T, typename BoxOut> 00077 struct buffer<box_tag, box_tag, BoxIn, T, BoxOut> 00078 { 00079 static inline void apply(BoxIn const& box_in, T const& distance, 00080 T const& chord_length, BoxIn& box_out) 00081 { 00082 detail::buffer::buffer_box(box_in, distance, box_out); 00083 } 00084 }; 00085 00086 // Many things to do. Point is easy, other geometries require self intersections 00087 // For point, note that it should output as a polygon (like the rest). Buffers 00088 // of a set of geometries are often lateron combined using a "dissolve" operation. 00089 // Two points close to each other get a combined kidney shaped buffer then. 00090 00091 } // namespace dispatch 00092 #endif // DOXYGEN_NO_DISPATCH 00093 00094 00106 template <typename Input, typename Output, typename T> 00107 inline void buffer(Input const& geometry_in, Output& geometry_out, 00108 T const& distance, T const& chord_length = -1) 00109 { 00110 concept::check<const Input>(); 00111 concept::check<Output>(); 00112 00113 dispatch::buffer 00114 < 00115 typename tag<Input>::type, 00116 typename tag<Output>::type, 00117 Input, 00118 T, 00119 Output 00120 >::apply(geometry_in, distance, chord_length, geometry_out); 00121 } 00122 00132 template <typename Output, typename Input, typename T> 00133 Output make_buffer(Input const& geometry, T const& distance, T const& chord_length = -1) 00134 { 00135 concept::check<const Input>(); 00136 concept::check<Output>(); 00137 00138 Output geometry_out; 00139 00140 dispatch::buffer 00141 < 00142 typename tag<Input>::type, 00143 typename tag<Output>::type, 00144 Input, 00145 T, 00146 Output 00147 >::apply(geometry, distance, chord_length, geometry_out); 00148 00149 return geometry_out; 00150 } 00151 00152 }} // namespace boost::geometry 00153 00154 #endif // BOOST_GEOMETRY_ALGORITHMS_BUFFER_HPP
|
December 1, 2009 |
Copyright © 1995-2009 Barend Gehrels, Geodan, Amsterdam Copyright © 2008-2009 Bruno Lalande, Paris Copyright © 2009 Mateusz Loskot, Cadcorp, London |