// Boost.Geometry (aka GGL, Generic Geometry Library) // Copyright (c) 2014-2015, Oracle and/or its affiliates. // Licensed under the Boost Software License version 1.0. // http://www.boost.org/users/license.html // Contributed and/or modified by Menelaos Karavelas, on behalf of Oracle // Contributed and/or modified by Adam Wulkiewicz, on behalf of Oracle #ifndef BOOST_TEST_MODULE #define BOOST_TEST_MODULE test_disjoint_coverage #endif // unit test to test disjoint for all geometry combinations #include #include #include #include #include #include #include #include #include #include #ifdef HAVE_TTMATH #include #endif namespace bg = ::boost::geometry; //============================================================================ struct test_disjoint { template static inline void apply(std::string const& case_id, Geometry1 const& geometry1, Geometry2 const& geometry2, bool expected_result) { bool result = bg::disjoint(geometry1, geometry2); BOOST_CHECK_MESSAGE(result == expected_result, "case ID: " << case_id << ", G1: " << bg::wkt(geometry1) << ", G2: " << bg::wkt(geometry2) << " -> Expected: " << expected_result << ", detected: " << result); result = bg::disjoint(geometry2, geometry1); BOOST_CHECK_MESSAGE(result == expected_result, "case ID: " << case_id << ", G1: " << bg::wkt(geometry2) << ", G2: " << bg::wkt(geometry1) << " -> Expected: " << expected_result << ", detected: " << result); #ifdef BOOST_GEOMETRY_TEST_DEBUG std::cout << "case ID: " << case_id << "; G1 - G2: "; std::cout << bg::wkt(geometry1) << " - "; std::cout << bg::wkt(geometry2) << std::endl; std::cout << std::boolalpha; std::cout << "expected/computed result: " << expected_result << " / " << result << std::endl; std::cout << std::endl; std::cout << std::noboolalpha; #endif } }; //============================================================================ // linear-areal geometries template inline void test_segment_box() { typedef bg::model::segment

S; typedef bg::model::box

B; typedef test_disjoint tester; tester::apply("s-b-01", from_wkt("SEGMENT(0 0,2 0)"), from_wkt("BOX(0 0,2 2)"), false); tester::apply("s-b-02", from_wkt("SEGMENT(1 1,3 3)"), from_wkt("BOX(0 0,2 2)"), false); tester::apply("s-b-03", from_wkt("SEGMENT(2 2,3 3)"), from_wkt("BOX(0 0,2 2)"), false); tester::apply("s-b-04", from_wkt("SEGMENT(4 4,3 3)"), from_wkt("BOX(0 0,2 2)"), true); tester::apply("s-b-05", from_wkt("SEGMENT(0 4,4 4)"), from_wkt("BOX(0 0,2 2)"), true); tester::apply("s-b-06", from_wkt("SEGMENT(4 0,4 4)"), from_wkt("BOX(0 0,2 2)"), true); tester::apply("s-b-07", from_wkt("SEGMENT(0 -2,0 -1)"), from_wkt("BOX(0 0,1 1)"), true); tester::apply("s-b-08", from_wkt("SEGMENT(-2 -2,-2 -1)"), from_wkt("BOX(0 0,1 1)"), true); tester::apply("s-b-09", from_wkt("SEGMENT(-2 -2,-2 -2)"), from_wkt("BOX(0 0,1 1)"), true); tester::apply("s-b-10", from_wkt("SEGMENT(-2 0,-2 0)"), from_wkt("BOX(0 0,1 1)"), true); tester::apply("s-b-11", from_wkt("SEGMENT(0 -2,0 -2)"), from_wkt("BOX(0 0,1 1)"), true); tester::apply("s-b-12", from_wkt("SEGMENT(-2 0,-1 0)"), from_wkt("BOX(0 0,1 1)"), true); // segment degenerates to a point tester::apply("s-b-13", from_wkt("SEGMENT(0 0,0 0)"), from_wkt("BOX(0 0,1 1)"), false); tester::apply("s-b-14", from_wkt("SEGMENT(1 1,1 1)"), from_wkt("BOX(0 0,2 2)"), false); tester::apply("s-b-15", from_wkt("SEGMENT(2 2,2 2)"), from_wkt("BOX(0 0,2 2)"), false); tester::apply("s-b-16", from_wkt("SEGMENT(2 0,2 0)"), from_wkt("BOX(0 0,2 2)"), false); tester::apply("s-b-17", from_wkt("SEGMENT(0 2,0 2)"), from_wkt("BOX(0 0,2 2)"), false); tester::apply("s-b-18", from_wkt("SEGMENT(2 2,2 2)"), from_wkt("BOX(0 0,1 1)"), true); } template inline void test_segment_ring() { typedef bg::model::segment

