Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Conversation

ScarletKuro
Copy link
Member

Description

Follow-up PR for: #10313

This fixes an issue where setting numberOfColors = 1 in GenerateGradientPalette causes the following line:

var t = i / (float)(numberOfColors - 1);

to return NaN, resulting in the end color being white.

The fix adds a special case to handle the situation when numberOfColors = 1. An alternative approach would be to throw an exception when numberOfColors is less than two, but I believe this approach is better. If someone wants to create a multi-gradient palette, GenerateGradientPalette could be reused, and there could be scenarios where the number of colors per segment is equal to one, which would cause the same problem again.

How Has This Been Tested?

Unit tests, visually

Type of Changes

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to not work as expected)
  • Documentation (fix or improvement to the website or code docs)

Checklist

  • The PR is submitted to the correct branch (dev).
  • My code follows the code style of this project.
  • I've added relevant tests.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Unexpected behavior or functionality not working as intended
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant