Commit 22b4e047 authored by Sebastian Eichelbaum's avatar Sebastian Eichelbaum
Browse files

[MERGE]

parents 66e2231e 3b811d56
......@@ -87,12 +87,14 @@ void WHistogramBasic::insert( double value )
return; // value = ( value > m_maximum ? m_maximum : m_minimum );
}
if( value == m_maximum )
if( std::abs( m_minimum - m_maximum ) <= 2.0 * wlimits::DBL_EPS )
{
value = m_maximum - wlimits::DBL_EPS;
m_bins.at( m_nbBuckets - 1 )++;
}
else
{
m_bins.at( static_cast< size_t >( ( value - m_minimum ) / std::abs( m_maximum - m_minimum ) * ( m_nbBuckets - 1 ) ) )++;
}
m_bins.at( static_cast< size_t >( std::abs( value - m_minimum ) / m_intervalWidth ) )++;
}
size_t WHistogramBasic::valuesSize() const
......
......@@ -64,7 +64,7 @@ public:
h.insert( 0.7234 );
TS_ASSERT_EQUALS( h.size(), 1000 );
TS_ASSERT_EQUALS( h.valuesSize(), 1 );
TS_ASSERT_EQUALS( h[723], 1 );
TS_ASSERT_EQUALS( h[722], 1 );
}
/**
......@@ -74,11 +74,11 @@ public:
{
WHistogramBasic h( 0.0, 1.0 );
h.insert( 0.001 );
TS_ASSERT_EQUALS( h[1], 1 );
TS_ASSERT_EQUALS( h[0], 1 );
h.insert( 0.0039999 );
TS_ASSERT_EQUALS( h[3], 1 );
h.insert( 0.0070001 );
TS_ASSERT_EQUALS( h[7], 1 );
TS_ASSERT_EQUALS( h[6], 1 );
}
/**
......@@ -132,6 +132,19 @@ public:
h.insert( 0.0 );
TS_ASSERT_EQUALS( h.valuesSize(), 2 );
}
/**
* Also for values near the maxium. You may also see #186 for further details.
*/
void testInsertAlmostMax( void )
{
double max = 10000.000000010001;
WHistogramBasic h( -2147483648, max );
h.insert( 10000 );
h.insert( max - 2.0 * wlimits::FLT_EPS );
TS_ASSERT_EQUALS( h[999], 2 );
}
};
#endif // WHISTOGRAMBASIC_TEST_H
......@@ -123,8 +123,8 @@ public:
{
// calculate min and max
// Calculating this once simply ensures that it does not need to be recalculated in textures, histograms ...
m_minimum = wlimits::MAX_DOUBLE;
m_maximum = wlimits::MIN_DOUBLE;
m_minimum = std::numeric_limits< T >::max();
m_maximum = std::numeric_limits< T >::min();
for( typename std::vector< T >::const_iterator iter = data->begin(); iter != data->end(); ++iter )
{
m_minimum = m_minimum > *iter ? *iter : m_minimum;
......@@ -145,8 +145,8 @@ public:
{
// calculate min and max
// Calculating this once simply ensures that it does not need to be recalculated in textures, histograms ...
m_minimum = wlimits::MAX_DOUBLE;
m_maximum = wlimits::MIN_DOUBLE;
m_minimum = std::numeric_limits< T >::max();
m_maximum = std::numeric_limits< T >::min();
for( typename std::vector< T >::const_iterator iter = data->begin(); iter != data->end(); ++iter )
{
m_minimum = m_minimum > *iter ? *iter : m_minimum;
......
......@@ -398,7 +398,7 @@ void WMHistogramView::calculateHistograms()
{
// create new histogram
// we do not use WDataSetScalar's getHistogram here as we want to set the min and max of the histogram ourselves
m_histograms[ k ] = boost::shared_ptr< WHistogramBasic >( new WHistogramBasic( min, max + 0.00000001, histoBins ) );
m_histograms[ k ] = boost::shared_ptr< WHistogramBasic >( new WHistogramBasic( min, max, histoBins ) );
if( m_data[ k ] )
{
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment