From 06ebf17a8d0eb2a23291ab584accd7b917474aba Mon Sep 17 00:00:00 2001 From: Menelaos Karavelas Date: Thu, 8 May 2014 22:24:01 +0300 Subject: [PATCH 01/28] [disjoint] add alternative (more robust) implementation of segment-box disjointness test; the alternative implementation does not use any divisions --- .../detail/disjoint/segment_box.hpp | 263 ++++++++++++++++++ 1 file changed, 263 insertions(+) create mode 100644 include/boost/geometry/algorithms/detail/disjoint/segment_box.hpp diff --git a/include/boost/geometry/algorithms/detail/disjoint/segment_box.hpp b/include/boost/geometry/algorithms/detail/disjoint/segment_box.hpp new file mode 100644 index 000000000..f4b150826 --- /dev/null +++ b/include/boost/geometry/algorithms/detail/disjoint/segment_box.hpp @@ -0,0 +1,263 @@ +// Boost.Geometry (aka GGL, Generic Geometry Library) + +// Copyright (c) 2014, Oracle and/or its affiliates. + +// Contributed and/or modified by Menelaos Karavelas, on behalf of Oracle + +// Licensed under the Boost Software License version 1.0. +// http://www.boost.org/users/license.html + +#ifndef BOOST_GEOMETRY_ALGORITHMS_DETAIL_DISJOINT_SEGMENT_BOX_HPP +#define BOOST_GEOMETRY_ALGORITHMS_DETAIL_DISJOINT_SEGMENT_BOX_HPP + +#include +#include + +#include + +#include +#include +#include + +#include + + +namespace boost { namespace geometry +{ + + +#ifndef DOXYGEN_NO_DETAIL +namespace detail { namespace disjoint +{ + + + +template +< + typename RelativeDistance, + typename SegmentPoint, + typename Box, + std::size_t I, + std::size_t Dimension +> +struct disjoint_segment_box_impl +{ + template + static inline bool apply(SegmentPoint const& p0, + SegmentPoint const& p1, + Box const& box, + RelativeDistancePair& t_min, + RelativeDistancePair& t_max) + { + typedef typename coordinate_type::type box_coordinate_type; + typedef typename coordinate_type + < + SegmentPoint + >::type point_coordinate_type; + + RelativeDistance c_p0 = boost::numeric_cast + < + point_coordinate_type + >( geometry::get(p0) ); + + RelativeDistance c_p1 = boost::numeric_cast + < + point_coordinate_type + >( geometry::get(p1) ); + + RelativeDistance c_b_min = boost::numeric_cast + < + box_coordinate_type + >( geometry::get(box) ); + + RelativeDistance c_b_max = boost::numeric_cast + < + box_coordinate_type + >( geometry::get(box) ); + + RelativeDistance ti_min, ti_max, diff; + + if ( geometry::get(p1) >= geometry::get(p0) ) + { + diff = c_p1 - c_p0; + ti_min = c_b_min - c_p0; + ti_max = c_b_max - c_p0; + } + else + { + diff = c_p0 - c_p1; + ti_min = c_p0 - c_b_max; + ti_max = c_p0 - c_b_min; + } + + RelativeDistance t_min_x_diff = t_min.first * diff; + RelativeDistance t_max_x_diff = t_max.first * diff; + + if ( t_min_x_diff > ti_max * t_min.second + || t_max_x_diff < ti_min * t_max.second ) + { + return true; + } + + if ( ti_min * t_min.second > t_min_x_diff ) + { + t_min.first = ti_min; + t_min.second = diff; + } + if ( ti_max * t_max.second < t_max_x_diff ) + { + t_max.first = ti_max; + t_max.second = diff; + } + + if ( t_min.first > t_min.second || t_max.first < 0 ) + { + return true; + } + + return disjoint_segment_box_impl + < + RelativeDistance, + SegmentPoint, + Box, + I + 1, + Dimension + >::apply(p0, p1, box, t_min, t_max); + } +}; + + +template +< + typename RelativeDistance, + typename SegmentPoint, + typename Box, + std::size_t Dimension +> +struct disjoint_segment_box_impl + < + RelativeDistance, SegmentPoint, Box, 0, Dimension + > +{ + static inline bool apply(SegmentPoint const& p0, + SegmentPoint const& p1, + Box const& box) + { + typedef typename coordinate_type::type box_coordinate_type; + typedef typename coordinate_type + < + SegmentPoint + >::type point_coordinate_type; + + RelativeDistance c_p0 = boost::numeric_cast + < + point_coordinate_type + >( geometry::get<0>(p0) ); + + RelativeDistance c_p1 = boost::numeric_cast + < + point_coordinate_type + >( geometry::get<0>(p1) ); + + RelativeDistance c_b_min = boost::numeric_cast + < + box_coordinate_type + >( geometry::get(box) ); + + RelativeDistance c_b_max = boost::numeric_cast + < + box_coordinate_type + >( geometry::get(box) ); + + std::pair t_min, t_max; + + RelativeDistance diff; + + if ( geometry::get<0>(p1) >= geometry::get<0>(p0) ) + { + diff = c_p1 - c_p0; + t_min.first = c_b_min - c_p0; + t_max.first = c_b_max - c_p0; + } + else + { + diff = c_p0 - c_p1; + t_min.first = c_p0 - c_b_max; + t_max.first = c_p0 - c_b_min; + } + + if ( t_min.first > diff || t_max.first < 0 ) + { + return true; + } + + t_min.second = t_max.second = diff; + + return disjoint_segment_box_impl + < + RelativeDistance, SegmentPoint, Box, 1, Dimension + >::apply(p0, p1, box, t_min, t_max); + } +}; + + +template +< + typename RelativeDistance, + typename SegmentPoint, + typename Box, + std::size_t Dimension +> +struct disjoint_segment_box_impl + < + RelativeDistance, SegmentPoint, Box, Dimension, Dimension + > +{ + template + static inline bool apply(SegmentPoint const&, SegmentPoint const&, + Box const&, + RelativeDistancePair&, RelativeDistancePair&) + { + return false; + } +}; + + +//========================================================================= + + +template +struct disjoint_segment_box_no_numeric_limits +{ + static inline bool apply(Segment const& segment, Box const& box) + { + assert_dimension_equal(); + + typedef typename util::calculation_type::geometric::binary + < + Segment, Box, void + >::type relative_distance_type; + + typedef typename point_type::type segment_point_type; + segment_point_type p0, p1; + geometry::detail::assign_point_from_index<0>(segment, p0); + geometry::detail::assign_point_from_index<1>(segment, p1); + + return disjoint_segment_box_impl + < + relative_distance_type, segment_point_type, Box, + 0, dimension::value + >::apply(p0, p1, box); + } +}; + + +}} // namespace detail::disjoint +#endif // DOXYGEN_NO_DETAIL + + + +}} // namespace boost::geometry + + +#endif // BOOST_GEOMETRY_ALGORITHMS_DETAIL_DISJOINT_SEGMENT_BOX_HPP From 001fa94c76c51459fcd0a666ba72a9e83a0c4188 Mon Sep 17 00:00:00 2001 From: Menelaos Karavelas Date: Wed, 21 May 2014 14:58:53 +0300 Subject: [PATCH 02/28] [disjoint] move basic disjoint dispatch in algorithms/dispatch/disjoint.hpp; use tag_cast to simplify dispatching --- .../geometry/algorithms/dispatch/disjoint.hpp | 70 +++++++++++++++++++ 1 file changed, 70 insertions(+) create mode 100644 include/boost/geometry/algorithms/dispatch/disjoint.hpp diff --git a/include/boost/geometry/algorithms/dispatch/disjoint.hpp b/include/boost/geometry/algorithms/dispatch/disjoint.hpp new file mode 100644 index 000000000..627bcff83 --- /dev/null +++ b/include/boost/geometry/algorithms/dispatch/disjoint.hpp @@ -0,0 +1,70 @@ +// Boost.Geometry (aka GGL, Generic Geometry Library) + +// 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-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. + +// Use, modification and distribution is subject to the Boost Software License, +// Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at +// http://www.boost.org/LICENSE_1_0.txt) + +#ifndef BOOST_GEOMETRY_ALGORITHMS_DISPATCH_DISJOINT_HPP +#define BOOST_GEOMETRY_ALGORITHMS_DISPATCH_DISJOINT_HPP + +#include + +#include +#include +#include +#include + +#include + + +namespace boost { namespace geometry +{ + + +#ifndef DOXYGEN_NO_DISPATCH +namespace dispatch +{ + + +template +< + typename Geometry1, typename Geometry2, + std::size_t DimensionCount = dimension::type::value, + typename Tag1 = typename tag_cast + < + typename tag::type, + segment_tag, box_tag, linear_tag, areal_tag + >::type, + typename Tag2 = typename tag_cast + < + typename tag::type, + segment_tag, box_tag, linear_tag, areal_tag + >::type, + bool Reverse = reverse_dispatch::type::value +> +struct disjoint + : not_implemented +{}; + +} // namespace dispatch +#endif // DOXYGEN_NO_DISPATCH + + +}} // namespace boost::geometry + + +#endif // BOOST_GEOMETRY_ALGORITHMS_DISPATCH_DISJOINT_HPP From d71975878ff591c83d36e73e77e151d7ea15768f Mon Sep 17 00:00:00 2001 From: Menelaos Karavelas Date: Wed, 21 May 2014 15:34:05 +0300 Subject: [PATCH 03/28] [disjoint/equals] move equals::point_point from algorithms/detail/disjoint/point_point.hpp to algorithms/detail/equals/point_point.hpp --- .../algorithms/detail/equals/point_point.hpp | 52 +++++++++++++++++++ include/boost/geometry/algorithms/equals.hpp | 2 +- 2 files changed, 53 insertions(+), 1 deletion(-) create mode 100644 include/boost/geometry/algorithms/detail/equals/point_point.hpp diff --git a/include/boost/geometry/algorithms/detail/equals/point_point.hpp b/include/boost/geometry/algorithms/detail/equals/point_point.hpp new file mode 100644 index 000000000..12daa85e9 --- /dev/null +++ b/include/boost/geometry/algorithms/detail/equals/point_point.hpp @@ -0,0 +1,52 @@ +// Boost.Geometry (aka GGL, Generic Geometry Library) + +// 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-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. + +// Use, modification and distribution is subject to the Boost Software License, +// Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at +// http://www.boost.org/LICENSE_1_0.txt) + +#ifndef BOOST_GEOMETRY_ALGORITHMS_DETAIL_EQUALS_POINT_POINT_HPP +#define BOOST_GEOMETRY_ALGORITHMS_DETAIL_EQUALS_POINT_POINT_HPP + +#include + + +namespace boost { namespace geometry +{ + + +#ifndef DOXYGEN_NO_DETAIL +namespace detail { namespace equals +{ + +/*! + \brief Internal utility function to detect of points are disjoint + \note To avoid circular references + */ +template +inline bool equals_point_point(Point1 const& point1, Point2 const& point2) +{ + return ! detail::disjoint::disjoint_point_point(point1, point2); +} + + +}} // namespace detail::equals +#endif // DOXYGEN_NO_DETAIL + + +}} // namespace boost::geometry + +#endif // BOOST_GEOMETRY_ALGORITHMS_DETAIL_EQUALS_POINT_POINT_HPP diff --git a/include/boost/geometry/algorithms/equals.hpp b/include/boost/geometry/algorithms/equals.hpp index 4cd577d69..081c8f2c4 100644 --- a/include/boost/geometry/algorithms/equals.hpp +++ b/include/boost/geometry/algorithms/equals.hpp @@ -32,7 +32,7 @@ #include -#include +#include #include #include From 5afdb4acbbda7eb57065d50f809ceb52a14157bb Mon Sep 17 00:00:00 2001 From: Menelaos Karavelas Date: Wed, 21 May 2014 15:36:22 +0300 Subject: [PATCH 04/28] [disjoint] add error message in algorithms/detail/disjoint.hpp to check whether this file is included somewhere or not; this file will go away --- include/boost/geometry/algorithms/detail/disjoint.hpp | 2 ++ 1 file changed, 2 insertions(+) diff --git a/include/boost/geometry/algorithms/detail/disjoint.hpp b/include/boost/geometry/algorithms/detail/disjoint.hpp index 10917cded..089acc523 100644 --- a/include/boost/geometry/algorithms/detail/disjoint.hpp +++ b/include/boost/geometry/algorithms/detail/disjoint.hpp @@ -15,6 +15,8 @@ #ifndef BOOST_GEOMETRY_ALGORITHMS_DETAIL_DISJOINT_HPP #define BOOST_GEOMETRY_ALGORITHMS_DETAIL_DISJOINT_HPP +#error This file should not be included; it will go away + // Note: contrary to most files, the geometry::detail::disjoint namespace // is partly implemented in separate files, to avoid circular references // disjoint -> get_turns -> disjoint From ce750e15ae5041b4c67bd1ae969c4be7a60afcec Mon Sep 17 00:00:00 2001 From: Menelaos Karavelas Date: Wed, 21 May 2014 15:37:51 +0300 Subject: [PATCH 05/28] [disjoint] move disjoint_interrupt_policy from algorithms/detail/disjoint.hpp to a separate file under policies --- .../policies/disjoint_interrupt_policy.hpp | 67 +++++++++++++++++++ 1 file changed, 67 insertions(+) create mode 100644 include/boost/geometry/policies/disjoint_interrupt_policy.hpp diff --git a/include/boost/geometry/policies/disjoint_interrupt_policy.hpp b/include/boost/geometry/policies/disjoint_interrupt_policy.hpp new file mode 100644 index 000000000..2a6e54b07 --- /dev/null +++ b/include/boost/geometry/policies/disjoint_interrupt_policy.hpp @@ -0,0 +1,67 @@ +// Boost.Geometry (aka GGL, Generic Geometry Library) + +// 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-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. + +// Use, modification and distribution is subject to the Boost Software License, +// Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at +// http://www.boost.org/LICENSE_1_0.txt) + +#ifndef BOOST_GEOMETRY_ALGORITHMS_POLICIES_DISJOINT_INTERRUPT_POLICY_HPP +#define BOOST_GEOMETRY_ALGORITHMS_POLICIES_DISJOINT_INTERRUPT_POLICY_HPP + +#include + + +namespace boost { namespace geometry +{ + + +#ifndef DOXYGEN_NO_DETAIL +namespace detail { namespace disjoint +{ + + +struct disjoint_interrupt_policy +{ + static bool const enabled = true; + bool has_intersections; + + inline disjoint_interrupt_policy() + : has_intersections(false) + {} + + template + inline bool apply(Range const& range) + { + // If there is any IP in the range, it is NOT disjoint + if (boost::size(range) > 0) + { + has_intersections = true; + return true; + } + return false; + } +}; + + + +}} // namespace detail::disjoint +#endif // DOXYGEN_NO_DETAIL + + +}} // namespace boost::geometry + + +#endif // BOOST_GEOMETRY_ALGORITHMS_POLICIES_DISJOINT_INTERRUPT_POLICY_HPP From b39c46575cd08a4446630b08cdafa529b2bf32f4 Mon Sep 17 00:00:00 2001 From: Menelaos Karavelas Date: Wed, 21 May 2014 15:45:35 +0300 Subject: [PATCH 06/28] [disjoint] add dispatch specialization for point-point and point-box; move equals::point_point code to proper place; --- .../algorithms/detail/disjoint/box_box.hpp | 33 +++++++++++++-- .../detail/disjoint/point_point.hpp | 42 +++++++++++-------- 2 files changed, 54 insertions(+), 21 deletions(-) diff --git a/include/boost/geometry/algorithms/detail/disjoint/box_box.hpp b/include/boost/geometry/algorithms/detail/disjoint/box_box.hpp index 24f9aa24e..931a52b8e 100644 --- a/include/boost/geometry/algorithms/detail/disjoint/box_box.hpp +++ b/include/boost/geometry/algorithms/detail/disjoint/box_box.hpp @@ -1,9 +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-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. @@ -15,7 +21,10 @@ #ifndef BOOST_GEOMETRY_ALGORITHMS_DETAIL_DISJOINT_BOX_BOX_HPP #define BOOST_GEOMETRY_ALGORITHMS_DETAIL_DISJOINT_BOX_BOX_HPP +#include + #include +#include namespace boost { namespace geometry @@ -81,6 +90,22 @@ inline bool disjoint_box_box(Box1 const& box1, Box2 const& box2) }} // namespace detail::disjoint #endif // DOXYGEN_NO_DETAIL + +#ifndef DOXYGEN_NO_DISPATCH +namespace dispatch +{ + + +template +struct disjoint + : detail::disjoint::box_box +{}; + + +} // namespace dispatch +#endif // DOXYGEN_NO_DISPATCH + + }} // namespace boost::geometry diff --git a/include/boost/geometry/algorithms/detail/disjoint/point_point.hpp b/include/boost/geometry/algorithms/detail/disjoint/point_point.hpp index e762e1fdd..b1d32bf95 100644 --- a/include/boost/geometry/algorithms/detail/disjoint/point_point.hpp +++ b/include/boost/geometry/algorithms/detail/disjoint/point_point.hpp @@ -1,9 +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-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,9 +25,13 @@ #include #include +#include #include +#include + + namespace boost { namespace geometry { @@ -81,23 +91,21 @@ inline bool disjoint_point_point(Point1 const& point1, Point2 const& point2) #endif // DOXYGEN_NO_DETAIL -#ifndef DOXYGEN_NO_DETAIL -namespace detail { namespace equals + + +#ifndef DOXYGEN_NO_DISPATCH +namespace dispatch { -/*! - \brief Internal utility function to detect of points are disjoint - \note To avoid circular references - */ -template -inline bool equals_point_point(Point1 const& point1, Point2 const& point2) -{ - return ! detail::disjoint::disjoint_point_point(point1, point2); -} + +template +struct disjoint + : detail::disjoint::point_point +{}; -}} // namespace detail::equals -#endif // DOXYGEN_NO_DETAIL +} // namespace dispatch +#endif // DOXYGEN_NO_DISPATCH }} // namespace boost::geometry From cf517dcb2e548035b1d8d4fa1ecaa1c834d3326b Mon Sep 17 00:00:00 2001 From: Menelaos Karavelas Date: Wed, 21 May 2014 16:12:02 +0300 Subject: [PATCH 07/28] [disjoint] add dispatch and fix copyright headers --- .../detail/disjoint/segment_box.hpp | 39 ++++++++++++++++--- 1 file changed, 34 insertions(+), 5 deletions(-) diff --git a/include/boost/geometry/algorithms/detail/disjoint/segment_box.hpp b/include/boost/geometry/algorithms/detail/disjoint/segment_box.hpp index f4b150826..46555f4e1 100644 --- a/include/boost/geometry/algorithms/detail/disjoint/segment_box.hpp +++ b/include/boost/geometry/algorithms/detail/disjoint/segment_box.hpp @@ -1,11 +1,22 @@ // Boost.Geometry (aka GGL, Generic Geometry Library) -// Copyright (c) 2014, Oracle and/or its affiliates. +// 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-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 -// Licensed under the Boost Software License version 1.0. -// http://www.boost.org/users/license.html +// Parts of Boost.Geometry are redesigned from Geodan's Geographic Library +// (geolib/GGL), copyright (c) 1995-2010 Geodan, Amsterdam, the Netherlands. + +// Use, modification and distribution is subject to the Boost Software License, +// Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at +// http://www.boost.org/LICENSE_1_0.txt) #ifndef BOOST_GEOMETRY_ALGORITHMS_DETAIL_DISJOINT_SEGMENT_BOX_HPP #define BOOST_GEOMETRY_ALGORITHMS_DETAIL_DISJOINT_SEGMENT_BOX_HPP @@ -16,11 +27,14 @@ #include #include +#include #include #include #include +#include + namespace boost { namespace geometry { @@ -227,9 +241,9 @@ struct disjoint_segment_box_impl template -struct disjoint_segment_box_no_numeric_limits +struct disjoint_segment_box { - static inline bool apply(Segment const& segment, Box const& box) + static inline bool apply(Segment const& segment, Box const& box) { assert_dimension_equal(); @@ -257,6 +271,21 @@ struct disjoint_segment_box_no_numeric_limits +#ifndef DOXYGEN_NO_DISPATCH +namespace dispatch +{ + + +template +struct disjoint + : detail::disjoint::disjoint_segment_box +{}; + + +} // namespace dispatch +#endif // DOXYGEN_NO_DISPATCH + + }} // namespace boost::geometry From 7f1bb277abbb3b5830fa5476e85b7db0eccddce8 Mon Sep 17 00:00:00 2001 From: Menelaos Karavelas Date: Wed, 21 May 2014 16:33:17 +0300 Subject: [PATCH 08/28] [disjoint] add files in algorithms/detail/disjoint with existing code and new code (for new geometry combinations); clean-up/simplify dispatch using tag_cast and clean-up dispatch specializations; --- .../detail/disjoint/areal_areal.hpp | 138 +++++++++++ .../detail/disjoint/linear_areal.hpp | 222 ++++++++++++++++++ .../detail/disjoint/linear_linear.hpp | 175 ++++++++++++++ .../detail/disjoint/linear_segment_or_box.hpp | 195 +++++++++++++++ .../algorithms/detail/disjoint/point_box.hpp | 94 ++++++++ .../detail/disjoint/point_geometry.hpp | 111 +++++++++ 6 files changed, 935 insertions(+) create mode 100644 include/boost/geometry/algorithms/detail/disjoint/areal_areal.hpp create mode 100644 include/boost/geometry/algorithms/detail/disjoint/linear_areal.hpp create mode 100644 include/boost/geometry/algorithms/detail/disjoint/linear_linear.hpp create mode 100644 include/boost/geometry/algorithms/detail/disjoint/linear_segment_or_box.hpp create mode 100644 include/boost/geometry/algorithms/detail/disjoint/point_box.hpp create mode 100644 include/boost/geometry/algorithms/detail/disjoint/point_geometry.hpp diff --git a/include/boost/geometry/algorithms/detail/disjoint/areal_areal.hpp b/include/boost/geometry/algorithms/detail/disjoint/areal_areal.hpp new file mode 100644 index 000000000..75e0ae293 --- /dev/null +++ b/include/boost/geometry/algorithms/detail/disjoint/areal_areal.hpp @@ -0,0 +1,138 @@ +// Boost.Geometry (aka GGL, Generic Geometry Library) + +// 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-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. + +// Use, modification and distribution is subject to the Boost Software License, +// Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at +// http://www.boost.org/LICENSE_1_0.txt) + +#ifndef BOOST_GEOMETRY_ALGORITHMS_DETAIL_DISJOINT_AREAL_AREAL_HPP +#define BOOST_GEOMETRY_ALGORITHMS_DETAIL_DISJOINT_AREAL_AREAL_HPP + +#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; +} + + + +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; + } +}; + + +}} // namespace detail::disjoint +#endif // DOXYGEN_NO_DETAIL + + + + +#ifndef DOXYGEN_NO_DISPATCH +namespace dispatch +{ + + +template +struct disjoint + : detail::disjoint::general_areal +{}; + + +template +struct disjoint + : detail::disjoint::general_areal +{}; + + +} // namespace dispatch +#endif // DOXYGEN_NO_DISPATCH + + +}} // namespace boost::geometry + + +#endif // BOOST_GEOMETRY_ALGORITHMS_DETAIL_DISJOINT_AREAL_AREAL_HPP diff --git a/include/boost/geometry/algorithms/detail/disjoint/linear_areal.hpp b/include/boost/geometry/algorithms/detail/disjoint/linear_areal.hpp new file mode 100644 index 000000000..b4e11e5b4 --- /dev/null +++ b/include/boost/geometry/algorithms/detail/disjoint/linear_areal.hpp @@ -0,0 +1,222 @@ +// Boost.Geometry (aka GGL, Generic Geometry Library) + +// 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-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. + +// Use, modification and distribution is subject to the Boost Software License, +// Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at +// http://www.boost.org/LICENSE_1_0.txt) + +#ifndef BOOST_GEOMETRY_ALGORITHMS_DETAIL_DISJOINT_LINEAR_AREAL_HPP +#define BOOST_GEOMETRY_ALGORITHMS_DETAIL_DISJOINT_LINEAR_AREAL_HPP + +#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 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 +< + typename Segment, + typename Areal, + typename Tag = typename tag::type +> +struct disjoint_segment_areal + : not_implemented +{}; + + +template +struct disjoint_segment_areal +{ + static inline bool apply(Segment const& segment, Polygon const& polygon) + { + typedef typename geometry::ring_type::type ring; + typedef typename geometry::interior_return_type + < + Polygon const + >::type interior_rings; + + if ( !disjoint_range_segment_or_box + < + ring, closure::value, Segment + >::apply(geometry::exterior_ring(polygon), segment) ) + { + return false; + } + + interior_rings const& irings = geometry::interior_rings(polygon); + + for (BOOST_AUTO_TPL(it, boost::begin(irings)); + it != boost::end(irings); ++it) + { + if ( !disjoint_range_segment_or_box + < + ring, closure::value, Segment + >::apply(*it, segment) ) + { + return false; + } + } + + typename point_type::type p; + detail::assign_point_from_index<0>(segment, p); + + return !geometry::covered_by(p, polygon); + } +}; + + +template +struct disjoint_segment_areal +{ + static inline + bool apply(Segment const& segment, MultiPolygon const& multipolygon) + { + return disjoint_multirange_segment_or_box + < + MultiPolygon, Segment + >::apply(multipolygon, segment); + } +}; + + +template +struct disjoint_segment_areal +{ + static inline bool apply(Segment const& segment, Ring const& ring) + { + if ( !disjoint_range_segment_or_box + < + Ring, closure::value, Segment + >::apply(ring, segment) ) + { + return false; + } + + typename point_type::type p; + detail::assign_point_from_index<0>(segment, p); + + return !geometry::covered_by(p, ring); + } +}; + + +}} // namespace detail::disjoint +#endif // DOXYGEN_NO_DETAIL + + + + +#ifndef DOXYGEN_NO_DISPATCH +namespace dispatch +{ + + +template +struct disjoint + : public detail::disjoint::disjoint_linear_areal +{}; + + +template +struct disjoint +{ + static inline + bool apply(Areal const& areal, Linear const& linear) + { + return detail::disjoint::disjoint_linear_areal + < + Linear, Areal + >::apply(linear, areal); + } +}; + + +template +struct disjoint +{ + static inline bool apply(Areal const& g1, Segment const& g2) + { + return detail::disjoint::disjoint_segment_areal + < + Segment, Areal + >::apply(g2, g1); + } +}; + + +template +struct disjoint + : detail::disjoint::disjoint_segment_areal +{}; + + +} // namespace dispatch +#endif // DOXYGEN_NO_DISPATCH + + +}} // namespace boost::geometry + + +#endif // BOOST_GEOMETRY_ALGORITHMS_DETAIL_DISJOINT_LINEAR_AREAL_HPP diff --git a/include/boost/geometry/algorithms/detail/disjoint/linear_linear.hpp b/include/boost/geometry/algorithms/detail/disjoint/linear_linear.hpp new file mode 100644 index 000000000..9cef8eaf5 --- /dev/null +++ b/include/boost/geometry/algorithms/detail/disjoint/linear_linear.hpp @@ -0,0 +1,175 @@ +// Boost.Geometry (aka GGL, Generic Geometry Library) + +// 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-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. + +// Use, modification and distribution is subject to the Boost Software License, +// Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at +// http://www.boost.org/LICENSE_1_0.txt) + +#ifndef BOOST_GEOMETRY_ALGORITHMS_DETAIL_DISJOINT_LINEAR_LINEAR_HPP +#define BOOST_GEOMETRY_ALGORITHMS_DETAIL_DISJOINT_LINEAR_LINEAR_HPP + +#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 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; + } +}; + + +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; + } +}; + + +}} // namespace detail::disjoint +#endif // DOXYGEN_NO_DETAIL + + + + +#ifndef DOXYGEN_NO_DISPATCH +namespace dispatch +{ + + +template +struct disjoint + : detail::disjoint::disjoint_linear +{}; + + +template +struct disjoint + : detail::disjoint::disjoint_segment +{}; + + +} // namespace dispatch +#endif // DOXYGEN_NO_DISPATCH + + +}} // namespace boost::geometry + + +#endif // BOOST_GEOMETRY_ALGORITHMS_DETAIL_DISJOINT_LINEAR_LINEAR_HPP diff --git a/include/boost/geometry/algorithms/detail/disjoint/linear_segment_or_box.hpp b/include/boost/geometry/algorithms/detail/disjoint/linear_segment_or_box.hpp new file mode 100644 index 000000000..d181726e2 --- /dev/null +++ b/include/boost/geometry/algorithms/detail/disjoint/linear_segment_or_box.hpp @@ -0,0 +1,195 @@ +// Boost.Geometry (aka GGL, Generic Geometry Library) + +// 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-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. + +// Use, modification and distribution is subject to the Boost Software License, +// Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at +// http://www.boost.org/LICENSE_1_0.txt) + +#ifndef BOOST_GEOMETRY_ALGORITHMS_DETAIL_DISJOINT_LINEAR_SEGMENT_OR_BOX_HPP +#define BOOST_GEOMETRY_ALGORITHMS_DETAIL_DISJOINT_LINEAR_SEGMENT_OR_BOX_HPP + +#include +#include + +#include + +#include + +#include + +#include + +#include + + +namespace boost { namespace geometry +{ + + +#ifndef DOXYGEN_NO_DETAIL +namespace detail { namespace disjoint +{ + + +template +struct disjoint_multirange_segment_or_box +{ + static inline + bool apply(MultiRange const& multirange, SegmentOrBox const& segment_or_box) + { + typedef typename boost::range_iterator + < + MultiRange const + >::type const_iterator; + + for (const_iterator it = boost::begin(multirange); + it != boost::end(multirange); ++it) + { + if ( !dispatch::disjoint + < + typename boost::range_value::type, + SegmentOrBox + >::apply(*it, segment_or_box) ) + { + return false; + } + } + return true; + } +}; + + +template +< + typename Range, + closure_selector Closure, + typename SegmentOrBox +> +struct disjoint_range_segment_or_box +{ + static inline + bool apply(Range const& range, SegmentOrBox const& segment_or_box) + { + typedef typename closeable_view::type view_type; + + typedef typename ::boost::range_value::type point_type; + typedef typename ::boost::range_iterator + < + view_type const + >::type const_iterator; + + typedef typename ::boost::range_size::type size_type; + + typedef typename geometry::model::referring_segment + < + point_type const + > range_segment; + + view_type view(range); + + const size_type count = ::boost::size(view); + + if ( count == 0 ) + { + return false; + } + else if ( count == 1 ) + { + return dispatch::disjoint + < + point_type, SegmentOrBox + >::apply(geometry::range::front(view), + segment_or_box); + } + else + { + const_iterator it0 = ::boost::begin(view); + const_iterator it1 = ::boost::begin(view) + 1; + const_iterator last = ::boost::end(view); + + for ( ; it1 != last ; ++it0, ++it1 ) + { + range_segment rng_segment(*it0, *it1); + if ( !dispatch::disjoint + < + range_segment, SegmentOrBox + >::apply(rng_segment, segment_or_box) ) + { + return false; + } + } + return true; + } + } +}; + + + + +template +< + typename Linear, + typename SegmentOrBox, + typename Tag = typename tag::type +> +struct disjoint_linear_segment_or_box + : not_implemented +{}; + + +template +struct disjoint_linear_segment_or_box + : disjoint_range_segment_or_box +{}; + + +template +struct disjoint_linear_segment_or_box + < + MultiLinestring, SegmentOrBox, multi_linestring_tag + > : disjoint_multirange_segment_or_box +{}; + + +}} // namespace detail::disjoint +#endif // DOXYGEN_NO_DETAIL + + +#ifndef DOXYGEN_NO_DISPATCH +namespace dispatch +{ + + +template +struct disjoint + : detail::disjoint::disjoint_linear_segment_or_box +{}; + + +template +struct disjoint + : detail::disjoint::disjoint_linear_segment_or_box +{}; + + +} // namespace dispatch +#endif // DOXYGEN_NO_DISPATCH + + +}} // namespace boost::geometry + + +#endif // BOOST_GEOMETRY_ALGORITHMS_DETAIL_DISJOINT_LINEAR_SEGMENT_OR_BOX_HPP diff --git a/include/boost/geometry/algorithms/detail/disjoint/point_box.hpp b/include/boost/geometry/algorithms/detail/disjoint/point_box.hpp new file mode 100644 index 000000000..ea6609a15 --- /dev/null +++ b/include/boost/geometry/algorithms/detail/disjoint/point_box.hpp @@ -0,0 +1,94 @@ +// Boost.Geometry (aka GGL, Generic Geometry Library) + +// 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-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. + +// Use, modification and distribution is subject to the Boost Software License, +// Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at +// http://www.boost.org/LICENSE_1_0.txt) + +#ifndef BOOST_GEOMETRY_ALGORITHMS_DETAIL_DISJOINT_POINT_BOX_HPP +#define BOOST_GEOMETRY_ALGORITHMS_DETAIL_DISJOINT_POINT_BOX_HPP + +#include + +#include +#include +#include + +#include + + +namespace boost { namespace geometry +{ + +#ifndef DOXYGEN_NO_DETAIL +namespace detail { namespace disjoint +{ + + +template +< + typename Point, typename Box, + std::size_t Dimension, std::size_t DimensionCount +> +struct point_box +{ + static inline bool apply(Point const& point, Box const& box) + { + if (get(point) < get(box) + || get(point) > get(box)) + { + return true; + } + return point_box + < + Point, Box, + Dimension + 1, DimensionCount + >::apply(point, box); + } +}; + + +template +struct point_box +{ + static inline bool apply(Point const& , Box const& ) + { + return false; + } +}; + + +}} // namespace detail::equals +#endif // DOXYGEN_NO_DETAIL + + +#ifndef DOXYGEN_NO_DISPATCH +namespace dispatch +{ + + +template +struct disjoint + : detail::disjoint::point_box +{}; + + +} // namespace dispatch +#endif // DOXYGEN_NO_DISPATCH + +}} // namespace boost::geometry + +#endif // BOOST_GEOMETRY_ALGORITHMS_DETAIL_DISJOINT_POINT_BOX_HPP diff --git a/include/boost/geometry/algorithms/detail/disjoint/point_geometry.hpp b/include/boost/geometry/algorithms/detail/disjoint/point_geometry.hpp new file mode 100644 index 000000000..a58bff41d --- /dev/null +++ b/include/boost/geometry/algorithms/detail/disjoint/point_geometry.hpp @@ -0,0 +1,111 @@ +// Boost.Geometry (aka GGL, Generic Geometry Library) + +// 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-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. + +// Use, modification and distribution is subject to the Boost Software License, +// Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at +// http://www.boost.org/LICENSE_1_0.txt) + +#ifndef BOOST_GEOMETRY_ALGORITHMS_DETAIL_DISJOINT_POINT_GEOMETRY_HPP +#define BOOST_GEOMETRY_ALGORITHMS_DETAIL_DISJOINT_POINT_GEOMETRY_HPP + +#include + +#include + +#include + +#include + + +namespace boost { namespace geometry +{ + + +#ifndef DOXYGEN_NO_DETAIL +namespace detail { namespace disjoint +{ + + +template +struct disjoint_point_linear +{ + static inline + bool apply(Point const& pt, Geometry const& g) + { + return !geometry::covered_by(pt, g); + } +}; + + +template +struct reverse_covered_by +{ + static inline + bool apply(Geometry1 const& geometry1, Geometry2 const& geometry2) + { + return !geometry::covered_by(geometry1, geometry2); + } +}; + + +}} // namespace detail::disjoint +#endif // DOXYGEN_NO_DETAIL + + + + +#ifndef DOXYGEN_NO_DISPATCH +namespace dispatch +{ + + +template +struct disjoint + : public detail::disjoint::disjoint_point_linear +{}; + + +template +struct disjoint + : detail::disjoint::reverse_covered_by +{}; + + +template +struct disjoint +{ + static inline bool apply(Point const& point, Segment const& segment) + { + typedef geometry::model::referring_segment other_segment; + + other_segment other(point, point); + return detail::disjoint::disjoint_segment + < + Segment, other_segment + >::apply(segment, other); + } +}; + + +} // namespace dispatch +#endif // DOXYGEN_NO_DISPATCH + + +}} // namespace boost::geometry + + + +#endif // BOOST_GEOMETRY_ALGORITHMS_DETAIL_DISJOINT_POINT_GEOMETRY_HPP From f8c0b46d43ecb04773ae6a7d4e9944fdfc84c286 Mon Sep 17 00:00:00 2001 From: Menelaos Karavelas Date: Wed, 21 May 2014 16:35:40 +0300 Subject: [PATCH 09/28] [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 From 4eca30216462a04805d31a15e5b27a1956652db1 Mon Sep 17 00:00:00 2001 From: Menelaos Karavelas Date: Wed, 21 May 2014 16:37:53 +0300 Subject: [PATCH 10/28] [extensions][ttmath] add unary operator-() for ttmath_big (needed for boost::geometry::math::abs) and also add binary operator-() (needed because of the unary overlaod) --- .../geometry/extensions/contrib/ttmath_stub.hpp | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/include/boost/geometry/extensions/contrib/ttmath_stub.hpp b/include/boost/geometry/extensions/contrib/ttmath_stub.hpp index d1383d1db..e2ade189b 100644 --- a/include/boost/geometry/extensions/contrib/ttmath_stub.hpp +++ b/include/boost/geometry/extensions/contrib/ttmath_stub.hpp @@ -116,6 +116,18 @@ struct ttmath_big : ttmath::Big<1,4> : ttmath::Big<1,4>(v) {} + // needed in order to work with boost::geometry::math::abs + inline ttmath_big operator-() const + { + return ttmath::Big<1,4>::operator-(); + } + + // needed because unary operator-() is defined (above) + inline ttmath_big operator-(ttmath_big const& other) const + { + return ttmath::Big<1,4>::operator-(other); + } + /* inline operator double() const { From 0d4eccd51046aec2c0490e797815978ee70ff234 Mon Sep 17 00:00:00 2001 From: Menelaos Karavelas Date: Wed, 21 May 2014 16:42:42 +0300 Subject: [PATCH 11/28] [buffer] remove inclusion of algorithms/detail/disjoint.hpp --- include/boost/geometry/algorithms/buffer.hpp | 1 - 1 file changed, 1 deletion(-) diff --git a/include/boost/geometry/algorithms/buffer.hpp b/include/boost/geometry/algorithms/buffer.hpp index 236c2c147..13d48c0d5 100644 --- a/include/boost/geometry/algorithms/buffer.hpp +++ b/include/boost/geometry/algorithms/buffer.hpp @@ -23,7 +23,6 @@ #include #include -#include #include #include #include From 1d3432f83c979a0a8fbc24a1698aa4e3aaf2d871 Mon Sep 17 00:00:00 2001 From: Menelaos Karavelas Date: Wed, 21 May 2014 16:43:32 +0300 Subject: [PATCH 12/28] [has self intersections] include header with disjoint interrupt policy --- .../boost/geometry/algorithms/detail/has_self_intersections.hpp | 1 + 1 file changed, 1 insertion(+) diff --git a/include/boost/geometry/algorithms/detail/has_self_intersections.hpp b/include/boost/geometry/algorithms/detail/has_self_intersections.hpp index 65a58ee8c..632ec595d 100644 --- a/include/boost/geometry/algorithms/detail/has_self_intersections.hpp +++ b/include/boost/geometry/algorithms/detail/has_self_intersections.hpp @@ -17,6 +17,7 @@ #include #include +#include #include #include #include From a7323f79f44fc0a0e9d8b5aae96b3ff19c9a573d Mon Sep 17 00:00:00 2001 From: Menelaos Karavelas Date: Wed, 21 May 2014 16:44:43 +0300 Subject: [PATCH 13/28] [point on border] replace inclusion of algorithms/detail/disjoint.hpp by algorithms/detail/equals/point_point.hpp --- include/boost/geometry/algorithms/detail/point_on_border.hpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/include/boost/geometry/algorithms/detail/point_on_border.hpp b/include/boost/geometry/algorithms/detail/point_on_border.hpp index 70113ab3a..d99ab3c90 100644 --- a/include/boost/geometry/algorithms/detail/point_on_border.hpp +++ b/include/boost/geometry/algorithms/detail/point_on_border.hpp @@ -26,7 +26,7 @@ #include #include -#include +#include namespace boost { namespace geometry From 957addb5e26e9f096f2381a0e6e8d98d1ea9da44 Mon Sep 17 00:00:00 2001 From: Menelaos Karavelas Date: Wed, 21 May 2014 16:47:45 +0300 Subject: [PATCH 14/28] [set ops P/P] replace inclusion of algorithms/detail/disjoint.hpp by algorithms/detail/equals/point_point.hpp --- .../geometry/algorithms/detail/overlay/pointlike_pointlike.hpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/include/boost/geometry/algorithms/detail/overlay/pointlike_pointlike.hpp b/include/boost/geometry/algorithms/detail/overlay/pointlike_pointlike.hpp index 321a512bf..157f1993a 100644 --- a/include/boost/geometry/algorithms/detail/overlay/pointlike_pointlike.hpp +++ b/include/boost/geometry/algorithms/detail/overlay/pointlike_pointlike.hpp @@ -26,7 +26,7 @@ #include #include -#include +#include #include From 531127252c0381f7e1496b8d2a818538a01213c8 Mon Sep 17 00:00:00 2001 From: Menelaos Karavelas Date: Wed, 21 May 2014 16:49:09 +0300 Subject: [PATCH 15/28] [overlay] replace inclusion of algorithms/detail/disjoint.hpp by algorithms/detail/equals/point_point.hpp --- .../geometry/algorithms/detail/overlay/append_no_duplicates.hpp | 2 +- .../algorithms/detail/overlay/append_no_dups_or_spikes.hpp | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/include/boost/geometry/algorithms/detail/overlay/append_no_duplicates.hpp b/include/boost/geometry/algorithms/detail/overlay/append_no_duplicates.hpp index 37066192a..0fd1fe4de 100644 --- a/include/boost/geometry/algorithms/detail/overlay/append_no_duplicates.hpp +++ b/include/boost/geometry/algorithms/detail/overlay/append_no_duplicates.hpp @@ -13,7 +13,7 @@ #include #include -#include +#include diff --git a/include/boost/geometry/algorithms/detail/overlay/append_no_dups_or_spikes.hpp b/include/boost/geometry/algorithms/detail/overlay/append_no_dups_or_spikes.hpp index b911b6b6d..a785bd608 100644 --- a/include/boost/geometry/algorithms/detail/overlay/append_no_dups_or_spikes.hpp +++ b/include/boost/geometry/algorithms/detail/overlay/append_no_dups_or_spikes.hpp @@ -13,7 +13,7 @@ #include #include -#include +#include namespace boost { namespace geometry From c2cf7215f0bcaf440776305101af626317364c2d Mon Sep 17 00:00:00 2001 From: Menelaos Karavelas Date: Wed, 21 May 2014 16:51:55 +0300 Subject: [PATCH 16/28] [overlay] replace include of algorithms/detail/disjoint.hpp by algorithms/detail/disjoint/box_box.hpp --- .../geometry/algorithms/detail/overlay/self_turn_points.hpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/include/boost/geometry/algorithms/detail/overlay/self_turn_points.hpp b/include/boost/geometry/algorithms/detail/overlay/self_turn_points.hpp index 46d0be3bf..e2a21a0fe 100644 --- a/include/boost/geometry/algorithms/detail/overlay/self_turn_points.hpp +++ b/include/boost/geometry/algorithms/detail/overlay/self_turn_points.hpp @@ -18,7 +18,7 @@ #include -#include +#include #include #include From 1035533676ed8dc4a22eb09f2e2a13a96b4dfca2 Mon Sep 17 00:00:00 2001 From: Menelaos Karavelas Date: Wed, 21 May 2014 16:53:39 +0300 Subject: [PATCH 17/28] [within] replace inclusion of algorithms/detail/disjoint/point_point.hpp by algorithms/detail/equals/point_point.hpp --- .../geometry/algorithms/detail/within/point_in_geometry.hpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/include/boost/geometry/algorithms/detail/within/point_in_geometry.hpp b/include/boost/geometry/algorithms/detail/within/point_in_geometry.hpp index a3841496f..18a46c279 100644 --- a/include/boost/geometry/algorithms/detail/within/point_in_geometry.hpp +++ b/include/boost/geometry/algorithms/detail/within/point_in_geometry.hpp @@ -24,7 +24,7 @@ #include #include -#include +#include #include #include From 050bedec65468ed51522c1e8c0887392d77a3d47 Mon Sep 17 00:00:00 2001 From: Menelaos Karavelas Date: Wed, 21 May 2014 16:55:02 +0300 Subject: [PATCH 18/28] [relate] replace inclusion of algorithms/detail/disjoint/point_point.hpp by algorithms/detail/equals/point_point.hpp --- .../geometry/algorithms/detail/relate/boundary_checker.hpp | 2 +- include/boost/geometry/algorithms/detail/relate/point_point.hpp | 2 +- .../boost/geometry/algorithms/detail/relate/topology_check.hpp | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/include/boost/geometry/algorithms/detail/relate/boundary_checker.hpp b/include/boost/geometry/algorithms/detail/relate/boundary_checker.hpp index 99553b9fe..f98c3e9b8 100644 --- a/include/boost/geometry/algorithms/detail/relate/boundary_checker.hpp +++ b/include/boost/geometry/algorithms/detail/relate/boundary_checker.hpp @@ -15,7 +15,7 @@ #include #include -#include +#include namespace boost { namespace geometry { diff --git a/include/boost/geometry/algorithms/detail/relate/point_point.hpp b/include/boost/geometry/algorithms/detail/relate/point_point.hpp index 3dcff8578..fcbb1d7ee 100644 --- a/include/boost/geometry/algorithms/detail/relate/point_point.hpp +++ b/include/boost/geometry/algorithms/detail/relate/point_point.hpp @@ -14,7 +14,7 @@ #ifndef BOOST_GEOMETRY_ALGORITHMS_DETAIL_RELATE_POINT_POINT_HPP #define BOOST_GEOMETRY_ALGORITHMS_DETAIL_RELATE_POINT_POINT_HPP -#include +#include #include #include diff --git a/include/boost/geometry/algorithms/detail/relate/topology_check.hpp b/include/boost/geometry/algorithms/detail/relate/topology_check.hpp index 9c343727a..98b857a48 100644 --- a/include/boost/geometry/algorithms/detail/relate/topology_check.hpp +++ b/include/boost/geometry/algorithms/detail/relate/topology_check.hpp @@ -13,7 +13,7 @@ #include -#include +#include #include namespace boost { namespace geometry { From c29c4cd246af19986e4539871bf8ba88d16b6580 Mon Sep 17 00:00:00 2001 From: Menelaos Karavelas Date: Wed, 21 May 2014 16:56:57 +0300 Subject: [PATCH 19/28] [strategies] replace inclusion of algorithms/detail/disjoint/point_point.hpp by algorithms/detail/equals/point_point.hpp --- include/boost/geometry/strategies/agnostic/point_in_point.hpp | 2 +- include/boost/geometry/strategies/cartesian/cart_intersect.hpp | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/include/boost/geometry/strategies/agnostic/point_in_point.hpp b/include/boost/geometry/strategies/agnostic/point_in_point.hpp index 8ef2a5d2c..e4f9bec4c 100644 --- a/include/boost/geometry/strategies/agnostic/point_in_point.hpp +++ b/include/boost/geometry/strategies/agnostic/point_in_point.hpp @@ -11,7 +11,7 @@ #ifndef BOOST_GEOMETRY_STRATEGY_AGNOSTIC_POINT_IN_POINT_HPP #define BOOST_GEOMETRY_STRATEGY_AGNOSTIC_POINT_IN_POINT_HPP -#include +#include #include #include diff --git a/include/boost/geometry/strategies/cartesian/cart_intersect.hpp b/include/boost/geometry/strategies/cartesian/cart_intersect.hpp index fa939cd23..66af2d2e9 100644 --- a/include/boost/geometry/strategies/cartesian/cart_intersect.hpp +++ b/include/boost/geometry/strategies/cartesian/cart_intersect.hpp @@ -20,7 +20,7 @@ #include #include #include -#include +#include #include #include From 90ac851e4e608ff6941017a3641a4f8692bd888a Mon Sep 17 00:00:00 2001 From: Menelaos Karavelas Date: Wed, 21 May 2014 17:06:36 +0300 Subject: [PATCH 20/28] [disjoint] add missing includes --- .../detail/disjoint/linear_linear.hpp | 1 + .../detail/disjoint/point_geometry.hpp | 1 + test/algorithms/disjoint_coverage.cpp | 1343 +++++++++++++++++ 3 files changed, 1345 insertions(+) create mode 100644 test/algorithms/disjoint_coverage.cpp diff --git a/include/boost/geometry/algorithms/detail/disjoint/linear_linear.hpp b/include/boost/geometry/algorithms/detail/disjoint/linear_linear.hpp index 9cef8eaf5..0eab4c649 100644 --- a/include/boost/geometry/algorithms/detail/disjoint/linear_linear.hpp +++ b/include/boost/geometry/algorithms/detail/disjoint/linear_linear.hpp @@ -34,6 +34,7 @@ #include #include +#include #include #include diff --git a/include/boost/geometry/algorithms/detail/disjoint/point_geometry.hpp b/include/boost/geometry/algorithms/detail/disjoint/point_geometry.hpp index a58bff41d..77234e0d4 100644 --- a/include/boost/geometry/algorithms/detail/disjoint/point_geometry.hpp +++ b/include/boost/geometry/algorithms/detail/disjoint/point_geometry.hpp @@ -24,6 +24,7 @@ #include #include +#include #include diff --git a/test/algorithms/disjoint_coverage.cpp b/test/algorithms/disjoint_coverage.cpp new file mode 100644 index 000000000..4fa1462be --- /dev/null +++ b/test/algorithms/disjoint_coverage.cpp @@ -0,0 +1,1343 @@ +// Boost.Geometry (aka GGL, Generic Geometry Library) + +// Copyright (c) 2014, Oracle and/or its affiliates. + +// Licensed under the Boost Software License version 1.0. +// http://www.boost.org/users/license.html + +// Contributed and/or modified by Menelaos Karavelas, on behalf of Oracle + +#ifndef BOOST_TEST_MODULE +#define BOOST_TEST_MODULE test_disjoint_coverage +#endif + +// unit test to test disjoint for all geometry combinations + +#include + +#include + +// general support; THIS HEADER SHOULD GO AWAY +#include + +// support for multi; THIS HEADER SHOULD GO AWAY +//#include + +#include +#include +#include + +// I should not need to include this +#include + +#include +#include +#include +#include +#include + +#include +#include +#include +#include +#include + +#include +#include +#include + +#include +#include + +#include "from_wkt.hpp" + + +#ifdef HAVE_TTMATH +#include +#endif + +namespace bg = ::boost::geometry; + +//============================================================================ + +template ::type> +struct pretty_print_geometry +{ + static inline std::ostream& apply(Geometry const& geometry) + { + std::cout << bg::wkt(geometry); + return std::cout; + } +}; + +template +struct pretty_print_geometry +{ + static inline std::ostream& apply(Segment const& segment) + { + std::cout << "SEGMENT" << bg::dsv(segment); + return std::cout; + } +}; + +template +struct pretty_print_geometry +{ + static inline std::ostream& apply(Ring const& ring) + { + std::cout << "RING" << bg::dsv(ring); + return std::cout; + } +}; + +template +struct pretty_print_geometry +{ + static inline std::ostream& apply(Box const& box) + { + std::cout << "BOX" << bg::dsv(box); + return std::cout; + } +}; + +//============================================================================ + +struct test_disjoint +{ + template + static inline void apply(Geometry1 const& geometry1, + Geometry2 const& geometry2, + bool expected_result) + { + bool result = bg::disjoint(geometry1, geometry2); + BOOST_CHECK( result == expected_result ); + + result = bg::disjoint(geometry2, geometry1); + BOOST_CHECK( result == expected_result ); + +#ifdef GEOMETRY_TEST_DEBUG + std::cout << "G1 - G2: "; + pretty_print_geometry::apply(geometry1) << " - "; + pretty_print_geometry::apply(geometry2) << std::endl; + std::cout << std::boolalpha; + std::cout << "expected/computed result: " + << expected_result << " / " << result << std::endl; + std::cout << std::endl; + std::cout << std::noboolalpha; +#endif + } +}; + +//============================================================================ + +// pointlike-pointlike geometries +template +inline void test_point_point() +{ + typedef test_disjoint tester; + + tester::apply(from_wkt

