1
0
mirror of https://github.com/DarthAffe/RGB.NET.git synced 2025-12-13 10:08:31 +00:00

Changed everything to use floats instead of doubles

This commit is contained in:
Darth Affe 2021-02-22 00:46:18 +01:00
parent 13afc29987
commit b328032df0
36 changed files with 433 additions and 472 deletions

View File

@ -19,7 +19,7 @@
{ {
if (!(obj is Color)) return false; if (!(obj is Color)) return false;
(double a, double r, double g, double b) = ((Color)obj).GetRGB(); (float a, float r, float g, float b) = ((Color)obj).GetRGB();
return color.A.EqualsInTolerance(a) && color.R.EqualsInTolerance(r) && color.G.EqualsInTolerance(g) && color.B.EqualsInTolerance(b); return color.A.EqualsInTolerance(a) && color.R.EqualsInTolerance(r) && color.G.EqualsInTolerance(g) && color.B.EqualsInTolerance(b);
} }
@ -50,10 +50,10 @@
if (blendColor.A.EqualsInTolerance(1)) if (blendColor.A.EqualsInTolerance(1))
return blendColor; return blendColor;
double resultA = (1.0 - ((1.0 - blendColor.A) * (1.0 - baseColor.A))); float resultA = (1.0f - ((1.0f - blendColor.A) * (1.0f - baseColor.A)));
double resultR = (((blendColor.R * blendColor.A) / resultA) + ((baseColor.R * baseColor.A * (1.0 - blendColor.A)) / resultA)); float resultR = (((blendColor.R * blendColor.A) / resultA) + ((baseColor.R * baseColor.A * (1.0f - blendColor.A)) / resultA));
double resultG = (((blendColor.G * blendColor.A) / resultA) + ((baseColor.G * baseColor.A * (1.0 - blendColor.A)) / resultA)); float resultG = (((blendColor.G * blendColor.A) / resultA) + ((baseColor.G * baseColor.A * (1.0f - blendColor.A)) / resultA));
double resultB = (((blendColor.B * blendColor.A) / resultA) + ((baseColor.B * baseColor.A * (1.0 - blendColor.A)) / resultA)); float resultB = (((blendColor.B * blendColor.A) / resultA) + ((baseColor.B * baseColor.A * (1.0f - blendColor.A)) / resultA));
return new Color(resultA, resultR, resultG, resultB); return new Color(resultA, resultR, resultG, resultB);
} }

View File

@ -32,22 +32,22 @@ namespace RGB.NET.Core
/// <summary> /// <summary>
/// Gets the alpha component value of this <see cref="Color"/> as percentage in the range [0..1]. /// Gets the alpha component value of this <see cref="Color"/> as percentage in the range [0..1].
/// </summary> /// </summary>
public double A { get; } public float A { get; }
/// <summary> /// <summary>
/// Gets the red component value of this <see cref="Color"/> as percentage in the range [0..1]. /// Gets the red component value of this <see cref="Color"/> as percentage in the range [0..1].
/// </summary> /// </summary>
public double R { get; } public float R { get; }
/// <summary> /// <summary>
/// Gets the green component value of this <see cref="Color"/> as percentage in the range [0..1]. /// Gets the green component value of this <see cref="Color"/> as percentage in the range [0..1].
/// </summary> /// </summary>
public double G { get; } public float G { get; }
/// <summary> /// <summary>
/// Gets the blue component value of this <see cref="Color"/> as percentage in the range [0..1]. /// Gets the blue component value of this <see cref="Color"/> as percentage in the range [0..1].
/// </summary> /// </summary>
public double B { get; } public float B { get; }
#endregion #endregion
@ -106,8 +106,8 @@ namespace RGB.NET.Core
/// <param name="r">The red component value of this <see cref="Color"/>.</param> /// <param name="r">The red component value of this <see cref="Color"/>.</param>
/// <param name="g">The green component value of this <see cref="Color"/>.</param> /// <param name="g">The green component value of this <see cref="Color"/>.</param>
/// <param name="b">The blue component value of this <see cref="Color"/>.</param> /// <param name="b">The blue component value of this <see cref="Color"/>.</param>
public Color(double r, double g, double b) public Color(float r, float g, float b)
: this(1.0, r, g, b) : this(1.0f, r, g, b)
{ } { }
/// <summary> /// <summary>
@ -117,7 +117,7 @@ namespace RGB.NET.Core
/// <param name="r">The red component value of this <see cref="Color"/>.</param> /// <param name="r">The red component value of this <see cref="Color"/>.</param>
/// <param name="g">The green component value of this <see cref="Color"/>.</param> /// <param name="g">The green component value of this <see cref="Color"/>.</param>
/// <param name="b">The blue component value of this <see cref="Color"/>.</param> /// <param name="b">The blue component value of this <see cref="Color"/>.</param>
public Color(double a, byte r, byte g, byte b) public Color(float a, byte r, byte g, byte b)
: this(a, r.GetPercentageFromByteValue(), g.GetPercentageFromByteValue(), b.GetPercentageFromByteValue()) : this(a, r.GetPercentageFromByteValue(), g.GetPercentageFromByteValue(), b.GetPercentageFromByteValue())
{ } { }
@ -128,7 +128,7 @@ namespace RGB.NET.Core
/// <param name="r">The red component value of this <see cref="Color"/>.</param> /// <param name="r">The red component value of this <see cref="Color"/>.</param>
/// <param name="g">The green component value of this <see cref="Color"/>.</param> /// <param name="g">The green component value of this <see cref="Color"/>.</param>
/// <param name="b">The blue component value of this <see cref="Color"/>.</param> /// <param name="b">The blue component value of this <see cref="Color"/>.</param>
public Color(double a, int r, int g, int b) public Color(float a, int r, int g, int b)
: this(a, (byte)r.Clamp(0, byte.MaxValue), (byte)g.Clamp(0, byte.MaxValue), (byte)b.Clamp(0, byte.MaxValue)) : this(a, (byte)r.Clamp(0, byte.MaxValue), (byte)g.Clamp(0, byte.MaxValue), (byte)b.Clamp(0, byte.MaxValue))
{ } { }
@ -139,7 +139,7 @@ namespace RGB.NET.Core
/// <param name="r">The red component value of this <see cref="Color"/>.</param> /// <param name="r">The red component value of this <see cref="Color"/>.</param>
/// <param name="g">The green component value of this <see cref="Color"/>.</param> /// <param name="g">The green component value of this <see cref="Color"/>.</param>
/// <param name="b">The blue component value of this <see cref="Color"/>.</param> /// <param name="b">The blue component value of this <see cref="Color"/>.</param>
public Color(int a, double r, double g, double b) public Color(int a, float r, float g, float b)
: this((byte)a.Clamp(0, byte.MaxValue), r, g, b) : this((byte)a.Clamp(0, byte.MaxValue), r, g, b)
{ } { }
@ -150,7 +150,7 @@ namespace RGB.NET.Core
/// <param name="r">The red component value of this <see cref="Color"/>.</param> /// <param name="r">The red component value of this <see cref="Color"/>.</param>
/// <param name="g">The green component value of this <see cref="Color"/>.</param> /// <param name="g">The green component value of this <see cref="Color"/>.</param>
/// <param name="b">The blue component value of this <see cref="Color"/>.</param> /// <param name="b">The blue component value of this <see cref="Color"/>.</param>
public Color(byte a, double r, double g, double b) public Color(byte a, float r, float g, float b)
: this(a.GetPercentageFromByteValue(), r, g, b) : this(a.GetPercentageFromByteValue(), r, g, b)
{ } { }
@ -161,7 +161,7 @@ namespace RGB.NET.Core
/// <param name="r">The red component value of this <see cref="Color"/>.</param> /// <param name="r">The red component value of this <see cref="Color"/>.</param>
/// <param name="g">The green component value of this <see cref="Color"/>.</param> /// <param name="g">The green component value of this <see cref="Color"/>.</param>
/// <param name="b">The blue component value of this <see cref="Color"/>.</param> /// <param name="b">The blue component value of this <see cref="Color"/>.</param>
public Color(double a, double r, double g, double b) public Color(float a, float r, float g, float b)
{ {
A = a.Clamp(0, 1); A = a.Clamp(0, 1);
R = r.Clamp(0, 1); R = r.Clamp(0, 1);
@ -269,14 +269,14 @@ namespace RGB.NET.Core
/// </summary> /// </summary>
/// <param name="components">The <see cref="ValueTuple"/> containing the components.</param> /// <param name="components">The <see cref="ValueTuple"/> containing the components.</param>
/// <returns>The color.</returns> /// <returns>The color.</returns>
public static implicit operator Color((double r, double g, double b) components) => new(components.r, components.g, components.b); public static implicit operator Color((float r, float g, float b) components) => new(components.r, components.g, components.b);
/// <summary> /// <summary>
/// Converts a <see cref="ValueTuple"/> of ARGB-components to a <see cref="Color"/>. /// Converts a <see cref="ValueTuple"/> of ARGB-components to a <see cref="Color"/>.
/// </summary> /// </summary>
/// <param name="components">The <see cref="ValueTuple"/> containing the components.</param> /// <param name="components">The <see cref="ValueTuple"/> containing the components.</param>
/// <returns>The color.</returns> /// <returns>The color.</returns>
public static implicit operator Color((double a, double r, double g, double b) components) => new(components.a, components.r, components.g, components.b); public static implicit operator Color((float a, float r, float g, float b) components) => new(components.a, components.r, components.g, components.b);
#endregion #endregion
} }

View File

