diff --git a/test/algorithms/append.cpp b/test/algorithms/append.cpp index c42262a59..6b33320a4 100644 --- a/test/algorithms/append.cpp +++ b/test/algorithms/append.cpp @@ -26,22 +26,44 @@ template -void test_geometry() +void test_geometry(bool check = true) { G geometry; typedef typename bg::point_type::type P; bg::append(geometry, bg::make_zero

()); - BOOST_CHECK_EQUAL(bg::num_points(geometry), 1u); + if (check) + { + BOOST_CHECK_EQUAL(bg::num_points(geometry), 1u); + } + + // Append a range + std::vector

v; + v.push_back(bg::make_zero

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

()); + bg::append(geometry, v); + + if (check) + { + BOOST_CHECK_EQUAL(bg::num_points(geometry), 3u); + } bg::clear(geometry); - BOOST_CHECK_EQUAL(bg::num_points(geometry), 0u); + + if (check) + { + BOOST_CHECK_EQUAL(bg::num_points(geometry), 0u); + } + //P p = boost::range::front(geometry); } template void test_all() { + test_geometry

(false); + test_geometry >(false); + test_geometry >(false); test_geometry >(); test_geometry >(); test_geometry >(); @@ -50,7 +72,7 @@ void test_all() test_geometry >(); //test_geometry >(); - test_geometry >(); + test_geometry >(); } int test_main(int, char* []) diff --git a/test/algorithms/assign.cpp b/test/algorithms/assign.cpp index 69a8d8a26..889decd2a 100644 --- a/test/algorithms/assign.cpp +++ b/test/algorithms/assign.cpp @@ -17,13 +17,13 @@ #include -template -void check_linestring_2d(const L& line) +template +void check_linestring_2d(Linestring const& line) { BOOST_CHECK((boost::size(line) == 3)); BOOST_CHECK((bg::num_points(line) == 3)); - typedef typename bg::point_type::type point_type; + typedef typename bg::point_type::type point_type; point_type const& p0 = line[0]; BOOST_CHECK(bg::get<0>(p0) == 1); BOOST_CHECK(bg::get<1>(p0) == 2); @@ -37,10 +37,10 @@ void check_linestring_2d(const L& line) BOOST_CHECK(bg::get<1>(p2) == 6); } -template +template void test_assign_linestring_2d() { - bg::model::linestring

line; + bg::model::linestring line; // Test assignment of plain array (note that this is only possible if adapted c-array is included! const double coors[3][2] = { {1, 2}, {3, 4}, {5, 6} }; @@ -48,7 +48,7 @@ void test_assign_linestring_2d() check_linestring_2d(line); // Test assignment of point array - P points[3]; + Point points[3]; bg::assign(points[0], 1, 2); bg::assign(points[1], 3, 4); bg::assign(points[2], 5, 6); @@ -64,36 +64,50 @@ void test_assign_linestring_2d() check_linestring_2d(line); } -template -void test_assign_box_2d() +namespace detail { + template + void test_assign_box_or_segment_2d() + { + BoxOrSegment geometry; + bg::assign(geometry, 1, 2, 3, 4); + BOOST_CHECK((bg::get(geometry) == 1)); + BOOST_CHECK((bg::get(geometry) == 2)); + BOOST_CHECK((bg::get(geometry) == 3)); + BOOST_CHECK((bg::get(geometry) == 4)); - typedef bg::model::box

B; - B b; - bg::assign(b, 1, 2, 3, 4); - BOOST_CHECK((bg::get(b) == 1)); - BOOST_CHECK((bg::get(b) == 2)); - BOOST_CHECK((bg::get(b) == 3)); - BOOST_CHECK((bg::get(b) == 4)); - - bg::assign_zero(b); - BOOST_CHECK((bg::get(b) == 0)); - BOOST_CHECK((bg::get(b) == 0)); - BOOST_CHECK((bg::get(b) == 0)); - BOOST_CHECK((bg::get(b) == 0)); - - bg::assign_inverse(b); - BOOST_CHECK((bg::get(b) > 9999)); - BOOST_CHECK((bg::get(b) > 9999)); - BOOST_CHECK((bg::get(b) < 9999)); - BOOST_CHECK((bg::get(b) < 9999)); + bg::assign_zero(geometry); + BOOST_CHECK((bg::get(geometry) == 0)); + BOOST_CHECK((bg::get(geometry) == 0)); + BOOST_CHECK((bg::get(geometry) == 0)); + BOOST_CHECK((bg::get(geometry) == 0)); + bg::assign_inverse(geometry); + BOOST_CHECK((bg::get(geometry) > 9999)); + BOOST_CHECK((bg::get(geometry) > 9999)); + BOOST_CHECK((bg::get(geometry) < 9999)); + BOOST_CHECK((bg::get(geometry) < 9999)); + } } -template +template +void test_assign_box_or_segment_2d() +{ + detail::test_assign_box_or_segment_2d >(); + detail::test_assign_box_or_segment_2d >(); +} + +template +void test_assign_box_2d() +{ + detail::test_assign_box_or_segment_2d >(); +} + + +template void test_assign_point_3d() { - P p; + Point p; bg::assign(p, 1, 2, 3); BOOST_CHECK(bg::get<0>(p) == 1); BOOST_CHECK(bg::get<1>(p) == 2); @@ -111,10 +125,10 @@ void test_assign_point_3d() } -template +template void test_assign_point_2d() { - P p; + Point p; bg::assign(p, 1, 2); BOOST_CHECK(bg::get<0>(p) == 1); BOOST_CHECK(bg::get<1>(p) == 2); @@ -145,12 +159,14 @@ int test_main(int, char* []) test_assign_point_2d >(); test_assign_point_2d >(); + // Segment (currently) cannot handle array's because derived from std::pair test_assign_box_2d(); test_assign_box_2d(); test_assign_box_2d(); - test_assign_box_2d >(); - test_assign_box_2d >(); - test_assign_box_2d >(); + + test_assign_box_or_segment_2d >(); + test_assign_box_or_segment_2d >(); + test_assign_box_or_segment_2d >(); test_assign_linestring_2d >(); test_assign_linestring_2d >(); diff --git a/test/algorithms/difference.cpp b/test/algorithms/difference.cpp index cf7a3d249..906e62b2e 100644 --- a/test/algorithms/difference.cpp +++ b/test/algorithms/difference.cpp @@ -17,9 +17,11 @@ #include #include #include +#include #include #include +#include #include #include @@ -32,7 +34,9 @@ template void test_all() { + typedef bg::model::box

box; typedef bg::model::polygon

polygon; + typedef bg::model::ring

ring; test_one( "star_ring", example_star, example_ring, @@ -93,6 +97,61 @@ void test_all() 8, 22, 2.43452380952381, 7, 27, 3.18452380952381); + // Other combi's + { + test_one( + "star_ring_ring", example_star, example_ring, + 5, 22, 1.1901714, 5, 27, 1.6701714); + + test_one( + "ring_star_ring", example_ring, example_star, + 5, 22, 1.6701714, 5, 27, 1.1901714); + + static std::string const clip = "POLYGON((2.5 0.5,5.5 2.5))"; + + test_one("star_box", + clip, example_star, + 4, 11, 2.833333, 4, 11, 0.833333); + + test_one("box_star", + example_star, clip, + 4, 11, 0.833333, 4, 11, 2.833333); + } + + // Counter clockwise + { + typedef bg::model::polygon polygon_ccw; + test_one( + "star_ring_ccw", example_star, example_ring, + 5, 22, 1.1901714, 5, 27, 1.6701714); + test_one( + "star_ring_ccw1", example_star, example_ring, + 5, 22, 1.1901714, 5, 27, 1.6701714); + test_one( + "star_ring_ccw2", example_star, example_ring, + 5, 22, 1.1901714, 5, 27, 1.6701714); + } + + + + // Multi + { + typedef bg::model::multi_polygon mp; + + test_one("simplex_multi", + case_multi_simplex[0], case_multi_simplex[1], + 5, 12, 5.58, 4, 12, 2.58); + + static std::string const clip = "POLYGON((2 2,4 4))"; + + test_one("simplex_multi_box_mp", + clip, case_multi_simplex[0], + 3, 11, 4.53333, 3, 11, 8.53333); + test_one("simplex_multi_mp_box", + case_multi_simplex[0], clip, + 3, 11, 8.53333, 3, 11, 4.53333); + } + /*** Experimental (cut), does not work: test_one( diff --git a/test/algorithms/test_difference.hpp b/test/algorithms/test_difference.hpp index b58b0ada5..69bd10224 100644 --- a/test/algorithms/test_difference.hpp +++ b/test/algorithms/test_difference.hpp @@ -16,6 +16,7 @@ #include #include +#include #include #include @@ -23,6 +24,11 @@ #include + +#include +#include +#include + #include #include @@ -49,11 +55,11 @@ void test_difference(std::string const& caseid, G1 const& g1, G2 const& g2, if (sym) { - bg::sym_difference(g1, g2, clip); + bg::sym_difference(g1, g2, clip); } else { - bg::difference(g1, g2, clip); + bg::difference(g1, g2, clip); } double area = 0; @@ -154,6 +160,9 @@ void test_one(std::string const& caseid, G2 g2; bg::read_wkt(wkt2, g2); + bg::correct(g1); + bg::correct(g2); + test_difference(caseid + "_a", g1, g2, expected_count1, expected_point_count1, expected_area1, percentage);