// Boost.Geometry (aka GGL, Generic Geometry Library) // Unit Test // Copyright (c) 2007-2012 Barend Gehrels, Amsterdam, the Netherlands. // Copyright (c) 2008-2012 Bruno Lalande, Paris, France. // Copyright (c) 2009-2012 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 #include #include #include #include #include template void check_transform(Geometry1 const& geometry1, Geometry2 const& expected) { Geometry2 geometry2; BOOST_CHECK(bg::transform(geometry1, geometry2)); std::ostringstream result_wkt, expected_wkt; result_wkt << bg::wkt(geometry2); expected_wkt << bg::wkt(expected); BOOST_CHECK_EQUAL(result_wkt.str(), expected_wkt.str()); } template void test_transform_point(Value value) { P1 p1; bg::set<0>(p1, 1); bg::set<1>(p1, 2); boost::variant v(p1); P2 expected; bg::assign(expected, p1); bg::multiply_value(expected, value); check_transform(p1, expected); check_transform(v, expected); } template void test_transform_linestring(Value value) { typedef bg::model::linestring line1_type; typedef bg::model::linestring line2_type; line1_type line1; line1.push_back(bg::make(1, 1)); line1.push_back(bg::make(2, 2)); boost::variant v(line1); line2_type expected; for (BOOST_AUTO(p, line1.begin()); p != line1.end(); ++p) { P2 new_point; bg::assign(new_point, *p); bg::multiply_value(new_point, value); expected.push_back(new_point); } check_transform(line1, expected); check_transform(v, expected); } template void test_all(Value value) { test_transform_point(value); test_transform_linestring(value); } template void test_transformations(double phi, double theta, double r) { typedef bg::model::point cartesian_type; cartesian_type p; // 1: using spherical coordinates { typedef bg::model::point > spherical_type; spherical_type sph1; assign_values(sph1, phi, theta, r); BOOST_CHECK(transform(sph1, p)); spherical_type sph2; BOOST_CHECK(transform(p, sph2)); BOOST_CHECK_CLOSE(bg::get<0>(sph1), bg::get<0>(sph2), 0.001); BOOST_CHECK_CLOSE(bg::get<1>(sph1), bg::get<1>(sph2), 0.001); } // 2: using spherical coordinates on unit sphere { typedef bg::model::point > spherical_type; spherical_type sph1, sph2; assign_values(sph1, phi, theta); BOOST_CHECK(transform(sph1, p)); BOOST_CHECK(transform(p, sph2)); BOOST_CHECK_CLOSE(bg::get<0>(sph1), bg::get<0>(sph2), 0.001); BOOST_CHECK_CLOSE(bg::get<1>(sph1), bg::get<1>(sph2), 0.001); } } int test_main(int, char* []) { typedef bg::model::d2::point_xy P; test_all(1.0); test_all, bg::model::d2::point_xy >(1.0); test_all >, bg::model::point > >(bg::math::d2r()); test_all >, bg::model::point > >(bg::math::r2d()); test_all >, bg::model::point > >(bg::math::d2r()); test_transformations(4, 52, 1); test_transformations(4, 52, 1); test_transformations < float, bg::radian >(3 * bg::math::d2r(), 51 * bg::math::d2r(), 1); test_transformations < double, bg::radian >(3 * bg::math::d2r(), 51 * bg::math::d2r(), 1); #if defined(HAVE_TTMATH) typedef bg::model::d2::point_xy PT; test_all(); test_transformations(4, 52, 1); test_transformations < ttmath_big, bg::radian >(3 * bg::math::d2r(), 51 * bg::math::d2r(), 1); #endif return 0; }