Skip to content

Commit

Permalink
fix(cpp): floating point truncation error
Browse files Browse the repository at this point in the history
  • Loading branch information
cathaypacific8747 committed Jun 2, 2024
1 parent c350c1c commit 3961215
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 12 deletions.
14 changes: 5 additions & 9 deletions src/am4/utils/cpp/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -79,22 +79,18 @@ 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();
// __itt_task_begin(domain, __itt_null, __itt_null, handle_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();
Expand Down
12 changes: 9 additions & 3 deletions src/am4/utils/cpp/route.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<float>(options.trips_per_day_per_ac)) {
acr.warnings.push_back(AircraftRoute::Warning::ERR_TRIPS_PER_DAY_TOO_HIGH);
return acr;
}
Expand Down Expand Up @@ -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<double, double, double, double>(&Route::calc_distance), "lat1"_a, "lon1"_a, "lat2"_a, "lon2"_a)
.def_static("calc_distance", py::overload_cast<const Airport&, const Airport&>(&Route::calc_distance), "a0"_a, "a1"_a)
.def_static(
"calc_distance", py::overload_cast<double, double, double, double>(&Route::calc_distance), "lat1"_a,
"lon1"_a, "lat2"_a, "lon2"_a
)
.def_static(
"calc_distance", py::overload_cast<const Airport&, const Airport&>(&Route::calc_distance), "a0"_a, "a1"_a
)
.def("__repr__", &Route::repr)
.def("to_dict", py::overload_cast<const Route&>(&to_dict));

Expand Down

0 comments on commit 3961215

Please sign in to comment.