("POINT(0 0)"), + from_wkt

("POINT(0 0)"), + false); + + tester::apply(from_wkt

("POINT(0 0)"), + from_wkt

("POINT(1 1)"), + true); +} + +template +inline void test_point_multipoint() +{ + typedef bg::model::multi_point

MP; + + typedef test_disjoint tester; + + tester::apply(from_wkt

("POINT(0 0)"), + from_wkt("MULTIPOINT(0 0,1 1)"), + false); + + tester::apply(from_wkt

("POINT(0 0)"), + from_wkt("MULTIPOINT(1 1,2 2)"), + true); +} + +template +inline void test_multipoint_multipoint() +{ + typedef bg::model::multi_point

MP; + + typedef test_disjoint tester; + + tester::apply(from_wkt("MULTIPOINT(0 0,1 0)"), + from_wkt("MULTIPOINT(0 0,1 1)"), + false); + + tester::apply(from_wkt("MULTIPOINT(0 0,1 0)"), + from_wkt("MULTIPOINT(1 1,2 2)"), + true); +} + +//============================================================================ + +// pointlike-linear geometries +template +inline void test_point_segment() +{ + typedef test_disjoint tester; + typedef bg::model::segment

S; + + tester::apply(from_wkt

("POINT(0 0)"), + from_wkt("SEGMENT(0 0,2 0)"), + false); + + tester::apply(from_wkt

("POINT(1 0)"), + from_wkt("SEGMENT(0 0,2 0)"), + false); + + tester::apply(from_wkt

("POINT(1 1)"), + from_wkt("SEGMENT(0 0,2 0)"), + true); +} + +template +inline void test_point_linestring() +{ + typedef bg::model::linestring

L; + + typedef test_disjoint tester; + + tester::apply(from_wkt

("POINT(0 0)"), + from_wkt("LINESTRING(0 0,2 2,4 4)"), + false); + + tester::apply(from_wkt

("POINT(1 1)"), + from_wkt("LINESTRING(0 0,2 2,4 4)"), + false); + + tester::apply(from_wkt

("POINT(3 3)"), + from_wkt("LINESTRING(0 0,2 2,4 4)"), + false); + + tester::apply(from_wkt

("POINT(1 0)"), + from_wkt("LINESTRING(0 0,2 2,4 4)"), + true); +} + +template +inline void test_point_multilinestring() +{ + typedef bg::model::linestring

L; + typedef bg::model::multi_linestring ML; + + typedef test_disjoint tester; + + tester::apply(from_wkt

("POINT(0 1)"), + from_wkt("MULTILINESTRING((0 0,2 2,4 4),(0 0,2 0,4 0))"), + true); + + tester::apply(from_wkt

("POINT(0 0)"), + from_wkt("MULTILINESTRING((0 0,2 2,4 4),(0 0,2 0,4 0))"), + false); + + tester::apply(from_wkt

("POINT(1 1)"), + from_wkt("MULTILINESTRING((0 0,2 2,4 4),(0 0,2 0,4 0))"), + false); + + tester::apply(from_wkt

("POINT(1 0)"), + from_wkt("MULTILINESTRING((0 0,2 2,4 4),(0 0,2 0,4 0))"), + false); +} + +template +inline void test_multipoint_segment() +{ + typedef test_disjoint tester; + typedef bg::model::multi_point

MP; + typedef bg::model::segment

S; + + tester::apply(from_wkt("MULTIPOINT(0 0,1 1)"), + from_wkt("SEGMENT(0 0,2 0)"), + false); + + tester::apply(from_wkt("MULTIPOINT(1 0,1 1)"), + from_wkt("SEGMENT(0 0,2 0)"), + false); + + tester::apply(from_wkt("MULTIPOINT(1 1,2 2)"), + from_wkt("SEGMENT(0 0,2 0)"), + true); +} + +template +inline void test_multipoint_linestring() +{ + typedef bg::model::multi_point

MP; + typedef bg::model::linestring

L; + + typedef test_disjoint tester; + + tester::apply(from_wkt("MULTIPOINT(0 0,1 0)"), + from_wkt("LINESTRING(0 0,2 2,4 4)"), + false); + + tester::apply(from_wkt("MULTIPOINT(1 0,1 1)"), + from_wkt("LINESTRING(0 0,2 2,4 4)"), + false); + + tester::apply(from_wkt("MULTIPOINT(1 0,3 3)"), + from_wkt("LINESTRING(0 0,2 2,4 4)"), + false); + + tester::apply(from_wkt("MULTIPOINT(1 0,2 0)"), + from_wkt("LINESTRING(0 0,2 2,4 4)"), + true); +} + +template +inline void test_multipoint_multilinestring() +{ + typedef bg::model::multi_point

MP; + typedef bg::model::linestring

L; + typedef bg::model::multi_linestring ML; + + typedef test_disjoint tester; + + tester::apply(from_wkt("MULTIPOINT(0 1,0 2)"), + from_wkt("MULTILINESTRING((0 0,2 2,4 4),(0 0,2 0,4 0))"), + true); + + tester::apply(from_wkt("POINT(0 0,1 0)"), + from_wkt("MULTILINESTRING((0 0,2 2,4 4),(0 0,2 0,4 0))"), + false); + + tester::apply(from_wkt("POINT(0 1,1 1)"), + from_wkt("MULTILINESTRING((0 0,2 2,4 4),(0 0,2 0,4 0))"), + false); + + tester::apply(from_wkt("POINT(0 1,1 0)"), + from_wkt("MULTILINESTRING((0 0,2 2,4 4),(0 0,2 0,4 0))"), + false); +} + +//============================================================================ + +// pointlike-areal geometries +template +inline void test_point_box() +{ + typedef test_disjoint tester; + typedef bg::model::box