S; typedef bg::model::ring R; // ccw, open typedef test_disjoint tester; tester::apply("s-r-01", from_wkt("SEGMENT(0 0,2 0)"), from_wkt("POLYGON((0 0,2 0,0 2))"), false); tester::apply("s-r-02", from_wkt("SEGMENT(1 0,3 3)"), from_wkt("POLYGON((0 0,2 0,0 2))"), false); tester::apply("s-r-03", from_wkt("SEGMENT(1 1,3 3)"), from_wkt("POLYGON((0 0,2 0,0 2))"), false); tester::apply("s-r-04", from_wkt("SEGMENT(2 2,3 3)"), from_wkt("POLYGON((0 0,2 0,0 2))"), true); } template inline void test_segment_polygon() { typedef bg::model::segment

S; typedef bg::model::polygon PL; // ccw, open typedef test_disjoint tester; tester::apply("s-pg-01", from_wkt("SEGMENT(0 0,2 0)"), from_wkt("POLYGON((0 0,2 0,0 2))"), false); tester::apply("s-pg-02", from_wkt("SEGMENT(1 0,3 3)"), from_wkt("POLYGON((0 0,2 0,0 2))"), false); tester::apply("s-pg-03", from_wkt("SEGMENT(1 1,3 3)"), from_wkt("POLYGON((0 0,2 0,0 2))"), false); tester::apply("s-pg-04", from_wkt("SEGMENT(2 2,3 3)"), from_wkt("POLYGON((0 0,2 0,0 2))"), true); } template inline void test_segment_multipolygon() { typedef bg::model::segment

S; typedef bg::model::polygon PL; // ccw, open typedef bg::model::multi_polygon MPL; typedef test_disjoint tester; tester::apply("s-mpg-01", from_wkt("SEGMENT(0 0,2 0)"), from_wkt("MULTIPOLYGON(((0 0,2 0,0 2)))"), false); tester::apply("s-mpg-02", from_wkt("SEGMENT(1 0,3 3)"), from_wkt("MULTIPOLYGON(((0 0,2 0,0 2)))"), false); tester::apply("s-mpg-03", from_wkt("SEGMENT(1 1,3 3)"), from_wkt("MULTIPOLYGON(((0 0,2 0,0 2)))"), false); tester::apply("s-mpg-04", from_wkt("SEGMENT(2 2,3 3)"), from_wkt("MULTIPOLYGON(((0 0,2 0,0 2)))"), true); } template inline void test_linestring_box() { typedef bg::model::linestring

L; typedef bg::model::box

