// Boost.Geometry (aka GGL, Generic Geometry Library) test file // // Copyright Alfredo Correa 2010 // 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 // not finished: #include #include #include int test_main(int, char* []) { // 1a: Check if Boost.Polygon's point fulfills Boost.Geometry's point concept bg::concept::check >(); // 1b: use a Boost.Polygon point in Boost.Geometry, calc. distance with two point types boost::polygon::point_data p1(1, 2); typedef bg::model::point bg_point; bg_point p2(3, 4); BOOST_CHECK_CLOSE(bg::distance(p1, p2), 2 * std::sqrt(2.0), 0.001); // 2a: Check if Boost.Polygon's box fulfills Boost.Geometry's box concept bg::concept::check >(); // 2b: use a Boost.Polygon rectangle in Boost.Geometry, compare with boxes boost::polygon::rectangle_data b1; bg::model::box b2; bg::assign(b1, 0, 1, 5, 6); bg::assign(b2, 0, 1, 5, 6); double a1 = bg::area(b1); double a2 = bg::area(b2); BOOST_CHECK_CLOSE(a1, a2, 0.001); // 3a: Check if Boost.Polygon's polygon fulfills Boost.Geometry's ring concept bg::concept::check >(); // 3b: use a Boost.Polygon polygon (ring) in Boost.Geometry // Filling it is a two-step process using Boost.Polygon std::vector > point_vector; point_vector.push_back(boost::polygon::point_data(0, 0)); point_vector.push_back(boost::polygon::point_data(0, 3)); point_vector.push_back(boost::polygon::point_data(4, 0)); point_vector.push_back(boost::polygon::point_data(0, 0)); boost::polygon::polygon_data r1; r1.set(point_vector.begin(), point_vector.end()); bg::model::linear_ring r2; r2.push_back(bg_point(0, 0)); r2.push_back(bg_point(0, 3)); r2.push_back(bg_point(4, 0)); r2.push_back(bg_point(0, 0)); a1 = bg::area(r1); a2 = bg::area(r2); BOOST_CHECK_CLOSE(a1, a2, 0.001); // 4a: Boost.Polygon's polygon with holes point_vector.clear(); point_vector.push_back(boost::polygon::point_data(0, 0)); point_vector.push_back(boost::polygon::point_data(0, 10)); point_vector.push_back(boost::polygon::point_data(10, 10)); point_vector.push_back(boost::polygon::point_data(10, 0)); point_vector.push_back(boost::polygon::point_data(0, 0)); boost::polygon::polygon_with_holes_data poly1; poly1.set(point_vector.begin(), point_vector.end()); // Fill the holes (we take two) std::vector > holes; holes.resize(2); point_vector.clear(); point_vector.push_back(boost::polygon::point_data(1, 1)); point_vector.push_back(boost::polygon::point_data(2, 1)); point_vector.push_back(boost::polygon::point_data(2, 2)); point_vector.push_back(boost::polygon::point_data(1, 2)); point_vector.push_back(boost::polygon::point_data(1, 1)); holes[0].set(point_vector.begin(), point_vector.end()); point_vector.clear(); point_vector.push_back(boost::polygon::point_data(3, 3)); point_vector.push_back(boost::polygon::point_data(4, 3)); point_vector.push_back(boost::polygon::point_data(4, 4)); point_vector.push_back(boost::polygon::point_data(3, 4)); point_vector.push_back(boost::polygon::point_data(3, 3)); holes[1].set(point_vector.begin(), point_vector.end()); poly1.set_holes(holes.begin(), holes.end()); a1 = boost::polygon::area(poly1); std::cout << boost::polygon::size(poly1) << std::endl; // not finished: a1 = bg::area(poly1); return 0; }