Fix rounding in COLOR4D::ToColour
Due to the implicit floor of the cast from double to unsigned char, there was a small rounding error in COLOUR4D's WX conversion function. This fixes the failing tests. Also make the cast to unsigned char explicit.
This commit is contained in:
parent
ee819216e2
commit
4c355c32d3
|
@ -79,6 +79,20 @@ COLOR4D::COLOR4D( EDA_COLOR_T aColor )
|
|||
}
|
||||
|
||||
|
||||
wxColour COLOR4D::ToColour() const
|
||||
{
|
||||
using CHAN_T = wxColourBase::ChannelType;
|
||||
|
||||
const wxColour colour(
|
||||
static_cast<CHAN_T>( r * 255 + 0.5 ),
|
||||
static_cast<CHAN_T>( g * 255 + 0.5 ),
|
||||
static_cast<CHAN_T>( b * 255 + 0.5 ),
|
||||
static_cast<CHAN_T>( a * 255 + 0.5 )
|
||||
);
|
||||
return colour;
|
||||
}
|
||||
|
||||
|
||||
COLOR4D COLOR4D::LegacyMix( COLOR4D aColor ) const
|
||||
{
|
||||
COLOR4D candidate;
|
||||
|
|
|
@ -89,11 +89,7 @@ public:
|
|||
|
||||
wxString ToWxString( long flags ) const;
|
||||
|
||||
wxColour ToColour() const
|
||||
{
|
||||
wxColour colour( r * 255, g * 255, b * 255, a * 255 );
|
||||
return colour;
|
||||
}
|
||||
wxColour ToColour() const;
|
||||
|
||||
/**
|
||||
* Function LegacyMix()
|
||||
|
|
|
@ -247,12 +247,11 @@ static std::vector<WX_CONV_CASE> wx_conv_cases = {
|
|||
{ { 0xFF, 0x00, 0x00, 0xFF }, { 0.999, 0.001, 0.0, 1.0 } },
|
||||
};
|
||||
|
||||
#ifdef HAVE_EXPECTED_FAILURES
|
||||
|
||||
/**
|
||||
* Check conversion to WxColour
|
||||
*/
|
||||
BOOST_AUTO_TEST_CASE( ToWx, *boost::unit_test::expected_failures( 3 ) )
|
||||
BOOST_AUTO_TEST_CASE( ToWx )
|
||||
{
|
||||
for( const auto& c : wx_conv_cases )
|
||||
{
|
||||
|
@ -266,8 +265,6 @@ BOOST_AUTO_TEST_CASE( ToWx, *boost::unit_test::expected_failures( 3 ) )
|
|||
}
|
||||
}
|
||||
|
||||
#endif // HAVE_EXPECTED_FAILURES
|
||||
|
||||
|
||||
/**
|
||||
* Check conversion from WxColour
|
||||
|
|
Loading…
Reference in New Issue