B; + + tester::apply(from_wkt

("POINT(0 0)"), + from_wkt("BOX(0 0,1 1)"), + false); + + tester::apply(from_wkt

("POINT(2 2)"), + from_wkt("BOX(0 0,1 0)"), + true); +} + +template +inline void test_point_ring() +{ + typedef bg::model::ring R; // ccw, open + + typedef test_disjoint tester; + + tester::apply(from_wkt

("POINT(0 0)"), + from_wkt("POLYGON((0 0,1 0,0 1))"), + false); + + tester::apply(from_wkt

("POINT(1 1)"), + from_wkt("POLYGON((0 0,1 0,0 1))"), + true); +} + +template +inline void test_point_polygon() +{ + typedef bg::model::polygon PL; // ccw, open + + typedef test_disjoint tester; + + tester::apply(from_wkt

("POINT(0 0)"), + from_wkt("POLYGON((0 0,1 0,0 1))"), + false); + + tester::apply(from_wkt

("POINT(1 1)"), + from_wkt("POLYGON((0 0,1 0,0 1))"), + true); +} + +template +inline void test_point_multipolygon() +{ + typedef bg::model::polygon

PL; + typedef bg::model::multi_polygon MPL; + + typedef test_disjoint tester; + + tester::apply(from_wkt

("POINT(0 0)"), + from_wkt("MULTIPOLYGON(((0 0,1 0,0 1)),((2 0,3 0,2 1)))"), + false); + + tester::apply(from_wkt

("POINT(1 1)"), + from_wkt("MULTIPOLYGON(((0 0,1 0,0 1)),((2 0,3 0,2 1)))"), + true); +} + +template +inline void test_multipoint_box() +{ + typedef test_disjoint tester; + typedef bg::model::multi_point

MP; + typedef bg::model::box

B; + + tester::apply(from_wkt("MULTIPOINT(0 0,1 1)"), + from_wkt("BOX(0 0,2 2)"), + false); + + tester::apply(from_wkt("MULTIPOINT(1 1,3 3)"), + from_wkt("BOX(0 0,2 2)"), + false); + + tester::apply(from_wkt("MULTIPOINT(3 3,4 4)"), + from_wkt("BOX(0 0,2 2)"), + true); +} + +template +inline void test_multipoint_ring() +{ + typedef bg::model::multi_point

MP; + typedef bg::model::ring R; // ccw, open + + typedef test_disjoint tester; + + tester::apply(from_wkt("MULTIPOINT(0 0,1 0)"), + from_wkt("POLYGON((0 0,1 0,0 1))"), + false); + + tester::apply(from_wkt("MULTIPOINT(1 0,1 1)"), + from_wkt("POLYGON((0 0,1 0,0 1))"), + false); + + tester::apply(from_wkt("MULTIPOINT(1 1,2 2)"), + from_wkt("POLYGON((0 0,1 0,0 1))"), + true); +} + +template +inline void test_multipoint_polygon() +{ + typedef bg::model::multi_point

MP; + typedef bg::model::polygon PL; // ccw, open + + typedef test_disjoint tester; + + tester::apply(from_wkt("MULTIPOINT(0 0,1 0)"), + from_wkt("POLYGON(((0 0,1 0,0 1)))"), + false); + + tester::apply(from_wkt("MULTIPOINT(0 0,2 0)"), + from_wkt("POLYGON(((0 0,1 0,0 1)))"), + false); + + tester::apply(from_wkt("MULTIPOINT(1 1,2 0)"), + from_wkt("POLYGON(((0 0,1 0,0 1)))"), + true); + + tester::apply(from_wkt("MULTIPOINT(1 1,2 3)"), + from_wkt("POLYGON(((0 0,1 0,0 1)))"), + true); +} + +template +inline void test_multipoint_multipolygon() +{ + typedef bg::model::multi_point

MP; + typedef bg::model::polygon PL; // ccw, open + typedef bg::model::multi_polygon MPL; + + typedef test_disjoint tester; + + tester::apply(from_wkt("MULTIPOINT(0 0,2 0)"), + from_wkt("MULTIPOLYGON((0 0,1 0,0 1)),(2 0,3 0,2 1))"), + false); + + tester::apply(from_wkt("MULTIPOINT(0 0,1 0)"), + from_wkt("MULTIPOLYGON((0 0,1 0,0 1)),(2 0,3 0,2 1))"), + false); + + tester::apply(from_wkt("MULTIPOINT(1 1,2 0)"), + from_wkt("MULTIPOLYGON((0 0,1 0,0 1)),(2 0,3 0,2 1))"), + false); + + tester::apply(from_wkt("MULTIPOINT(1 1,2 3)"), + from_wkt("MULTIPOLYGON((0 0,1 0,0 1)),(2 0,3 0,2 1))"), + true); +} + +//============================================================================ + +// linear-linear geometries +template +inline void test_segment_segment() +{ + typedef bg::model::segment

S; + + typedef test_disjoint tester; + + tester::apply(from_wkt("SEGMENT(0 0,2 0)"), + from_wkt("SEGMENT(0 0,0 2)"), + false); + + tester::apply(from_wkt("SEGMENT(0 0,2 0)"), + from_wkt("SEGMENT(2 0,3 0)"), + false); + + tester::apply(from_wkt("SEGMENT(0 0,2 0)"), + from_wkt("SEGMENT(1 0,3 0)"), + false); + + tester::apply(from_wkt("SEGMENT(0 0,2 0)"), + from_wkt("SEGMENT(1 0,1 1)"), + false); + + tester::apply(from_wkt("SEGMENT(0 0,2 0)"), + from_wkt("SEGMENT(1 1,2 2)"), + true); +} + +template +inline void test_linestring_segment() +{ + typedef bg::model::segment

S; + typedef bg::model::linestring

L; + + typedef test_disjoint tester; + + tester::apply(from_wkt("SEGMENT(0 0,2 0)"), + from_wkt("LINESTRING(0 0,0 2)"), + false); + + tester::apply(from_wkt("SEGMENT(0 0,2 0)"), + from_wkt("LINESTRING(2 0,3 0)"), + false); + + tester::apply(from_wkt("SEGMENT(0 0,2 0)"), + from_wkt("LINESTRING(1 0,3 0)"), + false); + + tester::apply(from_wkt("SEGMENT(0 0,2 0)"), + from_wkt("LINESTRING(1 0,1 1)"), + false); + + tester::apply(from_wkt("SEGMENT(0 0,2 0)"), + from_wkt("LINESTRING(1 1,2 2)"), + true); +} + +template +inline void test_multilinestring_segment() +{ + typedef bg::model::segment

S; + typedef bg::model::linestring

L; + typedef bg::model::multi_linestring ML; + + typedef test_disjoint tester; + + tester::apply(from_wkt("SEGMENT(0 0,2 0)"), + from_wkt("MULTILINESTRING((0 0,0 2))"), + false); + + tester::apply(from_wkt("SEGMENT(0 0,2 0)"), + from_wkt("MULTILINESTRING((2 0,3 0))"), + false); + + tester::apply(from_wkt("SEGMENT(0 0,2 0)"), + from_wkt("MULTILINESTRING((1 0,3 0))"), + false); + + tester::apply(from_wkt("SEGMENT(0 0,2 0)"), + from_wkt("MULTILINESTRING((1 0,1 1))"), + false); + + tester::apply(from_wkt("SEGMENT(0 0,2 0)"), + from_wkt("MULTILINESTRING((1 1,2 2))"), + true); +} + +template +inline void test_linestring_linestring() +{ + typedef bg::model::linestring

L; + + typedef test_disjoint tester; + + tester::apply(from_wkt("LINESTRING(0 0,2 0)"), + from_wkt("LINESTRING(0 0,0 2)"), + false); + + tester::apply(from_wkt("LINESTRING(0 0,2 0)"), + from_wkt("LINESTRING(2 0,3 0)"), + false); + + tester::apply(from_wkt("LINESTRING(0 0,2 0)"), + from_wkt("LINESTRING(1 0,3 0)"), + false); + + tester::apply(from_wkt("LINESTRING(0 0,2 0)"), + from_wkt("LINESTRING(1 0,1 1)"), + false); + + tester::apply(from_wkt("LINESTRING(0 0,2 0)"), + from_wkt("LINESTRING(1 1,2 2)"), + true); +} + +template +inline void test_linestring_multilinestring() +{ + typedef bg::model::linestring

L; + typedef bg::model::multi_linestring ML; + + typedef test_disjoint tester; + + tester::apply(from_wkt("LINESTRING(0 0,2 0)"), + from_wkt("MULTILINESTRING((0 0,0 2))"), + false); + + tester::apply(from_wkt("LINESTRING(0 0,2 0)"), + from_wkt("MULTILINESTRING((2 0,3 0))"), + false); + + tester::apply(from_wkt("LINESTRING(0 0,2 0)"), + from_wkt("MULTILINESTRING((1 0,3 0))"), + false); + + tester::apply(from_wkt("LINESTRING(0 0,2 0)"), + from_wkt("MULTILINESTRING((1 0,1 1))"), + false); + + tester::apply(from_wkt("LINESTRING(0 0,2 0)"), + from_wkt("MULTILINESTRING((1 1,2 2))"), + true); +} + +template +inline void test_multilinestring_multilinestring() +{ + typedef bg::model::linestring

L; + typedef bg::model::multi_linestring ML; + + typedef test_disjoint tester; + + tester::apply(from_wkt("MULTILINESTRING((0 0,2 0))"), + from_wkt("MULTILINESTRING((0 0,0 2))"), + false); + + tester::apply(from_wkt("MULTILINESTRING((0 0,2 0))"), + from_wkt("MULTILINESTRING((2 0,3 0))"), + false); + + tester::apply(from_wkt("MULTILINESTRING((0 0,2 0))"), + from_wkt("MULTILINESTRING((1 0,3 0))"), + false); + + tester::apply(from_wkt("MULTILINESTRING((0 0,2 0))"), + from_wkt("MULTILINESTRING((1 0,1 1))"), + false); + + tester::apply(from_wkt("MULTILINESTRING((0 0,2 0))"), + from_wkt("MULTILINESTRING((1 1,2 2))"), + true); +} + +//============================================================================ + +// linear-areal geometries +template +inline void test_segment_box() +{ + typedef bg::model::segment

