Skip to content

Commit

Permalink
fixing whitespace in string to double conversion
Browse files Browse the repository at this point in the history
  • Loading branch information
gangatp committed Apr 15, 2024
1 parent b203943 commit f0c320f
Show file tree
Hide file tree
Showing 3 changed files with 101 additions and 79 deletions.
47 changes: 19 additions & 28 deletions Source/Common/Math/NMR_Matrix.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -437,32 +437,23 @@ namespace NMR {
{
nfUint32 nValueCount = 0;
nfFloat nValues[12];

const nfChar * pszString = sString.c_str();
const nfChar * pCurrent = pszString;

nfBool bFinished = false;
while (!bFinished) {
// Find next space
const nfChar * pBegin = pCurrent;
while ((*pCurrent != ' ') && (*pCurrent))
pCurrent++;

// If we have not found a space, convert value to double
if (pBegin != pCurrent) {
if (nValueCount >= 12)
throw CNMRException(NMR_ERROR_TOOMANYVALUESINMATRIXSTRING);
nValues[nValueCount] = fnStringToFloat(pBegin);
nValueCount++;
}

// If we are finished, break, otherwise skip space!
if (!*pCurrent)
bFinished = true;
else
pCurrent++;
size_t pos = 0, start = 0;
std::string token;
while (pos < sString.length()) {
if (nValueCount >= 12)
throw CNMRException(NMR_ERROR_TOOMANYVALUESINMATRIXSTRING);
pos = sString.find(' ', start);
if (pos == std::string::npos)
pos = sString.length();
token = sString.substr(start, pos - start);
nValues[nValueCount] = fnStringToFloat(token.c_str());
start = pos + 1;
nValueCount++;
// skip multiple spaces
if (start < sString.length() && sString[start] == ' ')
start++;
}

if (nValueCount < 12)
throw CNMRException(NMR_ERROR_NOTENOUGHVALUESINMATRIXSTRING);

Expand All @@ -486,8 +477,8 @@ namespace NMR {
nfBool fnMATRIX3_isplanar(_In_ const NMATRIX3 mMatrix)
{
const double eps = 1e-7;
return (fabs(mMatrix.m_fields[2][0]) < eps) && (fabs(mMatrix.m_fields[2][1]) < eps) && (fabs(mMatrix.m_fields[2][2] - 1 ) < eps)
&& (fabs(mMatrix.m_fields[0][2]) < eps) && (fabs(mMatrix.m_fields[1][2]) < eps);
return (fabs(mMatrix.m_fields[2][0]) < eps) && (fabs(mMatrix.m_fields[2][1]) < eps) && (fabs(mMatrix.m_fields[2][2] - 1) < eps)
&& (fabs(mMatrix.m_fields[0][2]) < eps) && (fabs(mMatrix.m_fields[1][2]) < eps);
}

}
}
Loading

0 comments on commit f0c320f

Please sign in to comment.