// Boost.Geometry // Copyright (c) 2017 Oracle and/or its affiliates. // Contributed and/or modified by Vissarion Fysikopoulos, on behalf of Oracle // 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 #ifdef HAVE_TTMATH # include #endif typedef bg::srs::spheroid stype; typedef bg::strategy::andoyer andoyer_formula; typedef bg::strategy::thomas thomas_formula; typedef bg::strategy::vincenty vincenty_formula; template bool non_precise_ct() { typedef typename bg::coordinate_type

::type ct; return boost::is_integral::value || boost::is_float::value; } template void test_distance(double lon1, double lat1, double lon2, double lat2) { typedef typename bg::promote_floating_point < typename bg::select_calculation_type::type >::type calc_t; calc_t tolerance = non_precise_ct() || non_precise_ct() ? 5.0 : 0.001; P1 p1; P2 p2; bg::assign_values(p1, lon1, lat1); bg::assign_values(p2, lon2, lat2); // Test strategy that implements meridian distance against formula // that implements general distance // That may change in the future but in any case these calls must return // the same result calc_t dist_formula = FormulaPolicy::template inverse < double, true, false, false, false, false >::apply(lon1 * bg::math::d2r(), lat1 * bg::math::d2r(), lon2 * bg::math::d2r(), lat2 * bg::math::d2r(), stype()).distance; bg::strategy::distance::geographic strategy; calc_t dist_strategy = strategy.apply(p1, p2); BOOST_CHECK_CLOSE(dist_formula, dist_strategy, tolerance); } template void test_distance_reverse(double lon1, double lat1, double lon2, double lat2) { test_distance(lon1, lat1, lon2, lat2); test_distance(lon2, lat2, lon1, lat1); } template void test_meridian() { test_distance_reverse(0., 70., 0., 80.); test_distance_reverse(0, 70, 0., -80.); test_distance_reverse(0., -70., 0., 80.); test_distance_reverse(0., -70., 0., -80.); test_distance_reverse(0., 70., 180., 80.); test_distance_reverse(0., 70., 180., -80.); test_distance_reverse(0., -70., 180., 80.); test_distance_reverse(0., -70., 180., -80.); test_distance_reverse(350., 70., 170., 80.); test_distance_reverse(350., 70., 170., -80.); test_distance_reverse(350., -70., 170., 80.); test_distance_reverse(350., -70., 170., -80.); } template void test_all() { test_meridian(); test_meridian(); test_meridian(); } int test_main(int, char* []) { test_all > >(); test_all > >(); test_all > >(); return 0; }