Skip to content

Commit b8ec8c9

Browse files
committed
Fix limited random color ramp always returns 1 less color than set
(cherry-picked from 1d98b10)
1 parent 38f4f08 commit b8ec8c9

1 file changed

Lines changed: 4 additions & 1 deletion

File tree

src/core/symbology-ng/qgsvectorcolorrampv2.cpp

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -313,8 +313,11 @@ double QgsVectorRandomColorRampV2::value( int index ) const
313313

314314
QColor QgsVectorRandomColorRampV2::color( double value ) const
315315
{
316+
if ( value < 0 || value > 1 )
317+
return QColor();
318+
316319
int colorCnt = mColors.count();
317-
int colorIdx = static_cast< int >( value * ( colorCnt - 1 ) );
320+
int colorIdx = qMin( static_cast< int >( value * colorCnt ), colorCnt - 1 );
318321

319322
if ( colorIdx >= 0 && colorIdx < colorCnt )
320323
return mColors.at( colorIdx );

0 commit comments

Comments
 (0)