From 429b5e003731ad851a6993c827b53770351b54f5 Mon Sep 17 00:00:00 2001 From: Menelaos Karavelas Date: Fri, 14 Mar 2014 23:04:01 +0200 Subject: [PATCH 1/4] implementation and unit test for bg::append for multi-linestring and multi-polygon --- include/boost/geometry/algorithms/append.hpp | 2 +- .../geometry/multi/algorithms/append.hpp | 59 +++++++- test/algorithms/append.cpp | 129 ++++++++++++++---- 3 files changed, 161 insertions(+), 29 deletions(-) diff --git a/include/boost/geometry/algorithms/append.hpp b/include/boost/geometry/algorithms/append.hpp index 3e6e07020..594d80615 100644 --- a/include/boost/geometry/algorithms/append.hpp +++ b/include/boost/geometry/algorithms/append.hpp @@ -105,7 +105,7 @@ struct range_to_polygon typedef typename ring_type::type ring_type; static inline void apply(Polygon& polygon, Range const& range, - int ring_index, int ) + int ring_index, int = 0) { if (ring_index == -1) { diff --git a/include/boost/geometry/multi/algorithms/append.hpp b/include/boost/geometry/multi/algorithms/append.hpp index bb97af1aa..3eb606e6c 100644 --- a/include/boost/geometry/multi/algorithms/append.hpp +++ b/include/boost/geometry/multi/algorithms/append.hpp @@ -1,8 +1,13 @@ // 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) 2007-2014 Barend Gehrels, Amsterdam, the Netherlands. +// Copyright (c) 2008-2014 Bruno Lalande, Paris, France. +// Copyright (c) 2009-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 // Parts of Boost.Geometry are redesigned from Geodan's Geographic Library // (geolib/GGL), copyright (c) 1995-2010 Geodan, Amsterdam, the Netherlands. @@ -23,6 +28,34 @@ namespace boost { namespace geometry { + +#ifndef DOXYGEN_NO_DETAIL +namespace detail { namespace append +{ + + +template +struct append_to_multigeometry +{ + static inline void apply(MultiGeometry& multigeometry, + RangeOrPoint const& range_or_point, + int ring_index, int multi_index) + { + + dispatch::append + < + typename boost::range_value::type, + RangeOrPoint + >::apply(multigeometry[multi_index], range_or_point, ring_index); + } +}; + + +}} // namespace detail::append +#endif // DOXYGEN_NO_DETAIL + + + #ifndef DOXYGEN_NO_DISPATCH namespace dispatch { @@ -40,6 +73,26 @@ struct append_range : detail::append::append_range {}; +template +struct append_point + : detail::append::append_to_multigeometry +{}; + +template +struct append_range + : detail::append::append_to_multigeometry +{}; + +template +struct append_point + : detail::append::append_to_multigeometry +{}; + +template +struct append_range + : detail::append::append_to_multigeometry +{}; + } diff --git a/test/algorithms/append.cpp b/test/algorithms/append.cpp index 7c7728eeb..36d06a93b 100644 --- a/test/algorithms/append.cpp +++ b/test/algorithms/append.cpp @@ -1,9 +1,14 @@ // Boost.Geometry (aka GGL, Generic Geometry Library) // Unit Test -// 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) 2007-2014 Barend Gehrels, Amsterdam, the Netherlands. +// Copyright (c) 2008-2014 Bruno Lalande, Paris, France. +// Copyright (c) 2009-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 // Parts of Boost.Geometry are redesigned from Geodan's Geographic Library // (geolib/GGL), copyright (c) 1995-2010 Geodan, Amsterdam, the Netherlands. @@ -30,51 +35,116 @@ #include #include +// includes for multi-geometries +#include +#include +#include +#include +#include +#include +#include + BOOST_GEOMETRY_REGISTER_LINESTRING_TEMPLATED(std::vector) BOOST_GEOMETRY_REGISTER_LINESTRING_TEMPLATED(std::deque) -template -void test_geometry(G& geometry, bool check) +template +struct do_checks { - typedef typename bg::point_type::type P; - - bg::append(geometry, bg::make_zero

()); - if (check) + template + static inline void apply(G const& geometry, + std::size_t size1, + std::size_t = 0, + std::size_t = 0) { - BOOST_CHECK_EQUAL(bg::num_points(geometry), 1u); + BOOST_CHECK_EQUAL(bg::num_points(geometry), size1); } +}; - // Append a range - std::vector

