ESGRAF48/source/ResultWidget/PRMap.cpp

44 lines
768 B
C++
Raw Permalink Normal View History

2018-06-14 17:19:53 +00:00
#include "PRMap.h"
2019-10-05 14:14:45 +00:00
unsigned int PRMap::lookup(const Age& age, const unsigned int& points)
2018-06-14 17:19:53 +00:00
{
2019-10-05 14:14:45 +00:00
if (points >= m_PRs.size())
{
return 0;
}
auto ageIndex = [&]() -> size_t {
if (m_ages.empty())
{
return 0;
}
if (age < m_ages.front())
{
return 0;
}
if (m_ages.back() < age)
{
return m_ages.size() - 2;
}
for (size_t index = 1; index < m_ages.size(); ++index)
{
if (age < m_ages.at(index))
{
return index - 1;
}
}
2018-06-26 13:14:25 +00:00
return 0;
2019-10-05 14:14:45 +00:00
}();
2018-06-14 17:19:53 +00:00
2019-10-05 14:14:45 +00:00
if (ageIndex >= m_PRs.at(points).size())
{
return 0;
}
2018-06-14 17:19:53 +00:00
2019-10-05 14:14:45 +00:00
return m_PRs.at(points).at(ageIndex);
2018-06-14 17:19:53 +00:00
}