S; + typedef bg::model::box

B; + + typedef test_disjoint tester; + + tester::apply(from_wkt("SEGMENT(0 0,2 0)"), + from_wkt("BOX(0 0,2 2)"), + false); + + tester::apply(from_wkt("SEGMENT(1 1,3 3)"), + from_wkt("BOX(0 0,2 2)"), + false); + + tester::apply(from_wkt("SEGMENT(2 2,3 3)"), + from_wkt("BOX(0 0,2 2)"), + false); + + tester::apply(from_wkt("SEGMENT(4 4,3 3)"), + from_wkt("BOX(0 0,2 2)"), + true); + + tester::apply(from_wkt("SEGMENT(0 4,4 4)"), + from_wkt("BOX(0 0,2 2)"), + true); + + tester::apply(from_wkt("SEGMENT(4 0,4 4)"), + from_wkt("BOX(0 0,2 2)"), + true); +} + +template +inline void test_segment_ring() +{ + typedef bg::model::segment

S; + typedef bg::model::ring R; // ccw, open + + typedef test_disjoint tester; + + tester::apply(from_wkt("SEGMENT(0 0,2 0)"), + from_wkt("POLYGON((0 0,2 0,0 2))"), + false); + + tester::apply(from_wkt("SEGMENT(1 0,3 3)"), + from_wkt("POLYGON((0 0,2 0,0 2))"), + false); + + tester::apply(from_wkt("SEGMENT(1 1,3 3)"), + from_wkt("POLYGON((0 0,2 0,0 2))"), + false); + + tester::apply(from_wkt("SEGMENT(2 2,3 3)"), + from_wkt("POLYGON((0 0,2 0,0 2))"), + true); +} + +template +inline void test_segment_polygon() +{ + typedef bg::model::segment

S; + typedef bg::model::polygon PL; // ccw, open + + typedef test_disjoint tester; + + tester::apply(from_wkt("SEGMENT(0 0,2 0)"), + from_wkt("POLYGON((0 0,2 0,0 2))"), + false); + + tester::apply(from_wkt("SEGMENT(1 0,3 3)"), + from_wkt("POLYGON((0 0,2 0,0 2))"), + false); + + tester::apply(from_wkt("SEGMENT(1 1,3 3)"), + from_wkt("POLYGON((0 0,2 0,0 2))"), + false); + + tester::apply(from_wkt("SEGMENT(2 2,3 3)"), + from_wkt("POLYGON((0 0,2 0,0 2))"), + true); +} + +template +inline void test_segment_multipolygon() +{ + typedef bg::model::segment

S; + typedef bg::model::polygon PL; // ccw, open + typedef bg::model::multi_polygon MPL; + + typedef test_disjoint tester; + + tester::apply(from_wkt("SEGMENT(0 0,2 0)"), + from_wkt("MULTIPOLYGON(((0 0,2 0,0 2)))"), + false); + + tester::apply(from_wkt("SEGMENT(1 0,3 3)"), + from_wkt("MULTIPOLYGON(((0 0,2 0,0 2)))"), + false); + + tester::apply(from_wkt("SEGMENT(1 1,3 3)"), + from_wkt("MULTIPOLYGON(((0 0,2 0,0 2)))"), + false); + + tester::apply(from_wkt("SEGMENT(2 2,3 3)"), + from_wkt("MULTIPOLYGON(((0 0,2 0,0 2)))"), + true); +} + +template +inline void test_linestring_box() +{ + typedef bg::model::linestring

L; + typedef bg::model::box

B; + + typedef test_disjoint tester; + + tester::apply(from_wkt("LINESTRING(0 0,2 0)"), + from_wkt("BOX(0 0,2 2)"), + false); + + tester::apply(from_wkt("LINESTRING(1 1,3 3)"), + from_wkt("BOX(0 0,2 2)"), + false); + + tester::apply(from_wkt("LINESTRING(2 2,3 3)"), + from_wkt("BOX(0 0,2 2)"), + false); + + tester::apply(from_wkt("LINESTRING(4 4,3 3)"), + from_wkt("BOX(0 0,2 2)"), + true); +} + +template +inline void test_linestring_ring() +{ + typedef bg::model::linestring

L; + typedef bg::model::ring R; // ccw, open + + typedef test_disjoint tester; + + tester::apply(from_wkt("LINESTRING(0 0,2 0)"), + from_wkt("POLYGON((0 0,2 0,0 2))"), + false); + + tester::apply(from_wkt("LINESTRING(1 0,3 3)"), + from_wkt("POLYGON((0 0,2 0,0 2))"), + false); + + tester::apply(from_wkt("LINESTRING(1 1,3 3)"), + from_wkt("POLYGON((0 0,2 0,0 2))"), + false); + + tester::apply(from_wkt("LINESTRING(2 2,3 3)"), + from_wkt("POLYGON((0 0,2 0,0 2))"), + true); +} + +template +inline void test_linestring_polygon() +{ + typedef bg::model::linestring

L; + typedef bg::model::polygon PL; // ccw, open + + typedef test_disjoint tester; + + tester::apply(from_wkt("LINESTRING(0 0,2 0)"), + from_wkt("POLYGON((0 0,2 0,0 2))"), + false); + + tester::apply(from_wkt("LINESTRING(1 0,3 3)"), + from_wkt("POLYGON((0 0,2 0,0 2))"), + false); + + tester::apply(from_wkt("LINESTRING(1 1,3 3)"), + from_wkt("POLYGON((0 0,2 0,0 2))"), + false); + + tester::apply(from_wkt("LINESTRING(2 2,3 3)"), + from_wkt("POLYGON((0 0,2 0,0 2))"), + true); +} + +template +inline void test_linestring_multipolygon() +{ + typedef bg::model::linestring

L; + typedef bg::model::polygon PL; // ccw, open + typedef bg::model::multi_polygon MPL; + + typedef test_disjoint tester; + + tester::apply(from_wkt("LINESTRING(0 0,2 0)"), + from_wkt("MULTIPOLYGON(((0 0,2 0,0 2)))"), + false); + + tester::apply(from_wkt("LINESTRING(1 0,3 3)"), + from_wkt("MULTIPOLYGON(((0 0,2 0,0 2)))"), + false); + + tester::apply(from_wkt("LINESTRING(1 1,3 3)"), + from_wkt("MULTIPOLYGON(((0 0,2 0,0 2)))"), + false); + + tester::apply(from_wkt("LINESTRING(2 2,3 3)"), + from_wkt("MULTIPOLYGON(((0 0,2 0,0 2)))"), + true); +} + +template +inline void test_multilinestring_box() +{ + typedef bg::model::linestring

L; + typedef bg::model::multi_linestring ML; + typedef bg::model::box

B; + + typedef test_disjoint tester; + + tester::apply(from_wkt("MULTILINESTRING((0 0,2 0))"), + from_wkt("BOX(0 0,2 2)"), + false); + + tester::apply(from_wkt("MULTILINESTRING((1 1,3 3))"), + from_wkt("BOX(0 0,2 2)"), + false); + + tester::apply(from_wkt("MULTILINESTRING((2 2,3 3))"), + from_wkt("BOX(0 0,2 2)"), + false); + + tester::apply(from_wkt("MULTILINESTRING((4 4,3 3))"), + from_wkt("BOX(0 0,2 2)"), + true); +} + +template +inline void test_multilinestring_ring() +{ + typedef bg::model::linestring

L; + typedef bg::model::multi_linestring ML; + typedef bg::model::ring R; // ccw, open + + typedef test_disjoint tester; + + tester::apply(from_wkt("MULTILINESTRING((0 0,2 0))"), + from_wkt("POLYGON((0 0,2 0,0 2))"), + false); + + tester::apply(from_wkt("MULTILINESTRING((1 0,3 3))"), + from_wkt("POLYGON((0 0,2 0,0 2))"), + false); + + tester::apply(from_wkt("MULTILINESTRING((1 1,3 3))"), + from_wkt("POLYGON((0 0,2 0,0 2))"), + false); + + tester::apply(from_wkt("MULTILINESTRING((2 2,3 3))"), + from_wkt("POLYGON((0 0,2 0,0 2))"), + true); +} + +template +inline void test_multilinestring_polygon() +{ + typedef bg::model::linestring

L; + typedef bg::model::multi_linestring ML; + typedef bg::model::polygon PL; // ccw, open + + typedef test_disjoint tester; + + tester::apply(from_wkt("MULTILINESTRING((0 0,2 0))"), + from_wkt("POLYGON((0 0,2 0,0 2))"), + false); + + tester::apply(from_wkt("MULTILINESTRING((1 0,3 3))"), + from_wkt("POLYGON((0 0,2 0,0 2))"), + false); + + tester::apply(from_wkt("MULTILINESTRING((1 1,3 3))"), + from_wkt("POLYGON((0 0,2 0,0 2))"), + false); + + tester::apply(from_wkt("MULTILINESTRING((2 2,3 3))"), + from_wkt("POLYGON((0 0,2 0,0 2))"), + true); +} + +template +inline void test_multilinestring_multipolygon() +{ + typedef bg::model::linestring

L; + typedef bg::model::multi_linestring ML; + typedef bg::model::polygon PL; // ccw, open + typedef bg::model::multi_polygon MPL; + + typedef test_disjoint tester; + + tester::apply(from_wkt("MULTILINESTRING((0 0,2 0))"), + from_wkt("MULTIPOLYGON(((0 0,2 0,0 2)))"), + false); + + tester::apply(from_wkt("MULTILINESTRING((1 0,3 3))"), + from_wkt("MULTIPOLYGON(((0 0,2 0,0 2)))"), + false); + + tester::apply(from_wkt("MULTILINESTRING((1 1,3 3))"), + from_wkt("MULTIPOLYGON(((0 0,2 0,0 2)))"), + false); + + tester::apply(from_wkt("MULTILINESTRING((2 2,3 3))"), + from_wkt("MULTIPOLYGON(((0 0,2 0,0 2)))"), + true); +} + +//============================================================================ + +// areal-areal geometries +template +inline void test_box_box() +{ + typedef bg::model::box

B; + + typedef test_disjoint tester; + + tester::apply(from_wkt("BOX(2 2,3 3)"), + from_wkt("BOX(0 0,2 2)"), + false); + + tester::apply(from_wkt("BOX(1 1,3 3)"), + from_wkt("BOX(0 0,2 2)"), + false); + + tester::apply(from_wkt("BOX(3 3,4 4)"), + from_wkt("BOX(0 0,2 2)"), + true); +} + +template +inline void test_ring_box() +{ + typedef bg::model::box

B; + typedef bg::model::ring R; // ccw, open + + typedef test_disjoint tester; + + tester::apply(from_wkt("BOX(2 2,3 3)"), + from_wkt("POLYGON((0 0,2 0,2 2,0 2))"), + false); + + tester::apply(from_wkt("BOX(1 1,3 3)"), + from_wkt("POLYGON((0 0,2 0,2 2,0 2))"), + false); + + tester::apply(from_wkt("BOX(3 3,4 4)"), + from_wkt("POLYGON((0 0,2 0,2 2,0 2))"), + true); +} + +template +inline void test_polygon_box() +{ + typedef bg::model::box

B; + typedef bg::model::polygon PL; // ccw, open + + typedef test_disjoint tester; + + tester::apply(from_wkt("BOX(2 2,3 3)"), + from_wkt("POLYGON((0 0,2 0,2 2,0 2))"), + false); + + tester::apply(from_wkt("BOX(1 1,3 3)"), + from_wkt("POLYGON((0 0,2 0,2 2,0 2))"), + false); + + tester::apply(from_wkt("BOX(3 3,4 4)"), + from_wkt("POLYGON((0 0,2 0,2 2,0 2))"), + true); +} + +template +inline void test_multipolygon_box() +{ + typedef bg::model::box

B; + typedef bg::model::polygon PL; // ccw, open + typedef bg::model::multi_polygon MPL; + + typedef test_disjoint tester; + + tester::apply(from_wkt("BOX(2 2,3 3)"), + from_wkt("MULTIPOLYGON(((0 0,2 0,2 2,0 2)))"), + false); + + tester::apply(from_wkt("BOX(1 1,3 3)"), + from_wkt("MULTIPOLYGON(((0 0,2 0,2 2,0 2)))"), + false); + + tester::apply(from_wkt("BOX(3 3,4 4)"), + from_wkt("MULTIPOLYGON(((0 0,2 0,2 2,0 2)))"), + true); +} + +template +inline void test_ring_ring() +{ + typedef bg::model::ring R; // ccw, open + + typedef test_disjoint tester; + + tester::apply(from_wkt("POLYGON((2 2,2 3,3 3,3 2))"), + from_wkt("POLYGON((0 0,2 0,2 2,0 2))"), + false); + + tester::apply(from_wkt("POLYGON((1 1,1 3,3 3,3 1))"), + from_wkt("POLYGON((0 0,2 0,2 2,0 2))"), + false); + + tester::apply(from_wkt("POLYGON((3 3,3 4,4 4,4 3))"), + from_wkt("POLYGON((0 0,2 0,2 2,0 2))"), + true); +} + +template +inline void test_polygon_ring() +{ + typedef bg::model::ring R; // ccw, open + typedef bg::model::polygon PL; // ccw, open + + typedef test_disjoint tester; + + tester::apply(from_wkt("POLYGON((2 2,2 3,3 3,3 2))"), + from_wkt("POLYGON((0 0,2 0,2 2,0 2))"), + false); + + tester::apply(from_wkt("POLYGON((1 1,1 3,3 3,3 1))"), + from_wkt("POLYGON((0 0,2 0,2 2,0 2))"), + false); + + tester::apply(from_wkt("POLYGON((3 3,3 4,4 4,4 3))"), + from_wkt("POLYGON((0 0,2 0,2 2,0 2))"), + true); +} + +template +inline void test_multipolygon_ring() +{ + typedef bg::model::ring R; // ccw, open + typedef bg::model::polygon PL; // ccw, open + typedef bg::model::multi_polygon MPL; + + typedef test_disjoint tester; + + tester::apply(from_wkt("POLYGON((2 2,2 3,3 3,3 2))"), + from_wkt("MULTIPOLYGON(((0 0,2 0,2 2,0 2)))"), + false); + + tester::apply(from_wkt("POLYGON((1 1,1 3,3 3,3 1))"), + from_wkt("MULTIPOLYGON(((0 0,2 0,2 2,0 2)))"), + false); + + tester::apply(from_wkt("POLYGON((3 3,3 4,4 4,4 3))"), + from_wkt("MULTIPOLYGON(((0 0,2 0,2 2,0 2)))"), + true); +} + +template +inline void test_polygon_polygon() +{ + typedef bg::model::polygon PL; // ccw, open + + typedef test_disjoint tester; + + tester::apply(from_wkt("POLYGON((2 2,2 3,3 3,3 2))"), + from_wkt("POLYGON((0 0,2 0,2 2,0 2))"), + false); + + tester::apply(from_wkt("POLYGON((1 1,1 3,3 3,3 1))"), + from_wkt("POLYGON((0 0,2 0,2 2,0 2))"), + false); + + tester::apply(from_wkt("POLYGON((3 3,3 4,4 4,4 3))"), + from_wkt("POLYGON((0 0,2 0,2 2,0 2))"), + true); +} + +template +inline void test_polygon_multipolygon() +{ + typedef bg::model::polygon PL; // ccw, open + typedef bg::model::multi_polygon MPL; + + typedef test_disjoint tester; + + tester::apply(from_wkt("POLYGON((2 2,2 3,3 3,3 2))"), + from_wkt("MULTIPOLYGON(((0 0,2 0,2 2,0 2)))"), + false); + + tester::apply(from_wkt("POLYGON((1 1,1 3,3 3,3 1))"), + from_wkt("MULTIPOLYGON(((0 0,2 0,2 2,0 2)))"), + false); + + tester::apply(from_wkt("POLYGON((3 3,3 4,4 4,4 3))"), + from_wkt("MULTIPOLYGON(((0 0,2 0,2 2,0 2)))"), + true); +} + +template +inline void test_multipolygon_multipolygon() +{ + typedef bg::model::polygon PL; // ccw, open + typedef bg::model::multi_polygon MPL; + + typedef test_disjoint tester; + + tester::apply(from_wkt("MULTIPOLYGON(((2 2,2 3,3 3,3 2)))"), + from_wkt("MULTIPOLYGON(((0 0,2 0,2 2,0 2)))"), + false); + + tester::apply(from_wkt("MULTIPOLYGON(((1 1,1 3,3 3,3 1)))"), + from_wkt("MULTIPOLYGON(((0 0,2 0,2 2,0 2)))"), + false); + + tester::apply(from_wkt("MULTIPOLYGON(((3 3,3 4,4 4,4 3)))"), + from_wkt("MULTIPOLYGON(((0 0,2 0,2 2,0 2)))"), + true); +} + +//============================================================================ + +template +inline void test_pointlike_pointlike() +{ + typedef bg::model::point point_type; + + test_point_point(); + // not implemented yet + // test_point_multipoint(); + + // test_multipoint_multipoint(); +} + +template +inline void test_pointlike_linear() +{ + typedef bg::model::point point_type; + + test_point_linestring(); + test_point_multilinestring(); + test_point_segment(); + + // not implemented yet + // test_multipoint_linestring(); + // test_multipoint_multilinestring(); + // test_multipoint_segment(); +} + +template +inline void test_pointlike_areal() +{ + typedef bg::model::point point_type; + + test_point_polygon(); + test_point_multipolygon(); + test_point_ring(); + test_point_box(); + + // not implemented yet + // test_multipoint_polygon(); + // test_multipoint_multipolygon(); + // test_multipoint_ring(); + // test_multipoint_box(); +} + +template +inline void test_linear_linear() +{ + typedef bg::model::point point_type; + + test_linestring_linestring(); + test_linestring_multilinestring(); + test_linestring_segment(); + + test_multilinestring_multilinestring(); + test_multilinestring_segment(); + + test_segment_segment(); +} + +template +inline void test_linear_areal() +{ + typedef bg::model::point point_type; + + test_segment_polygon(); + test_segment_multipolygon(); + test_segment_ring(); + test_segment_box(); + + test_linestring_polygon(); + test_linestring_multipolygon(); + test_linestring_ring(); + test_linestring_box(); + + test_multilinestring_polygon(); + test_multilinestring_multipolygon(); + test_multilinestring_ring(); + test_multilinestring_box(); +} + +template +inline void test_areal_areal() +{ + typedef bg::model::point point_type; + + test_polygon_polygon(); + test_polygon_multipolygon(); + test_polygon_ring(); + test_polygon_box(); + + test_multipolygon_multipolygon(); + test_multipolygon_ring(); + test_multipolygon_box(); + + test_ring_ring(); + test_ring_box(); + + test_box_box(); +} + +//============================================================================ + +BOOST_AUTO_TEST_CASE( test_pointlike_pointlike_all ) +{ + test_pointlike_pointlike(); + test_pointlike_pointlike(); +#ifdef HAVE_TTMATH + test_pointlike_pointlike(); +#endif +} + +BOOST_AUTO_TEST_CASE( test_pointlike_linear_all ) +{ + test_pointlike_linear(); + test_pointlike_linear(); +#ifdef HAVE_TTMATH + test_pointlike_linear(); +#endif +} + +BOOST_AUTO_TEST_CASE( test_pointlike_areal_all ) +{ + test_pointlike_areal(); + test_pointlike_areal(); +#ifdef HAVE_TTMATH + test_pointlike_areal(); +#endif +} + +BOOST_AUTO_TEST_CASE( test_linear_linear_all ) +{ + test_linear_linear(); + test_linear_linear(); +#ifdef HAVE_TTMATH + test_linear_linear(); +#endif +} + +BOOST_AUTO_TEST_CASE( test_linear_areal_all ) +{ + test_linear_areal(); + test_linear_areal(); +#ifdef HAVE_TTMATH + test_linear_areal(); +#endif +} + +BOOST_AUTO_TEST_CASE( test_areal_areal_all ) +{ + test_areal_areal(); + test_areal_areal(); +#ifdef HAVE_TTMATH + test_areal_areal(); +#endif +} From da4ee4d6fe970746b69f6751614cb0f57a2cd41b Mon Sep 17 00:00:00 2001 From: Menelaos Karavelas Date: Wed, 21 May 2014 17:07:00 +0300 Subject: [PATCH 21/28] [test][disjoint] add unit test for checking which geometry combinations work with disjoint --- test/algorithms/Jamfile.v2 | 1 + test/algorithms/disjoint_coverage.cpp | 10 +--------- 2 files changed, 2 insertions(+), 9 deletions(-) diff --git a/test/algorithms/Jamfile.v2 b/test/algorithms/Jamfile.v2 index 63b7fe3c4..e871cb545 100644 --- a/test/algorithms/Jamfile.v2 +++ b/test/algorithms/Jamfile.v2 @@ -30,6 +30,7 @@ test-suite boost-geometry-algorithms [ run difference_linear_linear.cpp ] [ run difference_pl_pl.cpp ] [ run disjoint.cpp ] + [ run disjoint_coverage.cpp ] [ run distance.cpp : : : msvc:/bigobj ] [ run distance_areal_areal.cpp ] [ run distance_linear_areal.cpp ] diff --git a/test/algorithms/disjoint_coverage.cpp b/test/algorithms/disjoint_coverage.cpp index 4fa1462be..0b99056cd 100644 --- a/test/algorithms/disjoint_coverage.cpp +++ b/test/algorithms/disjoint_coverage.cpp @@ -17,18 +17,11 @@ #include -// general support; THIS HEADER SHOULD GO AWAY -#include - -// support for multi; THIS HEADER SHOULD GO AWAY -//#include - #include #include #include -// I should not need to include this -#include +#include #include #include @@ -47,7 +40,6 @@ #include #include -#include #include "from_wkt.hpp" From b6522c4e749784211e26080abcffefc4e161656a Mon Sep 17 00:00:00 2001 From: Menelaos Karavelas Date: Wed, 21 May 2014 17:14:56 +0300 Subject: [PATCH 22/28] [disjoint] move main file to detail/disjoint/interface.hpp --- .../algorithms/{disjoint.hpp => detail/disjoint/interface.hpp} | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename include/boost/geometry/algorithms/{disjoint.hpp => detail/disjoint/interface.hpp} (100%) diff --git a/include/boost/geometry/algorithms/disjoint.hpp b/include/boost/geometry/algorithms/detail/disjoint/interface.hpp similarity index 100% rename from include/boost/geometry/algorithms/disjoint.hpp rename to include/boost/geometry/algorithms/detail/disjoint/interface.hpp From 57921a7e89d1f13e354e75a67e0217e766e67d0f Mon Sep 17 00:00:00 2001 From: Menelaos Karavelas Date: Wed, 21 May 2014 17:18:38 +0300 Subject: [PATCH 23/28] [disjoint] clean-up code in detail/disjoint/interface.hpp; create and add proper includes in detail/disjoint/implementation.hpp; re-create algorithms/disjoint.hpp and add the above two includes; --- .../detail/disjoint/implementation.hpp | 36 +++++++++++++++++++ .../algorithms/detail/disjoint/interface.hpp | 16 ++------- .../boost/geometry/algorithms/disjoint.hpp | 27 ++++++++++++++ 3 files changed, 66 insertions(+), 13 deletions(-) create mode 100644 include/boost/geometry/algorithms/detail/disjoint/implementation.hpp create mode 100644 include/boost/geometry/algorithms/disjoint.hpp diff --git a/include/boost/geometry/algorithms/detail/disjoint/implementation.hpp b/include/boost/geometry/algorithms/detail/disjoint/implementation.hpp new file mode 100644 index 000000000..0c8079b8e --- /dev/null +++ b/include/boost/geometry/algorithms/detail/disjoint/implementation.hpp @@ -0,0 +1,36 @@ +// Boost.Geometry (aka GGL, Generic Geometry Library) + +// 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-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. + +// Use, modification and distribution is subject to the Boost Software License, +// Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at +// http://www.boost.org/LICENSE_1_0.txt) + +#ifndef BOOST_GEOMETRY_ALGORITHMS_DETAIL_DISJOINT_IMPLEMENTATION_HPP +#define BOOST_GEOMETRY_ALGORITHMS_DETAIL_DISJOINT_IMPLEMENTATION_HPP + + +#include +#include +#include +#include +#include +#include +#include +#include +#include + + +#endif // BOOST_GEOMETRY_ALGORITHMS_DETAIL_DISJOINT_IMPLEMENTATION_HPP diff --git a/include/boost/geometry/algorithms/detail/disjoint/interface.hpp b/include/boost/geometry/algorithms/detail/disjoint/interface.hpp index 65c51a6b3..ec9057ba0 100644 --- a/include/boost/geometry/algorithms/detail/disjoint/interface.hpp +++ b/include/boost/geometry/algorithms/detail/disjoint/interface.hpp @@ -18,8 +18,8 @@ // Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at // http://www.boost.org/LICENSE_1_0.txt) -#ifndef BOOST_GEOMETRY_ALGORITHMS_DISJOINT_HPP -#define BOOST_GEOMETRY_ALGORITHMS_DISJOINT_HPP +#ifndef BOOST_GEOMETRY_ALGORITHMS_DETAIL_DISJOINT_INTERFACE_HPP +#define BOOST_GEOMETRY_ALGORITHMS_DETAIL_DISJOINT_INTERFACE_HPP #include @@ -29,16 +29,6 @@ #include -#include -#include -#include -#include -#include -#include -#include -#include -#include - #include @@ -194,4 +184,4 @@ inline bool disjoint(Geometry1 const& geometry1, }} // namespace boost::geometry -#endif // BOOST_GEOMETRY_ALGORITHMS_DISJOINT_HPP +#endif // BOOST_GEOMETRY_ALGORITHMS_DETAIL_DISJOINT_INTERFACE_HPP diff --git a/include/boost/geometry/algorithms/disjoint.hpp b/include/boost/geometry/algorithms/disjoint.hpp new file mode 100644 index 000000000..f997487c7 --- /dev/null +++ b/include/boost/geometry/algorithms/disjoint.hpp @@ -0,0 +1,27 @@ +// Boost.Geometry (aka GGL, Generic Geometry Library) + +// 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-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. + +// Use, modification and distribution is subject to the Boost Software License, +// Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at +// http://www.boost.org/LICENSE_1_0.txt) + +#ifndef BOOST_GEOMETRY_ALGORITHMS_DISJOINT_HPP +#define BOOST_GEOMETRY_ALGORITHMS_DISJOINT_HPP + +#include +#include + +#endif // BOOST_GEOMETRY_ALGORITHMS_DISJOINT_HPP From 8e03f95ec863d8fc4c5a2af3cb564633fb6d5287 Mon Sep 17 00:00:00 2001 From: Menelaos Karavelas Date: Wed, 21 May 2014 17:26:27 +0300 Subject: [PATCH 24/28] [multi][get turns] remove unused include --- .../boost/geometry/multi/algorithms/detail/overlay/get_turns.hpp | 1 - 1 file changed, 1 deletion(-) diff --git a/include/boost/geometry/multi/algorithms/detail/overlay/get_turns.hpp b/include/boost/geometry/multi/algorithms/detail/overlay/get_turns.hpp index b61775b8f..0affcff98 100644 --- a/include/boost/geometry/multi/algorithms/detail/overlay/get_turns.hpp +++ b/include/boost/geometry/multi/algorithms/detail/overlay/get_turns.hpp @@ -16,7 +16,6 @@ #include -#include #include #include From 0df67aa716185ba78b56c37240706c50d3e334e2 Mon Sep 17 00:00:00 2001 From: Menelaos Karavelas Date: Wed, 21 May 2014 17:33:33 +0300 Subject: [PATCH 25/28] [disjoint] add missing include of basic dispatch --- include/boost/geometry/algorithms/detail/disjoint/box_box.hpp | 2 ++ 1 file changed, 2 insertions(+) diff --git a/include/boost/geometry/algorithms/detail/disjoint/box_box.hpp b/include/boost/geometry/algorithms/detail/disjoint/box_box.hpp index 931a52b8e..ccff9799f 100644 --- a/include/boost/geometry/algorithms/detail/disjoint/box_box.hpp +++ b/include/boost/geometry/algorithms/detail/disjoint/box_box.hpp @@ -26,6 +26,8 @@ #include #include +#include + namespace boost { namespace geometry { From 3ec53c8626e995e1d301fe9c768bab052b448a7b Mon Sep 17 00:00:00 2001 From: Menelaos Karavelas Date: Thu, 22 May 2014 02:24:14 +0300 Subject: [PATCH 26/28] [test][disjoint] fix definition of polygon that is inconsistent with WKTs used --- test/algorithms/disjoint_coverage.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/algorithms/disjoint_coverage.cpp b/test/algorithms/disjoint_coverage.cpp index 0b99056cd..1f2aa8aa3 100644 --- a/test/algorithms/disjoint_coverage.cpp +++ b/test/algorithms/disjoint_coverage.cpp @@ -364,7 +364,7 @@ inline void test_point_polygon() template inline void test_point_multipolygon() { - typedef bg::model::polygon

PL; + typedef bg::model::polygon PL; // ccw, open typedef bg::model::multi_polygon MPL; typedef test_disjoint tester; From 21b785138123bc28b3ac1438c63ea0e141eb30fe Mon Sep 17 00:00:00 2001 From: Menelaos Karavelas Date: Fri, 23 May 2014 14:12:01 +0300 Subject: [PATCH 27/28] [disjoint][segment-box] factor-out common code in disjoint_segment_box_impl --- .../detail/disjoint/segment_box.hpp | 90 ++++++++----------- 1 file changed, 35 insertions(+), 55 deletions(-) diff --git a/include/boost/geometry/algorithms/detail/disjoint/segment_box.hpp b/include/boost/geometry/algorithms/detail/disjoint/segment_box.hpp index 46555f4e1..08ac1c236 100644 --- a/include/boost/geometry/algorithms/detail/disjoint/segment_box.hpp +++ b/include/boost/geometry/algorithms/detail/disjoint/segment_box.hpp @@ -24,6 +24,8 @@ #include #include +#include + #include #include @@ -45,23 +47,16 @@ namespace detail { namespace disjoint { - -template -< - typename RelativeDistance, - typename SegmentPoint, - typename Box, - std::size_t I, - std::size_t Dimension -> -struct disjoint_segment_box_impl +template +struct compute_tmin_tmax_per_dim { - template - static inline bool apply(SegmentPoint const& p0, + template + static inline void apply(SegmentPoint const& p0, SegmentPoint const& p1, Box const& box, - RelativeDistancePair& t_min, - RelativeDistancePair& t_max) + RelativeDistance& ti_min, + RelativeDistance& ti_max, + RelativeDistance& diff) { typedef typename coordinate_type::type box_coordinate_type; typedef typename coordinate_type @@ -89,8 +84,6 @@ struct disjoint_segment_box_impl box_coordinate_type >( geometry::get(box) ); - RelativeDistance ti_min, ti_max, diff; - if ( geometry::get(p1) >= geometry::get(p0) ) { diff = c_p1 - c_p0; @@ -103,6 +96,30 @@ struct disjoint_segment_box_impl ti_min = c_p0 - c_b_max; ti_max = c_p0 - c_b_min; } + } +}; + + +template +< + typename RelativeDistance, + typename SegmentPoint, + typename Box, + std::size_t I, + std::size_t Dimension +> +struct disjoint_segment_box_impl +{ + template + static inline bool apply(SegmentPoint const& p0, + SegmentPoint const& p1, + Box const& box, + RelativeDistancePair& t_min, + RelativeDistancePair& t_max) + { + RelativeDistance ti_min, ti_max, diff; + + compute_tmin_tmax_per_dim::apply(p0, p1, box, ti_min, ti_max, diff); RelativeDistance t_min_x_diff = t_min.first * diff; RelativeDistance t_max_x_diff = t_max.first * diff; @@ -157,48 +174,11 @@ struct disjoint_segment_box_impl SegmentPoint const& p1, Box const& box) { - typedef typename coordinate_type::type box_coordinate_type; - typedef typename coordinate_type - < - SegmentPoint - >::type point_coordinate_type; - - RelativeDistance c_p0 = boost::numeric_cast - < - point_coordinate_type - >( geometry::get<0>(p0) ); - - RelativeDistance c_p1 = boost::numeric_cast - < - point_coordinate_type - >( geometry::get<0>(p1) ); - - RelativeDistance c_b_min = boost::numeric_cast - < - box_coordinate_type - >( geometry::get(box) ); - - RelativeDistance c_b_max = boost::numeric_cast - < - box_coordinate_type - >( geometry::get(box) ); - std::pair t_min, t_max; - RelativeDistance diff; - if ( geometry::get<0>(p1) >= geometry::get<0>(p0) ) - { - diff = c_p1 - c_p0; - t_min.first = c_b_min - c_p0; - t_max.first = c_b_max - c_p0; - } - else - { - diff = c_p0 - c_p1; - t_min.first = c_p0 - c_b_max; - t_max.first = c_p0 - c_b_min; - } + compute_tmin_tmax_per_dim<0>::apply(p0, p1, box, + t_min.first, t_max.first, diff); if ( t_min.first > diff || t_max.first < 0 ) { From 939517e19858e7b3a068f023a34393402cf814e2 Mon Sep 17 00:00:00 2001 From: Menelaos Karavelas Date: Fri, 23 May 2014 20:47:06 +0300 Subject: [PATCH 28/28] [disjoint] remove obsolete file algorithms/detail/disjoint.hpp --- .../geometry/algorithms/detail/disjoint.hpp | 248 ------------------ 1 file changed, 248 deletions(-) delete mode 100644 include/boost/geometry/algorithms/detail/disjoint.hpp diff --git a/include/boost/geometry/algorithms/detail/disjoint.hpp b/include/boost/geometry/algorithms/detail/disjoint.hpp deleted file mode 100644 index 089acc523..000000000 --- a/include/boost/geometry/algorithms/detail/disjoint.hpp +++ /dev/null @@ -1,248 +0,0 @@ -// 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 - -// Parts of Boost.Geometry are redesigned from Geodan's Geographic Library -// (geolib/GGL), copyright (c) 1995-2010 Geodan, Amsterdam, the Netherlands. - -// Use, modification and distribution is subject to the Boost Software License, -// Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at -// http://www.boost.org/LICENSE_1_0.txt) - -#ifndef BOOST_GEOMETRY_ALGORITHMS_DETAIL_DISJOINT_HPP -#define BOOST_GEOMETRY_ALGORITHMS_DETAIL_DISJOINT_HPP - -#error This file should not be included; it will go away - -// Note: contrary to most files, the geometry::detail::disjoint namespace -// is partly implemented in separate files, to avoid circular references -// disjoint -> get_turns -> disjoint - -#include - -#include - -#include -#include -#include - -#include - -#include - -#include -#include - - -namespace boost { namespace geometry -{ - - -#ifndef DOXYGEN_NO_DETAIL -namespace detail { namespace disjoint -{ - - -struct disjoint_interrupt_policy -{ - static bool const enabled = true; - bool has_intersections; - - inline disjoint_interrupt_policy() - : has_intersections(false) - {} - - template - inline bool apply(Range const& range) - { - // If there is any IP in the range, it is NOT disjoint - if (boost::size(range) > 0) - { - has_intersections = true; - return true; - } - return false; - } -}; - - - -template -< - typename Point, typename Box, - std::size_t Dimension, std::size_t DimensionCount -> -struct point_box -{ - static inline bool apply(Point const& point, Box const& box) - { - if (get(point) < get(box) - || get(point) > get(box)) - { - return true; - } - return point_box - < - Point, Box, - Dimension + 1, DimensionCount - >::apply(point, box); - } -}; - - -template -struct point_box -{ - static inline bool apply(Point const& , Box const& ) - { - return false; - } -}; - - -// Segment - Box intersection -// Based on Ray-AABB intersection -// http://www.siggraph.org/education/materials/HyperGraph/raytrace/rtinter3.htm - -// TODO - later maybe move to strategy::intersects and add a policy to conditionally extract intersection points - -template -struct segment_box_intersection_dim -{ - //BOOST_STATIC_ASSERT(I < dimension::value); - //BOOST_STATIC_ASSERT(I < dimension::value); - //BOOST_STATIC_ASSERT(dimension::value == dimension::value); - - typedef typename coordinate_type::type point_coordinate; - - template static inline - bool apply(Point const& p0, Point const& p1, Box const& b, RelativeDistance & t_near, RelativeDistance & t_far) - { - //// WARNING! - RelativeDistance must be IEEE float for this to work (division by 0) - //BOOST_STATIC_ASSERT(boost::is_float::value); - //// Ray origin is in segment point 0 - //RelativeDistance ray_d = geometry::get(p1) - geometry::get(p0); - //RelativeDistance tn = ( geometry::get(b) - geometry::get(p0) ) / ray_d; - //RelativeDistance tf = ( geometry::get(b) - geometry::get(p0) ) / ray_d; - - // TODO - should we support also unsigned integers? - BOOST_STATIC_ASSERT(!boost::is_unsigned::value); - point_coordinate ray_d = geometry::get(p1) - geometry::get(p0); - RelativeDistance tn, tf; - if ( is_zero(ray_d) ) - { - tn = dist_div_by_zero(geometry::get(b) - geometry::get(p0)); - tf = dist_div_by_zero(geometry::get(b) - geometry::get(p0)); - } - else - { - tn = static_cast(geometry::get(b) - geometry::get(p0)) / ray_d; - tf = static_cast(geometry::get(b) - geometry::get(p0)) / ray_d; - } - - if ( tf < tn ) - ::std::swap(tn, tf); - - if ( t_near < tn ) - t_near = tn; - if ( tf < t_far ) - t_far = tf; - - return 0 <= t_far && t_near <= t_far && t_near <= 1; - } - - template static inline - R dist_div_by_zero(T const& val) - { - if ( is_zero(val) ) - return 0; - else if ( val < 0 ) - return -(::std::numeric_limits::max)(); - else - return (::std::numeric_limits::max)(); - } - - template static inline - bool is_zero(T const& val) - { - // ray_d == 0 is here because eps of rational is 0 which isn't < than 0 - return val == 0 || math::abs(val) < ::std::numeric_limits::epsilon(); - } -}; - -template -struct segment_box_intersection_impl -{ - BOOST_STATIC_ASSERT(0 < CurrentDimension); - - typedef segment_box_intersection_dim for_dim; - - template - static inline bool apply(Point const& p0, Point const& p1, Box const& b, - RelativeDistance & t_near, RelativeDistance & t_far) - { - return segment_box_intersection_impl::apply(p0, p1, b, t_near, t_far) - && for_dim::apply(p0, p1, b, t_near, t_far); - } -}; - -template -struct segment_box_intersection_impl -{ - typedef segment_box_intersection_dim for_dim; - - template - static inline bool apply(Point const& p0, Point const& p1, Box const& b, - RelativeDistance & t_near, RelativeDistance & t_far) - { - return for_dim::apply(p0, p1, b, t_near, t_far); - } -}; - -template -struct segment_box_intersection -{ - typedef segment_box_intersection_impl::value> impl; - - static inline bool apply(Point const& p0, Point const& p1, Box const& b) - { - typedef - typename geometry::promote_floating_point< - typename geometry::select_most_precise< - typename coordinate_type::type, - typename coordinate_type::type - >::type - >::type relative_distance_type; - - relative_distance_type t_near = -(::std::numeric_limits::max)(); - relative_distance_type t_far = (::std::numeric_limits::max)(); - - // relative_distance = 0 < t_near ? t_near : 0; - - return impl::apply(p0, p1, b, t_near, t_far); - } -}; - -template -< - typename Geometry1, typename Geometry2 -> -struct reverse_covered_by -{ - static inline bool apply(Geometry1 const& geometry1, Geometry2 const& geometry2) - { - return ! geometry::covered_by(geometry1, geometry2); - } -}; - - -}} // namespace detail::disjoint -#endif // DOXYGEN_NO_DETAIL - - -}} // namespace boost::geometry - -#endif // BOOST_GEOMETRY_ALGORITHMS_DETAIL_DISJOINT_HPP