diff options
Diffstat (limited to 'utils/sofa-info.cpp')
-rw-r--r-- | utils/sofa-info.cpp | 43 |
1 files changed, 28 insertions, 15 deletions
diff --git a/utils/sofa-info.cpp b/utils/sofa-info.cpp index e762ca25..7f37a5a5 100644 --- a/utils/sofa-info.cpp +++ b/utils/sofa-info.cpp @@ -159,13 +159,20 @@ static double GetUniformAzimStep(const double epsilon, const std::vector<double> * can uniformly cover the list. Ideally this will be over half, but in * degenerate cases this can fall to a minimum of 5 (the lower limit). */ -static double GetUniformElevStep(const double epsilon, const std::vector<double> &elems) +static double GetUniformElevStep(const double epsilon, std::vector<double> &elems) { if(elems.size() < 5) return 0.0; + /* Reverse the elevations so it increments starting with -90 (flipped from + * +90). This makes it easier to work out a proper stepping value. + */ + std::reverse(elems.begin(), elems.end()); + for(auto &v : elems) v *= -1.0; + uint count{static_cast<uint>(std::ceil(180.0 / (elems[1]-elems[0])))}; count = std::min(count, 255u); + double ret{0.0}; for(;count >= 5;--count) { const double step{180.0 / count}; @@ -182,9 +189,16 @@ static double GetUniformElevStep(const double epsilon, const std::vector<double> good &= !(idx < elems.size()) || !(std::abs(target-elems[idx++]) > epsilon); } if(good) - return step; + { + ret = step; + break; + } } - return 0.0; + /* Re-reverse the elevations to restore the correct order. */ + for(auto &v : elems) v *= -1.0; + std::reverse(elems.begin(), elems.end()); + + return ret; } /* Attempts to produce a compatible layout. Most data sets tend to be @@ -195,7 +209,7 @@ static double GetUniformElevStep(const double epsilon, const std::vector<double> */ static void PrintCompatibleLayout(const uint m, const float *xyzs) { - fprintf(stdout, "\n"); + fputc('\n', stdout); auto aers = std::vector<double3>(m, double3{}); for(uint i{0u};i < m;++i) @@ -231,24 +245,23 @@ static void PrintCompatibleLayout(const uint m, const float *xyzs) }; elevs.erase(std::remove_if(elevs.begin(), elevs.end(), invalid_elev), elevs.end()); - /* Reverse the elevations so it increments starting with -90 (flipped - * from +90). This makes it easier to work out a proper stepping value. - */ - std::reverse(elevs.begin(), elevs.end()); - for(auto &ev : elevs) ev *= -1.0; - double step{GetUniformElevStep(0.1, elevs)}; if(step <= 0.0) { - fprintf(stdout, "Non-uniform elevations on field distance %f.\n", dist); + if(elevs.empty()) + fprintf(stdout, "No usable elevations on field distance %f.\n", dist); + else + { + fprintf(stdout, "Non-uniform elevations on field distance %.3f.\nGot: %+.2f", dist, + elevs[0]); + for(size_t ei{1u};ei < elevs.size();++ei) + fprintf(stdout, ", %+.2f", elevs[ei]); + fputc('\n', stdout); + } fds.erase(fds.begin() + static_cast<ptrdiff_t>(fi)); continue; } - /* Re-reverse the elevations to restore the correct order. */ - for(auto &ev : elevs) ev *= -1.0; - std::reverse(elevs.begin(), elevs.end()); - uint evStart{0u}; for(uint ei{0u};ei < elevs.size();ei++) { |