Refactor dynamics lat/lon parsing
Using C++11 idioms, and avoid conversion to C strings for atof
This commit is contained in:
parent
f5f3054a7a
commit
3893754537
1 changed files with 10 additions and 15 deletions
|
@ -38,22 +38,17 @@ using std::string;
|
||||||
****************************************************************************/
|
****************************************************************************/
|
||||||
static double processPosition(const string &pos)
|
static double processPosition(const string &pos)
|
||||||
{
|
{
|
||||||
string prefix;
|
string subs{pos};
|
||||||
string subs;
|
|
||||||
string degree;
|
|
||||||
string decimal;
|
|
||||||
int sign = 1;
|
int sign = 1;
|
||||||
double value;
|
const auto prefix = subs.substr(0, 1);
|
||||||
subs = pos;
|
if (prefix == "S" || (prefix == "W"))
|
||||||
prefix= subs.substr(0,1);
|
|
||||||
if (prefix == string("S") || (prefix == string("W")))
|
|
||||||
sign = -1;
|
sign = -1;
|
||||||
subs = subs.substr(1, subs.length());
|
subs = subs.substr(1, subs.length()); // drop first character
|
||||||
degree = subs.substr(0, subs.find(" ",0));
|
const auto spacePos = subs.find(" ", 0);
|
||||||
decimal = subs.substr(subs.find(" ",0), subs.length());
|
const auto degree = subs.substr(0, spacePos);
|
||||||
|
const auto decimal = subs.substr(spacePos, subs.length());
|
||||||
|
|
||||||
value = sign * (atof(degree.c_str()) + atof(decimal.c_str())/60.0);
|
return sign * stoi(degree) + (stof(decimal) / 60.0);
|
||||||
return value;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
FGGroundNetXMLLoader::FGGroundNetXMLLoader(FGGroundNetwork* net):
|
FGGroundNetXMLLoader::FGGroundNetXMLLoader(FGGroundNetwork* net):
|
||||||
|
|
Loading…
Add table
Reference in a new issue