B; typedef test_disjoint tester; tester::apply("l-b-01", from_wkt("LINESTRING(0 0,2 0)"), from_wkt("BOX(0 0,2 2)"), false); tester::apply("l-b-02", from_wkt("LINESTRING(1 1,3 3)"), from_wkt("BOX(0 0,2 2)"), false); tester::apply("l-b-03", from_wkt("LINESTRING(2 2,3 3)"), from_wkt("BOX(0 0,2 2)"), false); tester::apply("l-b-04", from_wkt("LINESTRING(4 4,3 3)"), from_wkt("BOX(0 0,2 2)"), true); } template inline void test_linestring_ring() { typedef bg::model::linestring

L; typedef bg::model::ring R; // ccw, open typedef test_disjoint tester; tester::apply("l-r-01", from_wkt("LINESTRING(0 0,2 0)"), from_wkt("POLYGON((0 0,2 0,0 2))"), false); tester::apply("l-r-02", from_wkt("LINESTRING(1 0,3 3)"), from_wkt("POLYGON((0 0,2 0,0 2))"), false); tester::apply("l-r-03", from_wkt("LINESTRING(1 1,3 3)"), from_wkt("POLYGON((0 0,2 0,0 2))"), false); tester::apply("l-r-04", from_wkt("LINESTRING(2 2,3 3)"), from_wkt("POLYGON((0 0,2 0,0 2))"), true); } template inline void test_linestring_polygon() { typedef bg::model::linestring

L; typedef bg::model::polygon PL; // ccw, open typedef test_disjoint tester; tester::apply("l-pg-01", from_wkt("LINESTRING(0 0,2 0)"), from_wkt("POLYGON((0 0,2 0,0 2))"), false); tester::apply("l-pg-02", from_wkt("LINESTRING(1 0,3 3)"), from_wkt("POLYGON((0 0,2 0,0 2))"), false); tester::apply("l-pg-03", from_wkt("LINESTRING(1 1,3 3)"), from_wkt("POLYGON((0 0,2 0,0 2))"), false); tester::apply("l-pg-04", from_wkt("LINESTRING(2 2,3 3)"), from_wkt("POLYGON((0 0,2 0,0 2))"), true); } template inline void test_linestring_multipolygon() { typedef bg::model::linestring

L; typedef bg::model::polygon PL; // ccw, open typedef bg::model::multi_polygon MPL; typedef test_disjoint tester; tester::apply("l-mpg-01", from_wkt("LINESTRING(0 0,2 0)"), from_wkt("MULTIPOLYGON(((0 0,2 0,0 2)))"), false); tester::apply("l-mpg-02", from_wkt("LINESTRING(1 0,3 3)"), from_wkt("MULTIPOLYGON(((0 0,2 0,0 2)))"), false); tester::apply("l-mpg-03", from_wkt("LINESTRING(1 1,3 3)"), from_wkt("MULTIPOLYGON(((0 0,2 0,0 2)))"), false); tester::apply("l-mpg-04", from_wkt("LINESTRING(2 2,3 3)"), from_wkt("MULTIPOLYGON(((0 0,2 0,0 2)))"), true); } template inline void test_multilinestring_box() { typedef bg::model::linestring

L; typedef bg::model::multi_linestring ML; typedef bg::model::box

B; typedef test_disjoint tester; tester::apply("ml-b-01", from_wkt("MULTILINESTRING((0 0,2 0))"), from_wkt("BOX(0 0,2 2)"), false); tester::apply("ml-b-02", from_wkt("MULTILINESTRING((1 1,3 3))"), from_wkt("BOX(0 0,2 2)"), false); tester::apply("ml-b-03", from_wkt("MULTILINESTRING((2 2,3 3))"), from_wkt("BOX(0 0,2 2)"), false); tester::apply("ml-b-04", from_wkt("MULTILINESTRING((4 4,3 3))"), from_wkt("BOX(0 0,2 2)"), true); } template inline void test_multilinestring_ring() { typedef bg::model::linestring

L; typedef bg::model::multi_linestring ML; typedef bg::model::ring R; // ccw, open typedef test_disjoint tester; tester::apply("ml-r-01", from_wkt("MULTILINESTRING((0 0,2 0))"), from_wkt("POLYGON((0 0,2 0,0 2))"), false); tester::apply("ml-r-02", from_wkt("MULTILINESTRING((1 0,3 3))"), from_wkt("POLYGON((0 0,2 0,0 2))"), false); tester::apply("ml-r-03", from_wkt("MULTILINESTRING((1 1,3 3))"), from_wkt("POLYGON((0 0,2 0,0 2))"), false); tester::apply("ml-r-04", from_wkt("MULTILINESTRING((2 2,3 3))"), from_wkt("POLYGON((0 0,2 0,0 2))"), true); } template inline void test_multilinestring_polygon() { typedef bg::model::linestring

L; typedef bg::model::multi_linestring ML; typedef bg::model::polygon PL; // ccw, open typedef test_disjoint tester; tester::apply("ml-pg-01", from_wkt("MULTILINESTRING((0 0,2 0))"), from_wkt("POLYGON((0 0,2 0,0 2))"), false); tester::apply("ml-pg-02", from_wkt("MULTILINESTRING((1 0,3 3))"), from_wkt("POLYGON((0 0,2 0,0 2))"), false); tester::apply("ml-pg-03", from_wkt("MULTILINESTRING((1 1,3 3))"), from_wkt("POLYGON((0 0,2 0,0 2))"), false); tester::apply("ml-pg-04", from_wkt("MULTILINESTRING((2 2,3 3))"), from_wkt("POLYGON((0 0,2 0,0 2))"), true); } template inline void test_multilinestring_multipolygon() { typedef bg::model::linestring

L; typedef bg::model::multi_linestring ML; typedef bg::model::polygon PL; // ccw, open typedef bg::model::multi_polygon MPL; typedef test_disjoint tester; tester::apply("ml-mpg-01", from_wkt("MULTILINESTRING((0 0,2 0))"), from_wkt("MULTIPOLYGON(((0 0,2 0,0 2)))"), false); tester::apply("ml-mpg-02", from_wkt("MULTILINESTRING((1 0,3 3))"), from_wkt("MULTIPOLYGON(((0 0,2 0,0 2)))"), false); tester::apply("ml-mpg-03", from_wkt("MULTILINESTRING((1 1,3 3))"), from_wkt("MULTIPOLYGON(((0 0,2 0,0 2)))"), false); tester::apply("ml-mpg-04", from_wkt("MULTILINESTRING((2 2,3 3))"), from_wkt("MULTIPOLYGON(((0 0,2 0,0 2)))"), true); } //============================================================================ template inline void test_linear_areal() { typedef bg::model::point point_type; test_segment_polygon(); test_segment_multipolygon(); test_segment_ring(); test_segment_box(); test_linestring_polygon(); test_linestring_multipolygon(); test_linestring_ring(); test_linestring_box(); test_multilinestring_polygon(); test_multilinestring_multipolygon(); test_multilinestring_ring(); test_multilinestring_box(); } //============================================================================ BOOST_AUTO_TEST_CASE( test_linear_areal_all ) { test_linear_areal(); test_linear_areal(); #ifdef HAVE_TTMATH test_linear_areal(); #endif }