// Boost.Geometry (aka GGL, Generic Geometry Library) test file // // Copyright Barend Gehrels 2007-2009, Geodan, Amsterdam, the Netherlands // Copyright Bruno Lalande 2008, 2009 // 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 template void test_transform_point(double value) { P1 p1; bg::set<0>(p1, 1); bg::set<1>(p1, 2); P2 p2; BOOST_CHECK(bg::transform(p1, p2)); BOOST_CHECK_CLOSE(value * bg::get<0>(p1), double(bg::get<0>(p2)), 0.001); BOOST_CHECK_CLOSE(value * bg::get<1>(p1), double(bg::get<1>(p2)), 0.001); } template void test_transform_linestring() { bg::model::linestring line1; line1.push_back(bg::make(1, 1)); line1.push_back(bg::make(2, 2)); bg::model::linestring line2; BOOST_CHECK(bg::transform(line1, line2)); BOOST_CHECK_EQUAL(line1.size(), line2.size()); std::ostringstream out1, out2; out1 << bg::wkt(line1); out2 << bg::wkt(line2); BOOST_CHECK_EQUAL(out1.str(), out1.str()); } template void test_all(double value = 1.0) { test_transform_point(value); test_transform_linestring(); } 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(sph1, phi, theta, r); BOOST_CHECK(transform(sph1, p)); spherical_type sph2; BOOST_CHECK(transform(p, sph2)); BOOST_CHECK_CLOSE(double(bg::get<0>(sph1)), double(bg::get<0>(sph2)), 0.001); BOOST_CHECK_CLOSE(double(bg::get<1>(sph1)), double(bg::get<1>(sph2)), 0.001); //std::cout << dsv(p) << std::endl; //std::cout << dsv(sph2) << std::endl; } // 2: using spherical coordinates on unit sphere { typedef bg::model::point > spherical_type; spherical_type sph1, sph2; assign(sph1, phi, theta); BOOST_CHECK(transform(sph1, p)); BOOST_CHECK(transform(p, sph2)); BOOST_CHECK_CLOSE(double(bg::get<0>(sph1)), double(bg::get<0>(sph2)), 0.001); BOOST_CHECK_CLOSE(double(bg::get<1>(sph1)), double(bg::get<1>(sph2)), 0.001); //std::cout << dsv(sph1) << " " << dsv(p) << " " << dsv(sph2) << std::endl; } } int test_main(int, char* []) { typedef bg::model::point_xy P; test_all(); test_all, bg::model::point_xy >(); 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(3 * bg::math::d2r, 51 * bg::math::d2r, 1); test_transformations(3 * bg::math::d2r, 51 * bg::math::d2r, 1); return 0; }