Mercurial > hg > svcore
comparison base/RangeMapper.cpp @ 341:db8fcd280234
* Fix log range mapper bug
author | Chris Cannam |
---|---|
date | Mon, 26 Nov 2007 13:33:14 +0000 |
parents | 2b40f83e7627 |
children | ca3b91119482 |
comparison
equal
deleted
inserted
replaced
340:516819f2b97b | 341:db8fcd280234 |
---|---|
74 } | 74 } |
75 | 75 |
76 int | 76 int |
77 LogRangeMapper::getPositionForValue(float value) const | 77 LogRangeMapper::getPositionForValue(float value) const |
78 { | 78 { |
79 float mapped = m_ratio * log10(value); | 79 int position = (log10(value) - m_minlog) * m_ratio + m_minpos; |
80 int position = lrintf(((mapped - m_minlog) / (m_maxlog - m_minlog)) | |
81 * (m_maxpos - m_minpos)); | |
82 if (position < m_minpos) position = m_minpos; | 80 if (position < m_minpos) position = m_minpos; |
83 if (position > m_maxpos) position = m_maxpos; | 81 if (position > m_maxpos) position = m_maxpos; |
84 // std::cerr << "LogRangeMapper::getPositionForValue: " << value << " -> " | 82 // std::cerr << "LogRangeMapper::getPositionForValue: " << value << " -> " |
85 // << position << " (minpos " << m_minpos << ", maxpos " << m_maxpos << ", ratio " << m_ratio << ", minlog " << m_minlog << ")" << std::endl; | 83 // << position << " (minpos " << m_minpos << ", maxpos " << m_maxpos << ", ratio " << m_ratio << ", minlog " << m_minlog << ")" << std::endl; |
86 return position; | 84 return position; |