Skip to content

Commit

Permalink
Fix histogram merging (#28)
Browse files Browse the repository at this point in the history
  • Loading branch information
tribal-tec authored Mar 17, 2017
1 parent d571c47 commit afa2a02
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 5 deletions.
9 changes: 4 additions & 5 deletions lexis/render/Histogram.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -28,19 +28,18 @@ Histogram& Histogram::operator+=( const Histogram& histogram )
return *this;
}

if( histogram.getBins().size() != getBins().size() ||
histogram.getMin() != getMin() ||
histogram.getMax() != getMax( ))
{
if( histogram.getBins().size() != getBins().size( ))
throw std::runtime_error( "Addition of incompatible histograms" );
}

const uint64_t* srcBins = histogram.getBins().data();

uint64_t* bins = getBins().data();
for( size_t i = 0; i < getBins().size(); ++i )
bins[ i ] += srcBins[ i ];

setMin( std::min( getMin(), histogram.getMin()));
setMax( std::max( getMax(), histogram.getMax()));

return *this;
}

Expand Down
17 changes: 17 additions & 0 deletions tests/render/histogram.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -65,3 +65,20 @@ BOOST_AUTO_TEST_CASE( sampleCurve )
BOOST_CHECK_EQUAL_COLLECTIONS( sampleRange.begin(), sampleRange.end(),
expectedRange.begin(), expectedRange.end( ));
}

BOOST_AUTO_TEST_CASE( mergeDifferentRange )
{
lexis::render::Histogram histogram1;
histogram1.setBins( { 10, 5, 0, 5 } );
histogram1.setMin(1);
histogram1.setMax(5);

lexis::render::Histogram histogram2;
histogram2.setBins( { 1, 2, 3, 4 } );
histogram2.setMin(0);
histogram2.setMax(4);

histogram1 += histogram2;
BOOST_CHECK_EQUAL( histogram1.getMin(), 0 );
BOOST_CHECK_EQUAL( histogram1.getMax(), 5 );
}

0 comments on commit afa2a02

Please sign in to comment.