forked from mpusz/mp-units
style: clang-format applied to the remaining files
This commit is contained in:
@@ -49,7 +49,8 @@ distance spherical_distance(position from, position to)
|
||||
if constexpr (sizeof(rep) >= 8) {
|
||||
// spherical law of cosines
|
||||
const auto central_angle = acos(sin(lat1) * sin(lat2) + cos(lat1) * cos(lat2) * cos(lon2 - lon1));
|
||||
// const auto central_angle = 2 * asin(sqrt(0.5 - cos(lat2 - lat1) / 2 + cos(lat1) * cos(lat2) * (1 - cos(lon2 - lon1)) / 2));
|
||||
// const auto central_angle = 2 * asin(sqrt(0.5 - cos(lat2 - lat1) / 2 + cos(lat1) * cos(lat2) * (1 - cos(lon2 -
|
||||
// lon1)) / 2));
|
||||
return distance(earth_radius * central_angle);
|
||||
} else {
|
||||
// the haversine formula
|
||||
|
||||
@@ -34,7 +34,8 @@ task::legs task::make_legs(const waypoints& wpts)
|
||||
task::legs res;
|
||||
res.reserve(wpts.size() - 1);
|
||||
auto to_leg = [](const waypoint& w1, const waypoint& w2) { return task::leg(w1, w2); };
|
||||
std::ranges::transform(wpts.cbegin(), prev(wpts.cend()), next(wpts.cbegin()), wpts.cend(), std::back_inserter(res), to_leg);
|
||||
std::ranges::transform(wpts.cbegin(), prev(wpts.cend()), next(wpts.cbegin()), wpts.cend(), std::back_inserter(res),
|
||||
to_leg);
|
||||
return res;
|
||||
}
|
||||
|
||||
@@ -64,24 +65,23 @@ distance glide_distance(const flight_point& pos, const glider& g, const task& t,
|
||||
((ground_alt - t.get_finish().alt) / dist_to_finish - 1 / glide_ratio(g.polar[0])));
|
||||
}
|
||||
|
||||
}
|
||||
} // namespace glide_computer
|
||||
|
||||
namespace {
|
||||
|
||||
using namespace glide_computer;
|
||||
|
||||
void print(std::string_view phase_name, timestamp start_ts, const glide_computer::flight_point& point, const glide_computer::flight_point& new_point)
|
||||
void print(std::string_view phase_name, timestamp start_ts, const glide_computer::flight_point& point,
|
||||
const glide_computer::flight_point& new_point)
|
||||
{
|
||||
std::cout << STD_FMT::format(
|
||||
"| {:<12} | {:>9%.1Q %q} (Total: {:>9%.1Q %q}) | {:>8%.1Q %q} (Total: {:>8%.1Q %q}) | {:>7%.0Q %q} ({:>6%.0Q %q}) |\n",
|
||||
phase_name, quantity_cast<si::minute>(new_point.ts - point.ts), quantity_cast<si::minute>(new_point.ts - start_ts),
|
||||
new_point.dist - point.dist, new_point.dist, new_point.alt - point.alt, new_point.alt);
|
||||
"| {:<12} | {:>9%.1Q %q} (Total: {:>9%.1Q %q}) | {:>8%.1Q %q} (Total: {:>8%.1Q %q}) | {:>7%.0Q %q} ({:>6%.0Q %q}) "
|
||||
"|\n",
|
||||
phase_name, quantity_cast<si::minute>(new_point.ts - point.ts), quantity_cast<si::minute>(new_point.ts - start_ts),
|
||||
new_point.dist - point.dist, new_point.dist, new_point.alt - point.alt, new_point.alt);
|
||||
}
|
||||
|
||||
flight_point takeoff(timestamp start_ts, const task& t)
|
||||
{
|
||||
return {start_ts, t.get_start().alt};
|
||||
}
|
||||
flight_point takeoff(timestamp start_ts, const task& t) { return {start_ts, t.get_start().alt}; }
|
||||
|
||||
flight_point tow(timestamp start_ts, const flight_point& pos, const aircraft_tow& at)
|
||||
{
|
||||
@@ -92,7 +92,8 @@ flight_point tow(timestamp start_ts, const flight_point& pos, const aircraft_tow
|
||||
return new_pos;
|
||||
}
|
||||
|
||||
flight_point circle(timestamp start_ts, const flight_point& pos, const glider& g, const weather& w, const task& t, height& height_to_gain)
|
||||
flight_point circle(timestamp start_ts, const flight_point& pos, const glider& g, const weather& w, const task& t,
|
||||
height& height_to_gain)
|
||||
{
|
||||
const height h_agl = agl(pos.alt, terrain_level_alt(t, pos));
|
||||
const height circling_height = std::min(w.cloud_base - h_agl, height_to_gain);
|
||||
@@ -114,7 +115,8 @@ flight_point glide(timestamp start_ts, const flight_point& pos, const glider& g,
|
||||
const auto alt = ground_alt + s.min_agl_height;
|
||||
const auto l3d = length_3d(dist, pos.alt - alt);
|
||||
const duration d = l3d / g.polar[0].v.common();
|
||||
const flight_point new_pos{pos.ts + d, terrain_level_alt(t, pos) + s.min_agl_height, t.get_leg_index(new_distance), new_distance};
|
||||
const flight_point new_pos{pos.ts + d, terrain_level_alt(t, pos) + s.min_agl_height, t.get_leg_index(new_distance),
|
||||
new_distance};
|
||||
|
||||
print("Glide", start_ts, pos, new_pos);
|
||||
return new_pos;
|
||||
@@ -135,9 +137,11 @@ flight_point final_glide(timestamp start_ts, const flight_point& pos, const glid
|
||||
|
||||
namespace glide_computer {
|
||||
|
||||
void estimate(timestamp start_ts, const glider& g, const weather& w, const task& t, const safety& s, const aircraft_tow& at)
|
||||
void estimate(timestamp start_ts, const glider& g, const weather& w, const task& t, const safety& s,
|
||||
const aircraft_tow& at)
|
||||
{
|
||||
std::cout << STD_FMT::format("| {:<12} | {:^28} | {:^26} | {:^21} |\n", "Flight phase", "Duration", "Distance", "Height");
|
||||
std::cout << STD_FMT::format("| {:<12} | {:^28} | {:^26} | {:^21} |\n", "Flight phase", "Duration", "Distance",
|
||||
"Height");
|
||||
std::cout << STD_FMT::format("|{0:-^14}|{0:-^30}|{0:-^28}|{0:-^23}|\n", "");
|
||||
|
||||
// ready to takeoff
|
||||
|
||||
@@ -25,7 +25,6 @@
|
||||
#include <units/bits/fmt_hacks.h>
|
||||
#include <units/isq/si/length.h>
|
||||
#include <units/quantity_kind.h>
|
||||
|
||||
#include <limits>
|
||||
#include <ostream>
|
||||
|
||||
|
||||
@@ -32,14 +32,14 @@
|
||||
|
||||
#include <units/chrono.h>
|
||||
#include <units/format.h>
|
||||
#include <units/math.h> // IWYU pragma: keep
|
||||
#include <units/math.h> // IWYU pragma: keep
|
||||
#include <algorithm>
|
||||
#include <array>
|
||||
#include <initializer_list>
|
||||
#include <iterator>
|
||||
#include <ostream>
|
||||
#include <ranges>
|
||||
#include <string> // IWYU pragma: keep
|
||||
#include <string> // IWYU pragma: keep
|
||||
#include <vector>
|
||||
|
||||
// An example of a really simplified tactical glide computer
|
||||
@@ -69,7 +69,7 @@ namespace glide_computer {
|
||||
|
||||
template<units::QuantityKind QK1, units::QuantityKind QK2>
|
||||
constexpr units::Dimensionless auto operator/(const QK1& lhs, const QK2& rhs)
|
||||
requires(!units::QuantityKindRelatedTo<QK1, QK2>) && requires { lhs.common() / rhs.common();}
|
||||
requires(!units::QuantityKindRelatedTo<QK1, QK2>) && requires { lhs.common() / rhs.common(); }
|
||||
{
|
||||
return lhs.common() / rhs.common();
|
||||
}
|
||||
@@ -149,7 +149,7 @@ public:
|
||||
const waypoint* end_;
|
||||
distance length_ = geographic::spherical_distance(begin().pos, end().pos);
|
||||
public:
|
||||
leg(const waypoint& b, const waypoint& e) noexcept: begin_(&b), end_(&e) {}
|
||||
leg(const waypoint& b, const waypoint& e) noexcept : begin_(&b), end_(&e) {}
|
||||
constexpr const waypoint& begin() const { return *begin_; };
|
||||
constexpr const waypoint& end() const { return *end_; }
|
||||
constexpr const distance get_length() const { return length_; }
|
||||
@@ -157,8 +157,11 @@ public:
|
||||
using legs = std::vector<leg>;
|
||||
|
||||
template<std::ranges::input_range R>
|
||||
requires std::same_as<std::ranges::range_value_t<R>, waypoint>
|
||||
explicit task(const R& r) : waypoints_(std::ranges::begin(r), std::ranges::end(r)) {}
|
||||
requires std::same_as<std::ranges::range_value_t<R>,
|
||||
waypoint> explicit task(const R& r) :
|
||||
waypoints_(std::ranges::begin(r), std::ranges::end(r))
|
||||
{
|
||||
}
|
||||
|
||||
task(std::initializer_list<waypoint> wpts) : waypoints_(wpts) {}
|
||||
|
||||
@@ -170,10 +173,14 @@ public:
|
||||
|
||||
distance get_length() const { return length_; }
|
||||
|
||||
distance get_leg_dist_offset(std::size_t leg_index) const { return leg_index == 0 ? distance{} : leg_total_distances_[leg_index - 1]; }
|
||||
distance get_leg_dist_offset(std::size_t leg_index) const
|
||||
{
|
||||
return leg_index == 0 ? distance{} : leg_total_distances_[leg_index - 1];
|
||||
}
|
||||
std::size_t get_leg_index(distance dist) const
|
||||
{
|
||||
return static_cast<std::size_t>(std::ranges::distance(leg_total_distances_.cbegin(), std::ranges::lower_bound(leg_total_distances_, dist)));
|
||||
return static_cast<std::size_t>(
|
||||
std::ranges::distance(leg_total_distances_.cbegin(), std::ranges::lower_bound(leg_total_distances_, dist)));
|
||||
}
|
||||
|
||||
private:
|
||||
@@ -214,6 +221,7 @@ inline units::isq::si::length<units::isq::si::kilometre> length_3d(distance dist
|
||||
|
||||
distance glide_distance(const flight_point& pos, const glider& g, const task& t, const safety& s, altitude ground_alt);
|
||||
|
||||
void estimate(timestamp start_ts, const glider& g, const weather& w, const task& t, const safety& s, const aircraft_tow& at);
|
||||
void estimate(timestamp start_ts, const glider& g, const weather& w, const task& t, const safety& s,
|
||||
const aircraft_tow& at);
|
||||
|
||||
} // namespace glide_computer
|
||||
|
||||
Reference in New Issue
Block a user