Skip to content

Commit 0b4bfe7

Browse files
committed
[experimental] update buffer and test with partition version with lambdas
1 parent 3f5c044 commit 0b4bfe7

File tree

6 files changed

+330
-267
lines changed

6 files changed

+330
-267
lines changed

include/boost/geometry/algorithms/detail/buffer/buffer_policies.hpp

Lines changed: 0 additions & 73 deletions
Original file line numberDiff line numberDiff line change
@@ -191,61 +191,6 @@ struct buffer_less
191191
}
192192
};
193193

194-
template <typename Strategy>
195-
struct piece_get_box
196-
{
197-
explicit piece_get_box(Strategy const& strategy)
198-
: m_strategy(strategy)
199-
{}
200-
201-
template <typename Box, typename Piece>
202-
inline void apply(Box& total, Piece const& piece) const
203-
{
204-
assert_coordinate_type_equal(total, piece.m_piece_border.m_envelope);
205-
206-
if (piece.m_piece_border.m_has_envelope)
207-
{
208-
geometry::expand(total, piece.m_piece_border.m_envelope,
209-
m_strategy);
210-
}
211-
}
212-
213-
Strategy const& m_strategy;
214-
};
215-
216-
template <typename Strategy>
217-
struct piece_overlaps_box
218-
{
219-
explicit piece_overlaps_box(Strategy const& strategy)
220-
: m_strategy(strategy)
221-
{}
222-
223-
template <typename Box, typename Piece>
224-
inline bool apply(Box const& box, Piece const& piece) const
225-
{
226-
assert_coordinate_type_equal(box, piece.m_piece_border.m_envelope);
227-
228-
if (piece.type == strategy::buffer::buffered_flat_end
229-
|| piece.type == strategy::buffer::buffered_concave)
230-
{
231-
// Turns cannot be inside a flat end (though they can be on border)
232-
// Neither we need to check if they are inside concave helper pieces
233-
234-
// Skip all pieces not used as soon as possible
235-
return false;
236-
}
237-
if (! piece.m_piece_border.m_has_envelope)
238-
{
239-
return false;
240-
}
241-
242-
return ! geometry::detail::disjoint::disjoint_box_box(box, piece.m_piece_border.m_envelope,
243-
m_strategy);
244-
}
245-
246-
Strategy const& m_strategy;
247-
};
248-
249194
template <typename Strategy>
250195
struct turn_get_box
251196
{
@@ -263,24 +208,6 @@ struct turn_get_box
263208
Strategy const& m_strategy;
264209
};
265210

