From 4badcdc600aea5bdbb38338e2ef44d061b257aeb Mon Sep 17 00:00:00 2001 From: Barend Gehrels Date: Sun, 20 Feb 2011 18:18:10 +0000 Subject: [PATCH] Moved dissolve to extension Fixed extensions connect/offset tests for gcc [SVN r69086] --- doc/make_qbk.py | 2 +- doc/quickref.xml | 4 - doc/reference.qbk | 4 - doc/reference/dissolve.qbk | 15 -- .../extensions/algorithms/connect.hpp | 37 +-- .../algorithms/detail/overlay/dissolver.hpp | 6 +- .../algorithms/detail/overlay/split_rings.hpp | 6 +- .../{ => extensions}/algorithms/dissolve.hpp | 6 +- .../multi/algorithms/dissolve.hpp | 10 +- include/boost/geometry/geometry.hpp | 1 - include/boost/geometry/multi/multi.hpp | 1 - include/boost/geometry/strategies/buffer.hpp | 2 + test/algorithms/algorithms_tests.sln | 6 - test/algorithms/test_dissolve.hpp | 152 ------------ test/extensions/Jamfile.v2 | 1 + test/extensions/algorithms/Jamfile.v2 | 16 ++ test/extensions/algorithms/connect.cpp | 5 +- test/{ => extensions}/algorithms/dissolve.cpp | 220 +++++++++++++++++- .../algorithms/dissolve.vcproj | 8 +- .../algorithms/extension_algorithms.sln | 6 + test/extensions/algorithms/offset.cpp | 20 +- test/multi/algorithms/multi_dissolve.cpp | 68 ------ test/multi/algorithms/multi_dissolve.vcproj | 174 -------------- 23 files changed, 291 insertions(+), 479 deletions(-) delete mode 100644 doc/reference/dissolve.qbk rename include/boost/geometry/{ => extensions}/algorithms/detail/overlay/dissolver.hpp (98%) rename include/boost/geometry/{ => extensions}/algorithms/detail/overlay/split_rings.hpp (98%) rename include/boost/geometry/{ => extensions}/algorithms/dissolve.hpp (97%) rename include/boost/geometry/{ => extensions}/multi/algorithms/dissolve.hpp (88%) delete mode 100644 test/algorithms/test_dissolve.hpp create mode 100644 test/extensions/algorithms/Jamfile.v2 rename test/{ => extensions}/algorithms/dissolve.cpp (62%) rename test/{ => extensions}/algorithms/dissolve.vcproj (93%) delete mode 100644 test/multi/algorithms/multi_dissolve.cpp delete mode 100644 test/multi/algorithms/multi_dissolve.vcproj diff --git a/doc/make_qbk.py b/doc/make_qbk.py index 415416e88..dca33bf19 100755 --- a/doc/make_qbk.py +++ b/doc/make_qbk.py @@ -57,7 +57,7 @@ call_doxygen() algorithms = ["append", "assign", "make", "clear" , "area", "buffer", "centroid", "combine", "convert", "correct" - , "convex_hull", "difference", "disjoint", "dissolve", "distance" + , "convex_hull", "difference", "disjoint", "distance" , "envelope", "equals", "for_each", "intersection", "intersects" , "length", "num_geometries", "num_interior_rings", "num_points" , "overlaps", "perimeter", "reverse", "simplify", "sym_difference" diff --git a/doc/quickref.xml b/doc/quickref.xml index e5b040568..bbd2bddfe 100644 --- a/doc/quickref.xml +++ b/doc/quickref.xml @@ -344,10 +344,6 @@ difference sym_difference - Dissolve - - dissolve - Envelope envelope diff --git a/doc/reference.qbk b/doc/reference.qbk index d535ff271..e53633121 100644 --- a/doc/reference.qbk +++ b/doc/reference.qbk @@ -92,10 +92,6 @@ [include reference/disjoint.qbk] [endsect] -[section:dissolve dissolve] -[include reference/dissolve.qbk] -[endsect] - [section:distance distance] [include reference/distance.qbk] diff --git a/doc/reference/dissolve.qbk b/doc/reference/dissolve.qbk deleted file mode 100644 index 62530158c..000000000 --- a/doc/reference/dissolve.qbk +++ /dev/null @@ -1,15 +0,0 @@ -[/============================================================================ - Boost.Geometry (aka GGL, Generic Geometry Library) - - Copyright (c) 2009-2011 Barend Gehrels, Geodan, Amsterdam, the Netherlands. - Copyright (c) 2009-2011 Mateusz Loskot (mateusz@loskot.net) - Copyright (c) 2009-2011 Bruno Lalande, Paris, France. - - 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) -=============================================================================/] - - -[/ Generated by doxygen_xml2qbk, don't change, will be overwritten automatically] -[/ Generated from doxy/doxygen_output/xml/group__dissolve.xml] diff --git a/include/boost/geometry/extensions/algorithms/connect.hpp b/include/boost/geometry/extensions/algorithms/connect.hpp index fd76ae876..d499ce746 100644 --- a/include/boost/geometry/extensions/algorithms/connect.hpp +++ b/include/boost/geometry/extensions/algorithms/connect.hpp @@ -38,17 +38,17 @@ namespace detail { namespace connect template struct node { - Point point; int index; bool is_from; + Point point; - node(int i, bool f, Point const& p) + node(int i, bool f, Point const& p) : index(i) , is_from(f) , point(p) {} - node() + node() : index(-1) , is_from(false) {} @@ -83,7 +83,7 @@ struct map_policy inline bool find_start(node& object, - std::map& included, + std::map& included, int expected_count = 1) { for (map_iterator_type it = map.begin(); @@ -211,7 +211,7 @@ struct fuzzy_policy {} inline bool find_start(node& object, - std::map& included, + std::map& included, int expected_count = 1) { for (map_iterator_type it = map.begin(); @@ -357,11 +357,11 @@ inline void debug(Policy const& policy) { std::cout << geometry::dsv(it->first) << " => " ; std::vector > const& range =it->second; - for ( std::vector >::const_iterator + for (typename std::vector >::const_iterator vit = boost::begin(range); vit != boost::end(range); ++vit) { - std::cout - << " (" << vit->index + std::cout + << " (" << vit->index << ", " << (vit->is_from ? "F" : "T") << ")" ; @@ -451,7 +451,7 @@ struct connect_multi_linestring included[closest.index] = true; copy(multi[closest.index], current, closest.is_from); } - else if ((included.size() != boost::size(multi))) + else if ((included.size() != std::size_t(boost::size(multi)))) { // Get one which is NOT found and go again node next; @@ -500,7 +500,7 @@ template struct connect : detail::connect::connect_multi_linestring < - Multi, + Multi, GeometryOut, Policy > @@ -526,7 +526,9 @@ inline void connect(Geometry const& geometry, Collection& output_collection) typedef detail::connect::map_policy < typename point_type::type - > policy; + > policy_type; + + policy_type policy; dispatch::connect < @@ -534,8 +536,8 @@ inline void connect(Geometry const& geometry, Collection& output_collection) typename tag::type, Geometry, geometry_out, - policy - >::apply(geometry, policy(), std::back_inserter(output_collection)); + policy_type + >::apply(geometry, policy, std::back_inserter(output_collection)); } @@ -545,7 +547,7 @@ template typename Geometry, typename Collection > -inline void connect(Geometry const& geometry, Collection& output_collection, +inline void connect(Geometry const& geometry, Collection& output_collection, typename coordinate_type::type const& limit) { typedef typename boost::range_value::type geometry_out; @@ -556,8 +558,9 @@ inline void connect(Geometry const& geometry, Collection& output_collection, typedef detail::connect::fuzzy_policy < typename point_type::type - > policy; + > policy_type; + policy_type policy(limit); dispatch::connect < @@ -565,8 +568,8 @@ inline void connect(Geometry const& geometry, Collection& output_collection, typename tag::type, Geometry, geometry_out, - policy - >::apply(geometry, policy(limit), std::back_inserter(output_collection)); + policy_type + >::apply(geometry, policy, std::back_inserter(output_collection)); } diff --git a/include/boost/geometry/algorithms/detail/overlay/dissolver.hpp b/include/boost/geometry/extensions/algorithms/detail/overlay/dissolver.hpp similarity index 98% rename from include/boost/geometry/algorithms/detail/overlay/dissolver.hpp rename to include/boost/geometry/extensions/algorithms/detail/overlay/dissolver.hpp index b6d34b54e..4201bb64f 100644 --- a/include/boost/geometry/algorithms/detail/overlay/dissolver.hpp +++ b/include/boost/geometry/extensions/algorithms/detail/overlay/dissolver.hpp @@ -5,8 +5,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_DETAIL_OVERLAY_DISSOLVER_HPP -#define BOOST_GEOMETRY_ALGORITHMS_DETAIL_OVERLAY_DISSOLVER_HPP +#ifndef BOOST_GEOMETRY_EXTENSIONS_ALGORITHMS_DETAIL_OVERLAY_DISSOLVER_HPP +#define BOOST_GEOMETRY_EXTENSIONS_ALGORITHMS_DETAIL_OVERLAY_DISSOLVER_HPP #include @@ -635,4 +635,4 @@ inline void dissolver(InputRange const& input_range, }} // namespace boost::geometry -#endif // BOOST_GEOMETRY_ALGORITHMS_DETAIL_OVERLAY_DISSOLVER_HPP +#endif // BOOST_GEOMETRY_EXTENSIONS_ALGORITHMS_DETAIL_OVERLAY_DISSOLVER_HPP diff --git a/include/boost/geometry/algorithms/detail/overlay/split_rings.hpp b/include/boost/geometry/extensions/algorithms/detail/overlay/split_rings.hpp similarity index 98% rename from include/boost/geometry/algorithms/detail/overlay/split_rings.hpp rename to include/boost/geometry/extensions/algorithms/detail/overlay/split_rings.hpp index 41000e973..ef241674b 100644 --- a/include/boost/geometry/algorithms/detail/overlay/split_rings.hpp +++ b/include/boost/geometry/extensions/algorithms/detail/overlay/split_rings.hpp @@ -5,8 +5,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_DETAIL_OVERLAY_SPLIT_RINGS_HPP -#define BOOST_GEOMETRY_ALGORITHMS_DETAIL_OVERLAY_SPLIT_RINGS_HPP +#ifndef BOOST_GEOMETRY_EXTENSIONS_ALGORITHMS_DETAIL_OVERLAY_SPLIT_RINGS_HPP +#define BOOST_GEOMETRY_EXTENSIONS_ALGORITHMS_DETAIL_OVERLAY_SPLIT_RINGS_HPP #define BOOST_GEOMETRY_CHECK_SPLIT_RINGS @@ -559,4 +559,4 @@ inline void split_rings(Geometry const& geometry, RingCollection& out) }} // namespace boost::geometry -#endif // BOOST_GEOMETRY_ALGORITHMS_DETAIL_OVERLAY_SPLIT_RINGS_HPP +#endif // BOOST_GEOMETRY_EXTENSIONS_ALGORITHMS_DETAIL_OVERLAY_SPLIT_RINGS_HPP diff --git a/include/boost/geometry/algorithms/dissolve.hpp b/include/boost/geometry/extensions/algorithms/dissolve.hpp similarity index 97% rename from include/boost/geometry/algorithms/dissolve.hpp rename to include/boost/geometry/extensions/algorithms/dissolve.hpp index 809a56e32..ce1b1bf81 100644 --- a/include/boost/geometry/algorithms/dissolve.hpp +++ b/include/boost/geometry/extensions/algorithms/dissolve.hpp @@ -5,8 +5,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_DISSOLVE_HPP -#define BOOST_GEOMETRY_ALGORITHMS_DISSOLVE_HPP +#ifndef BOOST_GEOMETRY_EXTENSIONS_ALGORITHMS_DISSOLVE_HPP +#define BOOST_GEOMETRY_EXTENSIONS_ALGORITHMS_DISSOLVE_HPP #include @@ -213,4 +213,4 @@ inline void dissolve(Geometry const& geometry, Collection& output_collection) }} // namespace boost::geometry -#endif // BOOST_GEOMETRY_ALGORITHMS_DISSOLVE_HPP +#endif // BOOST_GEOMETRY_EXTENSIONS_ALGORITHMS_DISSOLVE_HPP diff --git a/include/boost/geometry/multi/algorithms/dissolve.hpp b/include/boost/geometry/extensions/multi/algorithms/dissolve.hpp similarity index 88% rename from include/boost/geometry/multi/algorithms/dissolve.hpp rename to include/boost/geometry/extensions/multi/algorithms/dissolve.hpp index c4d53b5c5..7f5b78f91 100644 --- a/include/boost/geometry/multi/algorithms/dissolve.hpp +++ b/include/boost/geometry/extensions/multi/algorithms/dissolve.hpp @@ -5,8 +5,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_MULTI_ALGORITHMS_DISSOLVE_HPP -#define BOOST_GEOMETRY_MULTI_ALGORITHMS_DISSOLVE_HPP +#ifndef BOOST_GEOMETRY_EXTENSIONS_MULTI_ALGORITHMS_DISSOLVE_HPP +#define BOOST_GEOMETRY_EXTENSIONS_MULTI_ALGORITHMS_DISSOLVE_HPP #include @@ -16,10 +16,10 @@ #include #include -#include #include -#include +#include +#include namespace boost { namespace geometry @@ -95,4 +95,4 @@ struct dissolve }} // namespace boost::geometry -#endif // BOOST_GEOMETRY_MULTI_ALGORITHMS_DISSOLVE_HPP +#endif // BOOST_GEOMETRY_EXTENSIONS_MULTI_ALGORITHMS_DISSOLVE_HPP diff --git a/include/boost/geometry/geometry.hpp b/include/boost/geometry/geometry.hpp index 399a3353c..e7c1a2e2d 100644 --- a/include/boost/geometry/geometry.hpp +++ b/include/boost/geometry/geometry.hpp @@ -41,7 +41,6 @@ #include #include #include -#include #include #include #include diff --git a/include/boost/geometry/multi/multi.hpp b/include/boost/geometry/multi/multi.hpp index ac3b06fb9..6f017a7c4 100644 --- a/include/boost/geometry/multi/multi.hpp +++ b/include/boost/geometry/multi/multi.hpp @@ -27,7 +27,6 @@ #include #include #include -#include #include #include #include diff --git a/include/boost/geometry/strategies/buffer.hpp b/include/boost/geometry/strategies/buffer.hpp index daa71e715..4377aa884 100644 --- a/include/boost/geometry/strategies/buffer.hpp +++ b/include/boost/geometry/strategies/buffer.hpp @@ -204,6 +204,8 @@ struct join_bevel #endif + typedef typename coordinate_type::type coordinate_type; + template inline void apply(PointIn const& ip, PointIn const& vertex, PointIn const& perp1, PointIn const& perp2, diff --git a/test/algorithms/algorithms_tests.sln b/test/algorithms/algorithms_tests.sln index 86bcfbc3c..2d6308527 100644 --- a/test/algorithms/algorithms_tests.sln +++ b/test/algorithms/algorithms_tests.sln @@ -40,8 +40,6 @@ Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "length", "length.vcproj", " EndProject Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "perimeter", "perimeter.vcproj", "{EFC23FC0-86D3-4C81-A218-26F0D5A4D50B}" EndProject -Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "is_convex", "is_convex.vcproj", "{65EAD0CE-1AC7-4997-B618-55712AD7D8EA}" -EndProject Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "union", "union.vcproj", "{CA5EE1D6-CB4B-4A15-85C5-31D5C00289C4}" EndProject Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "overlaps", "overlaps.vcproj", "{30C37854-9ED6-4C1E-97FB-BF8637BD5811}" @@ -144,10 +142,6 @@ Global {EFC23FC0-86D3-4C81-A218-26F0D5A4D50B}.Debug|Win32.Build.0 = Debug|Win32 {EFC23FC0-86D3-4C81-A218-26F0D5A4D50B}.Release|Win32.ActiveCfg = Release|Win32 {EFC23FC0-86D3-4C81-A218-26F0D5A4D50B}.Release|Win32.Build.0 = Release|Win32 - {65EAD0CE-1AC7-4997-B618-55712AD7D8EA}.Debug|Win32.ActiveCfg = Debug|Win32 - {65EAD0CE-1AC7-4997-B618-55712AD7D8EA}.Debug|Win32.Build.0 = Debug|Win32 - {65EAD0CE-1AC7-4997-B618-55712AD7D8EA}.Release|Win32.ActiveCfg = Release|Win32 - {65EAD0CE-1AC7-4997-B618-55712AD7D8EA}.Release|Win32.Build.0 = Release|Win32 {CA5EE1D6-CB4B-4A15-85C5-31D5C00289C4}.Debug|Win32.ActiveCfg = Debug|Win32 {CA5EE1D6-CB4B-4A15-85C5-31D5C00289C4}.Debug|Win32.Build.0 = Debug|Win32 {CA5EE1D6-CB4B-4A15-85C5-31D5C00289C4}.Release|Win32.ActiveCfg = Release|Win32 diff --git a/test/algorithms/test_dissolve.hpp b/test/algorithms/test_dissolve.hpp deleted file mode 100644 index 3fa86765d..000000000 --- a/test/algorithms/test_dissolve.hpp +++ /dev/null @@ -1,152 +0,0 @@ -// Boost.Geometry (aka GGL, Generic Geometry Library) test file -// -// Copyright Barend Gehrels 2007-2009, 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_TEST_DISSOLVE_HPP -#define BOOST_GEOMETRY_TEST_DISSOLVE_HPP - -#include - -#include - -#include - -// To check results -#include -#include -#include -#include - -#include - -#include - -#include - - -#if defined(TEST_WITH_SVG) -# include -#endif - - - -template -void test_dissolve(std::string const& caseid, Geometry const& geometry, - std::size_t expected_hole_count, std::size_t expected_point_count, - double expected_length_or_area, double percentage) -{ - typedef typename bg::coordinate_type::type coordinate_type; - - static const bool is_line = bg::geometry_id::type::value == 2; - - std::vector dissolved_vector; - bg::dissolve_inserter(geometry, std::back_inserter(dissolved_vector)); - - typename bg::area_result::type length_or_area = 0; - //std::size_t holes = 0; - std::size_t count = 0; - - BOOST_FOREACH(GeometryOut& dissolved, dissolved_vector) - { - bg::unique(dissolved); - - - length_or_area += - is_line ? bg::length(dissolved) : bg::area(dissolved); - - //holes += bg::num_interior_rings(dissolved); - count += bg::num_points(dissolved); - } - - BOOST_CHECK_MESSAGE(count == expected_point_count, - "dissolve: " << caseid - << " #points expected: " << expected_point_count - << " detected: " << count - << " type: " << string_from_type::name() - ); - - - //BOOST_CHECK_EQUAL(holes, expected_hole_count); - BOOST_CHECK_CLOSE(length_or_area, expected_length_or_area, percentage); - - // Compile check, it should also compile inplace, outputting to the same geometry - { - std::vector dissolved; - bg::dissolve(geometry, dissolved); - } - - -#if defined(TEST_WITH_SVG) - { - std::ostringstream filename; - filename << "dissolve_" - << caseid << "_" - << string_from_type::name() - << ".svg"; - - std::ofstream svg(filename.str().c_str()); - - bg::svg_mapper - < - typename bg::point_type::type - > mapper(svg, 500, 500); - mapper.add(geometry); - - mapper.map(geometry, "opacity:0.6;fill:rgb(0,0,255);stroke:rgb(0,0,0);stroke-width:1"); - BOOST_FOREACH(GeometryOut& dissolved, dissolved_vector) - { - mapper.map(dissolved, "opacity:0.6;fill:none;stroke:rgb(255,0,0);stroke-width:5"); - } - } -#endif -} - - -template -void test_one(std::string const& caseid, std::string const& wkt, - std::size_t expected_hole_count, std::size_t expected_point_count, - double expected_length_or_area, double percentage = 0.001) -{ - Geometry geometry; - bg::read_wkt(wkt, geometry); - - test_dissolve(caseid, geometry, - expected_hole_count, expected_point_count, - expected_length_or_area, percentage); - -#ifdef BOOST_GEOMETRY_TEST_MULTI_PERMUTATIONS - // Test different combinations of a multi-polygon - - int n = geometry.size(); - - // test them in all orders - std::vector indices; - for (int i = 0; i < n; i++) - { - indices.push_back(i); - } - int permutation = 0; - do - { - std::ostringstream out; - out << caseid; - Geometry geometry2; - for (int i = 0; i < n; i++) - { - int index = indices[i]; - out << "_" << index; - geometry2.push_back(geometry[index]); - } - test_dissolve(out.str(), geometry2, expected_hole_count, - expected_point_count, expected_length_or_area, percentage); - } while (std::next_permutation(indices.begin(), indices.end())); -#endif - -} - - - -#endif diff --git a/test/extensions/Jamfile.v2 b/test/extensions/Jamfile.v2 index 4f1344e94..4c290e0a1 100644 --- a/test/extensions/Jamfile.v2 +++ b/test/extensions/Jamfile.v2 @@ -6,5 +6,6 @@ # Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at # http://www.boost.org/LICENSE_1_0.txt) +build-project algorithms ; build-project gis ; diff --git a/test/extensions/algorithms/Jamfile.v2 b/test/extensions/algorithms/Jamfile.v2 new file mode 100644 index 000000000..0762c6f33 --- /dev/null +++ b/test/extensions/algorithms/Jamfile.v2 @@ -0,0 +1,16 @@ +# test/extensions/algorithms/Jamfile.v2 +# +# Copyright (c) 2011 Barend Gehrels +# +# 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) + +test-suite boost-geometry-extensions-algorithms + : + [ run dissolve.cpp ] + [ run connect.cpp ] + [ run offset.cpp ] + [ run midpoints.cpp ] + [ run selected.cpp ] + ; diff --git a/test/extensions/algorithms/connect.cpp b/test/extensions/algorithms/connect.cpp index 6755c21dd..92e279deb 100644 --- a/test/extensions/algorithms/connect.cpp +++ b/test/extensions/algorithms/connect.cpp @@ -159,8 +159,6 @@ void test_all() typedef bg::model::linestring

linestring; typedef bg::model::multi_linestring multi_linestring; - goto disconnected; - test_one("ls_simplex", "MULTILINESTRING((0 0,1 1),(1 1,2 2))", 1, 3, 2 * std::sqrt(2.0)); @@ -194,10 +192,9 @@ void test_all() "MULTILINESTRING((0 0,0 1.01),(1.02 1.03,0.99 0),(0 0.98,1.001 1),(1.01 0,0 0))", 3, 7, 4.05163658, 0.01); -disconnected: test_one("ls_disconnected_ring4", "MULTILINESTRING((0.01 0,0 1.01),(1.02 1.03,0.99 0),(0 0.98,1.001 1),(1.01 0,0.02 0))", - 1, 8, 4.137147, 0.1); + 1, 8, 4.1172, 0.1); } diff --git a/test/algorithms/dissolve.cpp b/test/extensions/algorithms/dissolve.cpp similarity index 62% rename from test/algorithms/dissolve.cpp rename to test/extensions/algorithms/dissolve.cpp index a90d1178e..66c52a9c8 100644 --- a/test/algorithms/dissolve.cpp +++ b/test/extensions/algorithms/dissolve.cpp @@ -10,7 +10,189 @@ #include -#include +#include +#include + +// To check results +#include +#include +#include +#include + +#include + +#include + +#include + +#include + +#include +#include + +#include + + + + + + +#if defined(TEST_WITH_SVG) +# include +#endif + +template +struct map_segment +{ + map_segment(Mapper& m) + : m_mapper(&m) + {} + + map_segment& operator=(map_segment const& other) + { + if(this != &other) + { + this->m_mapper = other.m_mapper; + } + return *this; + } + + + template + inline void operator()(Segment const& s) + { + // create a little offset + m_mapper->map(s, "opacity:0.6;fill:none;stroke:rgb(0,0,0);stroke-width:2"); + } + + Mapper* m_mapper; +}; + + +template +void test_dissolve(std::string const& caseid, Geometry const& geometry, + std::size_t expected_hole_count, std::size_t expected_point_count, + double expected_length_or_area, double percentage) +{ + typedef typename bg::coordinate_type::type coordinate_type; + + static const bool is_line = bg::geometry_id::type::value == 2; + + //std::cout << bg::area(geometry) << std::endl; + + std::vector dissolved_vector; + bg::dissolve_inserter(geometry, std::back_inserter(dissolved_vector)); + + typename bg::area_result::type length_or_area = 0; + //std::size_t holes = 0; + std::size_t count = 0; + + BOOST_FOREACH(GeometryOut& dissolved, dissolved_vector) + { + bg::unique(dissolved); + + + length_or_area += + is_line ? bg::length(dissolved) : bg::area(dissolved); + + //holes += bg::num_interior_rings(dissolved); + count += bg::num_points(dissolved); + } + + BOOST_CHECK_MESSAGE(count == expected_point_count, + "dissolve: " << caseid + << " #points expected: " << expected_point_count + << " detected: " << count + << " type: " << string_from_type::name() + ); + + + //BOOST_CHECK_EQUAL(holes, expected_hole_count); + BOOST_CHECK_CLOSE(length_or_area, expected_length_or_area, percentage); + + // Compile check, it should also compile inplace, outputting to the same geometry + { + std::vector dissolved; + bg::dissolve(geometry, dissolved); + } + + +#if defined(TEST_WITH_SVG) + { + std::ostringstream filename; + filename << "dissolve_" + << caseid << "_" + << string_from_type::name() + << ".svg"; + + std::ofstream svg(filename.str().c_str()); + + typedef + bg::svg_mapper + < + typename bg::point_type::type + > mapper_type; + + mapper_type mapper(svg, 500, 500); + mapper.add(geometry); + + mapper.map(geometry, "opacity:0.6;fill:rgb(0,0,255);stroke:rgb(0,0,0);stroke-width:1;fill-rule:nonzero"); + + bg::for_each_segment(geometry, map_segment(mapper)); + + + BOOST_FOREACH(GeometryOut& dissolved, dissolved_vector) + { + mapper.map(dissolved, "opacity:0.6;fill:none;stroke:rgb(255,0,0);stroke-width:5"); + } + } +#endif +} + + +template +void test_one(std::string const& caseid, std::string const& wkt, + std::size_t expected_hole_count, std::size_t expected_point_count, + double expected_length_or_area, double percentage = 0.001) +{ + Geometry geometry; + bg::read_wkt(wkt, geometry); + + test_dissolve(caseid, geometry, + expected_hole_count, expected_point_count, + expected_length_or_area, percentage); + +#ifdef BOOST_GEOMETRY_TEST_MULTI_PERMUTATIONS + // Test different combinations of a multi-polygon + + int n = geometry.size(); + + // test them in all orders + std::vector indices; + for (int i = 0; i < n; i++) + { + indices.push_back(i); + } + int permutation = 0; + do + { + std::ostringstream out; + out << caseid; + Geometry geometry2; + for (int i = 0; i < n; i++) + { + int index = indices[i]; + out << "_" << index; + geometry2.push_back(geometry[index]); + } + test_dissolve(out.str(), geometry2, expected_hole_count, + expected_point_count, expected_length_or_area, percentage); + } while (std::next_permutation(indices.begin(), indices.end())); +#endif + +} + + template @@ -87,8 +269,6 @@ void test_all() test_one("case_1", "POLYGON((1 3,0 9,9 5,1 7,9 8,2 5,10 10,9 2,1 3))", 0, 7, 50.48056402439); -/* - // Mail // See power point, and http://en.wikipedia.org/wiki/Pentagram test_one("pentagram", @@ -96,8 +276,40 @@ void test_all() 0, 11, 25.6158412); - //Should be solved (completely) differently + // Multi-geometries + { + typedef bg::model::multi_polygon multi_polygon; + test_one("three_triangles", + "MULTIPOLYGON(((1 1,5 5,8 0,1 1)),((4 2,0 8,5 9,4 2)),((5 3,4 8,10 4,5 3)))" , + 1, 13, 42.614078674948232); + + test_one("simplex_two", + "MULTIPOLYGON(((0 0,1 4,4 1,0 0)),((2 2,3 6,6 3,2 2)))", + 0, 8, 14.7); + test_one("simplex_three", + "MULTIPOLYGON(((0 0,1 4,4 1,0 0)),((2 2,3 6,6 3,2 2)),((3 4,5 6,6 2,3 4)))", + 0, 14, 16.7945); + test_one("simplex_four", + "MULTIPOLYGON(((0 0,1 4,4 1,0 0)),((2 2,3 6,6 3,2 2)),((3 4,5 6,6 2,3 4)),((5 5,7 7,8 4,5 5)))", + 0, 18, 20.7581); + + // disjoint + test_one("simplex_disjoint", + "MULTIPOLYGON(((0 0,1 4,4 1,0 0)),((1 6,2 10,5 7,1 6)),((3 4,5 6,6 2,3 4)),((6 5,8 7,9 4,6 5)))", + 0, 16, 24.0); + + // new hole of four + test_one("new_hole", + "MULTIPOLYGON(((0 0,1 4,4 1,0 0)),((2 2,3 6,6 3,2 2)),((3 4,5 6,6 2,3 4)),((3 1,5 4,8 4,3 1)))", + 1, 18, 19.5206); + } + + + +/* + //Should be solved (completely) differently + // From mail on the ggl-mailing list test_one("mail_denis_1", "POLYGON((55 10, 141 237, 249 23, 21 171, 252 169, 24 89, 266 73, 55 10))", 0, 7, 50.48056402439); diff --git a/test/algorithms/dissolve.vcproj b/test/extensions/algorithms/dissolve.vcproj similarity index 93% rename from test/algorithms/dissolve.vcproj rename to test/extensions/algorithms/dissolve.vcproj index 7ced4d72f..4a4745690 100644 --- a/test/algorithms/dissolve.vcproj +++ b/test/extensions/algorithms/dissolve.vcproj @@ -20,7 +20,7 @@ OutputDirectory="$(SolutionDir)$(ConfigurationName)" IntermediateDirectory="$(ConfigurationName)\dissolve" ConfigurationType="1" - InheritedPropertySheets="..\boost.vsprops" + InheritedPropertySheets="..\..\boost.vsprops" CharacterSet="1" > @@ -114,7 +114,7 @@ /> ::type length = bg::length(moved_by_offset); - std::size_t count = bg::num_points(moved_by_offset); /* + std::size_t count = bg::num_points(moved_by_offset); BOOST_CHECK_MESSAGE(count == expected_point_count, "offset: " << caseid << " #points expected: " << expected_point_count @@ -91,13 +91,13 @@ void test_offset(std::string const& caseid, Geometry const& geometry, template void test_one(std::string const& caseid, std::string const& wkt, double distance, - double expected_length, double percentage = 0.001) + double expected_length_plus, double expected_length_minus, double percentage = 0.001) { Geometry geometry; bg::read_wkt(wkt, geometry); - test_offset(caseid + "_a", geometry, distance, expected_length, percentage); - test_offset(caseid + "_b", geometry, -distance, expected_length, percentage); + test_offset(caseid + "_a", geometry, distance, expected_length_plus, percentage); + test_offset(caseid + "_b", geometry, -distance, expected_length_minus, percentage); } @@ -116,12 +116,12 @@ void test_all() static std::string const curve = "LINESTRING(2 7,3 5,5 4,7 5,8 7)"; static std::string const reallife1 = "LINESTRING(76396.40464822574 410095.6795147947,76397.85016212701 410095.211865792,76401.30666443033 410095.0466387949,76405.05892643372 410096.1007777959,76409.45103273794 410098.257640797,76412.96309264141 410101.6522238015)"; - test_one("ls_simplex", simplex, 0.5, std::sqrt(2.0)); - test_one("one_bend", one_bend, 0.5, std::sqrt(2.0)); - test_one("two_bends", two_bends, 0.5, std::sqrt(2.0)); - test_one("overlapping", overlapping, 0.5, std::sqrt(2.0)); - test_one("curve", curve, 0.5, std::sqrt(2.0)); - test_one("reallife1", reallife1, 16.5, std::sqrt(2.0)); + test_one("ls_simplex", simplex, 0.5, std::sqrt(2.0), std::sqrt(2.0)); + test_one("one_bend", one_bend, 0.5, 10.17328, 8.8681); + test_one("two_bends", two_bends, 0.5, 13.2898, 12.92811); + test_one("overlapping", overlapping, 0.5, 27.1466, 22.0596); + test_one("curve", curve, 0.5, 7.7776, 10.0507); + test_one("reallife1", reallife1, 16.5, 5.4654, 36.4943); } diff --git a/test/multi/algorithms/multi_dissolve.cpp b/test/multi/algorithms/multi_dissolve.cpp deleted file mode 100644 index 04cb91256..000000000 --- a/test/multi/algorithms/multi_dissolve.cpp +++ /dev/null @@ -1,68 +0,0 @@ -// Boost.Geometry (aka GGL, Generic Geometry Library) test file -// -// Copyright Barend Gehrels 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) - -#include -#include - - -#include - -#include - -#include -#include -#include -#include -#include -#include - -#include -#include - -#include -#include - - -template -void test_all() -{ - typedef bg::model::polygon

