1
0
Fork 0

[elevations] Maintenance

This commit is contained in:
scttgs0 2023-05-14 02:56:20 -05:00
parent c2646de887
commit 95c62c0f30

View file

@ -25,13 +25,13 @@
#endif
#include <simgear/constants.h>
#include <simgear/math/SGMath.hxx>
#include <simgear/debug/logstream.hxx>
#include <simgear/math/SGMath.hxx>
#include <Array/array.hxx>
#include "global.hxx"
#include "debug.hxx"
#include "global.hxx"
// lookup node elevations for each point in the SGGeod list. Returns
@ -39,8 +39,10 @@
double tgAverageElevation(const std::string& root, const string_list elev_src,
const std::vector<SGGeod>& points_source)
{
using namespace std::string_literals;
bool done = false;
unsigned int i;
unsigned i;
TGArray array;
// make a copy so our routine is non-destructive.
@ -77,13 +79,13 @@ double tgAverageElevation( const std::string &root, const string_list elev_src,
i = 0;
bool found_file = false;
while (!found_file && i < elev_src.size()) {
std::string array_path = root + "/" + elev_src[i] + "/" + base + "/" + b.gen_index_str();
std::string array_path = root + "/"s + elev_src[i] + "/"s + base + "/"s + b.gen_index_str();
if (array.open(array_path)) {
found_file = true;
TG_LOG(SG_GENERAL, SG_DEBUG, "Using array_path = " << array_path);
}
i++;
++i;
}
// this will fill in a zero structure if no array data
@ -103,7 +105,7 @@ double tgAverageElevation( const std::string &root, const string_list elev_src,
done = false;
elev = array.altitude_from_grid(points[i].getLongitudeDeg() * 3600.0,
points[i].getLatitudeDeg() * 3600.0);
if ( elev > -9000 ) {
if (elev > -9000.0) {
points[i].setElevationM(elev);
}
}
@ -118,10 +120,11 @@ double tgAverageElevation( const std::string &root, const string_list elev_src,
// now find the average height of the queried points
double total = 0.0;
int count = 0;
for ( i = 0; i < points.size(); ++i ) {
total += points[i].getElevationM();
count++;
for (auto& point : points) {
total += point.getElevationM();
++count;
}
double average = total / (double)count;
TG_LOG(SG_GENERAL, SG_DEBUG, "Average surface height of point list = " << average);