From b9ff3a7fc46b53fa9f289418f67b9a4ef2fe28a4 Mon Sep 17 00:00:00 2001 From: Adam Wulkiewicz Date: Sun, 15 Jun 2014 02:29:57 +0200 Subject: [PATCH 1/4] [index][strategies][test] Modify some of the header includes. The purpose of this is to allow the compilation of the rtree without the need of including the geometry.hpp ond require only index/rtree.hpp or to make the order of includes irrelevant. Furthermore, this is backward compatible. Add missing variant include in the intersection tests. Fix the unused typedefs in the pythagoras_point_box test. --- include/boost/geometry/index/rtree.hpp | 17 ++++++++++------- .../cartesian/centroid_weighted_length.hpp | 3 ++- test/algorithms/test_intersection.hpp | 1 + test/strategies/pythagoras_point_box.cpp | 7 +++++++ 4 files changed, 20 insertions(+), 8 deletions(-) diff --git a/include/boost/geometry/index/rtree.hpp b/include/boost/geometry/index/rtree.hpp index e4f913ab8..09f07ffe7 100644 --- a/include/boost/geometry/index/rtree.hpp +++ b/include/boost/geometry/index/rtree.hpp @@ -12,17 +12,15 @@ #ifndef BOOST_GEOMETRY_INDEX_RTREE_HPP #define BOOST_GEOMETRY_INDEX_RTREE_HPP +// STD #include +// Boost #include #include -//#include -// START -#include - -#include -#include +// Boost.Geometry +#include #include #include #include @@ -34,8 +32,10 @@ #include #include -// END +#include + +// Boost.Geometry.Index #include #include @@ -1798,6 +1798,9 @@ inline void swap(rtree & }}} // namespace boost::geometry::index +// TODO: don't include the implementation at the end of the file +#include + #include #endif // BOOST_GEOMETRY_INDEX_RTREE_HPP diff --git a/include/boost/geometry/strategies/cartesian/centroid_weighted_length.hpp b/include/boost/geometry/strategies/cartesian/centroid_weighted_length.hpp index 48feae51d..b788738d1 100644 --- a/include/boost/geometry/strategies/cartesian/centroid_weighted_length.hpp +++ b/include/boost/geometry/strategies/cartesian/centroid_weighted_length.hpp @@ -13,7 +13,8 @@ #ifndef BOOST_GEOMETRY_STRATEGIES_CARTESIAN_CENTROID_WEIGHTED_LENGTH_HPP #define BOOST_GEOMETRY_STRATEGIES_CARTESIAN_CENTROID_WEIGHTED_LENGTH_HPP -#include +#include +#include #include #include #include diff --git a/test/algorithms/test_intersection.hpp b/test/algorithms/test_intersection.hpp index 53db6d8c1..36c4c1154 100644 --- a/test/algorithms/test_intersection.hpp +++ b/test/algorithms/test_intersection.hpp @@ -14,6 +14,7 @@ #include #include +#include #include #include diff --git a/test/strategies/pythagoras_point_box.cpp b/test/strategies/pythagoras_point_box.cpp index 1b450ec3c..d11e96e1c 100644 --- a/test/strategies/pythagoras_point_box.cpp +++ b/test/strategies/pythagoras_point_box.cpp @@ -27,6 +27,7 @@ # pragma warning( disable : 4101 ) #endif +#include #include #include @@ -184,6 +185,12 @@ inline void test_services() < bg::box_tag, bg::point_tag, Box, Point >::type reversed_pythagoras_pb_strategy_type; + + boost::ignore_unused + < + pythagoras_pb_strategy_type, + reversed_pythagoras_pb_strategy_type + >(); } Point p; From 2c730125c2f6ac6fead0aef4e15cc35a16e0317b Mon Sep 17 00:00:00 2001 From: Barend Gehrels Date: Sun, 15 Jun 2014 17:33:49 +0200 Subject: [PATCH 2/4] [doc] update release notes --- doc/release_notes.qbk | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/doc/release_notes.qbk b/doc/release_notes.qbk index b4712e2b9..4e8ffef9e 100644 --- a/doc/release_notes.qbk +++ b/doc/release_notes.qbk @@ -19,8 +19,9 @@ [*Additional functionality] -* added remove_spikes, algorithm to remove spikes from a ring, polygon or multi_polygon. -* added point_on_surface, generating a point lying on the surface (interior) of the polygon +* New algorithm buffer for inflating/deflating geometries (buffer itself already existed but that was only to enlarge a box) +* New algorithm remove_spikes, algorithm to remove spikes from a ring, polygon or multi_polygon. +* New algorithm point_on_surface, generating a point lying on the surface (interior) of the polygon [*Solved tickets] @@ -28,14 +29,12 @@ * [@https://svn.boost.org/trac/boost/ticket/9081 9081] Booleans create self-intersecting polygons from non-self-intersecting polygons * [@https://svn.boost.org/trac/boost/ticket/8310 8310] Wrong results with overlapping polygons (fixed using point_on_surface for disjoint) * [@https://svn.boost.org/trac/boost/ticket/9871 9871] Remove spike in polygon with only a spike +* [@https://svn.boost.org/trac/boost/ticket/9563 9563] (Sym)difference not successful, fixed by rescaling to robust type [*Bugfixes] * intersects(polygon) could return a self-intersection-point for its closing point, fixed -[*Solved tickets] - -* [@https://svn.boost.org/trac/boost/ticket/9563 9563] (Sym)difference not successful, fixed by rescaling to robust type [/=================] [heading Boost 1.55] From 76917a4e70929d418ebac780385d082848ae2c28 Mon Sep 17 00:00:00 2001 From: Adam Wulkiewicz Date: Mon, 16 Jun 2014 03:49:51 +0200 Subject: [PATCH 3/4] [within][covered_by][test][doc] Support Point in Segment. Add tests and update implementation status. Add the test for intersects(Point, Segment). --- doc/reference/status/covered_by_status.qbk | 2 +- doc/reference/status/within_status.qbk | 2 +- .../boost/geometry/algorithms/covered_by.hpp | 5 ++ .../detail/within/point_in_geometry.hpp | 48 +++++++++++++++---- include/boost/geometry/algorithms/within.hpp | 5 ++ test/algorithms/covered_by.cpp | 5 ++ test/algorithms/intersects.cpp | 11 +++++ test/algorithms/within_pointlike_xxx.cpp | 5 ++ 8 files changed, 71 insertions(+), 12 deletions(-) diff --git a/doc/reference/status/covered_by_status.qbk b/doc/reference/status/covered_by_status.qbk index cc550988b..3d9f98bab 100644 --- a/doc/reference/status/covered_by_status.qbk +++ b/doc/reference/status/covered_by_status.qbk @@ -2,7 +2,7 @@ [table [[ ][Point][Segment][Box][Linestring][Ring][Polygon][MultiPoint][MultiLinestring][MultiPolygon][Variant]] [[Point][ [$img/ok.png] ][ [$img/nyi.png] ][ [$img/nyi.png] ][ [$img/nyi.png] ][ [$img/nyi.png] ][ [$img/nyi.png] ][ [$img/nyi.png] ][ [$img/nyi.png] ][ [$img/nyi.png] ][ [$img/nyi.png] ]] -[[Segment][ [$img/nyi.png] ][ [$img/nyi.png] ][ [$img/nyi.png] ][ [$img/nyi.png] ][ [$img/nyi.png] ][ [$img/nyi.png] ][ [$img/nyi.png] ][ [$img/nyi.png] ][ [$img/nyi.png] ][ [$img/nyi.png] ]] +[[Segment][ [$img/ok.png] ][ [$img/nyi.png] ][ [$img/nyi.png] ][ [$img/nyi.png] ][ [$img/nyi.png] ][ [$img/nyi.png] ][ [$img/nyi.png] ][ [$img/nyi.png] ][ [$img/nyi.png] ][ [$img/nyi.png] ]] [[Box][ [$img/ok.png] ][ [$img/nyi.png] ][ [$img/ok.png] ][ [$img/nyi.png] ][ [$img/nyi.png] ][ [$img/nyi.png] ][ [$img/nyi.png] ][ [$img/nyi.png] ][ [$img/nyi.png] ][ [$img/nyi.png] ]] [[Linestring][ [$img/ok.png] ][ [$img/nyi.png] ][ [$img/nyi.png] ][ [$img/ok.png] ][ [$img/nyi.png] ][ [$img/nyi.png] ][ [$img/nyi.png] ][ [$img/ok.png] ][ [$img/nyi.png] ][ [$img/nyi.png] ]] [[Ring][ [$img/ok.png] ][ [$img/nyi.png] ][ [$img/nyi.png] ][ [$img/ok.png] ][ [$img/ok.png] ][ [$img/ok.png] ][ [$img/nyi.png] ][ [$img/ok.png] ][ [$img/ok.png] ][ [$img/ok.png] ]] diff --git a/doc/reference/status/within_status.qbk b/doc/reference/status/within_status.qbk index cc550988b..3d9f98bab 100644 --- a/doc/reference/status/within_status.qbk +++ b/doc/reference/status/within_status.qbk @@ -2,7 +2,7 @@ [table [[ ][Point][Segment][Box][Linestring][Ring][Polygon][MultiPoint][MultiLinestring][MultiPolygon][Variant]] [[Point][ [$img/ok.png] ][ [$img/nyi.png] ][ [$img/nyi.png] ][ [$img/nyi.png] ][ [$img/nyi.png] ][ [$img/nyi.png] ][ [$img/nyi.png] ][ [$img/nyi.png] ][ [$img/nyi.png] ][ [$img/nyi.png] ]] -[[Segment][ [$img/nyi.png] ][ [$img/nyi.png] ][ [$img/nyi.png] ][ [$img/nyi.png] ][ [$img/nyi.png] ][ [$img/nyi.png] ][ [$img/nyi.png] ][ [$img/nyi.png] ][ [$img/nyi.png] ][ [$img/nyi.png] ]] +[[Segment][ [$img/ok.png] ][ [$img/nyi.png] ][ [$img/nyi.png] ][ [$img/nyi.png] ][ [$img/nyi.png] ][ [$img/nyi.png] ][ [$img/nyi.png] ][ [$img/nyi.png] ][ [$img/nyi.png] ][ [$img/nyi.png] ]] [[Box][ [$img/ok.png] ][ [$img/nyi.png] ][ [$img/ok.png] ][ [$img/nyi.png] ][ [$img/nyi.png] ][ [$img/nyi.png] ][ [$img/nyi.png] ][ [$img/nyi.png] ][ [$img/nyi.png] ][ [$img/nyi.png] ]] [[Linestring][ [$img/ok.png] ][ [$img/nyi.png] ][ [$img/nyi.png] ][ [$img/ok.png] ][ [$img/nyi.png] ][ [$img/nyi.png] ][ [$img/nyi.png] ][ [$img/ok.png] ][ [$img/nyi.png] ][ [$img/nyi.png] ]] [[Ring][ [$img/ok.png] ][ [$img/nyi.png] ][ [$img/nyi.png] ][ [$img/ok.png] ][ [$img/ok.png] ][ [$img/ok.png] ][ [$img/nyi.png] ][ [$img/ok.png] ][ [$img/ok.png] ][ [$img/ok.png] ]] diff --git a/include/boost/geometry/algorithms/covered_by.hpp b/include/boost/geometry/algorithms/covered_by.hpp index 0f2bfdb3b..e50dc338a 100644 --- a/include/boost/geometry/algorithms/covered_by.hpp +++ b/include/boost/geometry/algorithms/covered_by.hpp @@ -114,6 +114,11 @@ struct covered_by // P/L +template +struct covered_by + : public detail::covered_by::use_point_in_geometry +{}; + template struct covered_by : public detail::covered_by::use_point_in_geometry 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 2db76eb73..b8caf464f 100644 --- a/include/boost/geometry/algorithms/detail/within/point_in_geometry.hpp +++ b/include/boost/geometry/algorithms/detail/within/point_in_geometry.hpp @@ -65,14 +65,11 @@ int point_in_range(Point const& point, Range const& range, Strategy const& strat iterator_type it = boost::begin(range); iterator_type end = boost::end(range); - bool stop = false; - for ( iterator_type previous = it++ ; - it != end && ! stop ; - ++previous, ++it ) + for ( iterator_type previous = it++ ; it != end ; ++previous, ++it ) { if ( ! strategy.apply(point, *previous, *it, state) ) { - stop = true; + break; } } @@ -138,6 +135,8 @@ namespace detail_dispatch { namespace within { // returns 0 if P is on the boundry of G // returns -1 if P is in the exterior of G +// TODO: replace magic numbers with enum + template ::type> struct point_in_geometry @@ -155,6 +154,35 @@ struct point_in_geometry } }; +template +struct point_in_geometry +{ + template static inline + int apply(Point const& point, Segment const& segment, Strategy const& strategy) + { + typedef typename geometry::point_type::type point_type; + point_type p0, p1; +// TODO: don't copy points + detail::assign_point_from_index<0>(segment, p0); + detail::assign_point_from_index<1>(segment, p1); + + typename Strategy::state_type state; + strategy.apply(point, p0, p1, state); + int r = detail::within::check_result_type(strategy.result(state)); + + if ( r != 0 ) + return -1; // exterior + + // if the point is equal to the one of the terminal points + if ( detail::equals::equals_point_point(point, p0) + || detail::equals::equals_point_point(point, p1) ) + return 0; // boundary + else + return 1; // interior + } +}; + + template struct point_in_geometry { @@ -165,17 +193,17 @@ struct point_in_geometry if ( count > 1 ) { if ( detail::within::point_in_range(point, linestring, strategy) != 0 ) - return -1; + return -1; // exterior // if the linestring doesn't have a boundary if ( detail::equals::equals_point_point(*boost::begin(linestring), *(--boost::end(linestring))) ) - return 1; + return 1; // interior // else if the point is equal to the one of the terminal points else if ( detail::equals::equals_point_point(point, *boost::begin(linestring)) || detail::equals::equals_point_point(point, *(--boost::end(linestring))) ) - return 0; + return 0; // boundary else - return 1; + return 1; // interior } // TODO: for now degenerated linestrings are ignored // throw an exception here? @@ -185,7 +213,7 @@ struct point_in_geometry return 1; }*/ - return -1; + return -1; // exterior } }; diff --git a/include/boost/geometry/algorithms/within.hpp b/include/boost/geometry/algorithms/within.hpp index 2bbf337db..f66b1ed1c 100644 --- a/include/boost/geometry/algorithms/within.hpp +++ b/include/boost/geometry/algorithms/within.hpp @@ -136,6 +136,11 @@ struct within // P/L +template +struct within + : public detail::within::use_point_in_geometry +{}; + template struct within : public detail::within::use_point_in_geometry diff --git a/test/algorithms/covered_by.cpp b/test/algorithms/covered_by.cpp index ad2cfac22..b4a00ea89 100644 --- a/test/algorithms/covered_by.cpp +++ b/test/algorithms/covered_by.cpp @@ -39,6 +39,11 @@ void test_all() */ + typedef bg::model::segment

