From f8c0b46d43ecb04773ae6a7d4e9944fdfc84c286 Mon Sep 17 00:00:00 2001 From: Menelaos Karavelas Date: Wed, 21 May 2014 16:35:40 +0300 Subject: [PATCH] [disjoint] move code from multi/algorithms/disjoint.hpp to files in algorithms/disjoint/detail; move code from algorithms/distance.hpp also to algorithms/disjoint/detail and in algorithms/dispatch/disjoint.hpp --- .../boost/geometry/algorithms/disjoint.hpp | 449 +----------------- .../geometry/multi/algorithms/disjoint.hpp | 40 +- 2 files changed, 27 insertions(+), 462 deletions(-) diff --git a/include/boost/geometry/algorithms/disjoint.hpp b/include/boost/geometry/algorithms/disjoint.hpp index 7ee61c602..65c51a6b3 100644 --- a/include/boost/geometry/algorithms/disjoint.hpp +++ b/include/boost/geometry/algorithms/disjoint.hpp @@ -1,12 +1,15 @@ // Boost.Geometry (aka GGL, Generic Geometry Library) -// Copyright (c) 2007-2012 Barend Gehrels, Amsterdam, the Netherlands. -// Copyright (c) 2008-2012 Bruno Lalande, Paris, France. -// Copyright (c) 2009-2012 Mateusz Loskot, London, UK. -// Copyright (c) 2013 Adam Wulkiewicz, Lodz, Poland. +// Copyright (c) 2007-2014 Barend Gehrels, Amsterdam, the Netherlands. +// Copyright (c) 2008-2014 Bruno Lalande, Paris, France. +// Copyright (c) 2009-2014 Mateusz Loskot, London, UK. +// Copyright (c) 2013-2014 Adam Wulkiewicz, Lodz, Poland. -// This file was modified by Oracle on 2013. -// Modifications copyright (c) 2013, Oracle and/or its affiliates. +// This file was modified by Oracle on 2013-2014. +// Modifications copyright (c) 2013-2014, Oracle and/or its affiliates. + +// Contributed and/or modified by Adam Wulkiewicz, on behalf of Oracle +// Contributed and/or modified by Menelaos Karavelas, on behalf of Oracle // Parts of Boost.Geometry are redesigned from Geodan's Geographic Library // (geolib/GGL), copyright (c) 1995-2010 Geodan, Amsterdam, the Netherlands. @@ -19,318 +22,35 @@ #define BOOST_GEOMETRY_ALGORITHMS_DISJOINT_HPP #include -#include -#include -#include #include #include #include -#include - -#include -#include -#include - -#include -#include -#include -#include -#include -#include -#include - #include -#include +#include +#include +#include +#include +#include +#include +#include +#include +#include -#include -#include - -#include -#include +#include namespace boost { namespace geometry { -#ifndef DOXYGEN_NO_DETAIL -namespace detail { namespace disjoint -{ - -template -struct check_each_ring_for_within -{ - bool has_within; - Geometry const& m_geometry; - - inline check_each_ring_for_within(Geometry const& g) - : has_within(false) - , m_geometry(g) - {} - - template - inline void apply(Range const& range) - { - if ( geometry::within(geometry::return_point_on_surface(range), m_geometry) ) - { - has_within = true; - } - } -}; - -template -inline bool rings_containing(FirstGeometry const& geometry1, - SecondGeometry const& geometry2) -{ - check_each_ring_for_within checker(geometry1); - geometry::detail::for_each_range(geometry2, checker); - return checker.has_within; -} - - - -struct assign_disjoint_policy -{ - // We want to include all points: - static bool const include_no_turn = true; - static bool const include_degenerate = true; - static bool const include_opposite = true; - - // We don't assign extra info: - template - < - typename Info, - typename Point1, - typename Point2, - typename IntersectionInfo, - typename DirInfo - > - static inline void apply(Info& , Point1 const& , Point2 const&, - IntersectionInfo const&, DirInfo const&) - {} -}; - - -template -struct disjoint_linear -{ - static inline bool apply(Geometry1 const& geometry1, Geometry2 const& geometry2) - { - typedef typename geometry::point_type::type point_type; - typedef detail::no_rescale_policy rescale_policy_type; - typedef overlay::turn_info - < - point_type, - typename segment_ratio_type::type - > turn_info; - std::deque turns; - - static const bool reverse1 = overlay::do_reverse::value>::value; // should be false - static const bool reverse2 = overlay::do_reverse::value>::value; // should be false - - // Specify two policies: - // 1) Stop at any intersection - // 2) In assignment, include also degenerate points (which are normally skipped) - disjoint_interrupt_policy policy; - rescale_policy_type robust_policy; - geometry::get_turns - < - reverse1, reverse2, - assign_disjoint_policy - >(geometry1, geometry2, robust_policy, turns, policy); - - return !policy.has_intersections; - } -}; - -template -struct disjoint_segment -{ - static inline bool apply(Segment1 const& segment1, Segment2 const& segment2) - { - typedef typename point_type::type point_type; - - // We don't need to rescale to detect disjointness - typedef no_rescale_policy rescale_policy_type; - rescale_policy_type robust_policy; - - typedef segment_intersection_points - < - point_type, - typename segment_ratio_type - < - point_type, - rescale_policy_type - >::type - > intersection_return_type; - - intersection_return_type is - = strategy::intersection::relate_cartesian_segments - < - policies::relate::segments_intersection_points - < - intersection_return_type - > - >::apply(segment1, segment2, robust_policy); - - return is.count == 0; - } -}; - -template -struct general_areal -{ - static inline bool apply(Geometry1 const& geometry1, Geometry2 const& geometry2) - { - if (! disjoint_linear::apply(geometry1, geometry2)) - { - return false; - } - - // If there is no intersection of segments, they might located - // inside each other - - // We check that using a point on the surface, and see if that is inside - // the other geometry. And vice versa. - - typedef typename geometry::point_type::type point_type1; - typedef typename geometry::point_type::type point_type2; - - if (rings_containing(geometry1, geometry2) - || rings_containing(geometry2, geometry1)) - { - return false; - } - - return true; - } -}; - -template -struct disjoint_segment_box -{ - static inline bool apply(Segment const& segment, Box const& box) - { - typedef typename point_type::type point_type; - point_type p0, p1; - geometry::detail::assign_point_from_index<0>(segment, p0); - geometry::detail::assign_point_from_index<1>(segment, p1); - - return ! detail::disjoint::segment_box_intersection::apply(p0, p1, box); - } -}; - -template -struct disjoint_linestring_box -{ - static inline bool apply(Linestring const& linestring, Box const& box) - { - typedef typename ::boost::range_value::type point_type; - typedef typename ::boost::range_const_iterator::type const_iterator; - typedef typename ::boost::range_size::type size_type; - - const size_type count = ::boost::size(linestring); - - if ( count == 0 ) - return false; - else if ( count == 1 ) - return detail::disjoint::point_box::value> - ::apply(*::boost::begin(linestring), box); - else - { - const_iterator it0 = ::boost::begin(linestring); - const_iterator it1 = ::boost::begin(linestring) + 1; - const_iterator last = ::boost::end(linestring); - - for ( ; it1 != last ; ++it0, ++it1 ) - { - if ( detail::disjoint::segment_box_intersection::apply(*it0, *it1, box) ) - return false; - } - return true; - } - } -}; - -template -struct disjoint_point_linear -{ - static inline - bool apply(Point const& pt, Geometry const& g) - { - return !geometry::covered_by(pt, g); - } -}; - -// computes disjointness of segment and linestring -template -struct disjoint_linestring_segment -{ - static inline - bool apply(Linestring const& ls, Segment const& seg) - { - return disjoint_linear - < - Linestring, segment_view - >::apply(ls, geometry::segment_view(seg)); - } -}; - -template -struct disjoint_linear_areal -{ - static inline - bool apply(Geometry1 const& g1, Geometry2 const& g2) - { - // if there are intersections - return false - if ( !disjoint_linear::apply(g1, g2) ) - return false; - - typedef typename point_type::type point1_type; - point1_type p; - geometry::point_on_border(p, g1); - return !geometry::covered_by(p, g2); - } -}; - -template -struct disjoint_segment_areal -{ - static inline - bool apply(Segment const& seg, Geometry const& g) - { - return disjoint_linear_areal - < - segment_view, Geometry - >::apply(segment_view(seg), g); - } -}; - -}} // namespace detail::disjoint -#endif // DOXYGEN_NO_DETAIL - - #ifndef DOXYGEN_NO_DISPATCH namespace dispatch { -template -< - typename Geometry1, typename Geometry2, - std::size_t DimensionCount = dimension::type::value, - typename Tag1 = typename tag::type, - typename Tag2 = typename tag::type, - bool Reverse = reverse_dispatch::type::value -> -struct disjoint - : detail::disjoint::general_areal -{}; - - // If reversal is needed, perform it template < @@ -339,7 +59,6 @@ template typename Tag1, typename Tag2 > struct disjoint - : disjoint { static inline bool apply(Geometry1 const& g1, Geometry2 const& g2) { @@ -353,136 +72,6 @@ struct disjoint }; -template -struct disjoint - : detail::disjoint::point_point -{}; - - -template -struct disjoint - : detail::disjoint::box_box -{}; - - -template -struct disjoint - : detail::disjoint::point_box -{}; - -template -struct disjoint - : detail::disjoint::reverse_covered_by -{}; - -template -struct disjoint - : detail::disjoint::reverse_covered_by -{}; - -template -struct disjoint - : detail::disjoint::disjoint_linear -{}; - -template -struct disjoint - : detail::disjoint::disjoint_segment -{}; - -template -struct disjoint - : detail::disjoint::disjoint_segment_box -{}; - -template -struct disjoint - : detail::disjoint::disjoint_linestring_box -{}; - -//template -//struct disjoint -// : detail::disjoint::disjoint_linear -//{}; -template -struct disjoint - : detail::disjoint::disjoint_linestring_segment -{}; - -template -struct disjoint - : detail::disjoint::disjoint_segment_areal -{}; - -template -struct disjoint -{ - static inline - bool apply(Polygon const& g1, Segment const& g2) - { - return detail::disjoint::disjoint_segment_areal::apply(g2, g1); - } -}; - -template -struct disjoint - : public detail::disjoint::disjoint_linear_areal -{}; - -template -struct disjoint - : public detail::disjoint::disjoint_linear_areal -{}; - -template -struct disjoint - : public detail::disjoint::disjoint_linear -{}; - -template -struct disjoint -{ - static inline bool apply(Polygon const& polygon, - MultiLinestring const& multilinestring) - { - return detail::disjoint::disjoint_linear_areal - < - MultiLinestring, - Polygon - >::apply(multilinestring, polygon); - } -}; - -template -struct disjoint - : public detail::disjoint::disjoint_linear_areal -{}; - -template -struct disjoint - : public detail::disjoint::disjoint_linear_areal -{}; - -template -struct disjoint - : public detail::disjoint::disjoint_linear_areal -{}; - -template -struct disjoint - : public detail::disjoint::disjoint_linear -{}; - -template -struct disjoint - : public detail::disjoint::disjoint_point_linear -{}; - -template -struct disjoint - : public detail::disjoint::disjoint_point_linear -{}; - } // namespace dispatch #endif // DOXYGEN_NO_DISPATCH diff --git a/include/boost/geometry/multi/algorithms/disjoint.hpp b/include/boost/geometry/multi/algorithms/disjoint.hpp index e5f57b2a8..55f0f01cd 100644 --- a/include/boost/geometry/multi/algorithms/disjoint.hpp +++ b/include/boost/geometry/multi/algorithms/disjoint.hpp @@ -1,8 +1,13 @@ // Boost.Geometry (aka GGL, Generic Geometry Library) -// Copyright (c) 2012 Barend Gehrels, Amsterdam, the Netherlands. -// Copyright (c) 2012 Bruno Lalande, Paris, France. -// Copyright (c) 2012 Mateusz Loskot, London, UK. +// Copyright (c) 2012-2014 Barend Gehrels, Amsterdam, the Netherlands. +// Copyright (c) 2012-2014 Bruno Lalande, Paris, France. +// Copyright (c) 2012-2014 Mateusz Loskot, London, UK. + +// This file was modified by Oracle on 2014. +// Modifications copyright (c) 2014, Oracle and/or its affiliates. + +// Contributed and/or modified by Menelaos Karavelas, on behalf of Oracle // Use, modification and distribution is subject to the Boost Software License, // Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at @@ -11,35 +16,6 @@ #ifndef BOOST_GEOMETRY_MULTI_ALGORITHMS_DISJOINT_HPP #define BOOST_GEOMETRY_MULTI_ALGORITHMS_DISJOINT_HPP - #include -#include -#include - -#include -#include - - -namespace boost { namespace geometry -{ - - -#ifndef DOXYGEN_NO_DISPATCH -namespace dispatch -{ - -template -struct disjoint - : detail::disjoint::reverse_covered_by -{}; - -} // namespace dispatch - - -#endif // DOXYGEN_NO_DISPATCH - - -}} // namespace boost::geometry - #endif // BOOST_GEOMETRY_MULTI_ALGORITHMS_DISJOINT_HPP