From: Mathias Froehlich Date: Sun, 24 Feb 2013 12:03:06 +0000 (+0100) Subject: spt: Normalize the bucket box meta filename lengths. X-Git-Url: https://git.mxchange.org/?a=commitdiff_plain;h=249155987de12e1a58e56c0735559c3144fa0f92;p=simgear.git spt: Normalize the bucket box meta filename lengths. --- diff --git a/simgear/scene/tgdb/BucketBox.hxx b/simgear/scene/tgdb/BucketBox.hxx index a61c23c6..1d43c3df 100644 --- a/simgear/scene/tgdb/BucketBox.hxx +++ b/simgear/scene/tgdb/BucketBox.hxx @@ -22,7 +22,9 @@ #include #include +#include #include +#include #include #include @@ -482,24 +484,48 @@ template std::basic_ostream& operator<<(std::basic_ostream& os, const BucketBox& bucketBox) { + std::basic_stringstream ss; + + double minSize = std::min(bucketBox.getWidthDeg(), bucketBox.getHeightDeg()); + + unsigned fieldPrecision = 0; + if (minSize <= 0.125) { + fieldPrecision = 3; + } else if (minSize <= 0.25) { + fieldPrecision = 2; + } else if (minSize <= 0.5) { + fieldPrecision = 1; + } + + unsigned lonFieldWidth = 3; + if (fieldPrecision) + lonFieldWidth += 1 + fieldPrecision; + + ss << std::fixed << std::setfill('0') << std::setprecision(fieldPrecision); + double lon = bucketBox.getLongitudeDeg(); if (lon < 0) - os << "w" << -lon; + ss << "w" << std::setw(lonFieldWidth) << -lon << std::setw(0); else - os << "e" << lon; + ss << "e" << std::setw(lonFieldWidth) << lon << std::setw(0); + unsigned latFieldWidth = 2; + if (fieldPrecision) + latFieldWidth += 1 + fieldPrecision; + double lat = bucketBox.getLatitudeDeg(); if (lat < -90) lat = -90; if (90 < lat) lat = 90; if (lat < 0) - os << "s" << -lat; + ss << "s" << std::setw(latFieldWidth) << -lat << std::setw(0); else - os << "n" << lat; + ss << "n" << std::setw(latFieldWidth) << lat << std::setw(0); - os << "-" << bucketBox.getWidthDeg() << "x" << bucketBox.getHeightDeg(); - return os; + ss << "-" << bucketBox.getWidthDeg() << "x" << bucketBox.getHeightDeg(); + + return os << ss.str(); } /// Stream inout operator.