From 31e4145e473e9792f8c2db68d88d82c5266a1317 Mon Sep 17 00:00:00 2001 From: Barend Gehrels Date: Wed, 4 Oct 2023 15:18:11 +0200 Subject: [PATCH] use partition_lambda for overlay pointlike with linear or areal --- .../detail/overlay/pointlike_areal.hpp | 138 ++++-------------- .../detail/overlay/pointlike_linear.hpp | 136 +++++------------ 2 files changed, 65 insertions(+), 209 deletions(-) diff --git a/include/boost/geometry/algorithms/detail/overlay/pointlike_areal.hpp b/include/boost/geometry/algorithms/detail/overlay/pointlike_areal.hpp index 503d656478..207abc2ead 100644 --- a/include/boost/geometry/algorithms/detail/overlay/pointlike_areal.hpp +++ b/include/boost/geometry/algorithms/detail/overlay/pointlike_areal.hpp @@ -24,7 +24,7 @@ #include #include -#include +#include #include #include #include @@ -63,103 +63,6 @@ template class multipoint_multipolygon_point { private: - template - struct expand_box_point - { - explicit expand_box_point(Strategy const& strategy) - : m_strategy(strategy) - {} - - template - inline void apply(Box& total, Point const& point) const - { - geometry::expand(total, point, m_strategy); - } - - Strategy const& m_strategy; - }; - - template - struct expand_box_boxpair - { - explicit expand_box_boxpair(Strategy const& strategy) - : m_strategy(strategy) - {} - - template - inline void apply(Box1& total, std::pair const& box_pair) const - { - geometry::expand(total, box_pair.first, m_strategy); - } - - Strategy const& m_strategy; - }; - - template - struct overlaps_box_point - { - explicit overlaps_box_point(Strategy const& strategy) - : m_strategy(strategy) - {} - - template - inline bool apply(Box const& box, Point const& point) const - { - return ! geometry::disjoint(point, box, m_strategy); - } - - Strategy const& m_strategy; - }; - - template - struct overlaps_box_boxpair - { - explicit overlaps_box_boxpair(Strategy const& strategy) - : m_strategy(strategy) - {} - - template - inline bool apply(Box1 const& box, std::pair const& box_pair) const - { - return ! geometry::disjoint(box, box_pair.first, m_strategy); - } - - Strategy const& m_strategy; - }; - - template - class item_visitor_type - { - public: - item_visitor_type(MultiPolygon const& multipolygon, - OutputIterator& oit, - Strategy const& strategy) - : m_multipolygon(multipolygon) - , m_oit(oit) - , m_strategy(strategy) - {} - - template - inline bool apply(Point const& item1, std::pair const& item2) - { - action_selector_pl - < - PointOut, overlay_intersection - >::apply(item1, - Policy::apply(item1, - range::at(m_multipolygon, - item2.second), - m_strategy), - m_oit); - - return true; - } - - private: - MultiPolygon const& m_multipolygon; - OutputIterator& m_oit; - Strategy const& m_strategy; - }; template static inline void fill_box_pairs(Iterator first, Iterator last, @@ -181,8 +84,6 @@ class multipoint_multipolygon_point OutputIterator oit, Strategy const& strategy) { - item_visitor_type item_visitor(multipolygon, oit, strategy); - typedef geometry::model::point < typename geometry::coordinate_type::type, @@ -198,14 +99,39 @@ class multipoint_multipolygon_point boost::end(multipolygon), box_pairs, strategy); - geometry::partition + partition_lambda < box_type - >::apply(multipoint, box_pairs, item_visitor, - expand_box_point(strategy), - overlaps_box_point(strategy), - expand_box_boxpair(strategy), - overlaps_box_boxpair(strategy)); + >(multipoint, box_pairs, + [&strategy](auto& box, auto const& point) + { + geometry::expand(box, point, strategy); + }, + [&strategy](auto const& box, auto const& point) + { + return ! geometry::disjoint(point, box, strategy); + }, + [&strategy](auto& box, auto const& pair) + { + geometry::expand(box, pair.first, strategy); + }, + [&strategy](auto const& box, auto const& pair) + { + return ! geometry::disjoint(box, pair.first, strategy); + }, + [&](auto const& point, auto const& pair) + { + action_selector_pl + < + PointOut, overlay_intersection + >::apply(point, + Policy::apply(point, + range::at(multipolygon, pair.second), + strategy), + oit); + return true; + } + ); return oit; } diff --git a/include/boost/geometry/algorithms/detail/overlay/pointlike_linear.hpp b/include/boost/geometry/algorithms/detail/overlay/pointlike_linear.hpp index 19045b250a..199064703d 100644 --- a/include/boost/geometry/algorithms/detail/overlay/pointlike_linear.hpp +++ b/include/boost/geometry/algorithms/detail/overlay/pointlike_linear.hpp @@ -27,7 +27,7 @@ #include #include -#include +#include #include #include #include @@ -123,98 +123,6 @@ template class multipoint_linear_point { private: - // structs for partition -- start - template - struct expand_box_point - { - expand_box_point(Strategy const& strategy) - : m_strategy(strategy) - {} - - template - inline void apply(Box& total, Point const& point) const - { - geometry::expand(total, point, m_strategy); - } - - Strategy const& m_strategy; - }; - - template - struct expand_box_segment - { - explicit expand_box_segment(Strategy const& strategy) - : m_strategy(strategy) - {} - - template - inline void apply(Box& total, Segment const& segment) const - { - geometry::expand(total, - geometry::return_envelope(segment, m_strategy), - m_strategy); - } - - Strategy const& m_strategy; - }; - - template - struct overlaps_box_point - { - explicit overlaps_box_point(Strategy const& strategy) - : m_strategy(strategy) - {} - - template - inline bool apply(Box const& box, Point const& point) const - { - return ! geometry::disjoint(point, box, m_strategy); - } - - Strategy const& m_strategy; - }; - - template - struct overlaps_box_segment - { - explicit overlaps_box_segment(Strategy const& strategy) - : m_strategy(strategy) - {} - - template - inline bool apply(Box const& box, Segment const& segment) const - { - return ! geometry::disjoint(segment, box, m_strategy); - } - - Strategy const& m_strategy; - }; - - template - class item_visitor_type - { - public: - item_visitor_type(OutputIterator& oit, Strategy const& strategy) - : m_oit(oit) - , m_strategy(strategy) - {} - - template - inline bool apply(Item1 const& item1, Item2 const& item2) - { - action_selector_pl - < - PointOut, overlay_intersection - >::apply(item1, Policy::apply(item1, item2, m_strategy), m_oit); - - return true; - } - - private: - OutputIterator& m_oit; - Strategy const& m_strategy; - }; - // structs for partition -- end class segment_range { @@ -246,24 +154,46 @@ class multipoint_linear_point OutputIterator oit, Strategy const& strategy) { - item_visitor_type item_visitor(oit, strategy); // TODO: disjoint Segment/Box may be called in partition multiple times // possibly for non-cartesian segments which could be slow. We should consider // passing a range of bounding boxes of segments after calculating them once. // Alternatively instead of a range of segments a range of Segment/Envelope pairs // should be passed, where envelope would be lazily calculated when needed the first time - geometry::partition - < - geometry::model::box + using box_type = geometry::model::box < typename boost::range_value::type - > - >::apply(multipoint, segment_range(linear), item_visitor, - expand_box_point(strategy), - overlaps_box_point(strategy), - expand_box_segment(strategy), - overlaps_box_segment(strategy)); + >; + + partition_lambda + < + box_type + >(multipoint, segment_range(linear), + [&strategy](auto& box, auto const& point) + { + geometry::expand(box, point, strategy); + }, + [&strategy](auto const& box, auto const& point) + { + return ! geometry::disjoint(point, box, strategy); + }, + [&strategy](auto& box, auto const& segment) + { + geometry::expand(box, geometry::return_envelope(segment, strategy), strategy); + }, + [&strategy](auto const& box, auto const& segment) + { + return ! geometry::disjoint(box, segment, strategy); + }, + [&](auto const& point, auto const& segment) + { + action_selector_pl + < + PointOut, overlay_intersection + >::apply(point, Policy::apply(point, segment, strategy), oit); + return true; + } + ); return oit; }