From b22a3c0530e8ecfe064b60243cebdcb9dcc4d431 Mon Sep 17 00:00:00 2001 From: Adam Wulkiewicz Date: Fri, 21 Aug 2015 19:41:01 +0200 Subject: [PATCH] [sections] Enlarge section bounding Boxes WRT epsilon. This allows the algorithms using sections to check spatial predicates using raw operators < (e.g. in Box/Box disjoint). There is no need to use less performant calls to math::smaller. Replace math::smaller usage in section functions preceeding() and exceeding() and therefore revert the change done recently. --- .../detail/sections/section_functions.hpp | 10 ++++----- .../detail/sections/sectionalize.hpp | 21 +++++++++++-------- 2 files changed, 17 insertions(+), 14 deletions(-) diff --git a/include/boost/geometry/algorithms/detail/sections/section_functions.hpp b/include/boost/geometry/algorithms/detail/sections/section_functions.hpp index 26980f154..7bc5c0804 100644 --- a/include/boost/geometry/algorithms/detail/sections/section_functions.hpp +++ b/include/boost/geometry/algorithms/detail/sections/section_functions.hpp @@ -18,7 +18,7 @@ #include #include #include -#include + namespace boost { namespace geometry { @@ -40,8 +40,8 @@ static inline bool preceding(int dir, Point const& point, { typename geometry::robust_point_type::type robust_point; geometry::recalculate(robust_point, point, robust_policy); - return (dir == 1 && math::smaller(get(robust_point), get(robust_box))) - || (dir == -1 && math::larger(get(robust_point), get(robust_box))); + return (dir == 1 && get(robust_point) < get(robust_box)) + || (dir == -1 && get(robust_point) > get(robust_box)); } template @@ -57,8 +57,8 @@ static inline bool exceeding(int dir, Point const& point, { typename geometry::robust_point_type::type robust_point; geometry::recalculate(robust_point, point, robust_policy); - return (dir == 1 && math::larger(get(robust_point), get(robust_box))) - || (dir == -1 && math::smaller(get(robust_point), get(robust_box))); + return (dir == 1 && get(robust_point) > get(robust_box)) + || (dir == -1 && get(robust_point) < get(robust_box)); } diff --git a/include/boost/geometry/algorithms/detail/sections/sectionalize.hpp b/include/boost/geometry/algorithms/detail/sections/sectionalize.hpp index 1ced39435..6443965e9 100644 --- a/include/boost/geometry/algorithms/detail/sections/sectionalize.hpp +++ b/include/boost/geometry/algorithms/detail/sections/sectionalize.hpp @@ -52,6 +52,8 @@ #include #include +#include + namespace boost { namespace geometry { @@ -599,19 +601,18 @@ inline void enlarge_sections(Sections& sections) // Reason: turns might, rarely, be missed otherwise (case: "buffer_mp1") // Drawback: not really, range is now completely inside the section. Section is a tiny bit too large, // which might cause (a small number) of more comparisons - // TODO: make dimension-agnostic + + // NOTE: above is old comment to the not used code expanding the Boxes by relaxed_epsilon(10) + + // Enlarge sections by scaled epsilon, this should be consistent with math::equals(). + // Points and Segments are equal-compared WRT machine epsilon, but Boxes aren't + // Enlarging Boxes ensures that they correspond to the bound objects, + // Segments in this case, since Sections are collections of Segments. for (typename boost::range_iterator::type it = boost::begin(sections); it != boost::end(sections); ++it) { - typedef typename boost::range_value::type section_type; - typedef typename section_type::box_type box_type; - typedef typename geometry::coordinate_type::type coordinate_type; - coordinate_type const reps = math::relaxed_epsilon(10.0); - geometry::set<0, 0>(it->bounding_box, geometry::get<0, 0>(it->bounding_box) - reps); - geometry::set<0, 1>(it->bounding_box, geometry::get<0, 1>(it->bounding_box) - reps); - geometry::set<1, 0>(it->bounding_box, geometry::get<1, 0>(it->bounding_box) + reps); - geometry::set<1, 1>(it->bounding_box, geometry::get<1, 1>(it->bounding_box) + reps); + detail::expand_by_epsilon(it->bounding_box); } } @@ -802,6 +803,8 @@ inline void sectionalize(Geometry const& geometry, Reverse, DimensionVector >::apply(geometry, robust_policy, sections, ring_id, max_count); + + detail::sectionalize::enlarge_sections(sections); }