@ -13,21 +13,21 @@ namespace RGB.NET.Core
/// </summary> /// </summary>
/// <param name="color"></param> /// <param name="color"></param>
/// <returns></returns> /// <returns></returns>
public static double GetHue(this Color color) => color.GetHSV().hue; public static float GetHue(this Color color) => color.GetHSV().hue;
/// <summary> /// <summary>
/// Gets the saturation component value (HSV-color space) of this <see cref="Color"/> in the range [0..1]. /// Gets the saturation component value (HSV-color space) of this <see cref="Color"/> in the range [0..1].
/// </summary> /// </summary>
/// <param name="color"></param> /// <param name="color"></param>
/// <returns></returns> /// <returns></returns>
public static double GetSaturation(this Color color) => color.GetHSV().saturation; public static float GetSaturation(this Color color) => color.GetHSV().saturation;
/// <summary> /// <summary>
/// Gets the value component value (HSV-color space) of this <see cref="Color"/> in the range [0..1]. /// Gets the value component value (HSV-color space) of this <see cref="Color"/> in the range [0..1].
/// </summary> /// </summary>
/// <param name="color"></param> /// <param name="color"></param>
/// <returns></returns> /// <returns></returns>
public static double GetValue(this Color color) => color.GetHSV().value; public static float GetValue(this Color color) => color.GetHSV().value;
/// <summary> /// <summary>
/// Gets the hue, saturation and value component values (HSV-color space) of this <see cref="Color"/>. /// Gets the hue, saturation and value component values (HSV-color space) of this <see cref="Color"/>.
@ -37,7 +37,7 @@ namespace RGB.NET.Core
/// </summary> /// </summary>
/// <param name="color"></param> /// <param name="color"></param>
/// <returns></returns> /// <returns></returns>
public static (double hue, double saturation, double value) GetHSV(this Color color) public static (float hue, float saturation, float value) GetHSV(this Color color)
=> CaclulateHSVFromRGB(color.R, color.G, color.B); => CaclulateHSVFromRGB(color.R, color.G, color.B);
#endregion #endregion
@ -51,9 +51,9 @@ namespace RGB.NET.Core
/// <param name="saturation">The saturation value to add.</param> /// <param name="saturation">The saturation value to add.</param>
/// <param name="value">The value value to add.</param> /// <param name="value">The value value to add.</param>
/// <returns>The new color after the modification.</returns> /// <returns>The new color after the modification.</returns>
public static Color AddHSV(this Color color, double hue = 0, double saturation = 0, double value = 0) public static Color AddHSV(this Color color, float hue = 0, float saturation = 0, float value = 0)
{ {
(double cHue, double cSaturation, double cValue) = color.GetHSV(); (float cHue, float cSaturation, float cValue) = color.GetHSV();
return Create(color.A, cHue + hue, cSaturation + saturation, cValue + value); return Create(color.A, cHue + hue, cSaturation + saturation, cValue + value);
} }
@ -64,9 +64,9 @@ namespace RGB.NET.Core
/// <param name="saturation">The saturation value to subtract.</param> /// <param name="saturation">The saturation value to subtract.</param>
/// <param name="value">The value value to subtract.</param> /// <param name="value">The value value to subtract.</param>
/// <returns>The new color after the modification.</returns> /// <returns>The new color after the modification.</returns>
public static Color SubtractHSV(this Color color, double hue = 0, double saturation = 0, double value = 0) public static Color SubtractHSV(this Color color, float hue = 0, float saturation = 0, float value = 0)
{ {
(double cHue, double cSaturation, double cValue) = color.GetHSV(); (float cHue, float cSaturation, float cValue) = color.GetHSV();
return Create(color.A, cHue - hue, cSaturation - saturation, cValue - value); return Create(color.A, cHue - hue, cSaturation - saturation, cValue - value);
} }
@ -77,9 +77,9 @@ namespace RGB.NET.Core
/// <param name="saturation">The saturation value to multiply.</param> /// <param name="saturation">The saturation value to multiply.</param>
/// <param name="value">The value value to multiply.</param> /// <param name="value">The value value to multiply.</param>
/// <returns>The new color after the modification.</returns> /// <returns>The new color after the modification.</returns>
public static Color MultiplyHSV(this Color color, double hue = 1, double saturation = 1, double value = 1) public static Color MultiplyHSV(this Color color, float hue = 1, float saturation = 1, float value = 1)
{ {
(double cHue, double cSaturation, double cValue) = color.GetHSV(); (float cHue, float cSaturation, float cValue) = color.GetHSV();
return Create(color.A, cHue * hue, cSaturation * saturation, cValue * value); return Create(color.A, cHue * hue, cSaturation * saturation, cValue * value);
} }
@ -90,9 +90,9 @@ namespace RGB.NET.Core
/// <param name="saturation">The saturation value to divide.</param> /// <param name="saturation">The saturation value to divide.</param>
/// <param name="value">The value value to divide.</param> /// <param name="value">The value value to divide.</param>
/// <returns>The new color after the modification.</returns> /// <returns>The new color after the modification.</returns>
public static Color DivideHSV(this Color color, double hue = 1, double saturation = 1, double value = 1) public static Color DivideHSV(this Color color, float hue = 1, float saturation = 1, float value = 1)
{ {
(double cHue, double cSaturation, double cValue) = color.GetHSV(); (float cHue, float cSaturation, float cValue) = color.GetHSV();
return Create(color.A, cHue / hue, cSaturation / saturation, cValue / value); return Create(color.A, cHue / hue, cSaturation / saturation, cValue / value);
} }
@ -103,9 +103,9 @@ namespace RGB.NET.Core
/// <param name="saturation">The saturation value to set.</param> /// <param name="saturation">The saturation value to set.</param>
/// <param name="value">The value value to set.</param> /// <param name="value">The value value to set.</param>
/// <returns>The new color after the modification.</returns> /// <returns>The new color after the modification.</returns>
public static Color SetHSV(this Color color, double? hue = null, double? saturation = null, double? value = null) public static Color SetHSV(this Color color, float? hue = null, float? saturation = null, float? value = null)
{ {
(double cHue, double cSaturation, double cValue) = color.GetHSV(); (float cHue, float cSaturation, float cValue) = color.GetHSV();
return Create(color.A, hue ?? cHue, saturation ?? cSaturation, value ?? cValue); return Create(color.A, hue ?? cHue, saturation ?? cSaturation, value ?? cValue);
} }
@ -120,8 +120,8 @@ namespace RGB.NET.Core
/// <param name="saturation">The saturation component value of this <see cref="Color"/>.</param> /// <param name="saturation">The saturation component value of this <see cref="Color"/>.</param>
/// <param name="value">The value component value of this <see cref="Color"/>.</param> /// <param name="value">The value component value of this <see cref="Color"/>.</param>
/// <returns>The color created from the values.</returns> /// <returns>The color created from the values.</returns>
public static Color Create(double hue, double saturation, double value) public static Color Create(float hue, float saturation, float value)
=> Create(1.0, hue, saturation, value); => Create(1.0f, hue, saturation, value);
/// <summary> /// <summary>
/// Creates a new instance of the <see cref="T:RGB.NET.Core.Color" /> struct using AHSV-Values. /// Creates a new instance of the <see cref="T:RGB.NET.Core.Color" /> struct using AHSV-Values.
@ -131,8 +131,8 @@ namespace RGB.NET.Core
/// <param name="saturation">The saturation component value of this <see cref="Color"/>.</param> /// <param name="saturation">The saturation component value of this <see cref="Color"/>.</param>
/// <param name="value">The value component value of this <see cref="Color"/>.</param> /// <param name="value">The value component value of this <see cref="Color"/>.</param>
/// <returns>The color created from the values.</returns> /// <returns>The color created from the values.</returns>
public static Color Create(byte a, double hue, double saturation, double value) public static Color Create(byte a, float hue, float saturation, float value)
=> Create((double)a / byte.MaxValue, hue, saturation, value); => Create((float)a / byte.MaxValue, hue, saturation, value);
/// <summary> /// <summary>
/// Creates a new instance of the <see cref="T:RGB.NET.Core.Color" /> struct using AHSV-Values. /// Creates a new instance of the <see cref="T:RGB.NET.Core.Color" /> struct using AHSV-Values.
@ -142,8 +142,8 @@ namespace RGB.NET.Core
/// <param name="saturation">The saturation component value of this <see cref="Color"/>.</param> /// <param name="saturation">The saturation component value of this <see cref="Color"/>.</param>
/// <param name="value">The value component value of this <see cref="Color"/>.</param> /// <param name="value">The value component value of this <see cref="Color"/>.</param>
/// <returns>The color created from the values.</returns> /// <returns>The color created from the values.</returns>
public static Color Create(int a, double hue, double saturation, double value) public static Color Create(int a, float hue, float saturation, float value)
=> Create((double)a / byte.MaxValue, hue, saturation, value); => Create((float)a / byte.MaxValue, hue, saturation, value);
/// <summary> /// <summary>
/// Creates a new instance of the <see cref="T:RGB.NET.Core.Color" /> struct using AHSV-Values. /// Creates a new instance of the <see cref="T:RGB.NET.Core.Color" /> struct using AHSV-Values.
@ -153,9 +153,9 @@ namespace RGB.NET.Core
/// <param name="saturation">The saturation component value of this <see cref="Color"/>.</param> /// <param name="saturation">The saturation component value of this <see cref="Color"/>.</param>
/// <param name="value">The value component value of this <see cref="Color"/>.</param> /// <param name="value">The value component value of this <see cref="Color"/>.</param>
/// <returns>The color created from the values.</returns> /// <returns>The color created from the values.</returns>
public static Color Create(double a, double hue, double saturation, double value) public static Color Create(float a, float hue, float saturation, float value)
{ {
(double r, double g, double b) = CalculateRGBFromHSV(hue, saturation, value); (float r, float g, float b) = CalculateRGBFromHSV(hue, saturation, value);
return new Color(a, r, g, b); return new Color(a, r, g, b);
} }
@ -163,33 +163,33 @@ namespace RGB.NET.Core
#region Helper #region Helper
private static (double h, double s, double v) CaclulateHSVFromRGB(double r, double g, double b) private static (float h, float s, float v) CaclulateHSVFromRGB(float r, float g, float b)
{ {
if (r.EqualsInTolerance(g) && g.EqualsInTolerance(b)) return (0, 0, r); if (r.EqualsInTolerance(g) && g.EqualsInTolerance(b)) return (0, 0, r);
double min = Math.Min(Math.Min(r, g), b); float min = Math.Min(Math.Min(r, g), b);
double max = Math.Max(Math.Max(r, g), b); float max = Math.Max(Math.Max(r, g), b);
double hue; float hue;
if (max.EqualsInTolerance(min)) if (max.EqualsInTolerance(min))
hue = 0; hue = 0;
else if (max.EqualsInTolerance(r)) // r is max else if (max.EqualsInTolerance(r)) // r is max
hue = (g - b) / (max - min); hue = (g - b) / (max - min);
else if (max.EqualsInTolerance(g)) // g is max else if (max.EqualsInTolerance(g)) // g is max
hue = 2.0 + ((b - r) / (max - min)); hue = 2.0f + ((b - r) / (max - min));
else // b is max else // b is max
hue = 4.0 + ((r - g) / (max - min)); hue = 4.0f + ((r - g) / (max - min));
hue *= 60.0; hue *= 60.0f;
hue = hue.Wrap(0, 360); hue = hue.Wrap(0, 360);
double saturation = max.EqualsInTolerance(0) ? 0 : 1.0 - (min / max); float saturation = max.EqualsInTolerance(0) ? 0 : 1.0f - (min / max);
double value = Math.Max(r, Math.Max(g, b)); float value = Math.Max(r, Math.Max(g, b));
return (hue, saturation, value); return (hue, saturation, value);
} }
private static (double r, double g, double b) CalculateRGBFromHSV(double h, double s, double v) private static (float r, float g, float b) CalculateRGBFromHSV(float h, float s, float v)
{ {
h = h.Wrap(0, 360); h = h.Wrap(0, 360);
s = s.Clamp(0, 1); s = s.Clamp(0, 1);
@ -198,12 +198,12 @@ namespace RGB.NET.Core
if (s <= 0.0) if (s <= 0.0)
return (v, v, v); return (v, v, v);
double hh = h / 60.0; float hh = h / 60.0f;
int i = (int)hh; int i = (int)hh;
double ff = hh - i; float ff = hh - i;
double p = v * (1.0 - s); float p = v * (1.0f - s);
double q = v * (1.0 - (s * ff)); float q = v * (1.0f - (s * ff));
double t = v * (1.0 - (s * (1.0 - ff))); float t = v * (1.0f - (s * (1.0f - ff)));
return i switch return i switch
{ {

View File

@ -49,7 +49,7 @@ namespace RGB.NET.Core
/// </summary> /// </summary>
/// <param name="color"></param> /// <param name="color"></param>
/// <returns></returns> /// <returns></returns>
public static (double a, double r, double g, double b) GetRGB(this Color color) public static (float a, float r, float g, float b) GetRGB(this Color color)
=> (color.A, color.R, color.G, color.B); => (color.A, color.R, color.G, color.B);
#endregion #endregion
@ -75,7 +75,7 @@ namespace RGB.NET.Core
/// <param name="g">The green value to add.</param> /// <param name="g">The green value to add.</param>
/// <param name="b">The blue value to add.</param> /// <param name="b">The blue value to add.</param>
/// <returns>The new color after the modification.</returns> /// <returns>The new color after the modification.</returns>
public static Color AddRGB(this Color color, double r = 0, double g = 0, double b = 0) public static Color AddRGB(this Color color, float r = 0, float g = 0, float b = 0)
=> new(color.A, color.R + r, color.G + g, color.B + b); => new(color.A, color.R + r, color.G + g, color.B + b);
/// <summary> /// <summary>
@ -91,7 +91,7 @@ namespace RGB.NET.Core
/// </summary> /// </summary>
/// <param name="a">The alpha value to add.</param> /// <param name="a">The alpha value to add.</param>
/// <returns>The new color after the modification.</returns> /// <returns>The new color after the modification.</returns>
public static Color AddA(this Color color, double a) public static Color AddA(this Color color, float a)
=> new(color.A + a, color.R, color.G, color.B); => new(color.A + a, color.R, color.G, color.B);
#endregion #endregion
@ -115,7 +115,7 @@ namespace RGB.NET.Core
/// <param name="g">The green value to subtract.</param> /// <param name="g">The green value to subtract.</param>
/// <param name="b">The blue value to subtract.</param> /// <param name="b">The blue value to subtract.</param>
/// <returns>The new color after the modification.</returns> /// <returns>The new color after the modification.</returns>
public static Color SubtractRGB(this Color color, double r = 0, double g = 0, double b = 0) public static Color SubtractRGB(this Color color, float r = 0, float g = 0, float b = 0)
=> new(color.A, color.R - r, color.G - g, color.B - b); => new(color.A, color.R - r, color.G - g, color.B - b);
/// <summary> /// <summary>
@ -131,7 +131,7 @@ namespace RGB.NET.Core
/// </summary> /// </summary>
/// <param name="a">The alpha value to subtract.</param> /// <param name="a">The alpha value to subtract.</param>
/// <returns>The new color after the modification.</returns> /// <returns>The new color after the modification.</returns>
public static Color SubtractA(this Color color, double aPercent) public static Color SubtractA(this Color color, float aPercent)
=> new(color.A - aPercent, color.R, color.G, color.B); => new(color.A - aPercent, color.R, color.G, color.B);
#endregion #endregion
@ -145,7 +145,7 @@ namespace RGB.NET.Core
/// <param name="g">The green value to multiply.</param> /// <param name="g">The green value to multiply.</param>
/// <param name="b">The blue value to multiply.</param> /// <param name="b">The blue value to multiply.</param>
/// <returns>The new color after the modification.</returns> /// <returns>The new color after the modification.</returns>
public static Color MultiplyRGB(this Color color, double r = 1, double g = 1, double b = 1) public static Color MultiplyRGB(this Color color, float r = 1, float g = 1, float b = 1)
=> new(color.A, color.R * r, color.G * g, color.B * b); => new(color.A, color.R * r, color.G * g, color.B * b);
/// <summary> /// <summary>
@ -153,7 +153,7 @@ namespace RGB.NET.Core
/// </summary> /// </summary>
/// <param name="a">The alpha value to multiply.</param> /// <param name="a">The alpha value to multiply.</param>
/// <returns>The new color after the modification.</returns> /// <returns>The new color after the modification.</returns>
public static Color MultiplyA(this Color color, double a) public static Color MultiplyA(this Color color, float a)
=> new(color.A * a, color.R, color.G, color.B); => new(color.A * a, color.R, color.G, color.B);
#endregion #endregion
@ -167,7 +167,7 @@ namespace RGB.NET.Core
/// <param name="g">The green value to divide.</param> /// <param name="g">The green value to divide.</param>
/// <param name="b">The blue value to divide.</param> /// <param name="b">The blue value to divide.</param>
/// <returns>The new color after the modification.</returns> /// <returns>The new color after the modification.</returns>
public static Color DivideRGB(this Color color, double r = 1, double g = 1, double b = 1) public static Color DivideRGB(this Color color, float r = 1, float g = 1, float b = 1)
=> new(color.A, color.R / r, color.G / g, color.B / b); => new(color.A, color.R / r, color.G / g, color.B / b);
/// <summary> /// <summary>
@ -175,7 +175,7 @@ namespace RGB.NET.Core
/// </summary> /// </summary>
/// <param name="a">The alpha value to divide.</param> /// <param name="a">The alpha value to divide.</param>
/// <returns>The new color after the modification.</returns> /// <returns>The new color after the modification.</returns>
public static Color DivideA(this Color color, double a) public static Color DivideA(this Color color, float a)
=> new(color.A / a, color.R, color.G, color.B); => new(color.A / a, color.R, color.G, color.B);
#endregion #endregion
@ -209,7 +209,7 @@ namespace RGB.NET.Core
/// <param name="g">The green value to set.</param> /// <param name="g">The green value to set.</param>
/// <param name="b">The blue value to set.</param> /// <param name="b">The blue value to set.</param>
/// <returns>The new color after the modification.</returns> /// <returns>The new color after the modification.</returns>
public static Color SetRGB(this Color color, double? r = null, double? g = null, double? b = null) public static Color SetRGB(this Color color, float? r = null, float? g = null, float? b = null)
=> new(color.A, r ?? color.R, g ?? color.G, b ?? color.B); => new(color.A, r ?? color.R, g ?? color.G, b ?? color.B);
/// <summary> /// <summary>
@ -224,7 +224,7 @@ namespace RGB.NET.Core
/// </summary> /// </summary>
/// <param name="a">The alpha value to set.</param> /// <param name="a">The alpha value to set.</param>
/// <returns>The new color after the modification.</returns> /// <returns>The new color after the modification.</returns>
public static Color SetA(this Color color, double a) => new(a, color.R, color.G, color.B); public static Color SetA(this Color color, float a) => new(a, color.R, color.G, color.B);
#endregion #endregion

View File

@ -4,16 +4,16 @@ using System.Runtime.CompilerServices;
namespace RGB.NET.Core namespace RGB.NET.Core
{ {
/// <summary> /// <summary>
/// Offers some extensions and helper-methods for the work with doubles /// Offers some extensions and helper-methods for the work with floats
/// </summary> /// </summary>
public static class DoubleExtensions public static class FloatExtensions
{ {
#region Constants #region Constants
/// <summary> /// <summary>
/// Defines the precision RGB.NET processes floating point comparisons in. /// Defines the precision RGB.NET processes floating point comparisons in.
/// </summary> /// </summary>
public const double TOLERANCE = 1E-10; public const float TOLERANCE = 1E-10f;
#endregion #endregion
@ -26,7 +26,7 @@ namespace RGB.NET.Core
/// <param name="value2">The first value to compare.</param> /// <param name="value2">The first value to compare.</param>
/// <returns><c>true</c> if the difference is smaller than the <see cref="TOLERANCE"/>; otherwise, <c>false</c>.</returns> /// <returns><c>true</c> if the difference is smaller than the <see cref="TOLERANCE"/>; otherwise, <c>false</c>.</returns>
[MethodImpl(MethodImplOptions.AggressiveInlining)] [MethodImpl(MethodImplOptions.AggressiveInlining)]
public static bool EqualsInTolerance(this double value1, double value2) => Math.Abs(value1 - value2) < TOLERANCE; public static bool EqualsInTolerance(this float value1, float value2) => Math.Abs(value1 - value2) < TOLERANCE;
/// <summary> /// <summary>
/// Clamps the provided value to be bigger or equal min and smaller or equal max. /// Clamps the provided value to be bigger or equal min and smaller or equal max.
@ -36,7 +36,7 @@ namespace RGB.NET.Core
/// <param name="max">The higher value of the range the value is clamped to.</param> /// <param name="max">The higher value of the range the value is clamped to.</param>
/// <returns>The clamped value.</returns> /// <returns>The clamped value.</returns>
[MethodImpl(MethodImplOptions.AggressiveInlining)] [MethodImpl(MethodImplOptions.AggressiveInlining)]
public static double Clamp(this double value, double min, double max) public static float Clamp(this float value, float min, float max)
{ {
// ReSharper disable ConvertIfStatementToReturnStatement - I'm not sure why, but inlining this statement reduces performance by ~10% // ReSharper disable ConvertIfStatementToReturnStatement - I'm not sure why, but inlining this statement reduces performance by ~10%
if (value < min) return min; if (value < min) return min;
@ -70,9 +70,9 @@ namespace RGB.NET.Core
/// <param name="max">The higher value of the range the value is wrapped into.</param> /// <param name="max">The higher value of the range the value is wrapped into.</param>
/// <returns>The wrapped value.</returns> /// <returns>The wrapped value.</returns>
[MethodImpl(MethodImplOptions.AggressiveInlining)] [MethodImpl(MethodImplOptions.AggressiveInlining)]
public static double Wrap(this double value, double min, double max) public static float Wrap(this float value, float min, float max)
{ {
double range = max - min; float range = max - min;
while (value >= max) while (value >= max)
value -= range; value -= range;
@ -84,17 +84,17 @@ namespace RGB.NET.Core
} }
[MethodImpl(MethodImplOptions.AggressiveInlining)] [MethodImpl(MethodImplOptions.AggressiveInlining)]
public static byte GetByteValueFromPercentage(this double percentage) public static byte GetByteValueFromPercentage(this float percentage)
{ {
if (double.IsNaN(percentage)) return 0; if (float.IsNaN(percentage)) return 0;
percentage = percentage.Clamp(0, 1.0); percentage = percentage.Clamp(0, 1.0f);
return (byte)(percentage >= 1.0 ? 255 : percentage * 256.0); return (byte)(percentage >= 1.0 ? 255 : percentage * 256.0);
} }
[MethodImpl(MethodImplOptions.AggressiveInlining)] [MethodImpl(MethodImplOptions.AggressiveInlining)]
public static double GetPercentageFromByteValue(this byte value) public static float GetPercentageFromByteValue(this byte value)
=> ((double)value) / byte.MaxValue; => ((float)value) / byte.MaxValue;
#endregion #endregion
} }

View File

@ -13,7 +13,7 @@ namespace RGB.NET.Core
/// <param name="x">The x-ammount to move.</param> /// <param name="x">The x-ammount to move.</param>
/// <param name="y">The y-ammount to move.</param> /// <param name="y">The y-ammount to move.</param>
/// <returns>The new location of the point.</returns> /// <returns>The new location of the point.</returns>
public static Point Translate(this Point point, double x = 0, double y = 0) => new(point.X + x, point.Y + y); public static Point Translate(this Point point, float x = 0, float y = 0) => new(point.X + x, point.Y + y);
/// <summary> /// <summary>
/// Rotates the specified <see cref="Point"/> by the given amuont around the given origin. /// Rotates the specified <see cref="Point"/> by the given amuont around the given origin.
@ -24,8 +24,8 @@ namespace RGB.NET.Core
/// <returns>The new location of the point.</returns> /// <returns>The new location of the point.</returns>
public static Point Rotate(this Point point, Rotation rotation, Point origin = new()) public static Point Rotate(this Point point, Rotation rotation, Point origin = new())
{ {
double sin = Math.Sin(rotation.Radians); float sin = MathF.Sin(rotation.Radians);
double cos = Math.Cos(rotation.Radians); float cos = MathF.Cos(rotation.Radians);
point = new Point(point.X - origin.X, point.Y - origin.Y); point = new Point(point.X - origin.X, point.Y - origin.Y);
point = new Point((point.X * cos) - (point.Y * sin), (point.X * sin) + (point.Y * cos)); point = new Point((point.X * cos) - (point.Y * sin), (point.X * sin) + (point.Y * cos));

View File

@ -20,7 +20,7 @@ namespace RGB.NET.Core
/// <param name="rect">The rectangle to modify.</param> /// <param name="rect">The rectangle to modify.</param>
/// <param name="x">The new x-location of the rectangle.</param> /// <param name="x">The new x-location of the rectangle.</param>
/// <returns>The modified <see cref="Rectangle"/>.</returns> /// <returns>The modified <see cref="Rectangle"/>.</returns>
public static Rectangle SetX(this Rectangle rect, double x) => new(new Point(x, rect.Location.Y), rect.Size); public static Rectangle SetX(this Rectangle rect, float x) => new(new Point(x, rect.Location.Y), rect.Size);
/// <summary> /// <summary>
/// Sets the <see cref="Point.Y"/> of the <see cref="Rectangle.Location"/> of the given rectangle. /// Sets the <see cref="Point.Y"/> of the <see cref="Rectangle.Location"/> of the given rectangle.
@ -28,7 +28,7 @@ namespace RGB.NET.Core
/// <param name="rect">The rectangle to modify.</param> /// <param name="rect">The rectangle to modify.</param>
/// <param name="y">The new y-location of the rectangle.</param> /// <param name="y">The new y-location of the rectangle.</param>
/// <returns>The modified <see cref="Rectangle"/>.</returns> /// <returns>The modified <see cref="Rectangle"/>.</returns>
public static Rectangle SetY(this Rectangle rect, double y) => new(new Point(rect.Location.X, y), rect.Size); public static Rectangle SetY(this Rectangle rect, float y) => new(new Point(rect.Location.X, y), rect.Size);
/// <summary> /// <summary>
/// Sets the <see cref="Rectangle.Size"/> of the given rectangle. /// Sets the <see cref="Rectangle.Size"/> of the given rectangle.
@ -44,7 +44,7 @@ namespace RGB.NET.Core
/// <param name="rect">The rectangle to modify.</param> /// <param name="rect">The rectangle to modify.</param>
/// <param name="width">The new width of the rectangle.</param> /// <param name="width">The new width of the rectangle.</param>
/// <returns>The modified <see cref="Rectangle"/>.</returns> /// <returns>The modified <see cref="Rectangle"/>.</returns>
public static Rectangle SetWidth(this Rectangle rect, double width) => new(rect.Location, new Size(width, rect.Size.Height)); public static Rectangle SetWidth(this Rectangle rect, float width) => new(rect.Location, new Size(width, rect.Size.Height));
/// <summary> /// <summary>
/// Sets the <see cref="Size.Height"/> of the <see cref="Rectangle.Size"/> of the given rectangle. /// Sets the <see cref="Size.Height"/> of the <see cref="Rectangle.Size"/> of the given rectangle.
@ -52,14 +52,14 @@ namespace RGB.NET.Core
/// <param name="rect">The rectangle to modify.</param> /// <param name="rect">The rectangle to modify.</param>
/// <param name="height">The new height of the rectangle.</param> /// <param name="height">The new height of the rectangle.</param>
/// <returns>The modified <see cref="Rectangle"/>.</returns> /// <returns>The modified <see cref="Rectangle"/>.</returns>
public static Rectangle SetHeight(this Rectangle rect, double height) => new(rect.Location, new Size(rect.Size.Width, height)); public static Rectangle SetHeight(this Rectangle rect, float height) => new(rect.Location, new Size(rect.Size.Width, height));
/// <summary> /// <summary>
/// Calculates the percentage of intersection of a rectangle. /// Calculates the percentage of intersection of a rectangle.
/// </summary> /// </summary>
/// <param name="intersectingRect">The intersecting rectangle.</param> /// <param name="intersectingRect">The intersecting rectangle.</param>
/// <returns>The percentage of intersection.</returns> /// <returns>The percentage of intersection.</returns>
public static double CalculateIntersectPercentage(this Rectangle rect, in Rectangle intersectingRect) public static float CalculateIntersectPercentage(this Rectangle rect, in Rectangle intersectingRect)
{ {
if (rect.IsEmpty || intersectingRect.IsEmpty) return 0; if (rect.IsEmpty || intersectingRect.IsEmpty) return 0;
@ -74,11 +74,11 @@ namespace RGB.NET.Core
/// <returns>A new <see cref="Rectangle"/> representing the intersection this <see cref="Rectangle"/> and the one provided as parameter.</returns> /// <returns>A new <see cref="Rectangle"/> representing the intersection this <see cref="Rectangle"/> and the one provided as parameter.</returns>
public static Rectangle CalculateIntersection(this Rectangle rect, in Rectangle intersectingRectangle) public static Rectangle CalculateIntersection(this Rectangle rect, in Rectangle intersectingRectangle)
{ {
double x1 = Math.Max(rect.Location.X, intersectingRectangle.Location.X); float x1 = Math.Max(rect.Location.X, intersectingRectangle.Location.X);
double x2 = Math.Min(rect.Location.X + rect.Size.Width, intersectingRectangle.Location.X + intersectingRectangle.Size.Width); float x2 = Math.Min(rect.Location.X + rect.Size.Width, intersectingRectangle.Location.X + intersectingRectangle.Size.Width);
double y1 = Math.Max(rect.Location.Y, intersectingRectangle.Location.Y); float y1 = Math.Max(rect.Location.Y, intersectingRectangle.Location.Y);
double y2 = Math.Min(rect.Location.Y + rect.Size.Height, intersectingRectangle.Location.Y + intersectingRectangle.Size.Height); float y2 = Math.Min(rect.Location.Y + rect.Size.Height, intersectingRectangle.Location.Y + intersectingRectangle.Size.Height);
if ((x2 >= x1) && (y2 >= y1)) if ((x2 >= x1) && (y2 >= y1))
return new Rectangle(x1, y1, x2 - x1, y2 - y1); return new Rectangle(x1, y1, x2 - x1, y2 - y1);
@ -99,7 +99,7 @@ namespace RGB.NET.Core
/// <param name="x">The X-location to test.</param> /// <param name="x">The X-location to test.</param>
/// <param name="y">The Y-location to test.</param> /// <param name="y">The Y-location to test.</param>
/// <returns><c>true</c> if the rectangle contains the given coordinates; otherwise <c>false</c>.</returns> /// <returns><c>true</c> if the rectangle contains the given coordinates; otherwise <c>false</c>.</returns>
public static bool Contains(this Rectangle rect, double x, double y) => (rect.Location.X <= x) && (x < (rect.Location.X + rect.Size.Width)) public static bool Contains(this Rectangle rect, float x, float y) => (rect.Location.X <= x) && (x < (rect.Location.X + rect.Size.Width))
&& (rect.Location.Y <= y) && (y < (rect.Location.Y + rect.Size.Height)); && (rect.Location.Y <= y) && (y < (rect.Location.Y + rect.Size.Height));
/// <summary> /// <summary>
@ -125,7 +125,7 @@ namespace RGB.NET.Core
/// <param name="x">The x-ammount to move.</param> /// <param name="x">The x-ammount to move.</param>
/// <param name="y">The y-ammount to move.</param> /// <param name="y">The y-ammount to move.</param>
/// <returns>The moved rectangle.</returns> /// <returns>The moved rectangle.</returns>
public static Rectangle Translate(this Rectangle rect, double x = 0, double y = 0) => new(rect.Location.Translate(x, y), rect.Size); public static Rectangle Translate(this Rectangle rect, float x = 0, float y = 0) => new(rect.Location.Translate(x, y), rect.Size);
/// <summary> /// <summary>
/// Rotates the specified <see cref="Rectangle"/> by the given amuont around the given origin. /// Rotates the specified <see cref="Rectangle"/> by the given amuont around the given origin.
@ -150,8 +150,8 @@ namespace RGB.NET.Core
new(rect.Location.X, rect.Location.Y + rect.Size.Height), // bottom right new(rect.Location.X, rect.Location.Y + rect.Size.Height), // bottom right
}; };
double sin = Math.Sin(rotation.Radians); float sin = MathF.Sin(rotation.Radians);
double cos = Math.Cos(rotation.Radians); float cos = MathF.Cos(rotation.Radians);
for (int i = 0; i < points.Length; i++) for (int i = 0; i < points.Length; i++)
{ {

View File

@ -16,7 +16,7 @@ namespace RGB.NET.Core
/// <summary> /// <summary>
/// Gets a [NaN,NaN]-Point. /// Gets a [NaN,NaN]-Point.
/// </summary> /// </summary>
public static Point Invalid => new(double.NaN, double.NaN); public static Point Invalid => new(float.NaN, float.NaN);
#endregion #endregion
@ -25,12 +25,12 @@ namespace RGB.NET.Core
/// <summary> /// <summary>
/// Gets the X-position of this <see cref="Point"/>. /// Gets the X-position of this <see cref="Point"/>.
/// </summary> /// </summary>
public double X { get; } public float X { get; }
/// <summary> /// <summary>
/// Gets the Y-position of this <see cref="Point"/>. /// Gets the Y-position of this <see cref="Point"/>.
/// </summary> /// </summary>
public double Y { get; } public float Y { get; }
#endregion #endregion
@ -41,7 +41,7 @@ namespace RGB.NET.Core
/// </summary> /// </summary>
/// <param name="x">The value used for the X-position.</param> /// <param name="x">The value used for the X-position.</param>
/// <param name="y">The value used for the Y-position.</param> /// <param name="y">The value used for the Y-position.</param>
public Point(double x, double y) public Point(float x, float y)
{ {
this.X = x; this.X = x;
this.Y = y; this.Y = y;
@ -67,8 +67,8 @@ namespace RGB.NET.Core
if (!(obj is Point)) return false; if (!(obj is Point)) return false;
Point comparePoint = (Point)obj; Point comparePoint = (Point)obj;
return ((double.IsNaN(X) && double.IsNaN(comparePoint.X)) || X.EqualsInTolerance(comparePoint.X)) return ((float.IsNaN(X) && float.IsNaN(comparePoint.X)) || X.EqualsInTolerance(comparePoint.X))
&& ((double.IsNaN(Y) && double.IsNaN(comparePoint.Y)) || Y.EqualsInTolerance(comparePoint.Y)); && ((float.IsNaN(Y) && float.IsNaN(comparePoint.Y)) || Y.EqualsInTolerance(comparePoint.Y));
} }
/// <summary> /// <summary>

View File

@ -35,7 +35,7 @@ namespace RGB.NET.Core
/// Gets a bool indicating if both, the width and the height of the rectangle is greater than zero. /// Gets a bool indicating if both, the width and the height of the rectangle is greater than zero.
/// <c>True</c> if the rectangle has a width or a height of zero; otherwise, <c>false</c>. /// <c>True</c> if the rectangle has a width or a height of zero; otherwise, <c>false</c>.
/// </summary> /// </summary>
public bool IsEmpty => (Size.Width <= DoubleExtensions.TOLERANCE) || (Size.Height <= DoubleExtensions.TOLERANCE); public bool IsEmpty => (Size.Width <= FloatExtensions.TOLERANCE) || (Size.Height <= FloatExtensions.TOLERANCE);
#endregion #endregion
@ -49,7 +49,7 @@ namespace RGB.NET.Core
/// <param name="y">The y-value of the <see cref="T:RGB.NET.Core.Location" />-position of this <see cref="T:RGB.NET.Core.Rectangle" />.</param> /// <param name="y">The y-value of the <see cref="T:RGB.NET.Core.Location" />-position of this <see cref="T:RGB.NET.Core.Rectangle" />.</param>
/// <param name="width">The width of the <see cref="T:RGB.NET.Core.Size"/> of this <see cref="T:RGB.NET.Core.Rectangle" />.</param> /// <param name="width">The width of the <see cref="T:RGB.NET.Core.Size"/> of this <see cref="T:RGB.NET.Core.Rectangle" />.</param>
/// <param name="height">The height of the <see cref="T:RGB.NET.Core.Size"/> of this <see cref="T:RGB.NET.Core.Rectangle" />.</param> /// <param name="height">The height of the <see cref="T:RGB.NET.Core.Size"/> of this <see cref="T:RGB.NET.Core.Rectangle" />.</param>
public Rectangle(double x, double y, double width, double height) public Rectangle(float x, float y, float width, float height)
: this(new Point(x, y), new Size(width, height)) : this(new Point(x, y), new Size(width, height))
{ } { }
@ -70,7 +70,7 @@ namespace RGB.NET.Core
this.Location = location; this.Location = location;
this.Size = size; this.Size = size;
Center = new Point(Location.X + (Size.Width / 2.0), Location.Y + (Size.Height / 2.0)); Center = new Point(Location.X + (Size.Width / 2.0f), Location.Y + (Size.Height / 2.0f));
} }
/// <inheritdoc /> /// <inheritdoc />
@ -91,10 +91,10 @@ namespace RGB.NET.Core
public Rectangle(IEnumerable<Rectangle> rectangles) public Rectangle(IEnumerable<Rectangle> rectangles)
{ {
bool hasPoint = false; bool hasPoint = false;
double posX = double.MaxValue; float posX = float.MaxValue;
double posY = double.MaxValue; float posY = float.MaxValue;
double posX2 = double.MinValue; float posX2 = float.MinValue;
double posY2 = double.MinValue; float posY2 = float.MinValue;
foreach (Rectangle rectangle in rectangles) foreach (Rectangle rectangle in rectangles)
{ {
@ -108,7 +108,7 @@ namespace RGB.NET.Core
(Point location, Size size) = hasPoint ? InitializeFromPoints(new Point(posX, posY), new Point(posX2, posY2)) : InitializeFromPoints(new Point(0, 0), new Point(0, 0)); (Point location, Size size) = hasPoint ? InitializeFromPoints(new Point(posX, posY), new Point(posX2, posY2)) : InitializeFromPoints(new Point(0, 0), new Point(0, 0));
Location = location; Location = location;
Size = size; Size = size;
Center = new Point(Location.X + (Size.Width / 2.0), Location.Y + (Size.Height / 2.0)); Center = new Point(Location.X + (Size.Width / 2.0f), Location.Y + (Size.Height / 2.0f));
} }
/// <inheritdoc /> /// <inheritdoc />
@ -131,10 +131,10 @@ namespace RGB.NET.Core
: this() : this()
{ {
bool hasPoint = false; bool hasPoint = false;
double posX = double.MaxValue; float posX = float.MaxValue;
double posY = double.MaxValue; float posY = float.MaxValue;
double posX2 = double.MinValue; float posX2 = float.MinValue;
double posY2 = double.MinValue; float posY2 = float.MinValue;
foreach (Point point in points) foreach (Point point in points)
{ {
@ -149,7 +149,7 @@ namespace RGB.NET.Core
Location = location; Location = location;
Size = size; Size = size;
Center = new Point(Location.X + (Size.Width / 2.0), Location.Y + (Size.Height / 2.0)); Center = new Point(Location.X + (Size.Width / 2.0f), Location.Y + (Size.Height / 2.0f));
} }
#endregion #endregion
@ -158,10 +158,10 @@ namespace RGB.NET.Core
private static (Point location, Size size) InitializeFromPoints(Point point1, Point point2) private static (Point location, Size size) InitializeFromPoints(Point point1, Point point2)
{ {
double posX = Math.Min(point1.X, point2.X); float posX = Math.Min(point1.X, point2.X);
double posY = Math.Min(point1.Y, point2.Y); float posY = Math.Min(point1.Y, point2.Y);
double width = Math.Max(point1.X, point2.X) - posX; float width = Math.Max(point1.X, point2.X) - posX;
double height = Math.Max(point1.Y, point2.Y) - posY; float height = Math.Max(point1.Y, point2.Y) - posY;
return (new Point(posX, posY), new Size(width, height)); return (new Point(posX, posY), new Size(width, height));
} }
@ -225,8 +225,8 @@ namespace RGB.NET.Core
// DarthAffe 20.02.2021: Used for normalization // DarthAffe 20.02.2021: Used for normalization
public static Rectangle operator /(Rectangle rectangle1, Rectangle rectangle2) public static Rectangle operator /(Rectangle rectangle1, Rectangle rectangle2)
{ {
double x = rectangle1.Location.X / (rectangle2.Size.Width - rectangle2.Location.X); float x = rectangle1.Location.X / (rectangle2.Size.Width - rectangle2.Location.X);
double y = rectangle1.Location.Y / (rectangle2.Size.Height - rectangle2.Location.Y); float y = rectangle1.Location.Y / (rectangle2.Size.Height - rectangle2.Location.Y);
Size size = rectangle1.Size / rectangle2.Size; Size size = rectangle1.Size / rectangle2.Size;
return new Rectangle(new Point(x, y), size); return new Rectangle(new Point(x, y), size);
} }

View File

@ -14,9 +14,9 @@ namespace RGB.NET.Core
{ {
#region Constants #region Constants
private const double TWO_PI = Math.PI * 2.0; private const float TWO_PI = MathF.PI * 2.0f;
private const double RADIANS_DEGREES_CONVERSION = 180.0 / Math.PI; private const float RADIANS_DEGREES_CONVERSION = 180.0f / MathF.PI;
private const double DEGREES_RADIANS_CONVERSION = Math.PI / 180.0; private const float DEGREES_RADIANS_CONVERSION = MathF.PI / 180.0f;
#endregion #endregion
@ -25,12 +25,12 @@ namespace RGB.NET.Core
/// <summary> /// <summary>
/// Gets the angle in degrees. /// Gets the angle in degrees.
/// </summary> /// </summary>
public double Degrees { get; } public float Degrees { get; }
/// <summary> /// <summary>
/// Gets the angle in radians. /// Gets the angle in radians.
/// </summary> /// </summary>
public double Radians { get; } public float Radians { get; }
/// <summary> /// <summary>
/// Gets a bool indicating if the rotation is > 0. /// Gets a bool indicating if the rotation is > 0.
@ -45,13 +45,13 @@ namespace RGB.NET.Core
/// Initializes a new instance of the <see cref="Rotation"/> class using the provided values. /// Initializes a new instance of the <see cref="Rotation"/> class using the provided values.
/// </summary> /// </summary>
/// <param name="scale">The rotation in degrees.</param> /// <param name="scale">The rotation in degrees.</param>
public Rotation(double degrees) public Rotation(float degrees)
: this(degrees, degrees * DEGREES_RADIANS_CONVERSION) : this(degrees, degrees * DEGREES_RADIANS_CONVERSION)
{ } { }
private Rotation(double degrees, double radians) private Rotation(float degrees, float radians)
{ {
this.Degrees = degrees % 360.0; this.Degrees = degrees % 360.0f;
this.Radians = radians % TWO_PI; this.Radians = radians % TWO_PI;
} }
@ -64,14 +64,14 @@ namespace RGB.NET.Core
/// </summary> /// </summary>
/// <param name="degrees">The angle in degrees.</param> /// <param name="degrees">The angle in degrees.</param>
/// <returns>The new rotation.</returns> /// <returns>The new rotation.</returns>
public static Rotation FromDegrees(double degrees) => new(degrees); public static Rotation FromDegrees(float degrees) => new(degrees);
/// <summary> /// <summary>
/// Creates a new Rotation out of the given radian-angle. /// Creates a new Rotation out of the given radian-angle.
/// </summary> /// </summary>
/// <param name="degrees">The angle in radians.</param> /// <param name="degrees">The angle in radians.</param>
/// <returns>The new rotation.</returns> /// <returns>The new rotation.</returns>
public static Rotation FromRadians(double radians) => new(radians * RADIANS_DEGREES_CONVERSION, radians); public static Rotation FromRadians(float radians) => new(radians * RADIANS_DEGREES_CONVERSION, radians);
/// <summary> /// <summary>
/// Tests whether the specified <see cref="Rotation" /> is equivalent to this <see cref="Rotation" />. /// Tests whether the specified <see cref="Rotation" /> is equivalent to this <see cref="Rotation" />.
@ -119,7 +119,7 @@ namespace RGB.NET.Core
/// <param name="rotation">The <see cref="Rotation"/>.</param> /// <param name="rotation">The <see cref="Rotation"/>.</param>
/// <param name="value">The value to add.</param> /// <param name="value">The value to add.</param>
/// <returns>A new <see cref="Rotation"/> representing the addition of the <see cref="Rotation"/> and the provided value.</returns> /// <returns>A new <see cref="Rotation"/> representing the addition of the <see cref="Rotation"/> and the provided value.</returns>
public static Rotation operator +(Rotation rotation, double value) => new(rotation.Degrees + value); public static Rotation operator +(Rotation rotation, float value) => new(rotation.Degrees + value);
/// <summary> /// <summary>
/// Returns a new <see cref="Rotation"/> representing the subtraction of the <see cref="Rotation"/> and the provided value. /// Returns a new <see cref="Rotation"/> representing the subtraction of the <see cref="Rotation"/> and the provided value.
@ -127,7 +127,7 @@ namespace RGB.NET.Core
/// <param name="rotation">The <see cref="Rotation"/>.</param> /// <param name="rotation">The <see cref="Rotation"/>.</param>
/// <param name="value">The value to substract.</param> /// <param name="value">The value to substract.</param>
/// <returns>A new <see cref="Rotation"/> representing the subtraction of the <see cref="Rotation"/> and the provided value.</returns> /// <returns>A new <see cref="Rotation"/> representing the subtraction of the <see cref="Rotation"/> and the provided value.</returns>
public static Rotation operator -(Rotation rotation, double value) => new(rotation.Degrees - value); public static Rotation operator -(Rotation rotation, float value) => new(rotation.Degrees - value);
/// <summary> /// <summary>
/// Returns a new <see cref="Rotation"/> representing the multiplication of the <see cref="Rotation"/> and the provided value. /// Returns a new <see cref="Rotation"/> representing the multiplication of the <see cref="Rotation"/> and the provided value.
@ -135,7 +135,7 @@ namespace RGB.NET.Core
/// <param name="rotation">The <see cref="Rotation"/>.</param> /// <param name="rotation">The <see cref="Rotation"/>.</param>
/// <param name="value">The value to multiply with.</param> /// <param name="value">The value to multiply with.</param>
/// <returns>A new <see cref="Rotation"/> representing the multiplication of the <see cref="Rotation"/> and the provided value.</returns> /// <returns>A new <see cref="Rotation"/> representing the multiplication of the <see cref="Rotation"/> and the provided value.</returns>
public static Rotation operator *(Rotation rotation, double value) => new(rotation.Degrees * value); public static Rotation operator *(Rotation rotation, float value) => new(rotation.Degrees * value);
/// <summary> /// <summary>
/// Returns a new <see cref="Rotation"/> representing the division of the <see cref="Rotation"/> and the provided value. /// Returns a new <see cref="Rotation"/> representing the division of the <see cref="Rotation"/> and the provided value.
@ -143,19 +143,19 @@ namespace RGB.NET.Core
/// <param name="rotation">The <see cref="Rotation"/>.</param> /// <param name="rotation">The <see cref="Rotation"/>.</param>
/// <param name="value">The value to device with.</param> /// <param name="value">The value to device with.</param>
/// <returns>A new <see cref="Rotation"/> representing the division of the <see cref="Rotation"/> and the provided value.</returns> /// <returns>A new <see cref="Rotation"/> representing the division of the <see cref="Rotation"/> and the provided value.</returns>
public static Rotation operator /(Rotation rotation, double value) => value.EqualsInTolerance(0) ? new Rotation(0) : new Rotation(rotation.Degrees / value); public static Rotation operator /(Rotation rotation, float value) => value.EqualsInTolerance(0) ? new Rotation(0) : new Rotation(rotation.Degrees / value);
/// <summary> /// <summary>
/// Converts a double to a <see cref="Rotation" />. /// Converts a float to a <see cref="Rotation" />.
/// </summary> /// </summary>
/// <param name="rotation">The rotation in degrees to convert.</param> /// <param name="rotation">The rotation in degrees to convert.</param>
public static implicit operator Rotation(double rotation) => new(rotation); public static implicit operator Rotation(float rotation) => new(rotation);
/// <summary> /// <summary>
/// Converts <see cref="Rotation" /> to a double representing the rotation in degrees. /// Converts <see cref="Rotation" /> to a float representing the rotation in degrees.
/// </summary> /// </summary>
/// <param name="rotation">The rotatio to convert.</param> /// <param name="rotation">The rotatio to convert.</param>
public static implicit operator double(Rotation rotation) => rotation.Degrees; public static implicit operator float(Rotation rotation) => rotation.Degrees;
#endregion #endregion
} }

View File

@ -16,12 +16,12 @@ namespace RGB.NET.Core
/// <summary> /// <summary>
/// Gets the horizontal scaling value. /// Gets the horizontal scaling value.
/// </summary> /// </summary>
public double Horizontal { get; } public float Horizontal { get; }
/// <summary> /// <summary>
/// Gets the vertical scaling value. /// Gets the vertical scaling value.
/// </summary> /// </summary>
public double Vertical { get; } public float Vertical { get; }
#endregion #endregion
@ -31,7 +31,7 @@ namespace RGB.NET.Core
/// Initializes a new instance of the <see cref="Scale"/> class using the provided values. /// Initializes a new instance of the <see cref="Scale"/> class using the provided values.
/// </summary> /// </summary>
/// <param name="scale">The value used for horizontal and vertical scaling. 0 if not set.</param> /// <param name="scale">The value used for horizontal and vertical scaling. 0 if not set.</param>
public Scale(double scale = 1.0) : this(scale, scale) public Scale(float scale = 1.0f) : this(scale, scale)
{ } { }
/// <summary> /// <summary>
@ -39,7 +39,7 @@ namespace RGB.NET.Core
/// </summary> /// </summary>
/// <param name="horizontal">The value used for horizontal scaling.</param> /// <param name="horizontal">The value used for horizontal scaling.</param>
/// <param name="vertical">The value used for vertical scaling.</param> /// <param name="vertical">The value used for vertical scaling.</param>
public Scale(double horizontal, double vertical) public Scale(float horizontal, float vertical)
{ {
this.Horizontal = horizontal; this.Horizontal = horizontal;
this.Vertical = vertical; this.Vertical = vertical;
@ -74,7 +74,7 @@ namespace RGB.NET.Core
/// </summary> /// </summary>
/// <param name="horizontalScale">The horizontal scaling value.</param> /// <param name="horizontalScale">The horizontal scaling value.</param>
/// <param name="verticalScale">The vertical scaling value.</param> /// <param name="verticalScale">The vertical scaling value.</param>
public void Deconstruct(out double horizontalScale, out double verticalScale) public void Deconstruct(out float horizontalScale, out float verticalScale)
{ {
horizontalScale = Horizontal; horizontalScale = Horizontal;
verticalScale = Vertical; verticalScale = Vertical;
@ -106,7 +106,7 @@ namespace RGB.NET.Core
/// <param name="scale">The <see cref="Scale"/>.</param> /// <param name="scale">The <see cref="Scale"/>.</param>
/// <param name="value">The value to add.</param> /// <param name="value">The value to add.</param>
/// <returns>A new <see cref="Scale"/> representing the addition of the <see cref="Scale"/> and the provided value.</returns> /// <returns>A new <see cref="Scale"/> representing the addition of the <see cref="Scale"/> and the provided value.</returns>
public static Scale operator +(Scale scale, double value) => new(scale.Horizontal + value, scale.Vertical + value); public static Scale operator +(Scale scale, float value) => new(scale.Horizontal + value, scale.Vertical + value);
/// <summary> /// <summary>
/// Returns a new <see cref="Scale"/> representing the subtraction of the <see cref="Scale"/> and the provided value. /// Returns a new <see cref="Scale"/> representing the subtraction of the <see cref="Scale"/> and the provided value.
@ -114,7 +114,7 @@ namespace RGB.NET.Core
/// <param name="scale">The <see cref="Scale"/>.</param> /// <param name="scale">The <see cref="Scale"/>.</param>
/// <param name="value">The value to substract.</param> /// <param name="value">The value to substract.</param>
/// <returns>A new <see cref="Scale"/> representing the subtraction of the <see cref="Scale"/> and the provided value.</returns> /// <returns>A new <see cref="Scale"/> representing the subtraction of the <see cref="Scale"/> and the provided value.</returns>
public static Scale operator -(Scale scale, double value) => new(scale.Horizontal - value, scale.Vertical - value); public static Scale operator -(Scale scale, float value) => new(scale.Horizontal - value, scale.Vertical - value);
/// <summary> /// <summary>
/// Returns a new <see cref="Scale"/> representing the multiplication of the <see cref="Scale"/> and the provided value. /// Returns a new <see cref="Scale"/> representing the multiplication of the <see cref="Scale"/> and the provided value.
@ -122,7 +122,7 @@ namespace RGB.NET.Core
/// <param name="scale">The <see cref="Scale"/>.</param> /// <param name="scale">The <see cref="Scale"/>.</param>
/// <param name="value">The value to multiply with.</param> /// <param name="value">The value to multiply with.</param>
/// <returns>A new <see cref="Scale"/> representing the multiplication of the <see cref="Scale"/> and the provided value.</returns> /// <returns>A new <see cref="Scale"/> representing the multiplication of the <see cref="Scale"/> and the provided value.</returns>
public static Scale operator *(Scale scale, double value) => new(scale.Horizontal * value, scale.Vertical * value); public static Scale operator *(Scale scale, float value) => new(scale.Horizontal * value, scale.Vertical * value);
/// <summary> /// <summary>
/// Returns a new <see cref="Scale"/> representing the division of the <see cref="Scale"/> and the provided value. /// Returns a new <see cref="Scale"/> representing the division of the <see cref="Scale"/> and the provided value.
@ -130,14 +130,14 @@ namespace RGB.NET.Core
/// <param name="scale">The <see cref="Scale"/>.</param> /// <param name="scale">The <see cref="Scale"/>.</param>
/// <param name="value">The value to device with.</param> /// <param name="value">The value to device with.</param>
/// <returns>A new <see cref="Scale"/> representing the division of the <see cref="Scale"/> and the provided value.</returns> /// <returns>A new <see cref="Scale"/> representing the division of the <see cref="Scale"/> and the provided value.</returns>
public static Scale operator /(Scale scale, double value) => value.EqualsInTolerance(0) ? new Scale(0) : new Scale(scale.Horizontal / value, scale.Vertical / value); public static Scale operator /(Scale scale, float value) => value.EqualsInTolerance(0) ? new Scale(0) : new Scale(scale.Horizontal / value, scale.Vertical / value);
/// <summary> /// <summary>
/// Converts a double to a <see cref="Scale" />. /// Converts a float to a <see cref="Scale" />.
/// </summary> /// </summary>
/// <param name="scale">The scale value to convert.</param> /// <param name="scale">The scale value to convert.</param>
public static implicit operator Scale(double scale) => new(scale); public static implicit operator Scale(float scale) => new(scale);
#endregion #endregion
} }

View File

@ -16,7 +16,7 @@ namespace RGB.NET.Core
/// <summary> /// <summary>
/// Gets a [NaN,NaN]-Size. /// Gets a [NaN,NaN]-Size.
/// </summary> /// </summary>
public static Size Invalid => new(double.NaN, double.NaN); public static Size Invalid => new(float.NaN, float.NaN);
#endregion #endregion
@ -25,12 +25,12 @@ namespace RGB.NET.Core
/// <summary> /// <summary>
/// Gets or sets the width component value of this <see cref="Size"/>. /// Gets or sets the width component value of this <see cref="Size"/>.
/// </summary> /// </summary>
public double Width { get; } public float Width { get; }
/// <summary> /// <summary>
/// Gets or sets the height component value of this <see cref="Size"/>. /// Gets or sets the height component value of this <see cref="Size"/>.
/// </summary> /// </summary>
public double Height { get; } public float Height { get; }
#endregion #endregion
@ -41,7 +41,7 @@ namespace RGB.NET.Core
/// Initializes a new instance of the <see cref="T:RGB.NET.Core.Size" /> using the provided size to define a square. /// Initializes a new instance of the <see cref="T:RGB.NET.Core.Size" /> using the provided size to define a square.
/// </summary> /// </summary>
/// <param name="size">The size used for the <see cref="P:RGB.NET.Core.Size.Width" /> component value and the <see cref="P:RGB.NET.Core.Size.Height" /> component value.</param> /// <param name="size">The size used for the <see cref="P:RGB.NET.Core.Size.Width" /> component value and the <see cref="P:RGB.NET.Core.Size.Height" /> component value.</param>
public Size(double size) public Size(float size)
: this(size, size) : this(size, size)
{ } { }
@ -50,7 +50,7 @@ namespace RGB.NET.Core
/// </summary> /// </summary>
/// <param name="width">The size used for the <see cref="Width"/> component value.</param> /// <param name="width">The size used for the <see cref="Width"/> component value.</param>
/// <param name="height">The size used for the <see cref="Height"/> component value.</param> /// <param name="height">The size used for the <see cref="Height"/> component value.</param>
public Size(double width, double height) public Size(float width, float height)
{ {
this.Width = width; this.Width = width;
this.Height = height; this.Height = height;
@ -75,9 +75,9 @@ namespace RGB.NET.Core
{ {
if (!(obj is Size size)) return false; if (!(obj is Size size)) return false;
(double width, double height) = size; (float width, float height) = size;
return ((double.IsNaN(Width) && double.IsNaN(width)) || Width.EqualsInTolerance(width)) return ((float.IsNaN(Width) && float.IsNaN(width)) || Width.EqualsInTolerance(width))
&& ((double.IsNaN(Height) && double.IsNaN(height)) || Height.EqualsInTolerance(height)); && ((float.IsNaN(Height) && float.IsNaN(height)) || Height.EqualsInTolerance(height));
} }
/// <summary> /// <summary>
@ -99,7 +99,7 @@ namespace RGB.NET.Core
/// </summary> /// </summary>
/// <param name="width">The width.</param> /// <param name="width">The width.</param>
/// <param name="height">The height.</param> /// <param name="height">The height.</param>
public void Deconstruct(out double width, out double height) public void Deconstruct(out float width, out float height)
{ {
width = Width; width = Width;
height = Height; height = Height;
@ -163,7 +163,7 @@ namespace RGB.NET.Core
/// <param name="size">The <see cref="Size"/>.</param> /// <param name="size">The <see cref="Size"/>.</param>
/// <param name="factor">The factor by which the <see cref="Size"/> should be multiplied.</param> /// <param name="factor">The factor by which the <see cref="Size"/> should be multiplied.</param>
/// <returns>A new <see cref="Size"/> representing the multiplication of the <see cref="Size"/> and the provided factor.</returns> /// <returns>A new <see cref="Size"/> representing the multiplication of the <see cref="Size"/> and the provided factor.</returns>
public static Size operator *(Size size, double factor) => new(size.Width * factor, size.Height * factor); public static Size operator *(Size size, float factor) => new(size.Width * factor, size.Height * factor);
/// <summary> /// <summary>
/// Returns a new <see cref="Size"/> representing the division of the two provided <see cref="Size"/>. /// Returns a new <see cref="Size"/> representing the division of the two provided <see cref="Size"/>.
@ -181,7 +181,7 @@ namespace RGB.NET.Core
/// <param name="size">The <see cref="Size"/>.</param> /// <param name="size">The <see cref="Size"/>.</param>
/// <param name="factor">The factor by which the <see cref="Size"/> should be divided.</param> /// <param name="factor">The factor by which the <see cref="Size"/> should be divided.</param>
/// <returns>A new <see cref="Size"/> representing the division of the <see cref="Size"/> and the provided factor.</returns> /// <returns>A new <see cref="Size"/> representing the division of the <see cref="Size"/> and the provided factor.</returns>
public static Size operator /(Size size, double factor) => factor.EqualsInTolerance(0) ? Invalid : new Size(size.Width / factor, size.Height / factor); public static Size operator /(Size size, float factor) => factor.EqualsInTolerance(0) ? Invalid : new Size(size.Width / factor, size.Height / factor);
/// <summary> /// <summary>
/// Returns a new <see cref="Size"/> representing the multiplication of the <see cref="Size"/> and the given <see cref="Scale"/>. /// Returns a new <see cref="Size"/> representing the multiplication of the <see cref="Size"/> and the given <see cref="Scale"/>.

View File

@ -324,7 +324,7 @@ namespace RGB.NET.Core
/// </summary> /// </summary>
public void AlignDevices() public void AlignDevices()
{ {
double posX = 0; float posX = 0;
foreach (IRGBDevice device in Devices) foreach (IRGBDevice device in Devices)
{ {
device.Location += new Point(posX, 0); device.Location += new Point(posX, 0);

View File

@ -23,10 +23,10 @@ namespace RGB.NET.Core
public RenderMode CalculationMode { get; set; } = RenderMode.Relative; public RenderMode CalculationMode { get; set; } = RenderMode.Relative;
/// <inheritdoc /> /// <inheritdoc />
public double Brightness { get; set; } public float Brightness { get; set; }
/// <inheritdoc /> /// <inheritdoc />
public double Opacity { get; set; } public float Opacity { get; set; }
#endregion #endregion
@ -37,7 +37,7 @@ namespace RGB.NET.Core
/// </summary> /// </summary>
/// <param name="brightness">The overall percentage brightness of the brush. (default: 1.0)</param> /// <param name="brightness">The overall percentage brightness of the brush. (default: 1.0)</param>
/// <param name="opacity">The overall percentage opacity of the brush. (default: 1.0)</param> /// <param name="opacity">The overall percentage opacity of the brush. (default: 1.0)</param>
protected AbstractBrush(double brightness = 1, double opacity = 1) protected AbstractBrush(float brightness = 1, float opacity = 1)
{ {
this.Brightness = brightness; this.Brightness = brightness;
this.Opacity = opacity; this.Opacity = opacity;

View File

@ -24,12 +24,12 @@ namespace RGB.NET.Core
/// <summary> /// <summary>
/// Gets or sets the overall percentage brightness of the <see cref="IBrush"/>. /// Gets or sets the overall percentage brightness of the <see cref="IBrush"/>.
/// </summary> /// </summary>
double Brightness { get; set; } float Brightness { get; set; }
/// <summary> /// <summary>
/// Gets or sets the overall percentage opacity of the <see cref="IBrush"/>. /// Gets or sets the overall percentage opacity of the <see cref="IBrush"/>.
/// </summary> /// </summary>
double Opacity { get; set; } float Opacity { get; set; }
/// <summary> /// <summary>
/// Performs the render pass of the <see cref="IBrush"/> and calculates the raw <see cref="Color"/> for all requested <see cref="RenderTarget"/>. /// Performs the render pass of the <see cref="IBrush"/> and calculates the raw <see cref="Color"/> for all requested <see cref="RenderTarget"/>.

View File

@ -1,75 +1,36 @@
using System; namespace RGB.NET.Core
namespace RGB.NET.Core
{ {
public class AverageSampler : ISampler public class AverageSampler : ISampler
{ {
#region Properties & Fields #region Properties & Fields
private Func<ReadOnlyMemory<Color>, int, int, int, int, Color> _sampleMethod = SampleWithoutAlpha; public bool SampleAlpha { get; set; }
private bool _sampleAlpha;
public bool SampleAlpha
{
get => _sampleAlpha;
set
{
_sampleAlpha = value;
_sampleMethod = value ? SampleWithAlpha : SampleWithoutAlpha;
}
}
#endregion #endregion
#region Methods #region Methods
public Color SampleColor(in ReadOnlyMemory<Color> data, int x, int y, int width, int height) => _sampleMethod(data, x, y, width, height); public Color SampleColor(int x, int y, int width, int height, GetColor getColor)
private static Color SampleWithAlpha(ReadOnlyMemory<Color> data, int x, int y, int width, int height)
{ {
ReadOnlySpan<Color> span = data.Span; int maxX = x + width;
int maxY = y + height; int maxY = y + height;
int count = width * height; int count = width * height;
double a = 0, r = 0, g = 0, b = 0; if (count == 0) return Color.Transparent;
float a = 0, r = 0, g = 0, b = 0;
for (int yPos = y; yPos < maxY; yPos++) for (int yPos = y; yPos < maxY; yPos++)
{ for (int xPos = x; xPos < maxX; xPos++)
ReadOnlySpan<Color> line = span.Slice((yPos * width) + x, width);
foreach (Color color in line)
{ {
Color color = getColor(x, y);
a += color.A; a += color.A;
r += color.R; r += color.R;
g += color.G; g += color.G;
b += color.B; b += color.B;
} }
}
if (count == 0) return Color.Transparent; return SampleAlpha
? new Color(a / count, r / count, g / count, b / count)
return new Color(a / count, r / count, g / count, b / count); : new Color(r / count, g / count, b / count);
}
private static Color SampleWithoutAlpha(ReadOnlyMemory<Color> data, int x, int y, int width, int height)
{
ReadOnlySpan<Color> span = data.Span;
int maxY = y + height;
int count = width * height;
double r = 0, g = 0, b = 0;
for (int yPos = y; yPos < maxY; yPos++)
{
ReadOnlySpan<Color> line = span.Slice((yPos * width) + x, width);
foreach (Color color in line)
{
r += color.R;
g += color.G;
b += color.B;
}
}
if (count == 0) return Color.Transparent;
return new Color(r / count, g / count, b / count);
} }
#endregion #endregion

View File

@ -1,9 +1,9 @@
using System; namespace RGB.NET.Core
namespace RGB.NET.Core
{ {
public delegate Color GetColor(int x, int y);
public interface ISampler public interface ISampler
{ {
Color SampleColor(in ReadOnlyMemory<Color> data, int x, int y, int width, int height); Color SampleColor(int x, int y, int width, int height, GetColor getColorFunc);
} }
} }

View File

@ -8,10 +8,10 @@ namespace RGB.NET.Devices.Corsair
internal static Rectangle ToRectangle(this _CorsairLedPosition position) internal static Rectangle ToRectangle(this _CorsairLedPosition position)
{ {
//HACK DarthAffe 08.07.2018: It seems like corsair introduced a bug here - it's always 0. //HACK DarthAffe 08.07.2018: It seems like corsair introduced a bug here - it's always 0.
double width = position.width < 0.5 ? 10 : position.width; float width = position.width < 0.5f ? 10 : (float)position.width;
double height = position.height < 0.5 ? 10 : position.height; float height = position.height < 0.5f ? 10 : (float)position.height;
double posX = position.left; float posX = (float)position.left;
double posY = position.top; float posY = (float)position.top;
return new Rectangle(posX, posY, width, height); return new Rectangle(posX, posY, width, height);
} }

View File

@ -59,27 +59,27 @@ namespace RGB.NET.Layout
/// Gets or sets the width of the <see cref="DeviceLayout"/>. /// Gets or sets the width of the <see cref="DeviceLayout"/>.
/// </summary> /// </summary>
[XmlElement("Width")] [XmlElement("Width")]
public double Width { get; set; } public float Width { get; set; }
/// <summary> /// <summary>
/// Gets or sets the height of the <see cref="DeviceLayout"/>. /// Gets or sets the height of the <see cref="DeviceLayout"/>.
/// </summary> /// </summary>
[XmlElement("Height")] [XmlElement("Height")]
public double Height { get; set; } public float Height { get; set; }
/// <summary> /// <summary>
/// Gets or sets the width of one 'unit' used for the calculation of led positions and sizes. /// Gets or sets the width of one 'unit' used for the calculation of led positions and sizes.
/// </summary> /// </summary>
[XmlElement("LedUnitWidth")] [XmlElement("LedUnitWidth")]
[DefaultValue(19.0)] [DefaultValue(19.0)]
public double LedUnitWidth { get; set; } = 19.0; public float LedUnitWidth { get; set; } = 19.0f;
/// <summary> /// <summary>
/// Gets or sets the height of one 'unit' used for the calculation of led positions and sizes. /// Gets or sets the height of one 'unit' used for the calculation of led positions and sizes.
/// </summary> /// </summary>
[XmlElement("LedUnitHeight")] [XmlElement("LedUnitHeight")]
[DefaultValue(19.0)] [DefaultValue(19.0)]
public double LedUnitHeight { get; set; } = 19.0; public float LedUnitHeight { get; set; } = 19.0f;
[XmlArray("Leds")] [XmlArray("Leds")]
public List<LedLayout> InternalLeds { get; set; } = new(); public List<LedLayout> InternalLeds { get; set; } = new();

View File

@ -38,12 +38,12 @@ namespace RGB.NET.Layout
/// <summary> /// <summary>
/// Gets or sets the width of the <see cref="IDeviceLayout"/>. /// Gets or sets the width of the <see cref="IDeviceLayout"/>.
/// </summary> /// </summary>
double Width { get; } float Width { get; }
/// <summary> /// <summary>
/// Gets or sets the height of the <see cref="IDeviceLayout"/>. /// Gets or sets the height of the <see cref="IDeviceLayout"/>.
/// </summary> /// </summary>
double Height { get; } float Height { get; }
/// <summary> /// <summary>
/// Gets or sets a list of <see cref="ILedLayout"/> representing all the <see cref="Led"/> of the <see cref="IDeviceLayout"/>. /// Gets or sets a list of <see cref="ILedLayout"/> representing all the <see cref="Led"/> of the <see cref="IDeviceLayout"/>.

View File

@ -22,22 +22,22 @@ namespace RGB.NET.Layout
/// <summary> /// <summary>
/// Gets the x-position of the <see cref="LedLayout"/>. /// Gets the x-position of the <see cref="LedLayout"/>.
/// </summary> /// </summary>
double X { get; } float X { get; }
/// <summary> /// <summary>
/// Gets the y-position of the <see cref="LedLayout"/>. /// Gets the y-position of the <see cref="LedLayout"/>.
/// </summary> /// </summary>
double Y { get; } float Y { get; }
/// <summary> /// <summary>
/// Gets the width of the <see cref="LedLayout"/>. /// Gets the width of the <see cref="LedLayout"/>.
/// </summary> /// </summary>
double Width { get; } float Width { get; }
/// <summary> /// <summary>
/// Gets the height of the <see cref="LedLayout"/>. /// Gets the height of the <see cref="LedLayout"/>.
/// </summary> /// </summary>
double Height { get; } float Height { get; }
object? CustomData { get; } object? CustomData { get; }
} }

View File

@ -83,25 +83,25 @@ namespace RGB.NET.Layout
/// Gets the x-position of the <see cref="LedLayout"/>. /// Gets the x-position of the <see cref="LedLayout"/>.
/// </summary> /// </summary>
[XmlIgnore] [XmlIgnore]
public double X { get; private set; } public float X { get; private set; }
/// <summary> /// <summary>
/// Gets the y-position of the <see cref="LedLayout"/>. /// Gets the y-position of the <see cref="LedLayout"/>.
/// </summary> /// </summary>
[XmlIgnore] [XmlIgnore]
public double Y { get; private set; } public float Y { get; private set; }
/// <summary> /// <summary>
/// Gets the width of the <see cref="LedLayout"/>. /// Gets the width of the <see cref="LedLayout"/>.
/// </summary> /// </summary>
[XmlIgnore] [XmlIgnore]
public double Width { get; private set; } public float Width { get; private set; }
/// <summary> /// <summary>
/// Gets the height of the <see cref="LedLayout"/>. /// Gets the height of the <see cref="LedLayout"/>.
/// </summary> /// </summary>
[XmlIgnore] [XmlIgnore]
public double Height { get; private set; } public float Height { get; private set; }
#endregion #endregion
@ -128,7 +128,7 @@ namespace RGB.NET.Layout
Y = GetLocationValue(DescriptiveY, lastLed?.Y ?? 0, Height, lastLed?.Height ?? 0); Y = GetLocationValue(DescriptiveY, lastLed?.Y ?? 0, Height, lastLed?.Height ?? 0);
} }
protected virtual double GetLocationValue(string value, double lastValue, double currentSize, double lastSize) protected virtual float GetLocationValue(string value, float lastValue, float currentSize, float lastSize)
{ {
try try
{ {
@ -143,21 +143,21 @@ namespace RGB.NET.Layout
return lastValue + lastSize; return lastValue + lastSize;
if (value.StartsWith("+", StringComparison.Ordinal)) if (value.StartsWith("+", StringComparison.Ordinal))
return lastValue + lastSize + double.Parse(value[1..], CultureInfo.InvariantCulture); return lastValue + lastSize + float.Parse(value[1..], CultureInfo.InvariantCulture);
if (string.Equals(value, "-", StringComparison.Ordinal)) if (string.Equals(value, "-", StringComparison.Ordinal))
return lastValue - currentSize; return lastValue - currentSize;
if (value.StartsWith("-", StringComparison.Ordinal)) if (value.StartsWith("-", StringComparison.Ordinal))
return lastValue - currentSize - double.Parse(value[1..], CultureInfo.InvariantCulture); return lastValue - currentSize - float.Parse(value[1..], CultureInfo.InvariantCulture);
if (string.Equals(value, "~", StringComparison.Ordinal)) if (string.Equals(value, "~", StringComparison.Ordinal))
return (lastValue + lastSize) - currentSize; return (lastValue + lastSize) - currentSize;
if (value.StartsWith("~", StringComparison.Ordinal)) if (value.StartsWith("~", StringComparison.Ordinal))
return (lastValue + lastSize) - currentSize - double.Parse(value[1..], CultureInfo.InvariantCulture); return (lastValue + lastSize) - currentSize - float.Parse(value[1..], CultureInfo.InvariantCulture);
return double.Parse(value, CultureInfo.InvariantCulture); return float.Parse(value, CultureInfo.InvariantCulture);
} }
catch catch
{ {
@ -165,7 +165,7 @@ namespace RGB.NET.Layout
} }
} }
protected virtual double GetSizeValue(string value, double unitSize) protected virtual float GetSizeValue(string value, float unitSize)
{ {
try try
{ {
@ -174,9 +174,9 @@ namespace RGB.NET.Layout
value = value.Replace(" ", string.Empty); value = value.Replace(" ", string.Empty);
if (value.EndsWith("mm", StringComparison.OrdinalIgnoreCase)) if (value.EndsWith("mm", StringComparison.OrdinalIgnoreCase))
return double.Parse(value[..^2], CultureInfo.InvariantCulture); return float.Parse(value[..^2], CultureInfo.InvariantCulture);
return unitSize * double.Parse(value, CultureInfo.InvariantCulture); return unitSize * float.Parse(value, CultureInfo.InvariantCulture);
} }
catch catch
{ {

View File

@ -20,46 +20,46 @@ namespace RGB.NET.Presets.Decorators
/// Gets or sets the attack-time (in seconds) of the decorator. (default: 0.2)<br /> /// Gets or sets the attack-time (in seconds) of the decorator. (default: 0.2)<br />
/// This is close to a synthesizer envelope. (See <see href="http://en.wikipedia.org/wiki/Synthesizer#ADSR_envelope" /> as reference) /// This is close to a synthesizer envelope. (See <see href="http://en.wikipedia.org/wiki/Synthesizer#ADSR_envelope" /> as reference)
/// </summary> /// </summary>
public double Attack { get; set; } = 0.2; public float Attack { get; set; } = 0.2f;
/// <summary> /// <summary>
/// Gets or sets the decay-time (in seconds) of the decorator. (default: 0)<br /> /// Gets or sets the decay-time (in seconds) of the decorator. (default: 0)<br />
/// This is close to a synthesizer envelope. (See <see href="http://en.wikipedia.org/wiki/Synthesizer#ADSR_envelope" /> as reference) /// This is close to a synthesizer envelope. (See <see href="http://en.wikipedia.org/wiki/Synthesizer#ADSR_envelope" /> as reference)
/// </summary> /// </summary>
public double Decay { get; set; } = 0; public float Decay { get; set; } = 0;
/// <summary> /// <summary>
/// Gets or sets the sustain-time (in seconds) of the decorator. (default: 0.3)<br /> /// Gets or sets the sustain-time (in seconds) of the decorator. (default: 0.3)<br />
/// This is close to a synthesizer envelope. (See <see href="http://en.wikipedia.org/wiki/Synthesizer#ADSR_envelope" /> as reference)<br /> /// This is close to a synthesizer envelope. (See <see href="http://en.wikipedia.org/wiki/Synthesizer#ADSR_envelope" /> as reference)<br />
/// Note that this value for naming reasons represents the time NOT the level. /// Note that this value for naming reasons represents the time NOT the level.
/// </summary> /// </summary>
public double Sustain { get; set; } = 0.3; public float Sustain { get; set; } = 0.3f;
/// <summary> /// <summary>
/// Gets or sets the release-time (in seconds) of the decorator. (default: 0.2)<br /> /// Gets or sets the release-time (in seconds) of the decorator. (default: 0.2)<br />
/// This is close to a synthesizer envelope. (See <see href="http://en.wikipedia.org/wiki/Synthesizer#ADSR_envelope" /> as reference) /// This is close to a synthesizer envelope. (See <see href="http://en.wikipedia.org/wiki/Synthesizer#ADSR_envelope" /> as reference)
/// </summary> /// </summary>
public double Release { get; set; } = 0.2; public float Release { get; set; } = 0.2f;
/// <summary> /// <summary>
/// Gets or sets the level to which the oppacity (percentage) should raise in the attack-cycle. (default: 1); /// Gets or sets the level to which the oppacity (percentage) should raise in the attack-cycle. (default: 1);
/// </summary> /// </summary>
public double AttackValue { get; set; } = 1; public float AttackValue { get; set; } = 1;
/// <summary> /// <summary>
/// Gets or sets the level at which the oppacity (percentage) should stay in the sustain-cycle. (default: 1); /// Gets or sets the level at which the oppacity (percentage) should stay in the sustain-cycle. (default: 1);
/// </summary> /// </summary>
public double SustainValue { get; set; } = 1; public float SustainValue { get; set; } = 1;
/// <summary> /// <summary>
/// Gets or sets the level at which the oppacity (percentage) should stay in the pause-cycle. (default: 0); /// Gets or sets the level at which the oppacity (percentage) should stay in the pause-cycle. (default: 0);
/// </summary> /// </summary>
public double PauseValue { get; set; } = 0; public float PauseValue { get; set; } = 0;
/// <summary> /// <summary>
/// Gets or sets the interval (in seconds) in which the decorator should repeat (if repetition is enabled). (default: 1) /// Gets or sets the interval (in seconds) in which the decorator should repeat (if repetition is enabled). (default: 1)
/// </summary> /// </summary>
public double Interval { get; set; } = 1; public float Interval { get; set; } = 1;
/// <summary> /// <summary>
/// Gets or sets the amount of repetitions the decorator should do until it's finished. Zero means infinite. (default: 0) /// Gets or sets the amount of repetitions the decorator should do until it's finished. Zero means infinite. (default: 0)
@ -67,10 +67,10 @@ namespace RGB.NET.Presets.Decorators
public int Repetitions { get; set; } = 0; public int Repetitions { get; set; } = 0;
private ADSRPhase _currentPhase; private ADSRPhase _currentPhase;
private double _currentPhaseValue; private float _currentPhaseValue;
private int _repetitionCount; private int _repetitionCount;
private double _currentValue; private float _currentValue;
#endregion #endregion
@ -90,14 +90,14 @@ namespace RGB.NET.Presets.Decorators
/// <inheritdoc /> /// <inheritdoc />
protected override void Update(double deltaTime) protected override void Update(double deltaTime)
{ {
_currentPhaseValue -= deltaTime; _currentPhaseValue -= (float)deltaTime;
// Using ifs instead of a switch allows to skip phases with time 0. // Using ifs instead of a switch allows to skip phases with time 0.
// ReSharper disable InvertIf // ReSharper disable InvertIf
if (_currentPhase == ADSRPhase.Attack) if (_currentPhase == ADSRPhase.Attack)
if (_currentPhaseValue > 0) if (_currentPhaseValue > 0)
_currentValue = PauseValue + (Math.Min(1, (Attack - _currentPhaseValue) / Attack) * (AttackValue - PauseValue)); _currentValue = PauseValue + (MathF.Min(1, (Attack - _currentPhaseValue) / Attack) * (AttackValue - PauseValue));
else else
{ {
_currentPhaseValue = Decay; _currentPhaseValue = Decay;
@ -106,7 +106,7 @@ namespace RGB.NET.Presets.Decorators
if (_currentPhase == ADSRPhase.Decay) if (_currentPhase == ADSRPhase.Decay)
if (_currentPhaseValue > 0) if (_currentPhaseValue > 0)
_currentValue = SustainValue + (Math.Min(1, _currentPhaseValue / Decay) * (AttackValue - SustainValue)); _currentValue = SustainValue + (MathF.Min(1, _currentPhaseValue / Decay) * (AttackValue - SustainValue));
else else
{ {
_currentPhaseValue = Sustain; _currentPhaseValue = Sustain;
@ -124,7 +124,7 @@ namespace RGB.NET.Presets.Decorators
if (_currentPhase == ADSRPhase.Release) if (_currentPhase == ADSRPhase.Release)
if (_currentPhaseValue > 0) if (_currentPhaseValue > 0)
_currentValue = PauseValue + (Math.Min(1, _currentPhaseValue / Release) * (SustainValue - PauseValue)); _currentValue = PauseValue + (MathF.Min(1, _currentPhaseValue / Release) * (SustainValue - PauseValue));
else else
{ {
_currentPhaseValue = Interval; _currentPhaseValue = Interval;

View File

@ -26,7 +26,7 @@ namespace RGB.NET.Presets.Decorators
/// <see cref="LinearGradient"/>: 360 unit = 1 offset. /// <see cref="LinearGradient"/>: 360 unit = 1 offset.
/// <see cref="RainbowGradient"/>: 1 unit = 1 degree. /// <see cref="RainbowGradient"/>: 1 unit = 1 degree.
/// </summary> /// </summary>
public double Speed { get; set; } public float Speed { get; set; }
// ReSharper restore MemberCanBePrivate.Global // ReSharper restore MemberCanBePrivate.Global
// ReSharper restore AutoPropertyCanBeMadeGetOnly.Global // ReSharper restore AutoPropertyCanBeMadeGetOnly.Global
@ -44,7 +44,7 @@ namespace RGB.NET.Presets.Decorators
/// <see cref="T:RGB.NET.Presets.Gradients.RainbowGradient" />: 1 unit = 1 degree.</param> /// <see cref="T:RGB.NET.Presets.Gradients.RainbowGradient" />: 1 unit = 1 degree.</param>
/// <param name="direction">The direction the <see cref="T:RGB.NET.Presets.Gradients.IGradient" /> is moved. /// <param name="direction">The direction the <see cref="T:RGB.NET.Presets.Gradients.IGradient" /> is moved.
/// True leads to an offset-increment (normaly moving to the right), false to an offset-decrement (normaly moving to the left).</param> /// True leads to an offset-increment (normaly moving to the right), false to an offset-decrement (normaly moving to the left).</param>
public MoveGradientDecorator(RGBSurface surface, double speed = 180.0, bool direction = true) public MoveGradientDecorator(RGBSurface surface, float speed = 180.0f, bool direction = true)
: base(surface) : base(surface)
{ {
this.Speed = speed; this.Speed = speed;
@ -58,7 +58,7 @@ namespace RGB.NET.Presets.Decorators
/// <inheritdoc /> /// <inheritdoc />
protected override void Update(double deltaTime) protected override void Update(double deltaTime)
{ {
double movement = Speed * deltaTime; float movement = Speed * (float)deltaTime;
if (!Direction) if (!Direction)
movement = -movement; movement = -movement;

View File

@ -20,7 +20,7 @@ namespace RGB.NET.Presets.Helper
/// <param name="endPoint">The end <see cref="Point"/> of the gradient.</param> /// <param name="endPoint">The end <see cref="Point"/> of the gradient.</param>
/// <param name="point">The <see cref="Point"/> on the gradient to which the offset is calculated.</param> /// <param name="point">The <see cref="Point"/> on the gradient to which the offset is calculated.</param>
/// <returns>The offset of the <see cref="Point"/> on the gradient.</returns> /// <returns>The offset of the <see cref="Point"/> on the gradient.</returns>
public static double CalculateLinearGradientOffset(in Point startPoint, in Point endPoint, in Point point) public static float CalculateLinearGradientOffset(in Point startPoint, in Point endPoint, in Point point)
{ {
Point intersectingPoint; Point intersectingPoint;
if (startPoint.Y.EqualsInTolerance(endPoint.Y)) // Horizontal case if (startPoint.Y.EqualsInTolerance(endPoint.Y)) // Horizontal case
@ -31,20 +31,20 @@ namespace RGB.NET.Presets.Helper
else // Diagonal case else // Diagonal case
{ {
double slope = (endPoint.Y - startPoint.Y) / (endPoint.X - startPoint.X); float slope = (endPoint.Y - startPoint.Y) / (endPoint.X - startPoint.X);
double orthogonalSlope = -1 / slope; float orthogonalSlope = -1 / slope;
double startYIntercept = startPoint.Y - (slope * startPoint.X); float startYIntercept = startPoint.Y - (slope * startPoint.X);
double pointYIntercept = point.Y - (orthogonalSlope * point.X); float pointYIntercept = point.Y - (orthogonalSlope * point.X);
double intersectingPointX = (pointYIntercept - startYIntercept) / (slope - orthogonalSlope); float intersectingPointX = (pointYIntercept - startYIntercept) / (slope - orthogonalSlope);
double intersectingPointY = (slope * intersectingPointX) + startYIntercept; float intersectingPointY = (slope * intersectingPointX) + startYIntercept;
intersectingPoint = new Point(intersectingPointX, intersectingPointY); intersectingPoint = new Point(intersectingPointX, intersectingPointY);
} }
// Calculate distances relative to the vector start // Calculate distances relative to the vector start
double intersectDistance = CalculateDistance(intersectingPoint, startPoint, endPoint); float intersectDistance = CalculateDistance(intersectingPoint, startPoint, endPoint);
double gradientLength = CalculateDistance(endPoint, startPoint, endPoint); float gradientLength = CalculateDistance(endPoint, startPoint, endPoint);
return intersectDistance / gradientLength; return intersectDistance / gradientLength;
} }
@ -57,9 +57,9 @@ namespace RGB.NET.Presets.Helper
/// <param name="origin">The origin of the vector.</param> /// <param name="origin">The origin of the vector.</param>
/// <param name="direction">The direction of the vector.</param> /// <param name="direction">The direction of the vector.</param>
/// <returns>The signed magnitude of a <see cref="Point"/> on a vector.</returns> /// <returns>The signed magnitude of a <see cref="Point"/> on a vector.</returns>
public static double CalculateDistance(in Point point, in Point origin, in Point direction) public static float CalculateDistance(in Point point, in Point origin, in Point direction)
{ {
double distance = CalculateDistance(point, origin); float distance = CalculateDistance(point, origin);
return (((point.Y < origin.Y) && (direction.Y > origin.Y)) return (((point.Y < origin.Y) && (direction.Y > origin.Y))
|| ((point.Y > origin.Y) && (direction.Y < origin.Y)) || ((point.Y > origin.Y) && (direction.Y < origin.Y))
@ -74,11 +74,11 @@ namespace RGB.NET.Presets.Helper
/// <param name="point1">The first <see cref="Point"/>.</param> /// <param name="point1">The first <see cref="Point"/>.</param>
/// <param name="point2">The second <see cref="Point"/>.</param> /// <param name="point2">The second <see cref="Point"/>.</param>
/// <returns>The distance between the two <see cref="Point"/>.</returns> /// <returns>The distance between the two <see cref="Point"/>.</returns>
public static double CalculateDistance(in Point point1, in Point point2) public static float CalculateDistance(in Point point1, in Point point2)
{ {
double x = point1.X - point2.X; float x = point1.X - point2.X;
double y = point1.Y - point2.Y; float y = point1.Y - point2.Y;
return Math.Sqrt((y * y) + (x * x)); return MathF.Sqrt((y * y) + (x * x));
} }
#endregion #endregion

View File

@ -18,23 +18,23 @@ namespace RGB.NET.Presets.Textures
{ {
#region Constants #region Constants
private const double PI2 = Math.PI * 2; private const float PI2 = MathF.PI * 2.0f;
#endregion #endregion
#region Properties & Fields #region Properties & Fields
private double _origin = Math.Atan2(-1, 0); private float _origin = MathF.Atan2(-1, 0);
/// <summary> /// <summary>
/// Gets or sets the origin (radian-angle) this <see cref="ConicalGradientTexture"/> is drawn to. (default: -π/2) /// Gets or sets the origin (radian-angle) this <see cref="ConicalGradientTexture"/> is drawn to. (default: -π/2)
/// </summary> /// </summary>
public double Origin public float Origin
{ {
get => _origin; get => _origin;
set => SetProperty(ref _origin, value); set => SetProperty(ref _origin, value);
} }
private Point _center = new(0.5, 0.5); private Point _center = new(0.5f, 0.5f);
/// <summary> /// <summary>
/// Gets or sets the center <see cref="Point"/> (as percentage in the range [0..1]) of the <see cref="IGradient"/> drawn by this <see cref="ConicalGradientTexture"/>. (default: 0.5, 0.5) /// Gets or sets the center <see cref="Point"/> (as percentage in the range [0..1]) of the <see cref="IGradient"/> drawn by this <see cref="ConicalGradientTexture"/>. (default: 0.5, 0.5)
/// </summary> /// </summary>
@ -86,9 +86,9 @@ namespace RGB.NET.Presets.Textures
protected override Color GetColor(in Point point) protected override Color GetColor(in Point point)
{ {
double angle = Math.Atan2(point.Y - Center.Y, point.X - Center.X) - Origin; float angle = MathF.Atan2(point.Y - Center.Y, point.X - Center.X) - Origin;
if (angle < 0) angle += PI2; if (angle < 0) angle += PI2;
double offset = angle / PI2; float offset = angle / PI2;
return Gradient.GetColor(offset); return Gradient.GetColor(offset);
} }

View File

@ -96,23 +96,23 @@ namespace RGB.NET.Presets.Textures.Gradients
/// </summary> /// </summary>
/// <param name="offset"></param> /// <param name="offset"></param>
/// <returns></returns> /// <returns></returns>
protected double ClipOffset(double offset) protected float ClipOffset(float offset)
{ {
double max = GradientStops.Max(stop => stop.Offset); float max = GradientStops.Max(stop => stop.Offset);
if (offset > max) if (offset > max)
return max; return max;
double min = GradientStops.Min(stop => stop.Offset); float min = GradientStops.Min(stop => stop.Offset);
return offset < min ? min : offset; return offset < min ? min : offset;
} }
/// <inheritdoc /> /// <inheritdoc />
public abstract Color GetColor(double offset); public abstract Color GetColor(float offset);
/// <inheritdoc /> /// <inheritdoc />
public virtual void Move(double offset) public virtual void Move(float offset)
{ {
offset /= 360.0; offset /= 360.0f;
foreach (GradientStop gradientStop in GradientStops) foreach (GradientStop gradientStop in GradientStops)
gradientStop.Offset += offset; gradientStop.Offset += offset;

View File

@ -12,11 +12,11 @@ namespace RGB.NET.Presets.Textures.Gradients
{ {
#region Properties & Fields #region Properties & Fields
private double _offset; private float _offset;
/// <summary> /// <summary>
/// Gets or sets the percentage offset to place this <see cref="GradientStop"/>. This should be inside the range of [0..1] but it's not necessary. /// Gets or sets the percentage offset to place this <see cref="GradientStop"/>. This should be inside the range of [0..1] but it's not necessary.
/// </summary> /// </summary>
public double Offset public float Offset
{ {
get => _offset; get => _offset;
set => SetProperty(ref _offset, value); set => SetProperty(ref _offset, value);
@ -41,7 +41,7 @@ namespace RGB.NET.Presets.Textures.Gradients
/// </summary> /// </summary>
/// <param name="offset">The percentage offset to place this <see cref="GradientStop"/>.</param> /// <param name="offset">The percentage offset to place this <see cref="GradientStop"/>.</param>
/// <param name="color">The <see cref="Color"/> of the <see cref="GradientStop"/>.</param> /// <param name="color">The <see cref="Color"/> of the <see cref="GradientStop"/>.</param>
public GradientStop(double offset, Color color) public GradientStop(float offset, Color color)
{ {
this.Offset = offset; this.Offset = offset;
this.Color = color; this.Color = color;

View File

@ -19,12 +19,12 @@ namespace RGB.NET.Presets.Textures.Gradients
/// </summary> /// </summary>
/// <param name="offset">The percentage offset to take the <see cref="Color"/> from.</param> /// <param name="offset">The percentage offset to take the <see cref="Color"/> from.</param>
/// <returns>The <see cref="Color"/> at the specific offset.</returns> /// <returns>The <see cref="Color"/> at the specific offset.</returns>
Color GetColor(double offset); Color GetColor(float offset);
/// <summary> /// <summary>
/// Moves the <see cref="IGradient"/> by the provided offset. /// Moves the <see cref="IGradient"/> by the provided offset.
/// </summary> /// </summary>
/// <param name="offset">The offset the <see cref="IGradient"/> should be moved.</param> /// <param name="offset">The offset the <see cref="IGradient"/> should be moved.</param>
void Move(double offset); void Move(float offset);
} }
} }

View File

@ -83,7 +83,7 @@ namespace RGB.NET.Presets.Textures.Gradients
/// </summary> /// </summary>
/// <param name="offset">The percentage offset to take the color from.</param> /// <param name="offset">The percentage offset to take the color from.</param>
/// <returns>The <see cref="T:RGB.NET.Core.Color" /> at the specific offset.</returns> /// <returns>The <see cref="T:RGB.NET.Core.Color" /> at the specific offset.</returns>
public override Color GetColor(double offset) public override Color GetColor(float offset)
{ {
if (GradientStops.Count == 0) return Color.Transparent; if (GradientStops.Count == 0) return Color.Transparent;
if (GradientStops.Count == 1) return GradientStops[0].Color; if (GradientStops.Count == 1) return GradientStops[0].Color;
@ -93,14 +93,14 @@ namespace RGB.NET.Presets.Textures.Gradients
(GradientStop gsBefore, GradientStop gsAfter) = GetEnclosingGradientStops(offset, _orderedGradientStops, WrapGradient); (GradientStop gsBefore, GradientStop gsAfter) = GetEnclosingGradientStops(offset, _orderedGradientStops, WrapGradient);
double blendFactor = 0; float blendFactor = 0;
if (!gsBefore.Offset.Equals(gsAfter.Offset)) if (!gsBefore.Offset.Equals(gsAfter.Offset))
blendFactor = ((offset - gsBefore.Offset) / (gsAfter.Offset - gsBefore.Offset)); blendFactor = ((offset - gsBefore.Offset) / (gsAfter.Offset - gsBefore.Offset));
double colA = ((gsAfter.Color.A - gsBefore.Color.A) * blendFactor) + gsBefore.Color.A; float colA = ((gsAfter.Color.A - gsBefore.Color.A) * blendFactor) + gsBefore.Color.A;
double colR = ((gsAfter.Color.R - gsBefore.Color.R) * blendFactor) + gsBefore.Color.R; float colR = ((gsAfter.Color.R - gsBefore.Color.R) * blendFactor) + gsBefore.Color.R;
double colG = ((gsAfter.Color.G - gsBefore.Color.G) * blendFactor) + gsBefore.Color.G; float colG = ((gsAfter.Color.G - gsBefore.Color.G) * blendFactor) + gsBefore.Color.G;
double colB = ((gsAfter.Color.B - gsBefore.Color.B) * blendFactor) + gsBefore.Color.B; float colB = ((gsAfter.Color.B - gsBefore.Color.B) * blendFactor) + gsBefore.Color.B;
return new Color(colA, colR, colG, colB); return new Color(colA, colR, colG, colB);
} }
@ -112,7 +112,7 @@ namespace RGB.NET.Presets.Textures.Gradients
/// <param name="orderedStops">The ordered list of <see cref="GradientStop"/> to choose from.</param> /// <param name="orderedStops">The ordered list of <see cref="GradientStop"/> to choose from.</param>
/// <param name="wrap">Bool indicating if the gradient should be wrapped or not.</param> /// <param name="wrap">Bool indicating if the gradient should be wrapped or not.</param>
/// <returns></returns> /// <returns></returns>
protected virtual (GradientStop gsBefore, GradientStop gsAfter) GetEnclosingGradientStops(double offset, LinkedList<GradientStop> orderedStops, bool wrap) protected virtual (GradientStop gsBefore, GradientStop gsAfter) GetEnclosingGradientStops(float offset, LinkedList<GradientStop> orderedStops, bool wrap)
{ {
LinkedList<GradientStop> gradientStops = new(orderedStops); LinkedList<GradientStop> gradientStops = new(orderedStops);

View File

@ -17,21 +17,21 @@ namespace RGB.NET.Presets.Textures.Gradients
{ {
#region Properties & Fields #region Properties & Fields
private double _startHue; private float _startHue;
/// <summary> /// <summary>
/// Gets or sets the hue (in degrees) to start from. /// Gets or sets the hue (in degrees) to start from.
/// </summary> /// </summary>
public double StartHue public float StartHue
{ {
get => _startHue; get => _startHue;
set => SetProperty(ref _startHue, value); set => SetProperty(ref _startHue, value);
} }
private double _endHue; private float _endHue;
/// <summary> /// <summary>
/// Gets or sets the hue (in degrees) to end the with. /// Gets or sets the hue (in degrees) to end the with.
/// </summary> /// </summary>
public double EndHue public float EndHue
{ {
get => _endHue; get => _endHue;
set => SetProperty(ref _endHue, value); set => SetProperty(ref _endHue, value);
@ -53,7 +53,7 @@ namespace RGB.NET.Presets.Textures.Gradients
/// </summary> /// </summary>
/// <param name="startHue">The hue (in degrees) to start from (default: 0)</param> /// <param name="startHue">The hue (in degrees) to start from (default: 0)</param>
/// <param name="endHue">The hue (in degrees) to end with (default: 360)</param> /// <param name="endHue">The hue (in degrees) to end with (default: 360)</param>
public RainbowGradient(double startHue = 0, double endHue = 360) public RainbowGradient(float startHue = 0, float endHue = 360)
{ {
this.StartHue = startHue; this.StartHue = startHue;
this.EndHue = endHue; this.EndHue = endHue;
@ -71,15 +71,15 @@ namespace RGB.NET.Presets.Textures.Gradients
/// </summary> /// </summary>
/// <param name="offset">The percentage offset to take the color from.</param> /// <param name="offset">The percentage offset to take the color from.</param>
/// <returns>The color at the specific offset.</returns> /// <returns>The color at the specific offset.</returns>
public Color GetColor(double offset) public Color GetColor(float offset)
{ {
double range = EndHue - StartHue; float range = EndHue - StartHue;
double hue = StartHue + (range * offset); float hue = StartHue + (range * offset);
return HSVColor.Create(hue, 1, 1); return HSVColor.Create(hue, 1, 1);
} }
/// <inheritdoc /> /// <inheritdoc />
public void Move(double offset) public void Move(float offset)
{ {
// RainbowGradient is calculated inverse // RainbowGradient is calculated inverse
offset *= -1; offset *= -1;

View File

@ -19,7 +19,7 @@ namespace RGB.NET.Presets.Textures
{ {
#region Properties & Fields #region Properties & Fields
private Point _startPoint = new(0, 0.5); private Point _startPoint = new(0, 0.5f);
/// <summary> /// <summary>
/// Gets or sets the start <see cref="Point"/> (as percentage in the range [0..1]) of the <see cref="IGradient"/> drawn by this <see cref="LinearGradientTexture"/>. (default: 0.0, 0.5) /// Gets or sets the start <see cref="Point"/> (as percentage in the range [0..1]) of the <see cref="IGradient"/> drawn by this <see cref="LinearGradientTexture"/>. (default: 0.0, 0.5)
/// </summary> /// </summary>
@ -29,7 +29,7 @@ namespace RGB.NET.Presets.Textures
set => SetProperty(ref _startPoint, value); set => SetProperty(ref _startPoint, value);
} }
private Point _endPoint = new(1, 0.5); private Point _endPoint = new(1, 0.5f);
/// <summary> /// <summary>
/// Gets or sets the end <see cref="Point"/> (as percentage in the range [0..1]) of the <see cref="IGradient"/> drawn by this <see cref="LinearGradientTexture"/>. (default: 1.0, 0.5) /// Gets or sets the end <see cref="Point"/> (as percentage in the range [0..1]) of the <see cref="IGradient"/> drawn by this <see cref="LinearGradientTexture"/>. (default: 1.0, 0.5)
/// </summary> /// </summary>
@ -70,7 +70,7 @@ namespace RGB.NET.Presets.Textures
protected override Color GetColor(in Point point) protected override Color GetColor(in Point point)
{ {
double offset = GradientHelper.CalculateLinearGradientOffset(StartPoint, EndPoint, point); float offset = GradientHelper.CalculateLinearGradientOffset(StartPoint, EndPoint, point);
return Gradient.GetColor(offset); return Gradient.GetColor(offset);
} }

View File

@ -16,9 +16,9 @@ namespace RGB.NET.Presets.Textures
{ {
#region Properties & Fields #region Properties & Fields
private double _referenceDistance = GradientHelper.CalculateDistance(new Point(0.5, 0.5), new Point(0, 0)); private float _referenceDistance = GradientHelper.CalculateDistance(new Point(0.5f, 0.5f), new Point(0, 0));
private Point _center = new(0.5, 0.5); private Point _center = new(0.5f, 0.5f);
/// <summary> /// <summary>
/// Gets or sets the center <see cref="Point"/> (as percentage in the range [0..1]) around which the <see cref="RadialGradientTexture"/> should be drawn. (default: 0.5, 0.5) /// Gets or sets the center <see cref="Point"/> (as percentage in the range [0..1]) around which the <see cref="RadialGradientTexture"/> should be drawn. (default: 0.5, 0.5)
/// </summary> /// </summary>
@ -61,15 +61,15 @@ namespace RGB.NET.Presets.Textures
private void CalculateReferenceDistance() private void CalculateReferenceDistance()
{ {
double referenceX = Center.X < 0.5 ? 1 : 0; float referenceX = Center.X < 0.5f ? 1 : 0;
double referenceY = Center.Y < 0.5 ? 1 : 0; float referenceY = Center.Y < 0.5f ? 1 : 0;
_referenceDistance = GradientHelper.CalculateDistance(new Point(referenceX, referenceY), Center); _referenceDistance = GradientHelper.CalculateDistance(new Point(referenceX, referenceY), Center);
} }
protected override Color GetColor(in Point point) protected override Color GetColor(in Point point)
{ {
double distance = GradientHelper.CalculateDistance(point, Center); float distance = GradientHelper.CalculateDistance(point, Center);
double offset = distance / _referenceDistance; float offset = distance / _referenceDistance;
return Gradient.GetColor(offset); return Gradient.GetColor(offset);
} }

View File

@ -221,36 +221,36 @@ namespace RGB.NET.Core.Tests.Color
[TestMethod] [TestMethod]
public void RGBPercentConstructorTest() public void RGBPercentConstructorTest()
{ {
Core.Color color = new(0.25341, 0.55367, 1); Core.Color color = new(0.25341f, 0.55367f, 1);
Assert.AreEqual(1, color.A, DoubleExtensions.TOLERANCE, "A is not 1"); Assert.AreEqual(1, color.A, FloatExtensions.TOLERANCE, "A is not 1");
Assert.AreEqual(0.25341, color.R, DoubleExtensions.TOLERANCE, "R is not 0.25341"); Assert.AreEqual(0.25341, color.R, FloatExtensions.TOLERANCE, "R is not 0.25341");
Assert.AreEqual(0.55367, color.G, DoubleExtensions.TOLERANCE, "G is not 0.55367"); Assert.AreEqual(0.55367, color.G, FloatExtensions.TOLERANCE, "G is not 0.55367");
Assert.AreEqual(1, color.B, DoubleExtensions.TOLERANCE, "B is not 1"); Assert.AreEqual(1, color.B, FloatExtensions.TOLERANCE, "B is not 1");
} }
[TestMethod] [TestMethod]
public void ARGBPercentConstructorTest() public void ARGBPercentConstructorTest()
{ {
Core.Color color = new(0.3315, 0.25341, 0.55367, 1); Core.Color color = new(0.3315f, 0.25341f, 0.55367f, 1);
Assert.AreEqual(0.3315, color.A, DoubleExtensions.TOLERANCE, "A is not 0.3315"); Assert.AreEqual(0.3315f, color.A, FloatExtensions.TOLERANCE, "A is not 0.3315");
Assert.AreEqual(0.25341, color.R, DoubleExtensions.TOLERANCE, "R is not 0.25341"); Assert.AreEqual(0.25341f, color.R, FloatExtensions.TOLERANCE, "R is not 0.25341");
Assert.AreEqual(0.55367, color.G, DoubleExtensions.TOLERANCE, "G is not 0.55367"); Assert.AreEqual(0.55367f, color.G, FloatExtensions.TOLERANCE, "G is not 0.55367");
Assert.AreEqual(1, color.B, DoubleExtensions.TOLERANCE, "B is not 1"); Assert.AreEqual(1, color.B, FloatExtensions.TOLERANCE, "B is not 1");
} }
[TestMethod] [TestMethod]
public void RGBPercentConstructorClampTest() public void RGBPercentConstructorClampTest()
{ {
Core.Color color1 = new(1.1, 1.1, 1.1); Core.Color color1 = new(1.1f, 1.1f, 1.1f);
Assert.AreEqual(1, color1.A, "A is not 1"); Assert.AreEqual(1, color1.A, "A is not 1");
Assert.AreEqual(1, color1.R, "R is not 1"); Assert.AreEqual(1, color1.R, "R is not 1");
Assert.AreEqual(1, color1.G, "G is not 1"); Assert.AreEqual(1, color1.G, "G is not 1");
Assert.AreEqual(1, color1.B, "B is not 1"); Assert.AreEqual(1, color1.B, "B is not 1");
Core.Color color2 = new(-1.0, -1.0, -1.0); Core.Color color2 = new(-1.0f, -1.0f, -1.0f);
Assert.AreEqual(1, color2.A, "A is not 1"); Assert.AreEqual(1, color2.A, "A is not 1");
Assert.AreEqual(0, color2.R, "R is not 0"); Assert.AreEqual(0, color2.R, "R is not 0");
@ -261,14 +261,14 @@ namespace RGB.NET.Core.Tests.Color
[TestMethod] [TestMethod]
public void ARGBPercentConstructorClampTest() public void ARGBPercentConstructorClampTest()
{ {
Core.Color color1 = new(1.1, 1.1, 1.1, 1.1); Core.Color color1 = new(1.1f, 1.1f, 1.1f, 1.1f);
Assert.AreEqual(1, color1.A, "A is not 1"); Assert.AreEqual(1, color1.A, "A is not 1");
Assert.AreEqual(1, color1.R, "R is not 1"); Assert.AreEqual(1, color1.R, "R is not 1");
Assert.AreEqual(1, color1.G, "G is not 1"); Assert.AreEqual(1, color1.G, "G is not 1");
Assert.AreEqual(1, color1.B, "B is not 1"); Assert.AreEqual(1, color1.B, "B is not 1");
Core.Color color2 = new(-1.0, -1.0, -1.0, -1.0); Core.Color color2 = new(-1.0f, -1.0f, -1.0f, -1.0f);
Assert.AreEqual(0, color2.A, "A is not 0"); Assert.AreEqual(0, color2.A, "A is not 0");
Assert.AreEqual(0, color2.R, "R is not 0"); Assert.AreEqual(0, color2.R, "R is not 0");

View File

@ -12,55 +12,55 @@ namespace RGB.NET.Core.Tests.Color
[TestMethod] [TestMethod]
public void AddHueTest() public void AddHueTest()
{ {
Core.Color baseColor = HSVColor.Create(180, 0.5, 0.5); Core.Color baseColor = HSVColor.Create(180, 0.5f, 0.5f);
Core.Color result = baseColor.AddHSV(hue: 30); Core.Color result = baseColor.AddHSV(hue: 30);
Assert.AreEqual(HSVColor.Create(210, 0.5, 0.5), result); Assert.AreEqual(HSVColor.Create(210, 0.5f, 0.5f), result);
} }
[TestMethod] [TestMethod]
public void AddHueWrapTest() public void AddHueWrapTest()
{ {
Core.Color baseColor = HSVColor.Create(180, 0.5, 0.5); Core.Color baseColor = HSVColor.Create(180, 0.5f, 0.5f);
Core.Color result = baseColor.AddHSV(hue: 220); Core.Color result = baseColor.AddHSV(hue: 220);
Assert.AreEqual(HSVColor.Create(40, 0.5, 0.5), result); Assert.AreEqual(HSVColor.Create(40, 0.5f, 0.5f), result);
} }
[TestMethod] [TestMethod]
public void AddSaturationTest() public void AddSaturationTest()
{ {
Core.Color baseColor = HSVColor.Create(180, 0.5, 0.5); Core.Color baseColor = HSVColor.Create(180, 0.5f, 0.5f);
Core.Color result = baseColor.AddHSV(saturation: 0.3); Core.Color result = baseColor.AddHSV(saturation: 0.3f);
Assert.AreEqual(HSVColor.Create(180, 0.8, 0.5), result); Assert.AreEqual(HSVColor.Create(180, 0.8f, 0.5f), result);
} }
[TestMethod] [TestMethod]
public void AddSaturationClampTest() public void AddSaturationClampTest()
{ {
Core.Color baseColor = HSVColor.Create(180, 0.5, 0.5); Core.Color baseColor = HSVColor.Create(180, 0.5f, 0.5f);
Core.Color result = baseColor.AddHSV(saturation: 0.8); Core.Color result = baseColor.AddHSV(saturation: 0.8f);
Assert.AreEqual(HSVColor.Create(180, 1.0, 0.5), result); Assert.AreEqual(HSVColor.Create(180, 1.0f, 0.5f), result);
} }
[TestMethod] [TestMethod]
public void AddValueTest() public void AddValueTest()
{ {
Core.Color baseColor = HSVColor.Create(180, 0.5, 0.5); Core.Color baseColor = HSVColor.Create(180, 0.5f, 0.5f);
Core.Color result = baseColor.AddHSV(value: 0.3); Core.Color result = baseColor.AddHSV(value: 0.3f);
Assert.AreEqual(HSVColor.Create(180, 0.5, 0.8), result); Assert.AreEqual(HSVColor.Create(180, 0.5f, 0.8f), result);
} }
[TestMethod] [TestMethod]
public void AddValueClampTest() public void AddValueClampTest()
{ {
Core.Color baseColor = HSVColor.Create(180, 0.5, 0.5); Core.Color baseColor = HSVColor.Create(180, 0.5f, 0.5f);
Core.Color result = baseColor.AddHSV(value: 0.8); Core.Color result = baseColor.AddHSV(value: 0.8f);
Assert.AreEqual(HSVColor.Create(180, 0.5, 1.0), result); Assert.AreEqual(HSVColor.Create(180, 0.5f, 1.0f), result);
} }
#endregion #endregion
@ -70,55 +70,55 @@ namespace RGB.NET.Core.Tests.Color
[TestMethod] [TestMethod]
public void SubtractHueTest() public void SubtractHueTest()
{ {
Core.Color baseColor = HSVColor.Create(180, 0.5, 0.5); Core.Color baseColor = HSVColor.Create(180, 0.5f, 0.5f);
Core.Color result = baseColor.SubtractHSV(hue: 30); Core.Color result = baseColor.SubtractHSV(hue: 30);
Assert.AreEqual(HSVColor.Create(150, 0.5, 0.5), result); Assert.AreEqual(HSVColor.Create(150, 0.5f, 0.5f), result);
} }
[TestMethod] [TestMethod]
public void SubtractHueWrapTest() public void SubtractHueWrapTest()
{ {
Core.Color baseColor = HSVColor.Create(180, 0.5, 0.5); Core.Color baseColor = HSVColor.Create(180, 0.5f, 0.5f);
Core.Color result = baseColor.SubtractHSV(hue: 220); Core.Color result = baseColor.SubtractHSV(hue: 220);
Assert.AreEqual(HSVColor.Create(320, 0.5, 0.5), result); Assert.AreEqual(HSVColor.Create(320, 0.5f, 0.5f), result);
} }
[TestMethod] [TestMethod]
public void SubtractSaturationTest() public void SubtractSaturationTest()
{ {
Core.Color baseColor = HSVColor.Create(180, 0.5, 0.5); Core.Color baseColor = HSVColor.Create(180, 0.5f, 0.5f);
Core.Color result = baseColor.SubtractHSV(saturation: 0.3); Core.Color result = baseColor.SubtractHSV(saturation: 0.3f);
Assert.AreEqual(HSVColor.Create(180, 0.2, 0.5), result); Assert.AreEqual(HSVColor.Create(180, 0.2f, 0.5f), result);
} }
[TestMethod] [TestMethod]
public void SubtractSaturationClampTest() public void SubtractSaturationClampTest()
{ {
Core.Color baseColor = HSVColor.Create(180, 0.5, 0.5); Core.Color baseColor = HSVColor.Create(180, 0.5f, 0.5f);
Core.Color result = baseColor.SubtractHSV(saturation: 0.8); Core.Color result = baseColor.SubtractHSV(saturation: 0.8f);
Assert.AreEqual(HSVColor.Create(180, 0, 0.5), result); Assert.AreEqual(HSVColor.Create(180, 0, 0.5f), result);
} }
[TestMethod] [TestMethod]
public void SubtractValueTest() public void SubtractValueTest()
{ {
Core.Color baseColor = HSVColor.Create(180, 0.5, 0.5); Core.Color baseColor = HSVColor.Create(180, 0.5f, 0.5f);
Core.Color result = baseColor.SubtractHSV(value: 0.3); Core.Color result = baseColor.SubtractHSV(value: 0.3f);
Assert.AreEqual(HSVColor.Create(180, 0.5, 0.2), result); Assert.AreEqual(HSVColor.Create(180, 0.5f, 0.2f), result);
} }
[TestMethod] [TestMethod]
public void SubtractValueClampTest() public void SubtractValueClampTest()
{ {
Core.Color baseColor = HSVColor.Create(180, 0.5, 0.5); Core.Color baseColor = HSVColor.Create(180, 0.5f, 0.5f);
Core.Color result = baseColor.SubtractHSV(value: .8); Core.Color result = baseColor.SubtractHSV(value: 0.8f);
Assert.AreEqual(HSVColor.Create(180, 0.5, 0), result); Assert.AreEqual(HSVColor.Create(180, 0.5f, 0), result);
} }
#endregion #endregion
@ -128,55 +128,55 @@ namespace RGB.NET.Core.Tests.Color
[TestMethod] [TestMethod]
public void MultiplyHueTest() public void MultiplyHueTest()
{ {
Core.Color baseColor = HSVColor.Create(180, 0.5, 0.5); Core.Color baseColor = HSVColor.Create(180, 0.5f, 0.5f);
Core.Color result = baseColor.MultiplyHSV(hue: 1.5); Core.Color result = baseColor.MultiplyHSV(hue: 1.5f);
Assert.AreEqual(HSVColor.Create(270, 0.5, 0.5), result); Assert.AreEqual(HSVColor.Create(270, 0.5f, 0.5f), result);
} }
[TestMethod] [TestMethod]
public void MultiplyHueWrapTest() public void MultiplyHueWrapTest()
{ {
Core.Color baseColor = HSVColor.Create(180, 0.5, 0.5); Core.Color baseColor = HSVColor.Create(180, 0.5f, 0.5f);
Core.Color result = baseColor.MultiplyHSV(hue: 3); Core.Color result = baseColor.MultiplyHSV(hue: 3);
Assert.AreEqual(HSVColor.Create(180, 0.5, 0.5), result); Assert.AreEqual(HSVColor.Create(180, 0.5f, 0.5f), result);
} }
[TestMethod] [TestMethod]
public void MultiplySaturationTest() public void MultiplySaturationTest()
{ {
Core.Color baseColor = HSVColor.Create(180, 0.2, 0.2); Core.Color baseColor = HSVColor.Create(180, 0.2f, 0.2f);
Core.Color result = baseColor.MultiplyHSV(saturation: 3); Core.Color result = baseColor.MultiplyHSV(saturation: 3);
Assert.AreEqual(HSVColor.Create(180, 0.6, 0.2), result); Assert.AreEqual(HSVColor.Create(180,0.6f, 0.2f), result);
} }
[TestMethod] [TestMethod]
public void MultiplySaturationClampTest() public void MultiplySaturationClampTest()
{ {
Core.Color baseColor = HSVColor.Create(180, 0.5, 0.5); Core.Color baseColor = HSVColor.Create(180, 0.5f, 0.5f);
Core.Color result = baseColor.MultiplyHSV(saturation: 3); Core.Color result = baseColor.MultiplyHSV(saturation: 3);
Assert.AreEqual(HSVColor.Create(180, 1.0, 0.5), result); Assert.AreEqual(HSVColor.Create(180, 1.0f, 0.5f), result);
} }
[TestMethod] [TestMethod]
public void MultiplyValueTest() public void MultiplyValueTest()
{ {
Core.Color baseColor = HSVColor.Create(180, 0.2, 0.2); Core.Color baseColor = HSVColor.Create(180, 0.2f, 0.2f);
Core.Color result = baseColor.MultiplyHSV(value: 3); Core.Color result = baseColor.MultiplyHSV(value: 3);
Assert.AreEqual(HSVColor.Create(180, 0.2, 0.6), result); Assert.AreEqual(HSVColor.Create(180, 0.2f,0.6f), result);
} }
[TestMethod] [TestMethod]
public void MultiplyValueClampTest() public void MultiplyValueClampTest()
{ {
Core.Color baseColor = HSVColor.Create(180, 0.5, 0.5); Core.Color baseColor = HSVColor.Create(180, 0.5f, 0.5f);
Core.Color result = baseColor.MultiplyHSV(value: 3); Core.Color result = baseColor.MultiplyHSV(value: 3);
Assert.AreEqual(HSVColor.Create(180, 0.5, 1.0), result); Assert.AreEqual(HSVColor.Create(180, 0.5f, 1.0f), result);
} }
#endregion #endregion
@ -186,28 +186,28 @@ namespace RGB.NET.Core.Tests.Color
[TestMethod] [TestMethod]
public void DivideHueTest() public void DivideHueTest()
{ {
Core.Color baseColor = HSVColor.Create(180, 0.5, 0.5); Core.Color baseColor = HSVColor.Create(180, 0.5f, 0.5f);
Core.Color result = baseColor.DivideHSV(hue: 30); Core.Color result = baseColor.DivideHSV(hue: 30);
Assert.AreEqual(HSVColor.Create(6, 0.5, 0.5), result); Assert.AreEqual(HSVColor.Create(6, 0.5f, 0.5f), result);
} }
[TestMethod] [TestMethod]
public void DivideSaturationTest() public void DivideSaturationTest()
{ {
Core.Color baseColor = HSVColor.Create(180, 0.6, 0.6); Core.Color baseColor = HSVColor.Create(180,0.6f,0.6f);
Core.Color result = baseColor.DivideHSV(saturation: 2); Core.Color result = baseColor.DivideHSV(saturation: 2);
Assert.AreEqual(HSVColor.Create(180, 0.3, 0.6), result); Assert.AreEqual(HSVColor.Create(180, 0.3f,0.6f), result);
} }
[TestMethod] [TestMethod]
public void DivideValueTest() public void DivideValueTest()
{ {
Core.Color baseColor = HSVColor.Create(180, 0.6, 0.6); Core.Color baseColor = HSVColor.Create(180,0.6f,0.6f);
Core.Color result = baseColor.DivideHSV(value: 2); Core.Color result = baseColor.DivideHSV(value: 2);
Assert.AreEqual(HSVColor.Create(180, 0.6, 0.3), result); Assert.AreEqual(HSVColor.Create(180,0.6f, 0.3f), result);
} }
#endregion #endregion
@ -217,64 +217,64 @@ namespace RGB.NET.Core.Tests.Color
[TestMethod] [TestMethod]
public void SetHueTest() public void SetHueTest()
{ {
Core.Color baseColor = HSVColor.Create(180, 0.5, 0.5); Core.Color baseColor = HSVColor.Create(180, 0.5f, 0.5f);
Core.Color result = baseColor.SetHSV(hue: 30); Core.Color result = baseColor.SetHSV(hue: 30);
Assert.AreEqual(HSVColor.Create(30, 0.5, 0.5), result); Assert.AreEqual(HSVColor.Create(30, 0.5f, 0.5f), result);
} }
[TestMethod] [TestMethod]
public void SetHueWrapTest() public void SetHueWrapTest()
{ {
Core.Color baseColor = HSVColor.Create(180, 0.5, 0.5); Core.Color baseColor = HSVColor.Create(180, 0.5f, 0.5f);
Core.Color result = baseColor.SetHSV(hue: 440); Core.Color result = baseColor.SetHSV(hue: 440);
Assert.AreEqual(HSVColor.Create(80, 0.5, 0.5), result); Assert.AreEqual(HSVColor.Create(80, 0.5f, 0.5f), result);
} }
[TestMethod] [TestMethod]
public void SetHueWrapNegativeTest() public void SetHueWrapNegativeTest()
{ {
Core.Color baseColor = HSVColor.Create(180, 0.5, 0.5); Core.Color baseColor = HSVColor.Create(180, 0.5f, 0.5f);
Core.Color result = baseColor.SetHSV(hue: -30); Core.Color result = baseColor.SetHSV(hue: -30);
Assert.AreEqual(HSVColor.Create(330, 0.5, 0.5), result); Assert.AreEqual(HSVColor.Create(330, 0.5f, 0.5f), result);
} }
[TestMethod] [TestMethod]
public void SetSaturationTest() public void SetSaturationTest()
{ {
Core.Color baseColor = HSVColor.Create(180, 0.5, 0.5); Core.Color baseColor = HSVColor.Create(180, 0.5f, 0.5f);
Core.Color result = baseColor.SetHSV(saturation: 0.3); Core.Color result = baseColor.SetHSV(saturation: 0.3f);
Assert.AreEqual(HSVColor.Create(180, 0.3, 0.5), result); Assert.AreEqual(HSVColor.Create(180, 0.3f, 0.5f), result);
} }
[TestMethod] [TestMethod]
public void SetSaturationClampTest() public void SetSaturationClampTest()
{ {
Core.Color baseColor = HSVColor.Create(180, 0.5, 0.5); Core.Color baseColor = HSVColor.Create(180, 0.5f, 0.5f);
Core.Color result = baseColor.SetHSV(saturation: 2); Core.Color result = baseColor.SetHSV(saturation: 2);
Assert.AreEqual(HSVColor.Create(180, 1.0, 0.5), result); Assert.AreEqual(HSVColor.Create(180, 1.0f, 0.5f), result);
} }
[TestMethod] [TestMethod]
public void SetValueTest() public void SetValueTest()
{ {
Core.Color baseColor = HSVColor.Create(180, 0.5, 0.5); Core.Color baseColor = HSVColor.Create(180, 0.5f, 0.5f);
Core.Color result = baseColor.SetHSV(value: 0.3); Core.Color result = baseColor.SetHSV(value: 0.3f);
Assert.AreEqual(HSVColor.Create(180, 0.5, 0.3), result); Assert.AreEqual(HSVColor.Create(180, 0.5f, 0.3f), result);
} }
[TestMethod] [TestMethod]
public void SetValueClampTest() public void SetValueClampTest()
{ {
Core.Color baseColor = HSVColor.Create(180, 0.5, 0.5); Core.Color baseColor = HSVColor.Create(180, 0.5f, 0.5f);
Core.Color result = baseColor.SetHSV(value: 2); Core.Color result = baseColor.SetHSV(value: 2);
Assert.AreEqual(HSVColor.Create(180, 0.5, 1.0), result); Assert.AreEqual(HSVColor.Create(180, 0.5f, 1.0f), result);
} }
#endregion #endregion

View File

@ -30,19 +30,19 @@ namespace RGB.NET.Core.Tests.Color
[TestMethod] [TestMethod]
public void BlendUpTest() public void BlendUpTest()
{ {
Core.Color baseColor = new(0.0, 0.0, 0.0); Core.Color baseColor = new(0.0f, 0.0f, 0.0f);
Core.Color blendColor = new(0.5, 1.0, 1.0, 1.0); Core.Color blendColor = new(0.5f, 1.0f, 1.0f, 1.0f);
Assert.AreEqual(new Core.Color(0.5, 0.5, 0.5), baseColor.Blend(blendColor)); Assert.AreEqual(new Core.Color(0.5f, 0.5f, 0.5f), baseColor.Blend(blendColor));
} }
[TestMethod] [TestMethod]
public void BlendDownTest() public void BlendDownTest()
{ {
Core.Color baseColor = new(1.0, 1.0, 1.0); Core.Color baseColor = new(1.0f, 1.0f, 1.0f);
Core.Color blendColor = new(0.5, 0.0, 0.0, 0.0); Core.Color blendColor = new(0.5f, 0.0f, 0.0f, 0.0f);
Assert.AreEqual(new Core.Color(0.5, 0.5, 0.5), baseColor.Blend(blendColor)); Assert.AreEqual(new Core.Color(0.5f, 0.5f, 0.5f), baseColor.Blend(blendColor));
} }
#endregion #endregion
@ -61,10 +61,10 @@ namespace RGB.NET.Core.Tests.Color
[TestMethod] [TestMethod]
public void AddRGBPercentTest() public void AddRGBPercentTest()
{ {
Core.Color baseColor = new(0.5, 0.5, 0.5, 0.5); Core.Color baseColor = new(0.5f, 0.5f, 0.5f, 0.5f);
Core.Color result = baseColor.AddRGB(0.2, 0.3, 0.4); Core.Color result = baseColor.AddRGB(0.2f, 0.3f, 0.4f);
Assert.AreEqual(new Core.Color(0.5, 0.7, 0.8, 0.9), result); Assert.AreEqual(new Core.Color(0.5f, 0.7f, 0.8f, 0.9f), result);
} }
[TestMethod] [TestMethod]
@ -79,10 +79,10 @@ namespace RGB.NET.Core.Tests.Color
[TestMethod] [TestMethod]
public void AddAPercentTest() public void AddAPercentTest()
{ {
Core.Color baseColor = new(0.5, 0.5, 0.5, 0.5); Core.Color baseColor = new(0.5f, 0.5f, 0.5f, 0.5f);
Core.Color result = baseColor.AddA(0.1); Core.Color result = baseColor.AddA(0.1f);
Assert.AreEqual(new Core.Color(0.6, 0.5, 0.5, 0.5), result); Assert.AreEqual(new Core.Color(0.6f, 0.5f, 0.5f, 0.5f), result);
} }
[TestMethod] [TestMethod]
@ -97,10 +97,10 @@ namespace RGB.NET.Core.Tests.Color
[TestMethod] [TestMethod]
public void AddRPercentTest() public void AddRPercentTest()
{ {
Core.Color baseColor = new(0.5, 0.5, 0.5, 0.5); Core.Color baseColor = new(0.5f, 0.5f, 0.5f, 0.5f);
Core.Color result = baseColor.AddRGB(r: 0.1); Core.Color result = baseColor.AddRGB(r: 0.1f);
Assert.AreEqual(new Core.Color(0.5, 0.6, 0.5, 0.5), result); Assert.AreEqual(new Core.Color(0.5f, 0.6f, 0.5f, 0.5f), result);
} }
[TestMethod] [TestMethod]
@ -115,10 +115,10 @@ namespace RGB.NET.Core.Tests.Color
[TestMethod] [TestMethod]
public void AddGPercentTest() public void AddGPercentTest()
{ {
Core.Color baseColor = new(0.5, 0.5, 0.5, 0.5); Core.Color baseColor = new(0.5f, 0.5f, 0.5f, 0.5f);
Core.Color result = baseColor.AddRGB(g: 0.1); Core.Color result = baseColor.AddRGB(g: 0.1f);
Assert.AreEqual(new Core.Color(0.5, 0.5, 0.6, 0.5), result); Assert.AreEqual(new Core.Color(0.5f, 0.5f, 0.6f, 0.5f), result);
} }
[TestMethod] [TestMethod]
@ -133,10 +133,10 @@ namespace RGB.NET.Core.Tests.Color
[TestMethod] [TestMethod]
public void AddBPercentTest() public void AddBPercentTest()
{ {
Core.Color baseColor = new(0.5, 0.5, 0.5, 0.5); Core.Color baseColor = new(0.5f, 0.5f, 0.5f, 0.5f);
Core.Color result = baseColor.AddRGB(b: 0.1); Core.Color result = baseColor.AddRGB(b: 0.1f);
Assert.AreEqual(new Core.Color(0.5, 0.5, 0.5, 0.6), result); Assert.AreEqual(new Core.Color(0.5f, 0.5f, 0.5f, 0.6f), result);
} }
#endregion #endregion
@ -155,10 +155,10 @@ namespace RGB.NET.Core.Tests.Color
[TestMethod] [TestMethod]
public void SubtractRGBPercentTest() public void SubtractRGBPercentTest()
{ {
Core.Color baseColor = new(0.5, 0.5, 0.5, 0.5); Core.Color baseColor = new(0.5f, 0.5f, 0.5f, 0.5f);
Core.Color result = baseColor.SubtractRGB(0.2, 0.3, 0.4); Core.Color result = baseColor.SubtractRGB(0.2f, 0.3f, 0.4f);
Assert.AreEqual(new Core.Color(0.5, 0.3, 0.2, 0.1), result); Assert.AreEqual(new Core.Color(0.5f, 0.3f, 0.2f, 0.1f), result);
} }
[TestMethod] [TestMethod]
@ -173,10 +173,10 @@ namespace RGB.NET.Core.Tests.Color
[TestMethod] [TestMethod]
public void SubtractAPercentTest() public void SubtractAPercentTest()
{ {
Core.Color baseColor = new(0.5, 0.5, 0.5, 0.5); Core.Color baseColor = new(0.5f, 0.5f, 0.5f, 0.5f);
Core.Color result = baseColor.SubtractA(0.1); Core.Color result = baseColor.SubtractA(0.1f);
Assert.AreEqual(new Core.Color(0.4, 0.5, 0.5, 0.5), result); Assert.AreEqual(new Core.Color(0.4f, 0.5f, 0.5f, 0.5f), result);
} }
[TestMethod] [TestMethod]
@ -191,10 +191,10 @@ namespace RGB.NET.Core.Tests.Color
[TestMethod] [TestMethod]
public void SubtractRPercentTest() public void SubtractRPercentTest()
{ {
Core.Color baseColor = new(0.5, 0.5, 0.5, 0.5); Core.Color baseColor = new(0.5f, 0.5f, 0.5f, 0.5f);
Core.Color result = baseColor.SubtractRGB(r: 0.1); Core.Color result = baseColor.SubtractRGB(r: 0.1f);
Assert.AreEqual(new Core.Color(0.5, 0.4, 0.5, 0.5), result); Assert.AreEqual(new Core.Color(0.5f, 0.4f, 0.5f, 0.5f), result);
} }
[TestMethod] [TestMethod]
@ -209,10 +209,10 @@ namespace RGB.NET.Core.Tests.Color
[TestMethod] [TestMethod]
public void SubtractGPercentTest() public void SubtractGPercentTest()
{ {
Core.Color baseColor = new(0.5, 0.5, 0.5, 0.5); Core.Color baseColor = new(0.5f, 0.5f, 0.5f, 0.5f);
Core.Color result = baseColor.SubtractRGB(g: 0.1); Core.Color result = baseColor.SubtractRGB(g: 0.1f);
Assert.AreEqual(new Core.Color(0.5, 0.5, 0.4, 0.5), result); Assert.AreEqual(new Core.Color(0.5f, 0.5f, 0.4f, 0.5f), result);
} }
[TestMethod] [TestMethod]
@ -227,10 +227,10 @@ namespace RGB.NET.Core.Tests.Color
[TestMethod] [TestMethod]
public void SubtractBPercentTest() public void SubtractBPercentTest()
{ {
Core.Color baseColor = new(0.5, 0.5, 0.5, 0.5); Core.Color baseColor = new(0.5f, 0.5f, 0.5f, 0.5f);
Core.Color result = baseColor.SubtractRGB(b: 0.1); Core.Color result = baseColor.SubtractRGB(b: 0.1f);
Assert.AreEqual(new Core.Color(0.5, 0.5, 0.5, 0.4), result); Assert.AreEqual(new Core.Color(0.5f, 0.5f, 0.5f, 0.4f), result);
} }
#endregion #endregion
@ -240,46 +240,46 @@ namespace RGB.NET.Core.Tests.Color
[TestMethod] [TestMethod]
public void MultiplyRGBPercentTest() public void MultiplyRGBPercentTest()
{ {
Core.Color baseColor = new(0.2, 0.2, 0.2, 0.2); Core.Color baseColor = new(0.2f, 0.2f, 0.2f, 0.2f);
Core.Color result = baseColor.MultiplyRGB(3, 4, 5); Core.Color result = baseColor.MultiplyRGB(3, 4, 5);
Assert.AreEqual(new Core.Color(0.2, 0.6, 0.8, 1.0), result); Assert.AreEqual(new Core.Color(0.2f, 0.6f, 0.8f, 1.0f), result);
} }
[TestMethod] [TestMethod]
public void MultiplyAPercentTest() public void MultiplyAPercentTest()
{ {
Core.Color baseColor = new(0.2, 0.2, 0.2, 0.2); Core.Color baseColor = new(0.2f, 0.2f, 0.2f, 0.2f);
Core.Color result = baseColor.MultiplyA(3); Core.Color result = baseColor.MultiplyA(3);
Assert.AreEqual(new Core.Color(0.6, 0.2, 0.2, 0.2), result); Assert.AreEqual(new Core.Color(0.6f, 0.2f, 0.2f, 0.2f), result);
} }
[TestMethod] [TestMethod]
public void MultiplyRPercentTest() public void MultiplyRPercentTest()
{ {
Core.Color baseColor = new(0.2, 0.2, 0.2, 0.2); Core.Color baseColor = new(0.2f, 0.2f, 0.2f, 0.2f);
Core.Color result = baseColor.MultiplyRGB(r: 3); Core.Color result = baseColor.MultiplyRGB(r: 3);
Assert.AreEqual(new Core.Color(0.2, 0.6, 0.2, 0.2), result); Assert.AreEqual(new Core.Color(0.2f, 0.6f, 0.2f, 0.2f), result);
} }
[TestMethod] [TestMethod]
public void MultiplyGPercentTest() public void MultiplyGPercentTest()
{ {
Core.Color baseColor = new(0.2, 0.2, 0.2, 0.2); Core.Color baseColor = new(0.2f, 0.2f, 0.2f, 0.2f);
Core.Color result = baseColor.MultiplyRGB(g: 3); Core.Color result = baseColor.MultiplyRGB(g: 3);
Assert.AreEqual(new Core.Color(0.2, 0.2, 0.6, 0.2), result); Assert.AreEqual(new Core.Color(0.2f, 0.2f, 0.6f, 0.2f), result);
} }
[TestMethod] [TestMethod]
public void MultiplyBPercentTest() public void MultiplyBPercentTest()
{ {
Core.Color baseColor = new(0.2, 0.2, 0.2, 0.2); Core.Color baseColor = new(0.2f, 0.2f, 0.2f, 0.2f);
Core.Color result = baseColor.MultiplyRGB(b: 3); Core.Color result = baseColor.MultiplyRGB(b: 3);
Assert.AreEqual(new Core.Color(0.2, 0.2, 0.2, 0.6), result); Assert.AreEqual(new Core.Color(0.2f, 0.2f, 0.2f, 0.6f), result);
} }
#endregion #endregion
@ -289,46 +289,46 @@ namespace RGB.NET.Core.Tests.Color
[TestMethod] [TestMethod]
public void DivideRGBPercentTest() public void DivideRGBPercentTest()
{ {
Core.Color baseColor = new(0.2, 0.6, 0.8, 1.0); Core.Color baseColor = new(0.2f, 0.6f, 0.8f, 1.0f);
Core.Color result = baseColor.DivideRGB(3, 4, 5); Core.Color result = baseColor.DivideRGB(3, 4, 5);
Assert.AreEqual(new Core.Color(0.2, 0.2, 0.2, 0.2), result); Assert.AreEqual(new Core.Color(0.2f, 0.2f, 0.2f, 0.2f), result);
} }
[TestMethod] [TestMethod]
public void DivideAPercentTest() public void DivideAPercentTest()
{ {
Core.Color baseColor = new(0.6, 0.2, 0.2, 0.2); Core.Color baseColor = new(0.6f, 0.2f, 0.2f, 0.2f);
Core.Color result = baseColor.DivideA(3); Core.Color result = baseColor.DivideA(3);
Assert.AreEqual(new Core.Color(0.2, 0.2, 0.2, 0.2), result); Assert.AreEqual(new Core.Color(0.2f, 0.2f, 0.2f, 0.2f), result);
} }
[TestMethod] [TestMethod]
public void DivideRPercentTest() public void DivideRPercentTest()
{ {
Core.Color baseColor = new(0.2, 0.6, 0.2, 0.2); Core.Color baseColor = new(0.2f, 0.6f, 0.2f, 0.2f);
Core.Color result = baseColor.DivideRGB(r: 3); Core.Color result = baseColor.DivideRGB(r: 3);
Assert.AreEqual(new Core.Color(0.2, 0.2, 0.2, 0.2), result); Assert.AreEqual(new Core.Color(0.2f, 0.2f, 0.2f, 0.2f), result);
} }
[TestMethod] [TestMethod]
public void DivideGPercentTest() public void DivideGPercentTest()
{ {
Core.Color baseColor = new(0.2, 0.2, 0.6, 0.2); Core.Color baseColor = new(0.2f, 0.2f, 0.6f, 0.2f);
Core.Color result = baseColor.DivideRGB(g: 3); Core.Color result = baseColor.DivideRGB(g: 3);
Assert.AreEqual(new Core.Color(0.2, 0.2, 0.2, 0.2), result); Assert.AreEqual(new Core.Color(0.2f, 0.2f, 0.2f, 0.2f), result);
} }
[TestMethod] [TestMethod]
public void DivideBPercentTest() public void DivideBPercentTest()
{ {
Core.Color baseColor = new(0.2, 0.2, 0.2, 0.6); Core.Color baseColor = new(0.2f, 0.2f, 0.2f, 0.6f);
Core.Color result = baseColor.DivideRGB(b: 3); Core.Color result = baseColor.DivideRGB(b: 3);
Assert.AreEqual(new Core.Color(0.2, 0.2, 0.2, 0.2), result); Assert.AreEqual(new Core.Color(0.2f, 0.2f, 0.2f, 0.2f), result);
} }
#endregion #endregion
@ -347,10 +347,10 @@ namespace RGB.NET.Core.Tests.Color
[TestMethod] [TestMethod]
public void SetRGBPercentTest() public void SetRGBPercentTest()
{ {
Core.Color baseColor = new(0.5, 0.5, 0.5, 0.5); Core.Color baseColor = new(0.5f, 0.5f, 0.5f, 0.5f);
Core.Color result = baseColor.SetRGB(0.2, 0.3, 0.4); Core.Color result = baseColor.SetRGB(0.2f, 0.3f, 0.4f);
Assert.AreEqual(new Core.Color(0.5, 0.2, 0.3, 0.4), result); Assert.AreEqual(new Core.Color(0.5f, 0.2f, 0.3f, 0.4f), result);
} }
[TestMethod] [TestMethod]
@ -365,10 +365,10 @@ namespace RGB.NET.Core.Tests.Color
[TestMethod] [TestMethod]
public void SetAPercentTest() public void SetAPercentTest()
{ {
Core.Color baseColor = new(0.5, 0.5, 0.5, 0.5); Core.Color baseColor = new(0.5f, 0.5f, 0.5f, 0.5f);
Core.Color result = baseColor.SetA(0.1); Core.Color result = baseColor.SetA(0.1f);
Assert.AreEqual(new Core.Color(0.1, 0.5, 0.5, 0.5), result); Assert.AreEqual(new Core.Color(0.1f, 0.5f, 0.5f, 0.5f), result);
} }
[TestMethod] [TestMethod]
@ -383,10 +383,10 @@ namespace RGB.NET.Core.Tests.Color
[TestMethod] [TestMethod]
public void SetRPercentTest() public void SetRPercentTest()
{ {
Core.Color baseColor = new(0.5, 0.5, 0.5, 0.5); Core.Color baseColor = new(0.5f, 0.5f, 0.5f, 0.5f);
Core.Color result = baseColor.SetRGB(r: 0.1); Core.Color result = baseColor.SetRGB(r: 0.1f);
Assert.AreEqual(new Core.Color(0.5, 0.1, 0.5, 0.5), result); Assert.AreEqual(new Core.Color(0.5f, 0.1f, 0.5f, 0.5f), result);
} }
[TestMethod] [TestMethod]
@ -401,10 +401,10 @@ namespace RGB.NET.Core.Tests.Color
[TestMethod] [TestMethod]
public void SetGPercentTest() public void SetGPercentTest()
{ {
Core.Color baseColor = new(0.5, 0.5, 0.5, 0.5); Core.Color baseColor = new(0.5f, 0.5f, 0.5f, 0.5f);
Core.Color result = baseColor.SetRGB(g: 0.1); Core.Color result = baseColor.SetRGB(g: 0.1f);
Assert.AreEqual(new Core.Color(0.5, 0.5, 0.1, 0.5), result); Assert.AreEqual(new Core.Color(0.5f, 0.5f, 0.1f, 0.5f), result);
} }
[TestMethod] [TestMethod]
@ -419,10 +419,10 @@ namespace RGB.NET.Core.Tests.Color
[TestMethod] [TestMethod]
public void SetBPercentTest() public void SetBPercentTest()
{ {
Core.Color baseColor = new(0.5, 0.5, 0.5, 0.5); Core.Color baseColor = new(0.5f, 0.5f, 0.5f, 0.5f);
Core.Color result = baseColor.SetRGB(b: 0.1); Core.Color result = baseColor.SetRGB(b: 0.1f);
Assert.AreEqual(new Core.Color(0.5, 0.5, 0.5, 0.1), result); Assert.AreEqual(new Core.Color(0.5f, 0.5f, 0.5f, 0.1f), result);
} }
#endregion #endregion