diff --git a/geometry/geometry.pro b/geometry/geometry.pro index 278139f11a..e4d81a191e 100644 --- a/geometry/geometry.pro +++ b/geometry/geometry.pro @@ -9,12 +9,13 @@ ROOT_DIR = .. include($$ROOT_DIR/common.pri) SOURCES += \ - distance_on_sphere.cpp \ - screenbase.cpp \ - packer.cpp \ - robust_orientation.cpp \ - region2d/binary_operators.cpp \ angles.cpp \ + distance_on_sphere.cpp \ + latlon.cpp \ + packer.cpp \ + region2d/binary_operators.cpp \ + robust_orientation.cpp \ + screenbase.cpp \ spline.cpp \ HEADERS += \ diff --git a/geometry/geometry_tests/latlon_test.cpp b/geometry/geometry_tests/latlon_test.cpp index 2bb306f0cc..e57cbbbd32 100644 --- a/geometry/geometry_tests/latlon_test.cpp +++ b/geometry/geometry_tests/latlon_test.cpp @@ -6,9 +6,8 @@ UNIT_TEST(LatLonPointConstructorTest) { m2::PointD basePoint(39.123, 42.456); - ms::LatLon wgsPoint(basePoint); - m2::PointD resultPoint(MercatorBounds::LonToX(wgsPoint.lon), - MercatorBounds::LatToY(wgsPoint.lat)); + ms::LatLon wgsPoint = MercatorBounds::ToLatLon(basePoint); + m2::PointD resultPoint = MercatorBounds::FromLatLon(wgsPoint); TEST_ALMOST_EQUAL_ULPS(basePoint.x, resultPoint.x, ()); TEST_ALMOST_EQUAL_ULPS(basePoint.y, resultPoint.y, ()); } diff --git a/geometry/latlon.cpp b/geometry/latlon.cpp new file mode 100644 index 0000000000..37a66c3e80 --- /dev/null +++ b/geometry/latlon.cpp @@ -0,0 +1,14 @@ +#include "latlon.hpp" + +#include "std/sstream.hpp" + +namespace ms +{ + +string DebugPrint(LatLon const & t) +{ + ostringstream out; + out << "LatLon [ " << t.lat << ", " << t.lon << " ]"; + return out.str(); +} +} // namespace ms diff --git a/geometry/latlon.hpp b/geometry/latlon.hpp index c2e818f2c2..c84909f293 100644 --- a/geometry/latlon.hpp +++ b/geometry/latlon.hpp @@ -1,8 +1,5 @@ #pragma once -#include "indexer/mercator.hpp" - -#include "std/sstream.hpp" #include "std/string.hpp" namespace ms @@ -11,19 +8,10 @@ namespace ms class LatLon { public: - LatLon(m2::PointD point) - : lat(MercatorBounds::YToLat(point.y)), lon(MercatorBounds::XToLon(point.x)) - { - } - + LatLon(double lat, double lon) : lat(lat), lon(lon) {} double lat, lon; }; -inline string DebugPrint(LatLon const & t) -{ - ostringstream out; - out << "LatLon [ " << t.lat << ", " << t.lon << " ]"; - return out.str(); -} +inline string DebugPrint(LatLon const & t); } // namespace ms diff --git a/indexer/mercator.hpp b/indexer/mercator.hpp index 5191821bc1..c24028f88d 100644 --- a/indexer/mercator.hpp +++ b/indexer/mercator.hpp @@ -6,6 +6,7 @@ // I sugest considering moving this compiation unit to another place. Probably to geometry. #pragma once +#include "geometry/latlon.hpp" #include "geometry/point2d.hpp" #include "geometry/rect2d.hpp" @@ -107,6 +108,16 @@ struct MercatorBounds return m2::PointD(LonToX(lon), LatToY(lat)); } + inline static m2::PointD FromLatLon(ms::LatLon const & point) + { + return FromLatLon(point.lat, point.lon); + } + + inline static ms::LatLon ToLatLon(m2::PointD const & point) + { + return {YToLat(point.y), XToLon(point.x)}; + } + /// Converts lat lon rect to mercator one inline static m2::RectD FromLatLonRect(m2::RectD const & latLonRect) { diff --git a/integration_tests/online_cross_tests.cpp b/integration_tests/online_cross_tests.cpp index d7059693bf..9a6dfdc165 100644 --- a/integration_tests/online_cross_tests.cpp +++ b/integration_tests/online_cross_tests.cpp @@ -8,42 +8,42 @@ namespace UNIT_TEST(OnlineCrossFetcherSmokeTest) { integration::OsrmRouterComponents & routerComponents = integration::GetAllMaps(); - TestOnlineFetcher({34.45, 61.76}, {38.94, 45.07}, + TestOnlineFetcher({61.76, 34.45}, {45.07, 38.94}, {"Russia_Central", "Russia_Southern", "Russia_Northwestern"}, routerComponents); } UNIT_TEST(OnlineRussiaNorthToSouthTest) { integration::OsrmRouterComponents & routerComponents = integration::GetAllMaps(); - TestOnlineCrosses({34.45, 61.76}, {38.94, 45.07}, + TestOnlineCrosses({61.76, 34.45}, {45.07, 38.94}, {"Russia_Central", "Russia_Southern", "Russia_Northwestern"}, routerComponents); } UNIT_TEST(OnlineEuropeTestNurnbergToMoscow) { integration::OsrmRouterComponents & routerComponents = integration::GetAllMaps(); - TestOnlineCrosses({11.082, 49.45}, {37.56, 55.74}, + TestOnlineCrosses({49.45, 11.082}, {55.74, 37.56}, {"Russia_Central", "Belarus", "Poland", "Germany_Bavaria", "Germany_Saxony"}, routerComponents); } UNIT_TEST(OnlineAmericanTestOttawaToWashington) { integration::OsrmRouterComponents & routerComponents = integration::GetAllMaps(); - TestOnlineCrosses({-75.69, 45.38}, {-77.031, 38.91}, + TestOnlineCrosses({45.38, -75.69}, {38.91, -77.031}, {"Canada_Ontario", "USA_New York", "USA_Pennsylvania", "USA_Maryland", "USA_District of Columbia"}, routerComponents); } UNIT_TEST(OnlineAsiaPhuketToPnompen) { integration::OsrmRouterComponents & routerComponents = integration::GetAllMaps(); - TestOnlineCrosses({98.23, 7.90}, {104.86, 11.56}, + TestOnlineCrosses({7.90, 98.23}, {11.56, 104.86}, {"Thailand", "Cambodia"}, routerComponents); } UNIT_TEST(OnlineAustraliaCanberraToPerth) { integration::OsrmRouterComponents & routerComponents = integration::GetAllMaps(); - TestOnlineCrosses({151.13, -33.88}, {115.88, -31.974}, + TestOnlineCrosses({-33.88, 151.13}, {-31.974, 115.88}, {"Australia"}, routerComponents); } } // namespace diff --git a/integration_tests/osrm_test_tools.cpp b/integration_tests/osrm_test_tools.cpp index bf8053f3f9..59fdf45440 100644 --- a/integration_tests/osrm_test_tools.cpp +++ b/integration_tests/osrm_test_tools.cpp @@ -4,6 +4,9 @@ #include "map/feature_vec_model.hpp" +#include "geometry/distance_on_sphere.hpp" +#include "geometry/latlon.hpp" + #include "routing/online_absent_fetcher.hpp" #include "routing/online_cross_fetcher.hpp" #include "routing/route.hpp" @@ -268,7 +271,7 @@ namespace integration return TestTurn(); } - void TestOnlineFetcher(m2::PointD const & startPoint, m2::PointD const & finalPoint, + void TestOnlineFetcher(ms::LatLon const & startPoint, ms::LatLon const & finalPoint, vector const & expected, OsrmRouterComponents & routerComponents) { auto countryFileGetter = [&routerComponents](m2::PointD const & p) -> string @@ -278,11 +281,11 @@ namespace integration auto localFileGetter = [&routerComponents](string const & countryFile) -> shared_ptr { //Always returns empty LocalFile - return shared_ptr(new LocalCountryFile()); + return make_shared(); }; routing::OnlineAbsentCountriesFetcher fetcher(countryFileGetter, localFileGetter); - fetcher.GenerateRequest(MercatorBounds::FromLatLon(startPoint.y, startPoint.x), - MercatorBounds::FromLatLon(finalPoint.y, finalPoint.x)); + fetcher.GenerateRequest(MercatorBounds::FromLatLon(startPoint), + MercatorBounds::FromLatLon(finalPoint)); vector absent; fetcher.GetAbsentCountries(absent); if (expected.size() < 2) @@ -298,13 +301,11 @@ namespace integration } } - void TestOnlineCrosses(m2::PointD const & startPoint, m2::PointD const & finalPoint, + void TestOnlineCrosses(ms::LatLon const & startPoint, ms::LatLon const & finalPoint, vector const & expected, OsrmRouterComponents & routerComponents) { - routing::OnlineCrossFetcher fetcher(OSRM_ONLINE_SERVER_URL, - MercatorBounds::FromLatLon(startPoint.y, startPoint.x), - MercatorBounds::FromLatLon(finalPoint.y, finalPoint.x)); + routing::OnlineCrossFetcher fetcher(OSRM_ONLINE_SERVER_URL, startPoint, finalPoint); fetcher.Do(); vector const & points = fetcher.GetMwmPoints(); TEST_EQUAL(points.size(), expected.size(), ()); diff --git a/integration_tests/osrm_test_tools.hpp b/integration_tests/osrm_test_tools.hpp index 31148491f6..fa56cd7788 100644 --- a/integration_tests/osrm_test_tools.hpp +++ b/integration_tests/osrm_test_tools.hpp @@ -43,9 +43,9 @@ namespace integration { class OsrmRouterComponents; - void TestOnlineCrosses(m2::PointD const & startPoint, m2::PointD const & finalPoint, + void TestOnlineCrosses(ms::LatLon const & startPoint, ms::LatLon const & finalPoint, vector const & expected, OsrmRouterComponents & routerComponents); - void TestOnlineFetcher(m2::PointD const & startPoint, m2::PointD const & finalPoint, + void TestOnlineFetcher(ms::LatLon const & startPoint, ms::LatLon const & finalPoint, vector const & expected, OsrmRouterComponents & routerComponents); OsrmRouterComponents & GetAllMaps(); diff --git a/routing/async_router.cpp b/routing/async_router.cpp index 2be8740b80..9e7ee87712 100644 --- a/routing/async_router.cpp +++ b/routing/async_router.cpp @@ -161,7 +161,7 @@ void AsyncRouter::CalculateRouteImpl(TReadyCallback const & callback) m_absentFetcher->GenerateRequest(startPoint, finalPoint); - // Run basic request + // Run basic request. code = m_router->CalculateRoute(startPoint, startDirection, finalPoint, route); double const elapsedSec = timer.ElapsedSeconds(); diff --git a/routing/online_absent_fetcher.cpp b/routing/online_absent_fetcher.cpp index 4a35e4121c..8370d7d9e7 100644 --- a/routing/online_absent_fetcher.cpp +++ b/routing/online_absent_fetcher.cpp @@ -6,29 +6,32 @@ #include "platform/country_file.hpp" #include "platform/local_country_file.hpp" +#include "std/vector.hpp" + using platform::CountryFile; using platform::LocalCountryFile; namespace routing { void OnlineAbsentCountriesFetcher::GenerateRequest(const m2::PointD & startPoint, - const m2::PointD & finalPoint) + const m2::PointD & finalPoint) { - // single mwm case + // Single mwm case. if (m_countryFileFn(startPoint) == m_countryFileFn(finalPoint)) return; unique_ptr fetcher = - make_unique(OSRM_ONLINE_SERVER_URL, startPoint, finalPoint); + make_unique(OSRM_ONLINE_SERVER_URL, MercatorBounds::ToLatLon(startPoint), + MercatorBounds::ToLatLon(finalPoint)); m_fetcherThread.Create(move(fetcher)); } void OnlineAbsentCountriesFetcher::GetAbsentCountries(vector & countries) { - // Have task check + // Check whether a request was scheduled to be run on the thread. if (!m_fetcherThread.GetRoutine()) return; m_fetcherThread.Join(); - for (auto point : m_fetcherThread.GetRoutineAs()->GetMwmPoints()) + for (auto const & point : m_fetcherThread.GetRoutineAs()->GetMwmPoints()) { string name = m_countryFileFn(point); auto localFile = m_countryLocalFileFn(name); diff --git a/routing/online_absent_fetcher.hpp b/routing/online_absent_fetcher.hpp index a8bfa44445..88ed3f06a4 100644 --- a/routing/online_absent_fetcher.hpp +++ b/routing/online_absent_fetcher.hpp @@ -4,6 +4,8 @@ #include "router.hpp" #include "routing_mapping.h" +#include "geometry/point2d.hpp" + #include "base/thread.hpp" #include "std/string.hpp" @@ -11,6 +13,10 @@ namespace routing { +/*! + * \brief The OnlineAbsentCountriesFetcher class incapsulates async fetching the map + * names from online OSRM server routines. + */ class OnlineAbsentCountriesFetcher { public: diff --git a/routing/online_cross_fetcher.cpp b/routing/online_cross_fetcher.cpp index ec57626282..947e34b517 100644 --- a/routing/online_cross_fetcher.cpp +++ b/routing/online_cross_fetcher.cpp @@ -45,8 +45,8 @@ string GenerateOnlineRequest(string const & serverURL, ms::LatLon const & startP strings::to_string(finalPoint.lon); } -OnlineCrossFetcher::OnlineCrossFetcher(string const & serverURL, m2::PointD const & startPoint, - m2::PointD const & finalPoint) +OnlineCrossFetcher::OnlineCrossFetcher(string const & serverURL, ms::LatLon const & startPoint, + ms::LatLon const & finalPoint) : m_request(GenerateOnlineRequest(serverURL, startPoint, finalPoint)) { LOG(LINFO, ("Check mwms by URL: ", GenerateOnlineRequest(serverURL, startPoint, finalPoint))); diff --git a/routing/online_cross_fetcher.hpp b/routing/online_cross_fetcher.hpp index e005cfa6bd..11056b5c69 100644 --- a/routing/online_cross_fetcher.hpp +++ b/routing/online_cross_fetcher.hpp @@ -34,12 +34,12 @@ public: /// \brief OnlineCrossFetcher helper class to make request to online OSRM server /// and get mwm name list /// \param serverURL Server URL - /// \param startPoint Start point coordinates in mercator - /// \param finalPoint Finish point coordinates in mercator - OnlineCrossFetcher(string const & serverURL, m2::PointD const & startPoint, - m2::PointD const & finalPoint); + /// \param startPoint Start point coordinates + /// \param finalPoint Finish point coordinates + OnlineCrossFetcher(string const & serverURL, ms::LatLon const & startPoint, + ms::LatLon const & finalPoint); - /// Override threads::IRoutine processing procedure. Calls online OSRM server and parses response. + /// Overrides threads::IRoutine processing procedure. Calls online OSRM server and parses response. void Do() override; /// \brief GetMwmPoints returns mwm representation points list. diff --git a/routing/routing_tests/online_cross_fetcher_test.cpp b/routing/routing_tests/online_cross_fetcher_test.cpp index 6f63a65b26..f037ca3522 100644 --- a/routing/routing_tests/online_cross_fetcher_test.cpp +++ b/routing/routing_tests/online_cross_fetcher_test.cpp @@ -13,8 +13,8 @@ namespace { UNIT_TEST(UrlGeneratorTest) { - TEST_EQUAL(GenerateOnlineRequest("http://mapsme.test.ru:10012", m2::PointD(37.726536, 55.690105), - m2::PointD(39.902344, 44.527843)), + TEST_EQUAL(GenerateOnlineRequest("http://mapsme.test.ru:10012", ms::LatLon(37.726536, 55.690105), + ms::LatLon(39.902344, 44.527843)), "http://mapsme.test.ru:10012/mapsme?loc=55.6901,37.7265&loc=44.5278,39.9023", ("Url parsed")); }