// 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; boost::geometry::set<0>(p1, 1); boost::geometry::set<1>(p1, 2); P2 p2; boost::geometry::transform(p1, p2); BOOST_CHECK_CLOSE(value * boost::geometry::get<0>(p1), double(boost::geometry::get<0>(p2)), 0.001); BOOST_CHECK_CLOSE(value * boost::geometry::get<1>(p1), double(boost::geometry::get<1>(p2)), 0.001); } template void test_transform_linestring() { boost::geometry::linestring line1; line1.push_back(boost::geometry::make(1, 1)); line1.push_back(boost::geometry::make(2, 2)); boost::geometry::linestring line2; boost::geometry::transform(line1, line2); BOOST_CHECK_EQUAL(line1.size(), line2.size()); std::ostringstream out1, out2; out1 << boost::geometry::wkt(line1); out2 << boost::geometry::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) { using namespace boost::geometry; typedef point cartesian_type; cartesian_type p; // 1: using spherical coordinates { typedef point > spherical_type; spherical_type sph1; assign(sph1, phi, theta, r); transform(sph1, p); spherical_type sph2; transform(p, sph2); BOOST_CHECK_CLOSE(double(boost::geometry::get<0>(sph1)), double(boost::geometry::get<0>(sph2)), 0.001); BOOST_CHECK_CLOSE(double(boost::geometry::get<1>(sph1)), double(boost::geometry::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 point > spherical_type; spherical_type sph1, sph2; assign(sph1, phi, theta); transform(sph1, p); transform(p, sph2); BOOST_CHECK_CLOSE(double(boost::geometry::get<0>(sph1)), double(boost::geometry::get<0>(sph2)), 0.001); BOOST_CHECK_CLOSE(double(boost::geometry::get<1>(sph1)), double(boost::geometry::get<1>(sph2)), 0.001); //std::cout << dsv(sph1) << " " << dsv(p) << " " << dsv(sph2) << std::endl; } } int test_main(int, char* []) { using namespace boost::geometry; using namespace boost::geometry::cs; using namespace boost::geometry::math; typedef boost::geometry::point_xy P; test_all(); test_all, boost::geometry::point_xy >(); test_all >, boost::geometry::point > >(d2r); test_all >, boost::geometry::point > >(r2d); test_all >, boost::geometry::point > >(d2r); test_transformations(4, 52, 1); test_transformations(4, 52, 1); test_transformations(3 * d2r, 51 * d2r, 1); test_transformations(3 * d2r, 51 * d2r, 1); return 0; }