(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 @@
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-