// Boost.Geometry // Unit Test // 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 "test_formula.hpp" #include "vertex_longitude_cases.hpp" #include #include #include #include #include #include #include #define BOOST_GEOMETRY_TEST_DEBUG namespace bg = boost::geometry; template CT test_vrt_lon_sph(CT lon1r, CT lat1r, CT lon2r, CT lat2r) { CT a1 = bg::formula::spherical_azimuth(lon1r, lat1r, lon2r, lat2r); typedef bg::model::point > point; bg::model::segment segment(point(lon1r, lat1r), point(lon2r, lat2r)); bg::model::box box; bg::envelope(segment, box); CT vertex_lat; CT lat_sum = lat1r + lat2r; if (lat_sum > CT(0)) { vertex_lat = bg::get_as_radian(box); } else { vertex_lat = bg::get_as_radian(box); } bg::strategy::azimuth::spherical<> azimuth; return bg::formula::vertex_longitude :: apply(lon1r, lat1r, lon2r, lat2r, vertex_lat, a1, azimuth); } template < template class FormulaPolicy, typename CT > CT test_vrt_lon_geo(CT lon1r, CT lat1r, CT lon2r, CT lat2r) { // WGS84 bg::srs::spheroid spheroid(6378137.0, 6356752.3142451793); typedef FormulaPolicy formula; CT a1 = formula::apply(lon1r, lat1r, lon2r, lat2r, spheroid).azimuth; typedef bg::model::point > geo_point; bg::model::segment segment(geo_point(lon1r, lat1r), geo_point(lon2r, lat2r)); bg::model::box box; bg::envelope(segment, box); CT vertex_lat; CT lat_sum = lat1r + lat2r; if (lat_sum > CT(0)) { vertex_lat = bg::get_as_radian(box); } else { vertex_lat = bg::get_as_radian(box); } bg::strategy::azimuth::geographic<> azimuth_geographic; return bg::formula::vertex_longitude ::apply(lon1r, lat1r, lon2r, lat2r, vertex_lat, a1, azimuth_geographic); } void test_all(expected_results const& results) { double const d2r = bg::math::d2r(); double lon1r = results.p1.lon * d2r; double lat1r = results.p1.lat * d2r; double lon2r = results.p2.lon * d2r; double lat2r = results.p2.lat * d2r; if(lon1r > lon2r) { std::swap(lon1r, lon2r); std::swap(lat1r, lat2r); } double res_an = test_vrt_lon_geo (lon1r, lat1r, lon2r, lat2r); double res_th = test_vrt_lon_geo (lon1r, lat1r, lon2r, lat2r); double res_vi = test_vrt_lon_geo (lon1r, lat1r, lon2r, lat2r); double res_sh = test_vrt_lon_sph(lon1r, lat1r, lon2r, lat2r); bg::math::normalize_longitude(res_an); bg::math::normalize_longitude(res_th); bg::math::normalize_longitude(res_vi); bg::math::normalize_longitude(res_sh); check_one(res_an, results.andoyer * d2r, res_vi, 0.001); check_one(res_th, results.thomas * d2r, res_vi, 0.01);//in some tests thomas gives low accuracy check_one(res_vi, results.vincenty * d2r, res_vi, 0.0000001); check_one(res_sh, results.spherical * d2r, res_vi, 1); } int test_main(int, char*[]) { for (size_t i = 0; i < expected_size; ++i) { test_all(expected[i]); } return 0; }