From 551069e555ca1865a3689694a1cbbcd2899584d1 Mon Sep 17 00:00:00 2001 From: Adam Wulkiewicz Date: Fri, 14 Feb 2014 18:44:14 +0100 Subject: [PATCH] relate() added has_disjoint_sub_geometries check - not working for all special cases, should be replaced with e.g. for_each_disjoint_sub_geometry --- .../detail/relate/boundary_checker.hpp | 6 +- .../detail/relate/linear_linear.hpp | 64 +++++++++++++++++++ 2 files changed, 68 insertions(+), 2 deletions(-) diff --git a/include/boost/geometry/algorithms/detail/relate/boundary_checker.hpp b/include/boost/geometry/algorithms/detail/relate/boundary_checker.hpp index b237d1698..7db4963c7 100644 --- a/include/boost/geometry/algorithms/detail/relate/boundary_checker.hpp +++ b/include/boost/geometry/algorithms/detail/relate/boundary_checker.hpp @@ -51,12 +51,14 @@ public: if ( BoundaryQuery == boundary_front_explicit ) { - BOOST_ASSERT(this->template is_boundary(pt, sid)); +// TODO: temporarily disable + //BOOST_ASSERT(this->template is_boundary(pt, sid)); return true; } else if ( BoundaryQuery == boundary_back_explicit ) { - BOOST_ASSERT(this->template is_boundary(pt, sid)); +// TODO: temporarily disable + //BOOST_ASSERT(this->template is_boundary(pt, sid)); return true; } else if ( BoundaryQuery == boundary_front ) diff --git a/include/boost/geometry/algorithms/detail/relate/linear_linear.hpp b/include/boost/geometry/algorithms/detail/relate/linear_linear.hpp index c31142b44..3d4653ca7 100644 --- a/include/boost/geometry/algorithms/detail/relate/linear_linear.hpp +++ b/include/boost/geometry/algorithms/detail/relate/linear_linear.hpp @@ -28,6 +28,52 @@ namespace boost { namespace geometry #ifndef DOXYGEN_NO_DETAIL namespace detail { namespace relate { +template ::type> +struct has_disjoint_sub_geometries {}; + +template +struct has_disjoint_sub_geometries +{ + template + static inline bool apply(TurnIt first, TurnIt last, Geometry const& /*geometry*/) + { + BOOST_ASSERT(first != last); + return false; + } +}; + +template +struct has_disjoint_sub_geometries +{ + template + static inline bool apply(TurnIt first, TurnIt last, Geometry const& geometry) + { + BOOST_ASSERT(first != last); + + std::size_t count = boost::size(geometry); + std::vector detected_intersections(count, false); + for ( TurnIt it = first ; it != last ; ++it ) + { + int multi_index = it->operations[OpId].seg_id.multi_index; + BOOST_ASSERT(multi_index >= 0); + std::size_t index = static_cast(multi_index); + BOOST_ASSERT(index < count); + detected_intersections[index] = true; + } + + for ( std::vector::iterator it = detected_intersections.begin() ; + it != detected_intersections.end() ; ++it ) + { + if ( *it == false ) + return true; + } + + return false; + } +}; + // update_result template @@ -114,6 +160,24 @@ struct linear_linear return res; } +// TODO: this works bout we don't know what should be set exactly +// replace it with something like: for_each_disjoint_subgeometry + if ( has_disjoint_sub_geometries<0, Geometry1>::apply(turns.begin(), turns.end(), geometry1) ) + { +// TODO: +// check if there is an interior and/or boundary + res.template update(); + res.template update(); + } + + if ( has_disjoint_sub_geometries<1, Geometry2>::apply(turns.begin(), turns.end(), geometry2) ) + { +// TODO: +// check if there is an interior and/or boundary + res.template update(); + res.template update(); + } + boundary_checker boundary_checker1(geometry1); boundary_checker boundary_checker2(geometry2);