// 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 #if defined(TEST_WITH_SVG) # include #endif template inline void test_remove_spikes(std::string const& id, Geometry const& geometry, int expected_count) { namespace bg = boost::geometry; typedef typename bg::point_type::type point_type; Geometry processed = geometry; //bg::remove_spikes(processed, bg::remove_elongated_spikes()); bg::remove_spikes(processed, bg::remove_by_normalized()); bg::unique(processed); int detected = bg::num_points(processed); BOOST_CHECK_MESSAGE(detected == expected_count, "remove_spikes: " << bg::wkt(geometry) << " -> Expected: " << expected_count << " detected: " << detected); #if defined(TEST_WITH_SVG) { std::ostringstream filename; filename << "remove_spikes_" << id << ".svg"; std::ofstream svg(filename.str().c_str()); bg::svg_mapper::type> mapper(svg, 500, 500); mapper.add(geometry); mapper.map(geometry, "opacity:0.6;fill:rgb(0,0,255);stroke:rgb(0,0,255);stroke-width:1"); mapper.map(processed, "opacity:0.6;fill:rgb(0,255,0);stroke:rgb(0,255,0);stroke-width:1"); } #endif } template void test_geometry(std::string const& id, std::string const& wkt, int expected_count) { Geometry geometry; boost::geometry::read_wkt(wkt, geometry); test_remove_spikes(id, geometry, expected_count); } #if ! defined(GGL_TEST_MULTI) template void test_all() { typedef boost::geometry::linear_ring

ring; typedef boost::geometry::polygon

polygon; test_geometry("box", "POLYGON((0 0,0 4,4 4,4 0,0 0))", 5); test_geometry("spike_right", "POLYGON((0 0,0 4,4 4,4 2,6 2,4 2,4 0,0 0))", 6); test_geometry("spike_at_first", "POLYGON((0 0,-1 3,0 0,0 4,4 4,4 0,0 0))", 5); test_geometry("spike_at_closing", "POLYGON((-1 0,0 0,0 4,4 4,4 0,0 0,-1 0))", 5); test_geometry("double_spike", "POLYGON((0 0,0 4,4 4,4 2,6 2,5 2,4 2,4 0,0 0))", 6); test_geometry("three_double_spike", "POLYGON((0 0,0 4,4 4,4 2,6 2,5 2,4.5 2,4 2,4 0,0 0))", 6); } int test_main(int, char* []) { test_all >(); return 0; } #endif