v; - v.push_back(bg::make_zero

()); - v.push_back(bg::make_zero

()); - bg::append(geometry, v); - if (check) +template<> +struct do_checks +{ + template + static inline void apply(G const& geometry, + std::size_t size1, + std::size_t size2 = 0, + std::size_t size3 = 0) { - BOOST_CHECK_EQUAL(bg::num_points(geometry), 3u); + do_checks::apply(geometry, size1); + BOOST_CHECK_EQUAL(bg::num_points(geometry[0]), size2); + BOOST_CHECK_EQUAL(bg::num_points(geometry[1]), size3); } +}; - bg::clear(geometry); - if (check) + +template +struct test_geometry +{ + template + static inline void apply(G& geometry, bool check) { - BOOST_CHECK_EQUAL(bg::num_points(geometry), 0u); - } + typedef typename bg::point_type::type P; + typedef do_checks checks; + + bg::append(geometry, bg::make_zero

(), -1, 0); + if (check) + { + checks::apply(geometry, 1u, 1u, 0u); + } + + // Append a range + std::vector

v; + v.push_back(bg::make_zero

()); + v.push_back(bg::make_zero

()); + bg::append(geometry, v, -1, 1); + + if (check) + { + checks::apply(geometry, 3u, 1u, 2u); + } + + bg::clear(geometry); + + if (check) + { + do_checks::apply(geometry, 0u); + // BOOST_CHECK_EQUAL(bg::num_points(geometry), 0u); + } + + //P p = boost::range::front(geometry); + } +}; + - //P p = boost::range::front(geometry); -} template void test_geometry_and_variant(bool check = true) { G geometry; boost::variant variant_geometry = G(); - test_geometry(geometry, check); - test_geometry(variant_geometry, check); + test_geometry::apply(geometry, check); + test_geometry::apply(variant_geometry, check); } + +template +void test_multigeometry_and_variant(bool check = true) +{ + typedef typename boost::range_value::type G; + + G geometry; + MG multigeometry; + bg::traits::push_back::apply(multigeometry, geometry); + bg::traits::push_back::apply(multigeometry, geometry); + + boost::variant variant_multigeometry = multigeometry; + test_geometry::apply(multigeometry, check); + test_geometry::apply(variant_multigeometry, check); +} + + template void test_all() { @@ -84,6 +154,15 @@ void test_all() test_geometry_and_variant >(); test_geometry_and_variant >(); test_geometry_and_variant >(); + test_geometry_and_variant >(); + test_multigeometry_and_variant + < + bg::model::multi_linestring > + >(); + test_multigeometry_and_variant + < + bg::model::multi_polygon > + >(); test_geometry_and_variant >(); test_geometry_and_variant >(); From 4039c284972a45883aeefe9d6237d938a9e21db3 Mon Sep 17 00:00:00 2001 From: Menelaos Karavelas Date: Sat, 15 Mar 2014 11:52:04 +0200 Subject: [PATCH 2/4] removed commented lines as per Bruno's suggestion --- test/algorithms/append.cpp | 4 ---- 1 file changed, 4 deletions(-) diff --git a/test/algorithms/append.cpp b/test/algorithms/append.cpp index 36d06a93b..2a3d01a86 100644 --- a/test/algorithms/append.cpp +++ b/test/algorithms/append.cpp @@ -110,10 +110,7 @@ struct test_geometry if (check) { do_checks::apply(geometry, 0u); - // BOOST_CHECK_EQUAL(bg::num_points(geometry), 0u); } - - //P p = boost::range::front(geometry); } }; @@ -166,7 +163,6 @@ void test_all() test_geometry_and_variant >(); test_geometry_and_variant >(); - //test_geometry_and_variant >(); } int test_main(int, char* []) From 971247df047e4e40ae2757e523954e65dcaf505f Mon Sep 17 00:00:00 2001 From: Menelaos Karavelas Date: Mon, 17 Mar 2014 09:42:14 +0200 Subject: [PATCH 3/4] updated the documentation wrt multi-linestrings and multi-polygons --- doc/generated/append_status.qbk | 5 ++--- doc/reference/algorithms/append.qbk | 16 ++++++++++++++++ include/boost/geometry/algorithms/append.hpp | 2 +- 3 files changed, 19 insertions(+), 4 deletions(-) diff --git a/doc/generated/append_status.qbk b/doc/generated/append_status.qbk index 51329f887..ba6925202 100644 --- a/doc/generated/append_status.qbk +++ b/doc/generated/append_status.qbk @@ -1,4 +1,3 @@ -[/NOTE: adapted manually, multi-linestring/multi-polygon do compile but not run!] [heading Supported geometries] [table [[ ][Point][Range]] @@ -9,6 +8,6 @@ [[Ring][ [$img/ok.png] ][ [$img/ok.png] ]] [[Polygon][ [$img/ok.png] ][ [$img/ok.png] ]] [[MultiPoint][ [$img/ok.png] ][ [$img/ok.png] ]] -[[MultiLinestring][ [$img/nyi.png] ][ [$img/nyi.png] ]] -[[MultiPolygon][ [$img/nyi.png] ][ [$img/nyi.png] ]] +[[MultiLinestring][ [$img/ok.png] ][ [$img/ok.png] ]] +[[MultiPolygon][ [$img/ok.png] ][ [$img/ok.png] ]] ] diff --git a/doc/reference/algorithms/append.qbk b/doc/reference/algorithms/append.qbk index 3582dfbf4..c1be7df5c 100644 --- a/doc/reference/algorithms/append.qbk +++ b/doc/reference/algorithms/append.qbk @@ -26,6 +26,22 @@ either the exterior ring (the default) or specify a zero-based index for one of the interior rings. In the last case, the interior rings are not resized automatically, so ensure that the zero-based index is smaller than the number of interior rings]] +[[__multi_linestring__][Appends point or range to the end of the + linestring with the given multi index. + The multi-linestring is not resized automatically, so ensure + that the multi index is smaller than then number of linestring + in the multi-linestring.]] +[[__multi_polygon__][Appends point or range to the end of the polygon + (without explicitly closing it) with the given multi-index. + The point or range is appended at the end of the + exterior ring (the default) or specify a zero-based ring index for + the interior rings. + The multi-polygon is not resized automatically, so ensure + that the multi index is smaller than then number of polygon + in the multi-polygon. The same applies for the interior rings + of the polygon: the interior rings are not resized + automatically, so ensure that the zero-based ring index is + smaller than the number of interior rings of the polygon.]] ] [heading Complexity] diff --git a/include/boost/geometry/algorithms/append.hpp b/include/boost/geometry/algorithms/append.hpp index 594d80615..9c2c042f1 100644 --- a/include/boost/geometry/algorithms/append.hpp +++ b/include/boost/geometry/algorithms/append.hpp @@ -275,7 +275,7 @@ struct append > \param range_or_point The point or range to add \param ring_index The index of the ring in case of a polygon: exterior ring (-1, the default) or interior ring index -\param multi_index Reserved for multi polygons or multi linestrings +\param multi_index The index of the geometry to which the points are appended \qbk{[include reference/algorithms/append.qbk]} } From 79bbb5a40846d18674b7ce73420de8953499fe63 Mon Sep 17 00:00:00 2001 From: Menelaos Karavelas Date: Mon, 17 Mar 2014 09:51:37 +0200 Subject: [PATCH 4/4] [geometry][append] updated copyright headers --- doc/reference/algorithms/append.qbk | 11 ++++++++--- include/boost/geometry/algorithms/append.hpp | 11 ++++++++--- 2 files changed, 16 insertions(+), 6 deletions(-) diff --git a/doc/reference/algorithms/append.qbk b/doc/reference/algorithms/append.qbk index c1be7df5c..402f41cc6 100644 --- a/doc/reference/algorithms/append.qbk +++ b/doc/reference/algorithms/append.qbk @@ -1,9 +1,14 @@ [/============================================================================ Boost.Geometry (aka GGL, Generic Geometry Library) - Copyright (c) 2009-2012 Barend Gehrels, Amsterdam, the Netherlands. - Copyright (c) 2009-2012 Mateusz Loskot, London, UK. - Copyright (c) 2009-2012 Bruno Lalande, Paris, France. + Copyright (c) 2009-2014 Barend Gehrels, Amsterdam, the Netherlands. + Copyright (c) 2009-2014 Mateusz Loskot, London, UK. + Copyright (c) 2009-2014 Bruno Lalande, Paris, France. + + 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 diff --git a/include/boost/geometry/algorithms/append.hpp b/include/boost/geometry/algorithms/append.hpp index 9c2c042f1..1dafac04b 100644 --- a/include/boost/geometry/algorithms/append.hpp +++ b/include/boost/geometry/algorithms/append.hpp @@ -1,8 +1,13 @@ // 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) 2007-2014 Barend Gehrels, Amsterdam, the Netherlands. +// Copyright (c) 2008-2014 Bruno Lalande, Paris, France. +// Copyright (c) 2009-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 // Parts of Boost.Geometry are redesigned from Geodan's Geographic Library // (geolib/GGL), copyright (c) 1995-2010 Geodan, Amsterdam, the Netherlands.