// 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 #include #if defined(TEST_WITH_SVG) # include # include # include #endif template void test_offset(std::string const& caseid, Geometry const& geometry, double distance, double expected_length, double percentage) { typedef typename bg::coordinate_type::type coordinate_type; typedef typename bg::point_type::type point_type; typedef bg::strategy::buffer::join_round < point_type, point_type > join_strategy; GeometryOut moved_by_offset; bg::offset(geometry, moved_by_offset, join_strategy(2), distance); typename bg::length_result::type length = bg::length(moved_by_offset); /* std::size_t count = bg::num_points(moved_by_offset); BOOST_CHECK_MESSAGE(count == expected_point_count, "offset: " << caseid << " #points expected: " << expected_point_count << " detected: " << count << " type: " << string_from_type::name() ); */ //BOOST_CHECK_EQUAL(holes, expected_hole_count); BOOST_CHECK_CLOSE(length, expected_length, percentage); #if defined(TEST_WITH_SVG) { std::ostringstream filename; filename << "offset_" << caseid << "_" << string_from_type::name() << ".svg"; std::ofstream svg(filename.str().c_str()); bg::svg_mapper < typename bg::point_type::type > mapper(svg, 500, 500); mapper.add(geometry); mapper.add(moved_by_offset); mapper.map(geometry, "opacity:0.6;fill:rgb(0,0,255);stroke:rgb(0,0,0);stroke-width:1"); mapper.map(moved_by_offset, "opacity:0.6;fill:none;stroke:rgb(255,0,0);stroke-width:5"); } #endif } template void test_one(std::string const& caseid, std::string const& wkt, double distance, double expected_length_plus, double expected_length_minus, double percentage = 0.001) { Geometry geometry; bg::read_wkt(wkt, geometry); test_offset(caseid + "_a", geometry, distance, expected_length_plus, percentage); test_offset(caseid + "_b", geometry, -distance, expected_length_minus, percentage); } template void test_all() { typedef bg::model::linestring

linestring; static std::string const simplex = "LINESTRING(0 0,1 1)"; static std::string const one_bend = "LINESTRING(0 0,4 5,7 4)"; static std::string const two_bends = "LINESTRING(0 0,4 5,7 4,10 6)"; static std::string const overlapping = "LINESTRING(0 0,4 5,7 4,10 6, 10 2,2 2)"; static std::string const curve = "LINESTRING(2 7,3 5,5 4,7 5,8 7)"; static std::string const reallife1 = "LINESTRING(76396.40464822574 410095.6795147947,76397.85016212701 410095.211865792,76401.30666443033 410095.0466387949,76405.05892643372 410096.1007777959,76409.45103273794 410098.257640797,76412.96309264141 410101.6522238015)"; test_one("ls_simplex", simplex, 0.5, std::sqrt(2.0), std::sqrt(2.0)); test_one("one_bend", one_bend, 0.5, 10.17328, 8.8681); test_one("two_bends", two_bends, 0.5, 13.2898, 12.92811); test_one("overlapping", overlapping, 0.5, 27.1466, 22.0596); test_one("curve", curve, 0.5, 7.7776, 10.0507); test_one("reallife1", reallife1, 16.5, 5.4654, 36.4943); } int test_main(int, char* []) { test_all >(); return 0; }