refactor(example): get_length() renamed to get_distance()

This commit is contained in:
Mateusz Pusz
2023-04-11 09:12:48 +02:00
parent 565465d284
commit 1866973532
3 changed files with 9 additions and 9 deletions

View File

@@ -43,7 +43,7 @@ std::vector<distance> task::make_leg_total_distances(const legs& legs)
{
std::vector<distance> res;
res.reserve(legs.size());
auto to_length = [](const leg& l) { return l.get_length(); };
auto to_length = [](const leg& l) { return l.get_distance(); };
std::transform_inclusive_scan(legs.cbegin(), legs.cend(), std::back_inserter(res), std::plus(), to_length);
return res;
}
@@ -52,7 +52,7 @@ 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;
return l.begin().alt + alt_diff * ((pos.dist - t.get_leg_dist_offset(pos.leg_idx)) / l.get_length());
return l.begin().alt + alt_diff * ((pos.dist - t.get_leg_dist_offset(pos.leg_idx)) / l.get_distance());
}
// Returns `x` of the intersection of a glide line and a terrain line.
@@ -60,7 +60,7 @@ altitude terrain_level_alt(const task& t, const flight_point& pos)
// 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)
{
const auto dist_to_finish = t.get_length() - pos.dist;
const auto dist_to_finish = t.get_distance() - pos.dist;
return quantity_cast<isq::distance>(ground_alt + s.min_agl_height - pos.alt) /
((ground_alt - t.get_finish().alt) / dist_to_finish - 1 / glide_ratio(g.polar[0]));
}
@@ -124,7 +124,7 @@ flight_point glide(timestamp start_ts, const flight_point& pos, const glider& g,
flight_point final_glide(timestamp start_ts, const flight_point& pos, const glider& g, const task& t)
{
const auto dist = t.get_length() - pos.dist;
const auto dist = t.get_distance() - pos.dist;
const auto l3d = length_3d(dist, pos.alt - t.get_finish().alt);
const duration d = l3d / g.polar[0].v;
const flight_point new_pos{pos.ts + d, t.get_finish().alt, t.get_legs().size() - 1, pos.dist + dist};
@@ -152,7 +152,7 @@ void estimate(timestamp start_ts, const glider& g, const weather& w, const task&
// estimate the altitude needed to reach the finish line from this place
const altitude final_glide_alt =
t.get_finish().alt + quantity_cast<isq::height>(t.get_length()) / glide_ratio(g.polar[0]);
t.get_finish().alt + quantity_cast<isq::height>(t.get_distance() / glide_ratio(g.polar[0]));
// how much height we still need to gain in the thermalls to reach the destination?
height height_to_gain = final_glide_alt - pos.alt;

View File

@@ -133,7 +133,7 @@ public:
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 distance get_length() const { return length_; }
constexpr distance get_distance() const { return length_; }
};
using legs = std::vector<leg>;
@@ -151,7 +151,7 @@ public:
const waypoint& get_start() const { return waypoints_.front(); }
const waypoint& get_finish() const { return waypoints_.back(); }
distance get_length() const { return length_; }
distance get_distance() const { return length_; }
distance get_leg_dist_offset(std::size_t leg_index) const
{

View File

@@ -126,12 +126,12 @@ void print(const task& t)
std::cout << "- Start: " << t.get_start().name << "\n";
std::cout << "- Finish: " << t.get_finish().name << "\n";
std::cout << "- Length: " << STD_FMT::format("{:%.1Q %q}", t.get_length()) << "\n";
std::cout << "- Length: " << STD_FMT::format("{:%.1Q %q}", t.get_distance()) << "\n";
std::cout << "- Legs: "
<< "\n";
for (const auto& l : t.get_legs())
std::cout << STD_FMT::format(" * {} -> {} ({:%.1Q %q})\n", l.begin().name, l.end().name, l.get_length());
std::cout << STD_FMT::format(" * {} -> {} ({:%.1Q %q})\n", l.begin().name, l.end().name, l.get_distance());
std::cout << "\n";
}