Merge pull request #383 from RogueException/feature/color-improvements

Throw an exception when creating a Color with an invalid float value
This commit is contained in:
RogueException
2016-11-26 23:33:54 -04:00
committed by GitHub

View File

@@ -32,6 +32,12 @@ namespace Discord
} }
public Color(float r, float g, float b) public Color(float r, float g, float b)
{ {
if (r < 0.0f || r > 1.0f)
throw new ArgumentOutOfRangeException(nameof(r), "A float value must be within [0,1]");
if (g < 0.0f || g > 1.0f)
throw new ArgumentOutOfRangeException(nameof(g), "A float value must be within [0,1]");
if (b < 0.0f || b > 1.0f)
throw new ArgumentOutOfRangeException(nameof(b), "A float value must be within [0,1]");
RawValue = RawValue =
((uint)(r * 255.0f) << 16) | ((uint)(r * 255.0f) << 16) |
((uint)(g * 255.0f) << 8) | ((uint)(g * 255.0f) << 8) |