Skip to content

Commit

Permalink
Catch bad_numeric_cast, rethrow better
Browse files Browse the repository at this point in the history
Also, use long, not int32_t, for rxp moving average. This seems slightly
clearer to me.

Per @abellgithub's comments on 51b1149.
  • Loading branch information
gadomski committed Sep 15, 2014
1 parent f424a95 commit 6797ac4
Showing 1 changed file with 16 additions and 6 deletions.
22 changes: 16 additions & 6 deletions src/drivers/rxp/RxpReader.cpp
Expand Up @@ -353,19 +353,29 @@ Inclination RxpInclFixPointcloud::getInclMovingAverage() const
{
auto middle = m_incl.begin() + m_inclIdx;
double time = (m_incl[m_inclIdx].time + m_incl[m_inclIdx + 1].time) / 2;
int32_t roll(0), pitch(0);
long roll(0), pitch(0);
for (auto it = middle - m_windowSize + 1;
it != middle + m_windowSize + 1;
++it)
{
roll += it->roll;
pitch += it->pitch;
}
return {
time,
boost::numeric_cast<int16_t>(static_cast<int32_t>(roll / (m_windowSize * 2))),
boost::numeric_cast<int16_t>(static_cast<int32_t>(pitch / (m_windowSize * 2)))
};
try
{
return {
time,
boost::numeric_cast<int16_t>(roll
/ (static_cast<long>(m_windowSize) * 2)),
boost::numeric_cast<int16_t>(pitch
/ (static_cast<long>(m_windowSize) * 2))
};
}
catch (boost::numeric::bad_numeric_cast& e)
{
throw pdal_error("Unable to calculate inclination moving average due "
" to invalid roll or pitch value.");
}
}


Expand Down

0 comments on commit 6797ac4

Please sign in to comment.