diff --git a/include/boost/geometry/algorithms/area.hpp b/include/boost/geometry/algorithms/area.hpp index 698ff4030..ce0fde036 100644 --- a/include/boost/geometry/algorithms/area.hpp +++ b/include/boost/geometry/algorithms/area.hpp @@ -31,6 +31,9 @@ #include #include +#include +#include + /*! \defgroup area area: calculate area of a geometry @@ -84,24 +87,8 @@ struct box_area }; - - -/*! - \brief Calculate area of a ring, specialized per order - */ -template -< - typename Ring, - order_selector Order, - // closing_selector Closed -- for now assuming CLOSED, p(0) == p(n-1) - typename Strategy -> +template struct ring_area -{}; - - -template -struct ring_area { BOOST_CONCEPT_ASSERT( (geometry::concept::AreaStrategy) ); @@ -114,7 +101,6 @@ struct ring_area // Ignore warning (because using static method sometimes) on strategy boost::ignore_unused_variable_warning(strategy); - // A closed linear_ring has at least four points, // if not, there is no (zero) area if (boost::size(ring) < 4) @@ -122,39 +108,32 @@ struct ring_area return type(); } - typedef typename boost::range_iterator::type iterator_type; + typedef reversible_view view_type; + typedef typename boost::range_iterator::type iterator_type; + view_type view(ring); typename Strategy::state_type state; + iterator_type it = boost::begin(view); - iterator_type it = boost::begin(ring); for (iterator_type previous = it++; - it != boost::end(ring); + it != boost::end(view); previous = it++) { strategy.apply(*previous, *it, state); } + return strategy.result(state); - - } -}; - -template -struct ring_area -{ - typedef typename Strategy::return_type type; - static inline type apply(Ring const& ring, Strategy const& strategy) - { - // Counter clockwise rings negate the area result - return -ring_area::apply(ring, strategy); } }; }} // namespace detail::area + #endif // DOXYGEN_NO_DETAIL + #ifndef DOXYGEN_NO_DISPATCH namespace dispatch { @@ -181,13 +160,17 @@ struct area {}; -// Area of ring currently returns area of closed rings but it might be argued -// that it is 0.0, because a ring is just a line. template struct area - : detail::area::ring_area + : detail::area::ring_area + < + Geometry, + order_as_direction::value, + Strategy + > {}; + template struct area : detail::calculate_polygon_sum @@ -198,7 +181,7 @@ struct area detail::area::ring_area < typename ring_type::type, - Order, + order_as_direction::value, Strategy > > @@ -261,6 +244,8 @@ inline typename Strategy::return_type area( >::apply(geometry, strategy); } + }} // namespace boost::geometry + #endif // BOOST_GEOMETRY_ALGORITHMS_AREA_HPP diff --git a/include/boost/geometry/extensions/algorithms/buffer/sectionalizing_buffer.hpp b/include/boost/geometry/extensions/algorithms/buffer/sectionalizing_buffer.hpp new file mode 100644 index 000000000..840c8d56b --- /dev/null +++ b/include/boost/geometry/extensions/algorithms/buffer/sectionalizing_buffer.hpp @@ -0,0 +1,162 @@ +// Boost.Geometry (aka GGL, Generic Geometry Library) +// +// Copyright Barend Gehrels 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_DETAIL_BUFFER_SECTIONALIZING_BUFFER_HPP +#define BOOST_GEOMETRY_ALGORITHMS_DETAIL_BUFFER_SECTIONALIZING_BUFFER_HPP + +#include + +#include +#include + +#include +#include + +#include + +#include +#include +#include +#include + +#include +#include + +#include + + + +namespace boost { namespace geometry +{ + + +#ifndef DOXYGEN_NO_DETAIL +namespace detail { namespace buffer +{ + + + +template +< + typename GeometryOut, typename Geometry, + typename DistanceStrategy, + typename JoinStrategy +#ifdef BOOST_GEOMETRY_DEBUG_WITH_MAPPER + , typename Mapper +#endif +> +void sectionalizing_buffer(Geometry const& geometry, + std::vector& buffered, + DistanceStrategy const& distance_strategy, + JoinStrategy const& join_strategy +#ifdef BOOST_GEOMETRY_DEBUG_WITH_MAPPER + , Mapper& mapper +#endif + ) +{ + typedef typename point_type::type point_type; + typedef geometry::box box_type; + typedef geometry::sections sections_type; + typedef typename geometry::ring_type::type ring_type; + + // TEMPORARY + typedef intersecting_inserter + < + std::vector + > inserter_type; + + + sections_type sections; + geometry::sectionalize(geometry, sections); + + + + // Buffer all sections separately, and put them in a temporary vector + std::vector buffered_sections; + BOOST_FOREACH(typename sections_type::value_type const& section, sections) + { + if (! section.duplicate) + { + typedef typename boost::range_iterator + < + typename geometry::range_type::type const + >::type iterator_type; + + + inserter_type inserter(buffered_sections); + + iterator_type begin, end; + typedef std::pair section_range; + geometry::get_section(geometry, section, begin, end); + geometry::detail::buffer::linestring_buffer + < + section_range, ring_type, DistanceStrategy, JoinStrategy + >::apply(std::make_pair(begin, end), inserter, + distance_strategy, + join_strategy +#ifdef BOOST_GEOMETRY_DEBUG_WITH_MAPPER + , mapper +#endif + ); + } + } + + // IF there are bowl-like shapes, there can still be self-intersections + std::vector dissolved; + BOOST_FOREACH(GeometryOut const& p, buffered_sections) + { + geometry::dissolve(p, dissolved); + } + + /*BOOST_FOREACH(GeometryOut const& p, buffered_sections) + { + if (geometry::intersects(p)) + { + //std::cout << "."; + } + }*/ + + // TEMP + //buffered.swap(dissolved); + //return; + // END TEMP + + + BOOST_FOREACH(GeometryOut const& p, dissolved) + { + if (buffered.empty()) + { + buffered.push_back(p); + //geometry::union_inserter(geometry, p, std::back_inserter(buffered)); + } + else if (boost::size(buffered) == 1) + { + std::vector unioned; + geometry::union_inserter(buffered.front(), p, std::back_inserter(unioned)); + buffered.swap(unioned); + } + else + { + std::cerr << " D " << buffered.size(); + /*std::vector dissolved; + dissolved.push_back(p); + geometry::dissolver(buffered, dissolved); + dissolved.swap(buffered);*/ + } + } + + // Output +} + + +}} // namespace detail::buffer +#endif // DOXYGEN_NO_DETAIL + + +}} // namespace boost::geometry + +#endif // BOOST_GEOMETRY_ALGORITHMS_DETAIL_BUFFER_SECTIONALIZING_BUFFER_HPP diff --git a/include/boost/geometry/extensions/algorithms/buffer/splitting_buffer.hpp b/include/boost/geometry/extensions/algorithms/buffer/splitting_buffer.hpp new file mode 100644 index 000000000..2d371f4f1 --- /dev/null +++ b/include/boost/geometry/extensions/algorithms/buffer/splitting_buffer.hpp @@ -0,0 +1,115 @@ +// Boost.Geometry (aka GGL, Generic Geometry Library) +// +// Copyright Barend Gehrels 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_DETAIL_BUFFER_SPLITTING_BUFFER_HPP +#define BOOST_GEOMETRY_ALGORITHMS_DETAIL_BUFFER_SPLITTING_BUFFER_HPP + +#include + +#include +#include + +#include +#include + +#include + +#include +#include +#include +#include + + +#include +#include + + + +namespace boost { namespace geometry +{ + + +#ifndef DOXYGEN_NO_DETAIL +namespace detail { namespace buffer +{ + + +template +< + typename GeometryOut, typename Geometry, + typename DistanceStrategy, + typename JoinStrategy +#ifdef BOOST_GEOMETRY_DEBUG_WITH_MAPPER + , typename Mapper +#endif +> +inline void splitting_buffer(Geometry const& geometry, + std::vector& buffered, + DistanceStrategy const& distance_strategy, + JoinStrategy const& join_strategy + + , int option + ) +{ + typedef typename ring_type::type ring_type; + typedef detail::buffer::intersecting_inserter + < + std::vector + > inserter_type; + + + inserter_type inserter(buffered); + + detail::buffer::linestring_buffer + < + Geometry, GeometryOut, DistanceStrategy, JoinStrategy + >::apply(geometry, inserter, distance_strategy, join_strategy); + + if (option == 0) + { + return; + } + + std::vector rings; + BOOST_FOREACH(GeometryOut const& polygon, buffered) + { +//std::cout << bg::wkt(polygon) << " ; POLYGON" << std::endl; + geometry::split_rings(polygon, rings); + } + + if (option == 1) + { + buffered.resize(rings.size()); + int i = 0; + BOOST_FOREACH(ring_type const& ring, rings) + { + exterior_ring(buffered[i++]) = ring; + } + return; + } + + std::vector buffered_and_unioned; + geometry::dissolver(rings, buffered_and_unioned); + + std::vector buffered_and_assembled; + detail::overlay::assemble(buffered_and_unioned, + std::map(), + buffered_and_unioned[0], buffered_and_unioned[0], 1, true, true, + std::back_inserter(buffered_and_assembled)); + + buffered = buffered_and_assembled; +} + + + +}} // namespace detail::buffer +#endif // DOXYGEN_NO_DETAIL + + +}} // namespace boost::geometry + +#endif // BOOST_GEOMETRY_ALGORITHMS_DETAIL_BUFFER_SPLITTING_BUFFER_HPP diff --git a/include/boost/geometry/extensions/algorithms/buffer/traversing_buffer.hpp b/include/boost/geometry/extensions/algorithms/buffer/traversing_buffer.hpp new file mode 100644 index 000000000..fe08b32c3 --- /dev/null +++ b/include/boost/geometry/extensions/algorithms/buffer/traversing_buffer.hpp @@ -0,0 +1,90 @@ +// Boost.Geometry (aka GGL, Generic Geometry Library) +// +// Copyright Barend Gehrels 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_DETAIL_BUFFER_TRAVERSING_BUFFER_HPP +#define BOOST_GEOMETRY_ALGORITHMS_DETAIL_BUFFER_TRAVERSING_BUFFER_HPP + +#include + +#include +#include + +#include +#include + +#include + +#include +#include +#include +#include + +#include +#include + +#include + + + +namespace boost { namespace geometry +{ + + +#ifndef DOXYGEN_NO_DETAIL +namespace detail { namespace buffer +{ + + +template +< + typename GeometryOut, typename Geometry, + typename DistanceStrategy, + typename JoinStrategy +#ifdef BOOST_GEOMETRY_DEBUG_WITH_MAPPER + , typename Mapper +#endif +> +inline void traversing_buffer(Geometry const& geometry, + std::vector& buffered, + DistanceStrategy const& distance_strategy, + JoinStrategy const& join_strategy +#ifdef BOOST_GEOMETRY_DEBUG_WITH_MAPPER + , Mapper& mapper +#endif + ) +{ + typedef typename ring_type::type ring_type; + typedef detail::buffer::intersecting_inserter + < + std::vector + > inserter_type; + + + inserter_type inserter(buffered); + + detail::buffer::linestring_buffer + < + Geometry, GeometryOut, DistanceStrategy, JoinStrategy + >::apply(geometry, inserter, distance_strategy, join_strategy); + + std::vector buffered_and_assembled; + detail::overlay::assemble(buffered, + std::map(), + buffered[0], buffered[0], 1, true, true, + std::back_inserter(buffered_and_assembled)); + + buffered = buffered_and_assembled; +} + + +}} // namespace detail::buffer +#endif // DOXYGEN_NO_DETAIL + + +}} // namespace boost::geometry + +#endif // BOOST_GEOMETRY_ALGORITHMS_DETAIL_BUFFER_TRAVERSING_BUFFER_HPP diff --git a/include/boost/geometry/util/order_as_direction.hpp b/include/boost/geometry/util/order_as_direction.hpp new file mode 100644 index 000000000..11e0e7de0 --- /dev/null +++ b/include/boost/geometry/util/order_as_direction.hpp @@ -0,0 +1,42 @@ +// Boost.Geometry (aka GGL, Generic Geometry Library) +// +// Copyright Barend Gehrels 2010, Geodan, Amsterdam, the Netherlands. +// Copyright Bruno Lalande 2008, 2009 +// 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_UTIL_ORDER_AS_DIRECTION_HPP +#define BOOST_GEOMETRY_UTIL_ORDER_AS_DIRECTION_HPP + +#include +#include + + +namespace boost { namespace geometry +{ + + +template +struct order_as_direction +{}; + + +template<> +struct order_as_direction +{ + static const iterate_direction value = iterate_forward; +}; + + +template<> +struct order_as_direction +{ + static const iterate_direction value = iterate_reverse; +}; + + +}} // namespace boost::geometry + + +#endif // BOOST_GEOMETRY_UTIL_ORDER_AS_DIRECTION_HPP