From 39612155471e352c9d3bb353e1a8f6b7b888e244 Mon Sep 17 00:00:00 2001 From: cathaypacific8747 <58929011+cathaypacific8747@users.noreply.github.com> Date: Sun, 2 Jun 2024 14:57:51 +0800 Subject: [PATCH] fix(cpp): floating point truncation error --- src/am4/utils/cpp/main.cpp | 14 +++++--------- src/am4/utils/cpp/route.cpp | 12 +++++++++--- 2 files changed, 14 insertions(+), 12 deletions(-) diff --git a/src/am4/utils/cpp/main.cpp b/src/am4/utils/cpp/main.cpp index 989ceb9..1641667 100644 --- a/src/am4/utils/cpp/main.cpp +++ b/src/am4/utils/cpp/main.cpp @@ -79,11 +79,10 @@ int main() { init(executable_path); // 1.3s // const auto& db = Database::Client(); - Airport ap0 = *Airport::search("SIN").ap; - // Airport ap1 = *Airport::search("TPE").ap; - Aircraft ac = *Aircraft::search("a32vip").ac; - auto options = AircraftRoute::Options(AircraftRoute::Options::TPDMode::STRICT_ALLOW_MULTIPLE_AC, 2); - // auto options = AircraftRoute::Options(AircraftRoute::Options::TPDMode::AUTO); + Airport ap0 = *Airport::search("BAH").ap; + Airport ap1 = *Airport::search("LUW").ap; + Aircraft ac = *Aircraft::search("mc214[sfc]").ac; + auto options = AircraftRoute::Options(AircraftRoute::Options::TPDMode::STRICT_ALLOW_MULTIPLE_AC, 5); User user = User::Default(); auto timer = Timer(); @@ -91,10 +90,7 @@ int main() { // auto rs = RoutesSearch(ap0, ac, options, user); // auto results = rs.get(); // std::cout << "results.size(): " << results.size() << std::endl; - auto a = Airport::search("vhhx"); - for (int i = 0; i < 1000; i++) { - std::ignore = Airport::suggest(a.parse_result); - } + auto results = AircraftRoute::create(ap0, ap1, ac, options, user); // __itt_task_end(domain); timer.stop(); // getchar(); diff --git a/src/am4/utils/cpp/route.cpp b/src/am4/utils/cpp/route.cpp index 77a6379..9dc2ce0 100644 --- a/src/am4/utils/cpp/route.cpp +++ b/src/am4/utils/cpp/route.cpp @@ -226,7 +226,8 @@ AircraftRoute AircraftRoute::create( acr.warnings.push_back(AircraftRoute::Warning::ERR_FLIGHT_TIME_ABOVE_SPECIFIED); return acr; } - if (options.tpd_mode != Options::TPDMode::AUTO && acr.flight_time > 24 / options.trips_per_day_per_ac) { + if (options.tpd_mode != Options::TPDMode::AUTO && + acr.flight_time > 24.0f / static_cast(options.trips_per_day_per_ac)) { acr.warnings.push_back(AircraftRoute::Warning::ERR_TRIPS_PER_DAY_TOO_HIGH); return acr; } @@ -646,8 +647,13 @@ void pybind_init_route(py::module_& m) { .def_readonly("direct_distance", &Route::direct_distance) .def_readonly("valid", &Route::valid) .def_static("create", &Route::create, "ap0"_a, "ap1"_a) - .def_static("calc_distance", py::overload_cast(&Route::calc_distance), "lat1"_a, "lon1"_a, "lat2"_a, "lon2"_a) - .def_static("calc_distance", py::overload_cast(&Route::calc_distance), "a0"_a, "a1"_a) + .def_static( + "calc_distance", py::overload_cast(&Route::calc_distance), "lat1"_a, + "lon1"_a, "lat2"_a, "lon2"_a + ) + .def_static( + "calc_distance", py::overload_cast(&Route::calc_distance), "a0"_a, "a1"_a + ) .def("__repr__", &Route::repr) .def("to_dict", py::overload_cast(&to_dict));