diff --git a/example/glide_computer/CMakeLists.txt b/example/glide_computer/CMakeLists.txt index 01e64578..d9f28018 100644 --- a/example/glide_computer/CMakeLists.txt +++ b/example/glide_computer/CMakeLists.txt @@ -22,6 +22,6 @@ cmake_minimum_required(VERSION 3.2) -add_library(glide_computer STATIC include/geographic.h glide_computer.cpp include/glide_computer.h) +add_library(glide_computer STATIC glide_computer.cpp include/glide_computer.h) target_link_libraries(glide_computer PRIVATE mp-units::core-fmt PUBLIC mp-units::si mp-units::utility example_utils) target_include_directories(glide_computer PUBLIC include) diff --git a/example/glide_computer/glide_computer.cpp b/example/glide_computer/glide_computer.cpp index 3d1b1f6c..0eacceed 100644 --- a/example/glide_computer/glide_computer.cpp +++ b/example/glide_computer/glide_computer.cpp @@ -21,6 +21,7 @@ // SOFTWARE. #include "glide_computer.h" +#include #include #include #include @@ -48,7 +49,7 @@ std::vector task::make_leg_total_distances(const legs& legs) return res; } -altitude terrain_level_alt(const task& t, const flight_point& pos) +geographic::msl_altitude terrain_level_alt(const task& t, const flight_point& pos) { const task::leg& l = t.get_legs()[pos.leg_idx]; const height alt_diff = l.end().alt - l.begin().alt; @@ -58,7 +59,8 @@ altitude terrain_level_alt(const task& t, const flight_point& pos) // Returns `x` of the intersection of a glide line and a terrain line. // y = -x / glide_ratio + pos.alt; // y = (finish_alt - ground_alt) / dist_to_finish * x + ground_alt + min_agl_height; -distance glide_distance(const flight_point& pos, const glider& g, const task& t, const safety& s, altitude ground_alt) +distance glide_distance(const flight_point& pos, const glider& g, const task& t, const safety& s, + geographic::msl_altitude ground_alt) { const auto dist_to_finish = t.get_distance() - pos.dist; return quantity_cast(ground_alt + s.min_agl_height - pos.alt) / @@ -150,8 +152,8 @@ void estimate(timestamp start_ts, const glider& g, const weather& w, const task& // estimate aircraft towing pos = tow(start_ts, pos, at); - // estimate the altitude needed to reach the finish line from this place - const altitude final_glide_alt = + // estimate the msl_altitude needed to reach the finish line from this place + const geographic::msl_altitude final_glide_alt = t.get_finish().alt + quantity_cast(t.get_distance() / glide_ratio(g.polar[0])); // how much height we still need to gain in the thermalls to reach the destination? diff --git a/example/glide_computer/include/glide_computer.h b/example/glide_computer/include/glide_computer.h index ad28d604..5b2f5edf 100644 --- a/example/glide_computer/include/glide_computer.h +++ b/example/glide_computer/include/glide_computer.h @@ -24,7 +24,6 @@ #include "geographic.h" #include -#include #include // IWYU pragma: keep #include #include @@ -54,14 +53,11 @@ namespace glide_computer { // https://en.wikipedia.org/wiki/Flight_planning#Units_of_measurement -inline constexpr struct mean_sea_level : mp_units::absolute_point_origin { -} mean_sea_level; QUANTITY_SPEC(rate_of_climb_speed, mp_units::isq::speed, mp_units::isq::height / mp_units::isq::time); // length using distance = mp_units::quantity]>; using height = mp_units::quantity; -using altitude = mp_units::quantity_point; // time using duration = mp_units::quantity; @@ -72,29 +68,7 @@ using timestamp = mp_units::quantity_point / mp_units::si::hour]>; using rate_of_climb = mp_units::quantity; -// text output -template -std::basic_ostream& operator<<(std::basic_ostream& os, const altitude& a) -{ - return os << a.absolute() << " AMSL"; -} - -} // namespace glide_computer - -template<> -struct STD_FMT::formatter : - formatter> { - template - auto format(const glide_computer::altitude& a, FormatContext& ctx) - { - formatter>::format(a.absolute(), ctx); - return STD_FMT::format_to(ctx.out(), " AMSL"); - } -}; - // definition of glide computer databases and utilities -namespace glide_computer { - struct glider { struct polar_point { velocity v; @@ -118,7 +92,7 @@ struct weather { struct waypoint { std::string name; geographic::position pos; - altitude alt; + geographic::msl_altitude alt; }; class task { @@ -184,14 +158,17 @@ struct aircraft_tow { struct flight_point { timestamp ts; - altitude alt; + geographic::msl_altitude alt; std::size_t leg_idx = 0; distance dist{}; }; -altitude terrain_level_alt(const task& t, const flight_point& pos); +geographic::msl_altitude terrain_level_alt(const task& t, const flight_point& pos); -constexpr height agl(altitude glider_alt, altitude terrain_level) { return glider_alt - terrain_level; } +constexpr height agl(geographic::msl_altitude glider_alt, geographic::msl_altitude terrain_level) +{ + return glider_alt - terrain_level; +} inline mp_units::quantity]> length_3d(distance dist, height h) @@ -199,7 +176,8 @@ inline mp_units::quantity +#include #include #include +#include #include #include #include @@ -35,6 +37,33 @@ namespace geographic { +// clang-format off +inline constexpr struct mean_sea_level : mp_units::absolute_point_origin {} mean_sea_level; +// clang-format on + +using msl_altitude = mp_units::quantity_point; + +// text output +template +std::basic_ostream& operator<<(std::basic_ostream& os, const msl_altitude& a) +{ + return os << a.absolute() << " AMSL"; +} + +} // namespace geographic + +template<> +struct STD_FMT::formatter : formatter { + template + auto format(const geographic::msl_altitude& a, FormatContext& ctx) + { + formatter::format(a.absolute(), ctx); + return STD_FMT::format_to(ctx.out(), " AMSL"); + } +}; + +namespace geographic { + template using latitude = mp_units::quantity>;