polygon; - typedef bg::model::multi_polygon multi_polygon; - - test_one("three_triangles", - "MULTIPOLYGON(((1 1,5 5,8 0,1 1)),((4 2,0 8,5 9,4 2)),((5 3,4 8,10 4,5 3)))" , - 1, 13, 42.614078674948232); - - test_one("simplex_two", - "MULTIPOLYGON(((0 0,1 4,4 1,0 0)),((2 2,3 6,6 3,2 2)))", - 0, 8, 14.7); - test_one("simplex_three", - "MULTIPOLYGON(((0 0,1 4,4 1,0 0)),((2 2,3 6,6 3,2 2)),((3 4,5 6,6 2,3 4)))", - 0, 14, 16.7945); - test_one("simplex_four", - "MULTIPOLYGON(((0 0,1 4,4 1,0 0)),((2 2,3 6,6 3,2 2)),((3 4,5 6,6 2,3 4)),((5 5,7 7,8 4,5 5)))", - 0, 18, 20.7581); - - // disjoint - test_one("simplex_disjoint", - "MULTIPOLYGON(((0 0,1 4,4 1,0 0)),((1 6,2 10,5 7,1 6)),((3 4,5 6,6 2,3 4)),((6 5,8 7,9 4,6 5)))", - 0, 16, 24.0); - - // new hole of four - test_one("new_hole", - "MULTIPOLYGON(((0 0,1 4,4 1,0 0)),((2 2,3 6,6 3,2 2)),((3 4,5 6,6 2,3 4)),((3 1,5 4,8 4,3 1)))", - 1, 18, 19.5206); - -} - - -int test_main(int, char* []) -{ - test_all >(); - - return 0; -} diff --git a/test/multi/algorithms/multi_dissolve.vcproj b/test/multi/algorithms/multi_dissolve.vcproj deleted file mode 100644 index 8efd35046..000000000 --- a/test/multi/algorithms/multi_dissolve.vcproj +++ /dev/null @@ -1,174 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -