Skip to content

Commit

Permalink
[experimental] update buffer and test with partition version with lam…
Browse files Browse the repository at this point in the history
…bdas
  • Loading branch information
barendgehrels committed Sep 29, 2023
1 parent 3f5c044 commit 0b4bfe7
Show file tree
Hide file tree
Showing 6 changed files with 330 additions and 267 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -191,61 +191,6 @@ struct buffer_less
}
};

template <typename Strategy>
struct piece_get_box
{
explicit piece_get_box(Strategy const& strategy)
: m_strategy(strategy)
{}

template <typename Box, typename Piece>
inline void apply(Box& total, Piece const& piece) const
{
assert_coordinate_type_equal(total, piece.m_piece_border.m_envelope);

if (piece.m_piece_border.m_has_envelope)
{
geometry::expand(total, piece.m_piece_border.m_envelope,
m_strategy);
}
}

Strategy const& m_strategy;
};

template <typename Strategy>
struct piece_overlaps_box
{
explicit piece_overlaps_box(Strategy const& strategy)
: m_strategy(strategy)
{}

template <typename Box, typename Piece>
inline bool apply(Box const& box, Piece const& piece) const
{
assert_coordinate_type_equal(box, piece.m_piece_border.m_envelope);

if (piece.type == strategy::buffer::buffered_flat_end
|| piece.type == strategy::buffer::buffered_concave)
{
// Turns cannot be inside a flat end (though they can be on border)
// Neither we need to check if they are inside concave helper pieces

// Skip all pieces not used as soon as possible
return false;
}
if (! piece.m_piece_border.m_has_envelope)
{
return false;
}

return ! geometry::detail::disjoint::disjoint_box_box(box, piece.m_piece_border.m_envelope,
m_strategy);
}

Strategy const& m_strategy;
};

template <typename Strategy>
struct turn_get_box
{
Expand All @@ -263,24 +208,6 @@ struct turn_get_box
Strategy const& m_strategy;
};

template <typename Strategy>
struct turn_overlaps_box
{
explicit turn_overlaps_box(Strategy const& strategy)
: m_strategy(strategy)
{}

template <typename Box, typename Turn>
inline bool apply(Box const& box, Turn const& turn) const
{
assert_coordinate_type_equal(turn.point, box);
return ! geometry::detail::disjoint::disjoint_point_box(turn.point, box,
m_strategy);
}

Strategy const& m_strategy;
};