seg; + test_geometry("POINT(1 1)", "LINESTRING(0 0, 2 2)", true); + test_geometry("POINT(0 0)", "LINESTRING(0 0, 1 1)", true); + test_geometry("POINT(1 0)", "LINESTRING(0 0, 1 1)", false); + // linestrings typedef bg::model::linestring

ls; test_geometry("POINT(0 0)", "LINESTRING(0 0,1 1,2 2)", true); diff --git a/test/algorithms/intersects.cpp b/test/algorithms/intersects.cpp index 8477d7907..82bd0fe8e 100644 --- a/test/algorithms/intersects.cpp +++ b/test/algorithms/intersects.cpp @@ -123,6 +123,16 @@ void test_intersects_point_linestring() test_geometry("POINT(0 0)", "MULTILINESTRING((0 0,2 2,4 0))", true); } +template +void test_intersects_point_segment() +{ + typedef bg::model::segment

seg; + + test_geometry("POINT(0 0)", "LINESTRING(0 0,2 2)", true); + test_geometry("POINT(1 1)", "LINESTRING(0 0,2 2)", true); + test_geometry("POINT(1 0)", "LINESTRING(0 0,2 2)", false); +} + template void test_all() { @@ -146,6 +156,7 @@ void test_all() "POLYGON((1941 2066,2055 2066,2055 2166,1941 2166))", "BOX(1941 2066, 2055 2166)", true); + test_intersects_point_segment

