// Boost.Geometry (aka GGL, Generic Geometry Library) // Unit Test // Copyright (c) 2007-2011 Barend Gehrels, Amsterdam, the Netherlands. // Copyright (c) 2008-2011 Bruno Lalande, Paris, France. // Copyright (c) 2009-2011 Mateusz Loskot, London, UK. // Parts of Boost.Geometry are redesigned from Geodan's Geographic Library // (geolib/GGL), copyright (c) 1995-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 //#define GEOMETRY_TEST_DEBUG template void test_polygon() { // Rotated square, length=sqrt(2) -> area=2 test_geometry("POLYGON((1 1,2 2,3 1,2 0,1 1))", 2.0); test_geometry("POLYGON((1 1,2 2,3 1,2 0,1 1))", 2.0); test_geometry("POLYGON((0 0,0 7,4 2,2 0,0 0))", 16.0); test_geometry("POLYGON((1 1,2 1,2 2,1 2,1 1))", -1.0); test_geometry("POLYGON((0 0,0 7,4 2,2 0,0 0), (1 1,2 1,2 2,1 2,1 1))", 15.0); } template void test_all() { test_geometry >("POLYGON((0 0,2 2))", 4.0); test_geometry >("POLYGON((2 2,0 0))", 4.0); test_polygon >(); test_polygon >(); // clockwise rings (second is wrongly ordered) test_geometry >("POLYGON((0 0,0 7,4 2,2 0,0 0))", 16.0); test_geometry >("POLYGON((0 0,2 0,4 2,0 7,0 0))", -16.0); test_geometry >("POLYGON((0 0,0 7,4 2,2 0,0 0))", 16.0); // ccw test_geometry > ("POLYGON((0 0,0 7,4 2,2 0,0 0), (1 1,2 1,2 2,1 2,1 1))", -15.0); } template void test_spherical() { bg::model::polygon geometry; // unit-sphere has area of 4-PI. Polygon covering 1/8 of it: double expected = 4.0 * boost::math::constants::pi() / 8.0; bg::read_wkt("POLYGON((0 0,0 90,90 0,0 0))", geometry); double area = bg::area(geometry); BOOST_CHECK_CLOSE(area, expected, 0.0001); // With strategy, radius 2 -> 4 pi r^2 bg::strategy::area::huiller < typename bg::point_type::type > strategy(2.0); area = bg::area(geometry, strategy); BOOST_CHECK_CLOSE(area, 2.0 * 2.0 * expected, 0.0001); } template void test_ccw() { typedef bg::model::polygon ccw_polygon; // counterclockwise rings (second is wrongly ordered) test_geometry("POLYGON((1 1,2 2,3 1,2 0,1 1))", -2.0); test_geometry("POLYGON((1 1,2 0,3 1,2 2,1 1))", +2.0); test_geometry("POLYGON((0 0,0 7,4 2,2 0,0 0))", -16.0); test_geometry("POLYGON((0 0,2 0,4 2,0 7,0 0))", +16.0); } template void test_open() { typedef bg::model::polygon open_polygon; test_geometry("POLYGON((1 1,2 2,3 1,2 0))", 2.0); // Note the triangular testcase used in CCW is not sensible for open/close } template void test_open_ccw() { typedef bg::model::polygon open_polygon; test_geometry("POLYGON((1 1,2 0,3 1,2 2))", 2.0); // Note the triangular testcase used in CCW is not sensible for open/close } int test_main(int, char* []) { test_all >(); test_all >(); test_all >(); test_spherical > >(); test_ccw >(); test_open >(); test_open_ccw >(); #ifdef HAVE_TTMATH test_all >(); #endif return 0; }