struct enriched_map_buffer_include_policy
{
template <typename Operation>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@
#include <boost/geometry/algorithms/detail/overlay/traversal_info.hpp>
#include <boost/geometry/algorithms/detail/overlay/traverse.hpp>
#include <boost/geometry/algorithms/detail/overlay/turn_info.hpp>
#include <boost/geometry/algorithms/detail/partition.hpp>
#include <boost/geometry/algorithms/detail/partition_lambda.hpp>
#include <boost/geometry/algorithms/detail/sections/sectionalize.hpp>
#include <boost/geometry/algorithms/detail/sections/section_box_policies.hpp>

Expand Down Expand Up @@ -358,22 +358,59 @@ struct buffered_piece_collection
// Check if a turn is inside any of the originals
inline void check_turn_in_original()
{
auto const& strategy = m_strategy;

struct specific_options : experimental::partition_options
{
struct include_turn_policy
{
static inline bool apply(buffer_turn_info_type const& turn)
{
return turn.is_turn_traversable && ! turn.within_original;
}
};

using include_policy1 = include_turn_policy;
};

turn_in_original_visitor
<
turn_vector_type,
Strategy
> visitor(m_turns, m_strategy);

geometry::partition
// Partition over the turns and original rings, visiting
// all turns located in an original and changing the turn's
// "count_in_original" and "within_original" values
experimental::partition
<
box_type,
include_turn_policy,
detail::partition::include_all_policy
>::apply(m_turns, original_rings, visitor,
turn_get_box<Strategy>(m_strategy),
turn_in_original_overlaps_box<Strategy>(m_strategy),
original_get_box<Strategy>(m_strategy),
original_overlaps_box<Strategy>(m_strategy));
box_type
>(m_turns, original_rings,
[&strategy](auto& box, auto const& turn)
{
geometry::expand(box, turn.point, strategy);
},
[&strategy](auto& box, auto const& turn)
{
return ! geometry::detail::disjoint::disjoint_point_box(turn.point,
box, strategy);
},
[&strategy](auto& box, auto const& original)
{
geometry::expand(box, original.m_box, strategy);
},
[&strategy](auto& box, auto const& original)
{
return ! detail::disjoint::disjoint_box_box(box,
original.m_box, strategy);
},
[&visitor](auto const& turn, auto const& original)
{
return visitor.apply(turn, original);
},
[](auto const&, int) {},
specific_options()
);

bool const deflate = m_distance_strategy.negative();

Expand Down Expand Up @@ -447,6 +484,8 @@ struct buffered_piece_collection
{
update_piece_administration();

auto const& strategy = m_strategy;

{
// Calculate the turns
piece_turn_visitor
Expand All @@ -461,32 +500,75 @@ struct buffered_piece_collection

detail::sectionalize::enlarge_sections(monotonic_sections, m_strategy);

geometry::partition
<
robust_box_type
>::apply(monotonic_sections, visitor,
detail::section::get_section_box<Strategy>(m_strategy),
detail::section::overlaps_section_box<Strategy>(m_strategy));
experimental::partition<robust_box_type>(monotonic_sections,
[&strategy](auto& box, auto const& section)
{
geometry::expand(box, section.bounding_box, strategy);
},
[&strategy](auto const& box, auto const& section)
{
return ! detail::disjoint::disjoint_box_box(box,
section.bounding_box, strategy);
},
[&visitor](auto const& section1, auto const& section2)
{
return visitor.apply(section1, section2);
}
);
}


update_turn_administration();

{
// Check if turns are inside pieces
turn_in_piece_visitor
<
typename geometry::cs_tag<point_type>::type,
turn_vector_type, piece_vector_type, DistanceStrategy, Strategy
> visitor(m_turns, m_pieces, m_distance_strategy, m_strategy);

geometry::partition
<
box_type
>::apply(m_turns, m_pieces, visitor,
turn_get_box<Strategy>(m_strategy),
turn_overlaps_box<Strategy>(m_strategy),
piece_get_box<Strategy>(m_strategy),
piece_overlaps_box<Strategy>(m_strategy));
// Partition over the turns and pieces, checking if turns are inside pieces.
experimental::partition<box_type>(m_turns, m_pieces,
[&strategy](auto& box, auto const& turn)
{
geometry::expand(box, turn.point, strategy);
},
[&strategy](auto& box, auto const& turn)
{
return ! geometry::detail::disjoint::disjoint_point_box(turn.point,
box, strategy);
},
[&strategy](auto& box, auto const& piece)
{
if (piece.m_piece_border.m_has_envelope)
{
geometry::expand(box, piece.m_piece_border.m_envelope, strategy);
}
},
[&strategy](auto& box, auto const& piece)
{
if (piece.type == strategy::buffer::buffered_flat_end
|| piece.type == strategy::buffer::buffered_concave)
{
// Turns cannot be inside a flat end (though they can be on border)
// Neither we need to check if they are inside concave helper pieces

// Skip all pieces not used as soon as possible
return false;
}
if (! piece.m_piece_border.m_has_envelope)
{
return false;
}

return ! geometry::detail::disjoint::disjoint_box_box(box,
piece.m_piece_border.m_envelope, strategy);
},
[&visitor](auto const& turn, auto const& piece)
{
return visitor.apply(turn, piece);
}
);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,42 +34,6 @@ namespace boost { namespace geometry
namespace detail { namespace buffer
{


template <typename Strategy>
struct original_get_box
{
explicit original_get_box(Strategy const& strategy)
: m_strategy(strategy)
{}

template <typename Box, typename Original>
inline void apply(Box& total, Original const& original) const
{
assert_coordinate_type_equal(total, original.m_box);
geometry::expand(total, original.m_box, m_strategy);
}

Strategy const& m_strategy;
};

template <typename Strategy>
struct original_overlaps_box
{
explicit original_overlaps_box(Strategy const& strategy)
: m_strategy(strategy)
{}

template <typename Box, typename Original>
inline bool apply(Box const& box, Original const& original) const
{
assert_coordinate_type_equal(box, original.m_box);
return ! detail::disjoint::disjoint_box_box(box, original.m_box,
m_strategy);
}

Strategy const& m_strategy;
};

struct include_turn_policy
{
template <typename Turn>
Expand All @@ -79,29 +43,6 @@ struct include_turn_policy
}
};

template <typename Strategy>
struct turn_in_original_overlaps_box
{
explicit turn_in_original_overlaps_box(Strategy const& strategy)
: m_strategy(strategy)
{}

template <typename Box, typename Turn>
inline bool apply(Box const& box, Turn const& turn) const
{
if (! turn.is_turn_traversable || turn.within_original)
{
// Skip all points already processed
return false;
}

return ! geometry::detail::disjoint::disjoint_point_box(
turn.point, box, m_strategy);
}

Strategy const& m_strategy;
};

//! Check if specified is in range of specified iterators
//! Return value of strategy (true if we can bail out)
template
Expand Down
Loading

0 comments on commit 0b4bfe7

Please sign in to comment.