From c9950313373024e4f9b76279df7a007f794e4ebf Mon Sep 17 00:00:00 2001 From: Barend Gehrels Date: Wed, 14 May 2014 13:22:48 +0200 Subject: [PATCH 1/6] [intersection] avoid circulare reference in index/intersection/distance --- .../detail/overlay/intersection_box_box.hpp | 84 +++++++++++++++++++ .../geometry/algorithms/intersection.hpp | 63 +------------- .../algorithms/intersection_content.hpp | 10 ++- .../geometry/strategies/intersection.hpp | 3 +- 4 files changed, 95 insertions(+), 65 deletions(-) create mode 100644 include/boost/geometry/algorithms/detail/overlay/intersection_box_box.hpp diff --git a/include/boost/geometry/algorithms/detail/overlay/intersection_box_box.hpp b/include/boost/geometry/algorithms/detail/overlay/intersection_box_box.hpp new file mode 100644 index 000000000..dd041b0d7 --- /dev/null +++ b/include/boost/geometry/algorithms/detail/overlay/intersection_box_box.hpp @@ -0,0 +1,84 @@ +// Boost.Geometry (aka GGL, Generic Geometry Library) + +// Copyright (c) 2007-2014 Barend Gehrels, 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_OVERLAY_INTERSECTION_BOX_BOX_HPP +#define BOOST_GEOMETRY_ALGORITHMS_DETAIL_OVERLAY_INTERSECTION_BOX_BOX_HPP + + +#include +#include + + +namespace boost { namespace geometry +{ + +#ifndef DOXYGEN_NO_DETAIL +namespace detail { namespace intersection +{ + +template +struct intersection_box_box +{ + template + < + typename Box1, typename Box2, + typename RobustPolicy, + typename BoxOut, + typename Strategy + > + static inline bool apply(Box1 const& box1, + Box2 const& box2, + RobustPolicy const& robust_policy, + BoxOut& box_out, + Strategy const& strategy) + { + typedef typename coordinate_type::type ct; + + ct min1 = get(box1); + ct min2 = get(box2); + ct max1 = get(box1); + ct max2 = get(box2); + + if (max1 < min2 || max2 < min1) + { + return false; + } + // Set dimensions of output coordinate + set(box_out, min1 < min2 ? min2 : min1); + set(box_out, max1 > max2 ? max2 : max1); + + return intersection_box_box + ::apply(box1, box2, robust_policy, box_out, strategy); + } +}; + +template +struct intersection_box_box +{ + template + < + typename Box1, typename Box2, + typename RobustPolicy, + typename BoxOut, + typename Strategy + > + static inline bool apply(Box1 const&, Box2 const&, + RobustPolicy const&, BoxOut&, Strategy const&) + { + return true; + } +}; + + +}} // namespace detail::intersection +#endif // DOXYGEN_NO_DETAIL + +}} // namespace boost::geometry + + +#endif // BOOST_GEOMETRY_ALGORITHMS_DETAIL_OVERLAY_INTERSECTION_BOX_BOX_HPP diff --git a/include/boost/geometry/algorithms/intersection.hpp b/include/boost/geometry/algorithms/intersection.hpp index 500cacc9f..ca3bb0682 100644 --- a/include/boost/geometry/algorithms/intersection.hpp +++ b/include/boost/geometry/algorithms/intersection.hpp @@ -12,6 +12,7 @@ #include #include +#include #include #include @@ -19,68 +20,6 @@ namespace boost { namespace geometry { -#ifndef DOXYGEN_NO_DETAIL -namespace detail { namespace intersection -{ - -template -struct intersection_box_box -{ - template - < - typename Box1, typename Box2, - typename RobustPolicy, - typename BoxOut, - typename Strategy - > - static inline bool apply(Box1 const& box1, - Box2 const& box2, - RobustPolicy const& robust_policy, - BoxOut& box_out, - Strategy const& strategy) - { - typedef typename coordinate_type::type ct; - - ct min1 = get(box1); - ct min2 = get(box2); - ct max1 = get(box1); - ct max2 = get(box2); - - if (max1 < min2 || max2 < min1) - { - return false; - } - // Set dimensions of output coordinate - set(box_out, min1 < min2 ? min2 : min1); - set(box_out, max1 > max2 ? max2 : max1); - - return intersection_box_box - ::apply(box1, box2, robust_policy, box_out, strategy); - } -}; - -template -struct intersection_box_box -{ - template - < - typename Box1, typename Box2, - typename RobustPolicy, - typename BoxOut, - typename Strategy - > - static inline bool apply(Box1 const&, Box2 const&, - RobustPolicy const&, BoxOut&, Strategy const&) - { - return true; - } -}; - - -}} // namespace detail::intersection -#endif // DOXYGEN_NO_DETAIL - - #ifndef DOXYGEN_NO_DISPATCH namespace dispatch diff --git a/include/boost/geometry/index/detail/algorithms/intersection_content.hpp b/include/boost/geometry/index/detail/algorithms/intersection_content.hpp index 955d6eb65..ed615c402 100644 --- a/include/boost/geometry/index/detail/algorithms/intersection_content.hpp +++ b/include/boost/geometry/index/detail/algorithms/intersection_content.hpp @@ -11,7 +11,8 @@ #ifndef BOOST_GEOMETRY_INDEX_DETAIL_ALGORITHMS_INTERSECTION_CONTENT_HPP #define BOOST_GEOMETRY_INDEX_DETAIL_ALGORITHMS_INTERSECTION_CONTENT_HPP -#include +#include +#include #include namespace boost { namespace geometry { namespace index { namespace detail { @@ -25,7 +26,12 @@ inline typename default_content_result::type intersection_content(Box const if ( geometry::intersects(box1, box2) ) { Box box_intersection; - geometry::intersection(box1, box2, box_intersection); + + strategy_intersection_empty dummy; + geometry::detail::intersection::intersection_box_box + < + 0, geometry::dimension::value + >::apply(box1, box2, box_intersection, dummy); return detail::content(box_intersection); } return 0; diff --git a/include/boost/geometry/strategies/intersection.hpp b/include/boost/geometry/strategies/intersection.hpp index d97baf66d..ef1b676fd 100644 --- a/include/boost/geometry/strategies/intersection.hpp +++ b/include/boost/geometry/strategies/intersection.hpp @@ -82,7 +82,8 @@ public: typedef RobustPolicy rescale_policy_type; }; - +// Version for box_box intersection or other detail calls not needing a strategy +struct strategy_intersection_empty {}; }} // namespace boost::geometry From 07696d76fdeedd8ac091f6c9b8a0ff64a6920954 Mon Sep 17 00:00:00 2001 From: Barend Gehrels Date: Wed, 14 May 2014 13:46:22 +0200 Subject: [PATCH 2/6] [overlay] Added missing include / removed obsolete include, causing unit test troubles after distance merge --- .../geometry/algorithms/detail/overlay/get_relative_order.hpp | 2 -- include/boost/geometry/policies/robustness/rescale_policy.hpp | 1 + 2 files changed, 1 insertion(+), 2 deletions(-) diff --git a/include/boost/geometry/algorithms/detail/overlay/get_relative_order.hpp b/include/boost/geometry/algorithms/detail/overlay/get_relative_order.hpp index 50a14ea24..d71f4ad51 100644 --- a/include/boost/geometry/algorithms/detail/overlay/get_relative_order.hpp +++ b/include/boost/geometry/algorithms/detail/overlay/get_relative_order.hpp @@ -10,8 +10,6 @@ #define BOOST_GEOMETRY_ALGORITHMS_DETAIL_OVERLAY_GET_RELATIVE_ORDER_HPP -#include - #include diff --git a/include/boost/geometry/policies/robustness/rescale_policy.hpp b/include/boost/geometry/policies/robustness/rescale_policy.hpp index 570ba8bef..5b3b56697 100644 --- a/include/boost/geometry/policies/robustness/rescale_policy.hpp +++ b/include/boost/geometry/policies/robustness/rescale_policy.hpp @@ -16,6 +16,7 @@ #include +#include #include #include From 09365f00869a34acc762c158b52d6991667ef437 Mon Sep 17 00:00:00 2001 From: Barend Gehrels Date: Wed, 14 May 2014 13:46:52 +0200 Subject: [PATCH 3/6] [unit test] Added copyright info --- test/algorithms/from_wkt.hpp | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/test/algorithms/from_wkt.hpp b/test/algorithms/from_wkt.hpp index 13d646356..2e47f2e24 100644 --- a/test/algorithms/from_wkt.hpp +++ b/test/algorithms/from_wkt.hpp @@ -1,3 +1,15 @@ +// Boost.Geometry (aka GGL, Generic Geometry Library) +// Unit Tests + +// 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. + +// 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_TEST_FROM_WKT_HPP #define BOOST_GEOMETRY_TEST_FROM_WKT_HPP From afb301f6ed6b52f3968bfcc071128d39470b67ec Mon Sep 17 00:00:00 2001 From: Barend Gehrels Date: Wed, 14 May 2014 13:47:22 +0200 Subject: [PATCH 4/6] [unit test] Made from_wkt inline and avoid abbreviations --- test/algorithms/from_wkt.hpp | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/test/algorithms/from_wkt.hpp b/test/algorithms/from_wkt.hpp index 2e47f2e24..5390db868 100644 --- a/test/algorithms/from_wkt.hpp +++ b/test/algorithms/from_wkt.hpp @@ -16,11 +16,11 @@ #include template -Geometry from_wkt(std::string const& wkt) +inline Geometry from_wkt(std::string const& wkt) { - Geometry res; - boost::geometry::read_wkt(wkt, res); - return res; + Geometry result; + boost::geometry::read_wkt(wkt, result); + return result; } #endif // BOOST_GEOMETRY_TEST_FROM_WKT_HPP From a703cae46e887a49fd70f17cc3e942006a81e4fd Mon Sep 17 00:00:00 2001 From: Barend Gehrels Date: Wed, 14 May 2014 14:18:48 +0200 Subject: [PATCH 5/6] [num_points][test] Added test for num_points which was not yet there --- test/algorithms/Jamfile.v2 | 1 + test/algorithms/num_points.cpp | 65 ++++++++++++++++++++++++++++++++++ 2 files changed, 66 insertions(+) create mode 100644 test/algorithms/num_points.cpp diff --git a/test/algorithms/Jamfile.v2 b/test/algorithms/Jamfile.v2 index de35ec60e..63b7fe3c4 100644 --- a/test/algorithms/Jamfile.v2 +++ b/test/algorithms/Jamfile.v2 @@ -47,6 +47,7 @@ test-suite boost-geometry-algorithms [ run intersects.cpp : : : msvc:/bigobj ] [ run length.cpp ] [ run make.cpp ] + [ run num_points.cpp ] [ run overlaps.cpp ] [ run perimeter.cpp ] [ run point_on_surface.cpp ] diff --git a/test/algorithms/num_points.cpp b/test/algorithms/num_points.cpp new file mode 100644 index 000000000..3abeed449 --- /dev/null +++ b/test/algorithms/num_points.cpp @@ -0,0 +1,65 @@ +// Boost.Geometry (aka GGL, Generic Geometry Library) +// Unit Test + +// 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. + +// 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_TEST_MODULE +#define BOOST_TEST_MODULE test_num_points +#endif + +#include +#include + +#include +#include +#include +#include + +#include +#include + +template +inline void test_num_points(std::string const& wkt, std::size_t expected) +{ + namespace bg = boost::geometry; + Geometry geometry; + boost::geometry::read_wkt(wkt, geometry); + std::size_t detected = bg::num_points(geometry); + BOOST_CHECK_EQUAL(expected, detected); + detected = bg::num_points(geometry, false); + BOOST_CHECK_EQUAL(expected, detected); + detected = bg::num_points(geometry, true); +} + +BOOST_AUTO_TEST_CASE( test_num_points_closed ) +{ + namespace bg = boost::geometry; + typedef bg::model::point point; + typedef bg::model::linestring linestring; + typedef bg::model::segment segment; + typedef bg::model::box box; + typedef bg::model::ring ring; + typedef bg::model::polygon polygon; + typedef bg::model::multi_point multi_point; + typedef bg::model::multi_linestring multi_linestring; + typedef bg::model::multi_polygon multi_polygon; + + test_num_points("POINT(0 0)", 1u); + test_num_points("LINESTRING(0 0,1 1)", 2u); + test_num_points("LINESTRING(0 0,1 1)", 2u); + test_num_points("POLYGON((0 0,10 10))", 4u); + test_num_points("POLYGON((0 0,1 1,0 1,0 0))", 4u); + test_num_points("POLYGON((0 0,10 10,0 10,0 0))", 4u); + test_num_points("POLYGON((0 0,0 10,10 10,10 0,0 0),(4 4,6 4,6 6,4 6,4 4))", 10u); + test_num_points("MULTIPOINT((0 0),(1 1))", 2u); + test_num_points("MULTILINESTRING((0 0,1 1),(2 2,3 3,4 4))", 5u); + test_num_points("MULTIPOLYGON(((0 0,0 10,10 10,10 0,0 0)),((0 10,1 10,1 9,0 10)))", 9u); +} + From 71be9ab855a6f21113672bb0a2443166a2ef2d82 Mon Sep 17 00:00:00 2001 From: Barend Gehrels Date: Wed, 14 May 2014 14:19:04 +0200 Subject: [PATCH 6/6] [test] added include for multi --- test/algorithms/from_wkt.hpp | 1 + 1 file changed, 1 insertion(+) diff --git a/test/algorithms/from_wkt.hpp b/test/algorithms/from_wkt.hpp index 5390db868..5c78afdea 100644 --- a/test/algorithms/from_wkt.hpp +++ b/test/algorithms/from_wkt.hpp @@ -14,6 +14,7 @@ #define BOOST_GEOMETRY_TEST_FROM_WKT_HPP #include +#include template inline Geometry from_wkt(std::string const& wkt)