(); test_intersects_point_linestring

(); test_intersects_polygon_polygon

(); test_intersects_linestring_polygon

(); diff --git a/test/algorithms/within_pointlike_xxx.cpp b/test/algorithms/within_pointlike_xxx.cpp index 8558f33c9..db281aecf 100644 --- a/test/algorithms/within_pointlike_xxx.cpp +++ b/test/algorithms/within_pointlike_xxx.cpp @@ -37,9 +37,14 @@ void test_p_p() template void test_p_l() { + typedef bg::model::segment

seg; typedef bg::model::linestring

ls; typedef bg::model::multi_linestring mls; + test_geometry("POINT(1 1)", "LINESTRING(0 0, 2 2)", true); + test_geometry("POINT(0 0)", "LINESTRING(0 0, 1 1)", false); + test_geometry("POINT(1 0)", "LINESTRING(0 0, 1 1)", false); + test_geometry("POINT(0 0)", "LINESTRING(0 0,1 1,2 2)", false); test_geometry("POINT(3 3)", "LINESTRING(0 0,1 1,2 2)", false); test_geometry("POINT(1 1)", "LINESTRING(0 0,2 2,3 3)", true); From 1403662e39cffcfd3f8586253101574e0e8461c2 Mon Sep 17 00:00:00 2001 From: Adam Wulkiewicz Date: Mon, 16 Jun 2014 03:59:07 +0200 Subject: [PATCH 4/4] [doc] Update status matrices for intersects() and disjoints() --- doc/reference/status/disjoint_status.qbk | 4 ++-- doc/reference/status/intersects_status.qbk | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/doc/reference/status/disjoint_status.qbk b/doc/reference/status/disjoint_status.qbk index 0760a55f8..7c838e7c4 100644 --- a/doc/reference/status/disjoint_status.qbk +++ b/doc/reference/status/disjoint_status.qbk @@ -1,8 +1,8 @@ [heading Supported geometries] [table [[ ][Point][Segment][Box][Linestring][Ring][Polygon][MultiPoint][MultiLinestring][MultiPolygon][Variant]] -[[Point][ [$img/ok.png] ][ [$img/nyi.png] ][ [$img/ok.png] ][ [$img/ok.png] ][ [$img/ok.png] ][ [$img/ok.png] ][ [$img/nyi.png] ][ [$img/ok.png] ][ [$img/ok.png] ][ [$img/ok.png] ]] -[[Segment][ [$img/nyi.png] ][ [$img/ok.png] ][ [$img/ok.png] ][ [$img/ok.png] ][ [$img/ok.png] ][ [$img/ok.png] ][ [$img/nyi.png] ][ [$img/nyi.png] ][ [$img/nyi.png] ][ [$img/ok.png] ]] +[[Point][ [$img/ok.png] ][ [$img/ok.png] ][ [$img/ok.png] ][ [$img/ok.png] ][ [$img/ok.png] ][ [$img/ok.png] ][ [$img/nyi.png] ][ [$img/ok.png] ][ [$img/ok.png] ][ [$img/ok.png] ]] +[[Segment][ [$img/ok.png] ][ [$img/ok.png] ][ [$img/ok.png] ][ [$img/ok.png] ][ [$img/ok.png] ][ [$img/ok.png] ][ [$img/nyi.png] ][ [$img/nyi.png] ][ [$img/nyi.png] ][ [$img/ok.png] ]] [[Box][ [$img/ok.png] ][ [$img/ok.png] ][ [$img/ok.png] ][ [$img/ok.png] ][ [$img/ok.png] ][ [$img/ok.png] ][ [$img/nyi.png] ][ [$img/nyi.png] ][ [$img/ok.png] ][ [$img/ok.png] ]] [[Linestring][ [$img/ok.png] ][ [$img/ok.png] ][ [$img/ok.png] ][ [$img/ok.png] ][ [$img/ok.png] ][ [$img/ok.png] ][ [$img/nyi.png] ][ [$img/nyi.png] ][ [$img/ok.png] ][ [$img/ok.png] ]] [[Ring][ [$img/ok.png] ][ [$img/ok.png] ][ [$img/ok.png] ][ [$img/ok.png] ][ [$img/ok.png] ][ [$img/ok.png] ][ [$img/nyi.png] ][ [$img/ok.png] ][ [$img/ok.png] ][ [$img/ok.png] ]] diff --git a/doc/reference/status/intersects_status.qbk b/doc/reference/status/intersects_status.qbk index 0760a55f8..7c838e7c4 100644 --- a/doc/reference/status/intersects_status.qbk +++ b/doc/reference/status/intersects_status.qbk @@ -1,8 +1,8 @@ [heading Supported geometries] [table [[ ][Point][Segment][Box][Linestring][Ring][Polygon][MultiPoint][MultiLinestring][MultiPolygon][Variant]] -[[Point][ [$img/ok.png] ][ [$img/nyi.png] ][ [$img/ok.png] ][ [$img/ok.png] ][ [$img/ok.png] ][ [$img/ok.png] ][ [$img/nyi.png] ][ [$img/ok.png] ][ [$img/ok.png] ][ [$img/ok.png] ]] -[[Segment][ [$img/nyi.png] ][ [$img/ok.png] ][ [$img/ok.png] ][ [$img/ok.png] ][ [$img/ok.png] ][ [$img/ok.png] ][ [$img/nyi.png] ][ [$img/nyi.png] ][ [$img/nyi.png] ][ [$img/ok.png] ]] +[[Point][ [$img/ok.png] ][ [$img/ok.png] ][ [$img/ok.png] ][ [$img/ok.png] ][ [$img/ok.png] ][ [$img/ok.png] ][ [$img/nyi.png] ][ [$img/ok.png] ][ [$img/ok.png] ][ [$img/ok.png] ]] +[[Segment][ [$img/ok.png] ][ [$img/ok.png] ][ [$img/ok.png] ][ [$img/ok.png] ][ [$img/ok.png] ][ [$img/ok.png] ][ [$img/nyi.png] ][ [$img/nyi.png] ][ [$img/nyi.png] ][ [$img/ok.png] ]] [[Box][ [$img/ok.png] ][ [$img/ok.png] ][ [$img/ok.png] ][ [$img/ok.png] ][ [$img/ok.png] ][ [$img/ok.png] ][ [$img/nyi.png] ][ [$img/nyi.png] ][ [$img/ok.png] ][ [$img/ok.png] ]] [[Linestring][ [$img/ok.png] ][ [$img/ok.png] ][ [$img/ok.png] ][ [$img/ok.png] ][ [$img/ok.png] ][ [$img/ok.png] ][ [$img/nyi.png] ][ [$img/nyi.png] ][ [$img/ok.png] ][ [$img/ok.png] ]] [[Ring][ [$img/ok.png] ][ [$img/ok.png] ][ [$img/ok.png] ][ [$img/ok.png] ][ [$img/ok.png] ][ [$img/ok.png] ][ [$img/nyi.png] ][ [$img/ok.png] ][ [$img/ok.png] ][ [$img/ok.png] ]]