// 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 template void test_transform_point(Value 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), bg::get<0>(p2), 0.001); BOOST_CHECK_CLOSE(value * bg::get<1>(p1), bg::get<1>(p2), 0.001); } template void test_transform_linestring(Value value) { bg::model::linestring line1; line1.push_back(bg::make(1, 1)); line1.push_back(bg::make(2, 2)); bg::model::linestring line2; bg::model::linestring 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); } BOOST_CHECK(bg::transform(line1, line2)); std::ostringstream result_wkt, expected_wkt; result_wkt << bg::wkt(line2); expected_wkt << bg::wkt(expected); BOOST_CHECK_EQUAL(result_wkt.str(), expected_wkt.str()); } 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(3 * bg::math::d2r, 51 * bg::math::d2r, 1); test_transformations(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(3 * bg::math::d2r, 51 * bg::math::d2r, 1); #endif return 0; }