// Boost.Geometry (aka GGL, Generic Geometry Library) // Unit Test // Copyright (c) 2015, Oracle and/or its affiliates. // Contributed and/or modified by Menelaos Karavelas, on behalf of Oracle // Licensed under the Boost Software License version 1.0. // http://www.boost.org/users/license.html #ifndef BOOST_TEST_MODULE #define BOOST_TEST_MODULE test_is_empty #endif #include #include #include #include #include #include #include #include #include #include #include namespace bg = boost::geometry; typedef bg::model::point point; typedef bg::model::linestring linestring; typedef bg::model::segment segment; typedef bg::model::box box; typedef bg::model::ring ring_cw_closed; typedef bg::model::ring ring_cw_open; typedef bg::model::ring ring_ccw_closed; typedef bg::model::ring ring_ccw_open; typedef bg::model::polygon polygon_cw_closed; typedef bg::model::polygon polygon_cw_open; typedef bg::model::polygon polygon_ccw_closed; typedef bg::model::polygon polygon_ccw_open; typedef bg::model::multi_point multi_point; typedef bg::model::multi_linestring multi_linestring; typedef bg::model::multi_polygon multi_polygon_cw_closed; typedef bg::model::multi_polygon multi_polygon_cw_open; typedef bg::model::multi_polygon multi_polygon_ccw_closed; typedef bg::model::multi_polygon multi_polygon_ccw_open; template struct box_dD { typedef boost::geometry::model::box < boost::geometry::model::point > type; }; template ::type> struct test_is_empty { static inline void apply(Geometry const& geometry, bool expected) { bool detected = bg::is_empty(geometry); BOOST_CHECK_MESSAGE( detected == expected, std::boolalpha << "Expected: " << expected << " detected: " << detected << " wkt: " << bg::wkt(geometry) << std::noboolalpha ); BOOST_CHECK_EQUAL(detected, bg::num_points(geometry) == 0); } static inline void apply(std::string const& wkt, bool expected) { Geometry geometry; bg::read_wkt(wkt, geometry); apply(geometry, expected); } }; template struct test_is_empty { static inline void apply(Box const& box, bool expected) { bool detected = bg::is_empty(box); BOOST_CHECK_MESSAGE( detected == expected, std::boolalpha << "Expected: " << expected << " detected: " << detected << " dsv: " << bg::dsv(box) << std::noboolalpha ); BOOST_CHECK_EQUAL(detected, bg::num_points(box) == 0); } static inline void apply(std::string const& wkt, bool expected) { Box box; bg::read_wkt(wkt, box); apply(box, expected); } }; BOOST_AUTO_TEST_CASE( test_point ) { test_is_empty::apply("POINT(0 0)", false); test_is_empty::apply("POINT(1 1)", false); } BOOST_AUTO_TEST_CASE( test_segment ) { test_is_empty::apply("SEGMENT(0 0,0 0)", false); test_is_empty::apply("SEGMENT(0 0,1 1)", false); } BOOST_AUTO_TEST_CASE( test_box ) { test_is_empty::apply("BOX(0 0,1 1)", false); // test higher-dimensional boxes test_is_empty::type>::apply("BOX(0 0 0,1 1 1)", false); test_is_empty::type>::apply("BOX(0 0 0 0,1 1 1 1)", false); test_is_empty::type>::apply("BOX(0 0 0 0 0,1 1 1 1 1)", false); } BOOST_AUTO_TEST_CASE( test_linestring ) { typedef test_is_empty tester; tester::apply("LINESTRING()", true); tester::apply("LINESTRING(0 0)", false); tester::apply("LINESTRING(0 0,0 0)", false); tester::apply("LINESTRING(0 0,0 0,1 1)", false); tester::apply("LINESTRING(0 0,0 0,0 0,1 1)", false); } BOOST_AUTO_TEST_CASE( test_multipoint ) { typedef test_is_empty tester; tester::apply("MULTIPOINT()", true); tester::apply("MULTIPOINT(0 0)", false); tester::apply("MULTIPOINT(0 0,0 0)", false); tester::apply("MULTIPOINT(0 0,0 0,1 1)", false); } BOOST_AUTO_TEST_CASE( test_multilinestring ) { typedef test_is_empty tester; tester::apply("MULTILINESTRING()", true); tester::apply("MULTILINESTRING(())", true); tester::apply("MULTILINESTRING((),())", true); tester::apply("MULTILINESTRING((),(0 0))", false); tester::apply("MULTILINESTRING((),(0 0),())", false); tester::apply("MULTILINESTRING((0 0))", false); tester::apply("MULTILINESTRING((0 0,1 0))", false); tester::apply("MULTILINESTRING((),(),(0 0,1 0))", false); tester::apply("MULTILINESTRING((0 0,1 0,0 1),(0 0,1 0,0 1,0 0))", false); } template void test_open_ring() { typedef test_is_empty tester; tester::apply("POLYGON(())", true); tester::apply("POLYGON((0 0))", false); tester::apply("POLYGON((0 0,1 0))", false); tester::apply("POLYGON((0 0,1 0,0 1))", false); tester::apply("POLYGON((0 0,0 0,1 0,0 1))", false); } template void test_closed_ring() { typedef test_is_empty tester; tester::apply("POLYGON(())", true); tester::apply("POLYGON((0 0))", false); tester::apply("POLYGON((0 0,0 0))", false); tester::apply("POLYGON((0 0,1 0,0 0))", false); tester::apply("POLYGON((0 0,1 0,0 1,0 0))", false); tester::apply("POLYGON((0 0,1 0,1 0,0 1,0 0))", false); } BOOST_AUTO_TEST_CASE( test_ring ) { test_open_ring(); test_open_ring(); test_closed_ring(); test_closed_ring(); } template void test_open_polygon() { typedef test_is_empty tester; tester::apply("POLYGON(())", true); tester::apply("POLYGON((),())", true); tester::apply("POLYGON((),(),())", true); tester::apply("POLYGON((),(0 0,0 1,1 0))", false); tester::apply("POLYGON((),(0 0,0 1,1 0),())", false); tester::apply("POLYGON((),(),(0 0,0 1,1 0))", false); tester::apply("POLYGON((0 0))", false); tester::apply("POLYGON((0 0,10 0),(0 0))", false); tester::apply("POLYGON((0 0,10 0),(1 1,2 1))", false); tester::apply("POLYGON((0 0,10 0,0 10))", false); tester::apply("POLYGON((0 0,10 0,0 10),())", false); tester::apply("POLYGON((0 0,10 0,0 10),(1 1))", false); tester::apply("POLYGON((0 0,10 0,0 10),(1 1,2 1))", false); tester::apply("POLYGON((0 0,10 0,0 10),(1 1,2 1,1 2))", false); tester::apply("POLYGON((0 0,10 0,10 10,0 10),(1 1,2 1,1 2))", false); } template void test_closed_polygon() { typedef test_is_empty tester; tester::apply("POLYGON(())", true); tester::apply("POLYGON((),())", true); tester::apply("POLYGON((),(),())", true); tester::apply("POLYGON((),(0 0,0 1,1 0,0 0))", false); tester::apply("POLYGON((),(0 0,0 1,1 0,0 0),())", false); tester::apply("POLYGON((),(),(0 0,0 1,1 0,0 0))", false); tester::apply("POLYGON((0 0))", false); tester::apply("POLYGON((0 0,10 0,0 0),(0 0))", false); tester::apply("POLYGON((0 0,10 0,0 0),(1 1,2 1,1 1))", false); tester::apply("POLYGON((0 0,10 0,0 10,0 0))", false); tester::apply("POLYGON((0 0,10 0,0 10,0 0),())", false); tester::apply("POLYGON((0 0,10 0,0 10,0 0),(1 1))", false); tester::apply("POLYGON((0 0,10 0,0 10,0 0),(1 1,2 1,1 1))", false); tester::apply("POLYGON((0 0,10 0,0 10,0 0),(1 1,2 1,1 2,1 1))", false); tester::apply("POLYGON((0 0,10 0,10 10,0 10,0 0),(1 1,2 1,1 2,1 1))", false); } BOOST_AUTO_TEST_CASE( test_polygon ) { test_open_polygon(); test_open_polygon(); test_closed_polygon(); test_closed_polygon(); } template void test_open_multipolygon() { typedef test_is_empty tester; tester::apply("MULTIPOLYGON()", true); tester::apply("MULTIPOLYGON((()))", true); tester::apply("MULTIPOLYGON(((),()))", true); tester::apply("MULTIPOLYGON(((),()),((),(),()))", true); tester::apply("MULTIPOLYGON(((),()),((),(0 0,10 0,10 10,0 10),()))", false); tester::apply("MULTIPOLYGON(((0 0,10 0,10 10,0 10),(1 1,2 1,1 2)))", false); tester::apply("MULTIPOLYGON(((0 0,10 0,10 10,0 10),(1 1,2 1,2 2,1 2),(5 5,6 5,6 6,5 6)))", false); tester::apply("MULTIPOLYGON(((0 0,10 0,10 10,0 10),(1 1,2 1,1 2)),((100 100,110 100,110 110),(101 101,102 101,102 102)))", false); } template void test_closed_multipolygon() { typedef test_is_empty tester; tester::apply("MULTIPOLYGON()", true); tester::apply("MULTIPOLYGON((()))", true); tester::apply("MULTIPOLYGON(((),()))", true); tester::apply("MULTIPOLYGON(((),()),((),(),()))", true); tester::apply("MULTIPOLYGON(((),()),((),(0 0,10 0,10 10,0 10,0 0),()))", false); tester::apply("MULTIPOLYGON(((0 0,10 0,10 10,0 10,0 0),(1 1,2 1,1 2,1 1)))", false); tester::apply("MULTIPOLYGON(((0 0,10 0,10 10,0 10,0 0),(1 1,2 1,2 2,1 2,1 1),(5 5,6 5,6 6,5 6,5 5)))", false); tester::apply("MULTIPOLYGON(((0 0,10 0,10 10,0 10,0 0),(1 1,2 1,1 2,1 1)),((100 100,110 100,110 110,100 100),(101 101,102 101,102 102,101 101)))", false); } BOOST_AUTO_TEST_CASE( test_multipolygon ) { test_open_multipolygon(); test_open_multipolygon(); test_closed_multipolygon(); test_closed_multipolygon(); } BOOST_AUTO_TEST_CASE( test_variant ) { typedef boost::variant < linestring, polygon_cw_open, polygon_cw_closed, multi_point > variant_geometry_type; typedef test_is_empty tester; linestring ls_empty; bg::read_wkt("LINESTRING()", ls_empty); linestring ls; bg::read_wkt("LINESTRING(1 1,2 2,5 6)", ls); polygon_cw_open p_open; bg::read_wkt("POLYGON((0 0,0 1,1 0))", p_open); polygon_cw_closed p_closed; bg::read_wkt("POLYGON(())", p_closed); multi_point mp; bg::read_wkt("MULTIPOINT((1 10))", mp); multi_point mp_empty; bg::read_wkt("MULTIPOINT((1 10))", mp); variant_geometry_type variant_geometry; variant_geometry = ls_empty; tester::apply(variant_geometry, true); variant_geometry = p_open; tester::apply(variant_geometry, false); variant_geometry = p_closed; tester::apply(variant_geometry, true); variant_geometry = mp; tester::apply(variant_geometry, false); variant_geometry = mp_empty; tester::apply(variant_geometry, true); variant_geometry = ls; tester::apply(variant_geometry, false); }