// Boost.Geometry // Unit Test // Copyright (c) 2017 Barend Gehrels, 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 template void check_geometry(Geometry const& geometry, std::string const& expected) { std::ostringstream out; out << bg::wkt_manipulator(geometry, false); BOOST_CHECK_EQUAL(out.str(), expected); } template void test_geometry(std::string const& wkt, std::string const& expected) { Geometry geometry; bg::read_wkt(wkt, geometry); // Test tye type bg::correct_closure(geometry); check_geometry(geometry, expected); // Test varianted type boost::variant v(geometry); bg::correct_closure(v); check_geometry(v, expected); } template void test_all() { typedef bg::model::ring cw_closed_ring_type; typedef bg::model::ring cw_open_ring_type; typedef bg::model::ring ccw_closed_ring_type; typedef bg::model::ring ccw_open_ring_type; // Define clockwise and counter clockwise polygon std::string cw_ring = "POLYGON((0 0,0 1,1 1,1 0,0 0))"; std::string cw_open_ring = "POLYGON((0 0,0 1,1 1,1 0))"; std::string ccw_ring = "POLYGON((0 0,1 0,1 1,0 1,0 0))"; std::string ccw_open_ring = "POLYGON((0 0,1 0,1 1,0 1))"; // Cases which should be closed or opened test_geometry(cw_open_ring, cw_ring); test_geometry(cw_ring, cw_open_ring); test_geometry(ccw_open_ring, ccw_ring); test_geometry(ccw_ring, ccw_open_ring); // Cases which are incorrect but should still be closed or opened test_geometry(ccw_open_ring, ccw_ring); test_geometry(cw_ring, cw_open_ring); // Cases where no action is necessary (even if order is incorrect) test_geometry(cw_ring, cw_ring); test_geometry(ccw_ring, ccw_ring); test_geometry(cw_open_ring, cw_open_ring); test_geometry(ccw_open_ring, ccw_open_ring); test_geometry(cw_ring, cw_ring); test_geometry(ccw_ring, ccw_ring); test_geometry(cw_open_ring, cw_open_ring); test_geometry(ccw_open_ring, ccw_open_ring); // Polygon cases std::string cw_polygon = "POLYGON((0 0,0 4,4 4,4 0,0 0),(1 1,2 1,2 2,1 2,1 1))"; std::string cw_open_polygon = "POLYGON((0 0,0 4,4 4,4 0),(1 1,2 1,2 2,1 2))"; typedef bg::model::polygon cw_closed_polygon_type; typedef bg::model::polygon cw_open_polygon_type; test_geometry(cw_open_polygon, cw_polygon); test_geometry(cw_polygon, cw_open_polygon); test_geometry(cw_polygon, cw_polygon); test_geometry(cw_open_polygon, cw_open_polygon); } int test_main(int, char* []) { test_all >(); test_all >(); test_all >(); test_all > >(); test_all > >(); return 0; }