266-
template <typename Strategy>
267-
struct turn_overlaps_box
268-
{
269-
explicit turn_overlaps_box(Strategy const& strategy)
270-
: m_strategy(strategy)
271-
{}
272-
273-
template <typename Box, typename Turn>
274-
inline bool apply(Box const& box, Turn const& turn) const
275-
{
276-
assert_coordinate_type_equal(turn.point, box);
277-
return ! geometry::detail::disjoint::disjoint_point_box(turn.point, box,
278-
m_strategy);
279-
}
280-
281-
Strategy const& m_strategy;
282-
};
283-
284211
struct enriched_map_buffer_include_policy
285212
{
286213
template <typename Operation>

include/boost/geometry/algorithms/detail/buffer/buffered_piece_collection.hpp

Lines changed: 107 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@
5454
#include <boost/geometry/algorithms/detail/overlay/traversal_info.hpp>
5555
#include <boost/geometry/algorithms/detail/overlay/traverse.hpp>
5656
#include <boost/geometry/algorithms/detail/overlay/turn_info.hpp>
57-
#include <boost/geometry/algorithms/detail/partition.hpp>
57+
#include <boost/geometry/algorithms/detail/partition_lambda.hpp>
5858
#include <boost/geometry/algorithms/detail/sections/sectionalize.hpp>
5959
#include <boost/geometry/algorithms/detail/sections/section_box_policies.hpp>
6060

@@ -358,22 +358,59 @@ struct buffered_piece_collection
358358
// Check if a turn is inside any of the originals
359359
inline void check_turn_in_original()
360360
{
361+
auto const& strategy = m_strategy;
362+
363+
struct specific_options : experimental::partition_options
364+
{
365+
struct include_turn_policy
366+
{
367+
static inline bool apply(buffer_turn_info_type const& turn)
368+
{
369+
return turn.is_turn_traversable && ! turn.within_original;
370+
}
371+
};
372+
373+
using include_policy1 = include_turn_policy;
374+
};
375+
361376
turn_in_original_visitor
362377
<
363378
turn_vector_type,
364379
Strategy
365380
> visitor(m_turns, m_strategy);
366381

367-
geometry::partition
382+
// Partition over the turns and original rings, visiting
383+
// all turns located in an original and changing the turn's
384+
// "count_in_original" and "within_original" values
385+
experimental::partition
368386
<
369-
box_type,
370-
include_turn_policy,
371-
detail::partition::include_all_policy
372-
>::apply(m_turns, original_rings, visitor,
373-
turn_get_box<Strategy>(m_strategy),
374-
turn_in_original_overlaps_box<Strategy>(m_strategy),
375-
original_get_box<Strategy>(m_strategy),
376-
original_overlaps_box<Strategy>(m_strategy));
387+
box_type
388+
>(m_turns, original_rings,
389+
[&strategy](auto& box, auto const& turn)
390+
{
391+
geometry::expand(box, turn.point, strategy);
392+
},
393+
[&strategy](auto& box, auto const& turn)
394+
{
395+
return ! geometry::detail::disjoint::disjoint_point_box(turn.point,
396+
box, strategy);
397+
},
398+
[&strategy](auto& box, auto const& original)
399+
{
400+
geometry::expand(box, original.m_box, strategy);
401+
},
402+
[&strategy](auto& box, auto const& original)
403+
{
404+
return ! detail::disjoint::disjoint_box_box(box,
405+
original.m_box, strategy);
406+
},
407+
[&visitor](auto const& turn, auto const& original)
408+
{
409+
return visitor.apply(turn, original);
410+
},
411+
[](auto const&, int) {},
412+
specific_options()
413+
);
377414

378415
bool const deflate = m_distance_strategy.negative();
379416

@@ -447,6 +484,8 @@ struct buffered_piece_collection
447484
{
448485
update_piece_administration();
449486

487+
auto const& strategy = m_strategy;
488+
450489
{
451490
// Calculate the turns
452491
piece_turn_visitor
@@ -461,32 +500,75 @@ struct buffered_piece_collection
461500

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

464-
geometry::partition
465-
<
466-
robust_box_type
467-
>::apply(monotonic_sections, visitor,
468-
detail::section::get_section_box<Strategy>(m_strategy),
469-
detail::section::overlaps_section_box<Strategy>(m_strategy));
503+
experimental::partition<robust_box_type>(monotonic_sections,
504+
[&strategy](auto& box, auto const& section)
505+
{
506+
geometry::expand(box, section.bounding_box, strategy);
507+
},
508+
[&strategy](auto const& box, auto const& section)
509+
{
510+
return ! detail::disjoint::disjoint_box_box(box,
511+
section.bounding_box, strategy);
512+
},
513+
[&visitor](auto const& section1, auto const& section2)
514+
{
515+
return visitor.apply(section1, section2);
516+
}
517+
);
470518
}
471519

520+
472521
update_turn_administration();
473522

474523
{
475-
// Check if turns are inside pieces
476524
turn_in_piece_visitor
477525
<
478526
typename geometry::cs_tag<point_type>::type,
479527
turn_vector_type, piece_vector_type, DistanceStrategy, Strategy
480528
> visitor(m_turns, m_pieces, m_distance_strategy, m_strategy);
481529

482-
geometry::partition
483-
<
484-
box_type
485-
>::apply(m_turns, m_pieces, visitor,
486-
turn_get_box<Strategy>(m_strategy),
487-
turn_overlaps_box<Strategy>(m_strategy),
488-
piece_get_box<Strategy>(m_strategy),
489-
piece_overlaps_box<Strategy>(m_strategy));
530+
// Partition over the turns and pieces, checking if turns are inside pieces.
531+
experimental::partition<box_type>(m_turns, m_pieces,
532+
[&strategy](auto& box, auto const& turn)
533+
{
534+
geometry::expand(box, turn.point, strategy);
535+
},
536+
[&strategy](auto& box, auto const& turn)
537+
{
538+
return ! geometry::detail::disjoint::disjoint_point_box(turn.point,
539+
box, strategy);
540+
},
541+
[&strategy](auto& box, auto const& piece)
542+
{
543+
if (piece.m_piece_border.m_has_envelope)
544+
{
545+
geometry::expand(box, piece.m_piece_border.m_envelope, strategy);
546+
}
547+
},
548+
[&strategy](auto& box, auto const& piece)
549+
{
550+
if (piece.type == strategy::buffer::buffered_flat_end
551+
|| piece.type == strategy::buffer::buffered_concave)
552+
{
553+
// Turns cannot be inside a flat end (though they can be on border)
554+
// Neither we need to check if they are inside concave helper pieces
555+
556+
// Skip all pieces not used as soon as possible
557+
return false;
558+
}
559+
if (! piece.m_piece_border.m_has_envelope)
560+
{
561+
return false;
562+
}
563+
564+
return ! geometry::detail::disjoint::disjoint_box_box(box,
565+
piece.m_piece_border.m_envelope, strategy);
566+
},
567+
[&visitor](auto const& turn, auto const& piece)
568+
{
569+
return visitor.apply(turn, piece);
570+
}
571+
);
490572
}
491573
}
492574

include/boost/geometry/algorithms/detail/buffer/turn_in_original_visitor.hpp

Lines changed: 0 additions & 59 deletions
Original file line numberDiff line numberDiff line change
@@ -34,42 +34,6 @@ namespace boost { namespace geometry
3434
namespace detail { namespace buffer
3535
{
3636

37-
38-
template <typename Strategy>
39-
struct original_get_box
40-
{
41-
explicit original_get_box(Strategy const& strategy)
42-
: m_strategy(strategy)
43-
{}
44-
45-
template <typename Box, typename Original>
46-
inline void apply(Box& total, Original const& original) const
47-
{
48-
assert_coordinate_type_equal(total, original.m_box);
49-
geometry::expand(total, original.m_box, m_strategy);
50-
}
51-
52-
Strategy const& m_strategy;
53-
};
54-
55-
template <typename Strategy>
56-
struct original_overlaps_box
57-
{
58-
explicit original_overlaps_box(Strategy const& strategy)
59-
: m_strategy(strategy)
60-
{}
61-
62-
template <typename Box, typename Original>
63-
inline bool apply(Box const& box, Original const& original) const
64-
{
65-
assert_coordinate_type_equal(box, original.m_box);
66-
return ! detail::disjoint::disjoint_box_box(box, original.m_box,
67-
m_strategy);
68-
}
69-
70-
Strategy const& m_strategy;
71-
};
72-
7337
struct include_turn_policy
7438
{
7539
template <typename Turn>
@@ -79,29 +43,6 @@ struct include_turn_policy
7943
}
8044
};
8145

82-
template <typename Strategy>
83-
struct turn_in_original_overlaps_box
84-
{
85-
explicit turn_in_original_overlaps_box(Strategy const& strategy)
86-
: m_strategy(strategy)
87-
{}
88-
89-
template <typename Box, typename Turn>
90-
inline bool apply(Box const& box, Turn const& turn) const
91-
{
92-
if (! turn.is_turn_traversable || turn.within_original)
93-
{
94-
// Skip all points already processed
95-
return false;
96-
}
97-
98-
return ! geometry::detail::disjoint::disjoint_point_box(
99-
turn.point, box, m_strategy);
100-
}
101-
102-
Strategy const& m_strategy;
103-
};
104-
10546
//! Check if specified is in range of specified iterators
10647
//! Return value of strategy (true if we can bail out)
10748
template

0 commit comments

Comments
 (0)