mirror of
https://github.com/DarthAffe/RGB.NET.git
synced 2025-12-12 17:48:31 +00:00
Changed everything to use floats instead of doubles
This commit is contained in:
parent
13afc29987
commit
b328032df0
@ -19,7 +19,7 @@
|
||||
{
|
||||
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);
|
||||
}
|
||||
|
||||
@ -50,10 +50,10 @@
|
||||
if (blendColor.A.EqualsInTolerance(1))
|
||||
return blendColor;
|
||||
|
||||
double resultA = (1.0 - ((1.0 - blendColor.A) * (1.0 - baseColor.A)));
|
||||
double resultR = (((blendColor.R * blendColor.A) / resultA) + ((baseColor.R * baseColor.A * (1.0 - blendColor.A)) / resultA));
|
||||
double resultG = (((blendColor.G * blendColor.A) / resultA) + ((baseColor.G * baseColor.A * (1.0 - blendColor.A)) / resultA));
|
||||
double resultB = (((blendColor.B * blendColor.A) / resultA) + ((baseColor.B * baseColor.A * (1.0 - blendColor.A)) / resultA));
|
||||
float resultA = (1.0f - ((1.0f - blendColor.A) * (1.0f - baseColor.A)));
|
||||
float resultR = (((blendColor.R * blendColor.A) / resultA) + ((baseColor.R * baseColor.A * (1.0f - blendColor.A)) / resultA));
|
||||
float resultG = (((blendColor.G * blendColor.A) / resultA) + ((baseColor.G * baseColor.A * (1.0f - 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);
|
||||
}
|
||||
|
||||
@ -32,22 +32,22 @@ namespace RGB.NET.Core
|
||||
/// <summary>
|
||||
/// Gets the alpha component value of this <see cref="Color"/> as percentage in the range [0..1].
|
||||
/// </summary>
|
||||
public double A { get; }
|
||||
public float A { get; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets the red component value of this <see cref="Color"/> as percentage in the range [0..1].
|
||||
/// </summary>
|
||||
public double R { get; }
|
||||
public float R { get; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets the green component value of this <see cref="Color"/> as percentage in the range [0..1].
|
||||
/// </summary>
|
||||
public double G { get; }
|
||||
public float G { get; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets the blue component value of this <see cref="Color"/> as percentage in the range [0..1].
|
||||
/// </summary>
|
||||
public double B { get; }
|
||||
public float B { get; }
|
||||
|
||||
#endregion
|
||||
|
||||
@ -106,8 +106,8 @@ namespace RGB.NET.Core
|
||||
/// <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="b">The blue component value of this <see cref="Color"/>.</param>
|
||||
public Color(double r, double g, double b)
|
||||
: this(1.0, r, g, b)
|
||||
public Color(float r, float g, float b)
|
||||
: this(1.0f, r, g, b)
|
||||
{ }
|
||||
|
||||
/// <summary>
|
||||
@ -117,7 +117,7 @@ namespace RGB.NET.Core
|
||||
/// <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="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())
|
||||
{ }
|
||||
|
||||
@ -128,7 +128,7 @@ namespace RGB.NET.Core
|
||||
/// <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="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))
|
||||
{ }
|
||||
|
||||
@ -139,7 +139,7 @@ namespace RGB.NET.Core
|
||||
/// <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="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)
|
||||
{ }
|
||||
|
||||
@ -150,7 +150,7 @@ namespace RGB.NET.Core
|
||||
/// <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="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)
|
||||
{ }
|
||||
|
||||
@ -161,7 +161,7 @@ namespace RGB.NET.Core
|
||||
/// <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="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);
|
||||
R = r.Clamp(0, 1);
|
||||
@ -269,14 +269,14 @@ namespace RGB.NET.Core
|
||||
/// </summary>
|
||||
/// <param name="components">The <see cref="ValueTuple"/> containing the components.</param>
|
||||
/// <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>
|
||||
/// Converts a <see cref="ValueTuple"/> of ARGB-components to a <see cref="Color"/>.
|
||||
/// </summary>
|
||||
/// <param name="components">The <see cref="ValueTuple"/> containing the components.</param>
|
||||
/// <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
|
||||
}
|
||||
|
||||
@ -13,21 +13,21 @@ namespace RGB.NET.Core
|
||||
/// </summary>
|
||||
/// <param name="color"></param>
|
||||
/// <returns></returns>
|
||||
public static double GetHue(this Color color) => color.GetHSV().hue;
|
||||
public static float GetHue(this Color color) => color.GetHSV().hue;
|
||||
|
||||
/// <summary>
|
||||
/// Gets the saturation component value (HSV-color space) of this <see cref="Color"/> in the range [0..1].
|
||||
/// </summary>
|
||||
/// <param name="color"></param>
|
||||
/// <returns></returns>
|
||||
public static double GetSaturation(this Color color) => color.GetHSV().saturation;
|
||||
public static float GetSaturation(this Color color) => color.GetHSV().saturation;
|
||||
|
||||
/// <summary>
|
||||
/// Gets the value component value (HSV-color space) of this <see cref="Color"/> in the range [0..1].
|
||||
/// </summary>
|
||||
/// <param name="color"></param>
|
||||
/// <returns></returns>
|
||||
public static double GetValue(this Color color) => color.GetHSV().value;
|
||||
public static float GetValue(this Color color) => color.GetHSV().value;
|
||||
|
||||
/// <summary>
|
||||
/// 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>
|
||||
/// <param name="color"></param>
|
||||
/// <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);
|
||||
|
||||
#endregion
|
||||
@ -51,9 +51,9 @@ namespace RGB.NET.Core
|
||||
/// <param name="saturation">The saturation value to add.</param>
|
||||
/// <param name="value">The value value to add.</param>
|
||||
/// <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);
|
||||
}
|
||||
|
||||
@ -64,9 +64,9 @@ namespace RGB.NET.Core
|
||||
/// <param name="saturation">The saturation value to subtract.</param>
|
||||
/// <param name="value">The value value to subtract.</param>
|
||||
/// <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);
|
||||
}
|
||||
|
||||
@ -77,9 +77,9 @@ namespace RGB.NET.Core
|
||||
/// <param name="saturation">The saturation value to multiply.</param>
|
||||
/// <param name="value">The value value to multiply.</param>
|
||||
/// <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);
|
||||
}
|
||||
|
||||
@ -90,9 +90,9 @@ namespace RGB.NET.Core
|
||||
/// <param name="saturation">The saturation value to divide.</param>
|
||||
/// <param name="value">The value value to divide.</param>
|
||||
/// <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);
|
||||
}
|
||||
|
||||
@ -103,9 +103,9 @@ namespace RGB.NET.Core
|
||||
/// <param name="saturation">The saturation value to set.</param>
|
||||
/// <param name="value">The value value to set.</param>
|
||||
/// <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);
|
||||
}
|
||||
|
||||
@ -120,8 +120,8 @@ namespace RGB.NET.Core
|
||||
/// <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>
|
||||
/// <returns>The color created from the values.</returns>
|
||||
public static Color Create(double hue, double saturation, double value)
|
||||
=> Create(1.0, hue, saturation, value);
|
||||
public static Color Create(float hue, float saturation, float value)
|
||||
=> Create(1.0f, hue, saturation, value);
|
||||
|
||||
/// <summary>
|
||||
/// 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="value">The value component value of this <see cref="Color"/>.</param>
|
||||
/// <returns>The color created from the values.</returns>
|
||||
public static Color Create(byte a, double hue, double saturation, double value)
|
||||
=> Create((double)a / byte.MaxValue, hue, saturation, value);
|
||||
public static Color Create(byte a, float hue, float saturation, float value)
|
||||
=> Create((float)a / byte.MaxValue, hue, saturation, value);
|
||||
|
||||
/// <summary>
|
||||
/// 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="value">The value component value of this <see cref="Color"/>.</param>
|
||||
/// <returns>The color created from the values.</returns>
|
||||
public static Color Create(int a, double hue, double saturation, double value)
|
||||
=> Create((double)a / byte.MaxValue, hue, saturation, value);
|
||||
public static Color Create(int a, float hue, float saturation, float value)
|
||||
=> Create((float)a / byte.MaxValue, hue, saturation, value);
|
||||
|
||||
/// <summary>
|
||||
/// 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="value">The value component value of this <see cref="Color"/>.</param>
|
||||
/// <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);
|
||||
}
|
||||
|
||||
@ -163,33 +163,33 @@ namespace RGB.NET.Core
|
||||
|
||||
#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);
|
||||
|
||||
double min = Math.Min(Math.Min(r, g), b);
|
||||
double max = Math.Max(Math.Max(r, g), b);
|
||||
float min = Math.Min(Math.Min(r, g), b);
|
||||
float max = Math.Max(Math.Max(r, g), b);
|
||||
|
||||
double hue;
|
||||
float hue;
|
||||
if (max.EqualsInTolerance(min))
|
||||
hue = 0;
|
||||
else if (max.EqualsInTolerance(r)) // r is max
|
||||
hue = (g - b) / (max - min);
|
||||
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
|
||||
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);
|
||||
|
||||
double saturation = max.EqualsInTolerance(0) ? 0 : 1.0 - (min / max);
|
||||
double value = Math.Max(r, Math.Max(g, b));
|
||||
float saturation = max.EqualsInTolerance(0) ? 0 : 1.0f - (min / max);
|
||||
float value = Math.Max(r, Math.Max(g, b));
|
||||
|
||||
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);
|
||||
s = s.Clamp(0, 1);
|
||||
@ -198,12 +198,12 @@ namespace RGB.NET.Core
|
||||
if (s <= 0.0)
|
||||
return (v, v, v);
|
||||
|
||||
double hh = h / 60.0;
|
||||
float hh = h / 60.0f;
|
||||
int i = (int)hh;
|
||||
double ff = hh - i;
|
||||
double p = v * (1.0 - s);
|
||||
double q = v * (1.0 - (s * ff));
|
||||
double t = v * (1.0 - (s * (1.0 - ff)));
|
||||
float ff = hh - i;
|
||||
float p = v * (1.0f - s);
|
||||
float q = v * (1.0f - (s * ff));
|
||||
float t = v * (1.0f - (s * (1.0f - ff)));
|
||||
|
||||
return i switch
|
||||
{
|
||||
|
||||
@ -49,7 +49,7 @@ namespace RGB.NET.Core
|
||||
/// </summary>
|
||||
/// <param name="color"></param>
|
||||
/// <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);
|
||||
|
||||
#endregion
|
||||
@ -75,7 +75,7 @@ namespace RGB.NET.Core
|
||||
/// <param name="g">The green value to add.</param>
|
||||
/// <param name="b">The blue value to add.</param>
|
||||
/// <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);
|
||||
|
||||
/// <summary>
|
||||
@ -91,7 +91,7 @@ namespace RGB.NET.Core
|
||||
/// </summary>
|
||||
/// <param name="a">The alpha value to add.</param>
|
||||
/// <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);
|
||||
|
||||
#endregion
|
||||
@ -115,7 +115,7 @@ namespace RGB.NET.Core
|
||||
/// <param name="g">The green value to subtract.</param>
|
||||
/// <param name="b">The blue value to subtract.</param>
|
||||
/// <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);
|
||||
|
||||
/// <summary>
|
||||
@ -131,7 +131,7 @@ namespace RGB.NET.Core
|
||||
/// </summary>
|
||||
/// <param name="a">The alpha value to subtract.</param>
|
||||
/// <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);
|
||||
|
||||
#endregion
|
||||
@ -145,7 +145,7 @@ namespace RGB.NET.Core
|
||||
/// <param name="g">The green value to multiply.</param>
|
||||
/// <param name="b">The blue value to multiply.</param>
|
||||
/// <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);
|
||||
|
||||
/// <summary>
|
||||
@ -153,7 +153,7 @@ namespace RGB.NET.Core
|
||||
/// </summary>
|
||||
/// <param name="a">The alpha value to multiply.</param>
|
||||
/// <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);
|
||||
|
||||
#endregion
|
||||
@ -167,7 +167,7 @@ namespace RGB.NET.Core
|
||||
/// <param name="g">The green value to divide.</param>
|
||||
/// <param name="b">The blue value to divide.</param>
|
||||
/// <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);
|
||||
|
||||
/// <summary>
|
||||
@ -175,7 +175,7 @@ namespace RGB.NET.Core
|
||||
/// </summary>
|
||||
/// <param name="a">The alpha value to divide.</param>
|
||||
/// <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);
|
||||
|
||||
#endregion
|
||||
@ -209,7 +209,7 @@ namespace RGB.NET.Core
|
||||
/// <param name="g">The green value to set.</param>
|
||||
/// <param name="b">The blue value to set.</param>
|
||||
/// <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);
|
||||
|
||||
/// <summary>
|
||||
@ -224,7 +224,7 @@ namespace RGB.NET.Core
|
||||
/// </summary>
|
||||
/// <param name="a">The alpha value to set.</param>
|
||||
/// <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
|
||||
|
||||
|
||||
@ -4,16 +4,16 @@ using System.Runtime.CompilerServices;
|
||||
namespace RGB.NET.Core
|
||||
{
|
||||
/// <summary>
|
||||
/// Offers some extensions and helper-methods for the work with doubles
|
||||
/// Offers some extensions and helper-methods for the work with floats
|
||||
/// </summary>
|
||||
public static class DoubleExtensions
|
||||
public static class FloatExtensions
|
||||
{
|
||||
#region Constants
|
||||
|
||||
/// <summary>
|
||||
/// Defines the precision RGB.NET processes floating point comparisons in.
|
||||
/// </summary>
|
||||
public const double TOLERANCE = 1E-10;
|
||||
public const float TOLERANCE = 1E-10f;
|
||||
|
||||
#endregion
|
||||
|
||||
@ -26,7 +26,7 @@ namespace RGB.NET.Core
|
||||
/// <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>
|
||||
[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>
|
||||
/// 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>
|
||||
/// <returns>The clamped value.</returns>
|
||||
[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%
|
||||
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>
|
||||
/// <returns>The wrapped value.</returns>
|
||||
[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)
|
||||
value -= range;
|
||||
@ -84,17 +84,17 @@ namespace RGB.NET.Core
|
||||
}
|
||||
|
||||
[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);
|
||||
}
|
||||
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public static double GetPercentageFromByteValue(this byte value)
|
||||
=> ((double)value) / byte.MaxValue;
|
||||
public static float GetPercentageFromByteValue(this byte value)
|
||||
=> ((float)value) / byte.MaxValue;
|
||||
|
||||
#endregion
|
||||
}
|
||||
|
||||
@ -13,7 +13,7 @@ namespace RGB.NET.Core
|
||||
/// <param name="x">The x-ammount to move.</param>
|
||||
/// <param name="y">The y-ammount to move.</param>
|
||||
/// <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>
|
||||
/// 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>
|
||||
public static Point Rotate(this Point point, Rotation rotation, Point origin = new())
|
||||
{
|
||||
double sin = Math.Sin(rotation.Radians);
|
||||
double cos = Math.Cos(rotation.Radians);
|
||||
float sin = MathF.Sin(rotation.Radians);
|
||||
float cos = MathF.Cos(rotation.Radians);
|
||||
|
||||
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));
|
||||
|
||||
@ -20,7 +20,7 @@ namespace RGB.NET.Core
|
||||
/// <param name="rect">The rectangle to modify.</param>
|
||||
/// <param name="x">The new x-location of the rectangle.</param>
|
||||
/// <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>
|
||||
/// 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="y">The new y-location of the rectangle.</param>
|
||||
/// <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>
|
||||
/// 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="width">The new width of the rectangle.</param>
|
||||
/// <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>
|
||||
/// 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="height">The new height of the rectangle.</param>
|
||||
/// <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>
|
||||
/// Calculates the percentage of intersection of a rectangle.
|
||||
/// </summary>
|
||||
/// <param name="intersectingRect">The intersecting rectangle.</param>
|
||||
/// <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;
|
||||
|
||||
@ -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>
|
||||
public static Rectangle CalculateIntersection(this Rectangle rect, in Rectangle intersectingRectangle)
|
||||
{
|
||||
double 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 x1 = Math.Max(rect.Location.X, intersectingRectangle.Location.X);
|
||||
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);
|
||||
double y2 = Math.Min(rect.Location.Y + rect.Size.Height, intersectingRectangle.Location.Y + intersectingRectangle.Size.Height);
|
||||
float y1 = Math.Max(rect.Location.Y, intersectingRectangle.Location.Y);
|
||||
float y2 = Math.Min(rect.Location.Y + rect.Size.Height, intersectingRectangle.Location.Y + intersectingRectangle.Size.Height);
|
||||
|
||||
if ((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="y">The Y-location to test.</param>
|
||||
/// <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));
|
||||
|
||||
/// <summary>
|
||||
@ -125,7 +125,7 @@ namespace RGB.NET.Core
|
||||
/// <param name="x">The x-ammount to move.</param>
|
||||
/// <param name="y">The y-ammount to move.</param>
|
||||
/// <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>
|
||||
/// 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
|
||||
};
|
||||
|
||||
double sin = Math.Sin(rotation.Radians);
|
||||
double cos = Math.Cos(rotation.Radians);
|
||||
float sin = MathF.Sin(rotation.Radians);
|
||||
float cos = MathF.Cos(rotation.Radians);
|
||||
|
||||
for (int i = 0; i < points.Length; i++)
|
||||
{
|
||||
|
||||
@ -16,7 +16,7 @@ namespace RGB.NET.Core
|
||||
/// <summary>
|
||||
/// Gets a [NaN,NaN]-Point.
|
||||
/// </summary>
|
||||
public static Point Invalid => new(double.NaN, double.NaN);
|
||||
public static Point Invalid => new(float.NaN, float.NaN);
|
||||
|
||||
#endregion
|
||||
|
||||
@ -25,12 +25,12 @@ namespace RGB.NET.Core
|
||||
/// <summary>
|
||||
/// Gets the X-position of this <see cref="Point"/>.
|
||||
/// </summary>
|
||||
public double X { get; }
|
||||
public float X { get; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets the Y-position of this <see cref="Point"/>.
|
||||
/// </summary>
|
||||
public double Y { get; }
|
||||
public float Y { get; }
|
||||
|
||||
#endregion
|
||||
|
||||
@ -41,7 +41,7 @@ namespace RGB.NET.Core
|
||||
/// </summary>
|
||||
/// <param name="x">The value used for the X-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.Y = y;
|
||||
@ -67,8 +67,8 @@ namespace RGB.NET.Core
|
||||
if (!(obj is Point)) return false;
|
||||
|
||||
Point comparePoint = (Point)obj;
|
||||
return ((double.IsNaN(X) && double.IsNaN(comparePoint.X)) || X.EqualsInTolerance(comparePoint.X))
|
||||
&& ((double.IsNaN(Y) && double.IsNaN(comparePoint.Y)) || Y.EqualsInTolerance(comparePoint.Y));
|
||||
return ((float.IsNaN(X) && float.IsNaN(comparePoint.X)) || X.EqualsInTolerance(comparePoint.X))
|
||||
&& ((float.IsNaN(Y) && float.IsNaN(comparePoint.Y)) || Y.EqualsInTolerance(comparePoint.Y));
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
|
||||
@ -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.
|
||||
/// <c>True</c> if the rectangle has a width or a height of zero; otherwise, <c>false</c>.
|
||||
/// </summary>
|
||||
public bool IsEmpty => (Size.Width <= DoubleExtensions.TOLERANCE) || (Size.Height <= DoubleExtensions.TOLERANCE);
|
||||
public bool IsEmpty => (Size.Width <= FloatExtensions.TOLERANCE) || (Size.Height <= FloatExtensions.TOLERANCE);
|
||||
|
||||
#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="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>
|
||||
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))
|
||||
{ }
|
||||
|
||||
@ -70,7 +70,7 @@ namespace RGB.NET.Core
|
||||
this.Location = location;
|
||||
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 />
|
||||
@ -91,10 +91,10 @@ namespace RGB.NET.Core
|
||||
public Rectangle(IEnumerable<Rectangle> rectangles)
|
||||
{
|
||||
bool hasPoint = false;
|
||||
double posX = double.MaxValue;
|
||||
double posY = double.MaxValue;
|
||||
double posX2 = double.MinValue;
|
||||
double posY2 = double.MinValue;
|
||||
float posX = float.MaxValue;
|
||||
float posY = float.MaxValue;
|
||||
float posX2 = float.MinValue;
|
||||
float posY2 = float.MinValue;
|
||||
|
||||
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));
|
||||
Location = location;
|
||||
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 />
|
||||
@ -131,10 +131,10 @@ namespace RGB.NET.Core
|
||||
: this()
|
||||
{
|
||||
bool hasPoint = false;
|
||||
double posX = double.MaxValue;
|
||||
double posY = double.MaxValue;
|
||||
double posX2 = double.MinValue;
|
||||
double posY2 = double.MinValue;
|
||||
float posX = float.MaxValue;
|
||||
float posY = float.MaxValue;
|
||||
float posX2 = float.MinValue;
|
||||
float posY2 = float.MinValue;
|
||||
|
||||
foreach (Point point in points)
|
||||
{
|
||||
@ -149,7 +149,7 @@ namespace RGB.NET.Core
|
||||
|
||||
Location = location;
|
||||
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
|
||||
@ -158,10 +158,10 @@ namespace RGB.NET.Core
|
||||
|
||||
private static (Point location, Size size) InitializeFromPoints(Point point1, Point point2)
|
||||
{
|
||||
double posX = Math.Min(point1.X, point2.X);
|
||||
double posY = Math.Min(point1.Y, point2.Y);
|
||||
double width = Math.Max(point1.X, point2.X) - posX;
|
||||
double height = Math.Max(point1.Y, point2.Y) - posY;
|
||||
float posX = Math.Min(point1.X, point2.X);
|
||||
float posY = Math.Min(point1.Y, point2.Y);
|
||||
float width = Math.Max(point1.X, point2.X) - posX;
|
||||
float height = Math.Max(point1.Y, point2.Y) - posY;
|
||||
|
||||
return (new Point(posX, posY), new Size(width, height));
|
||||
}
|
||||
@ -225,8 +225,8 @@ namespace RGB.NET.Core
|
||||
// DarthAffe 20.02.2021: Used for normalization
|
||||
public static Rectangle operator /(Rectangle rectangle1, Rectangle rectangle2)
|
||||
{
|
||||
double x = rectangle1.Location.X / (rectangle2.Size.Width - rectangle2.Location.X);
|
||||
double y = rectangle1.Location.Y / (rectangle2.Size.Height - rectangle2.Location.Y);
|
||||
float x = rectangle1.Location.X / (rectangle2.Size.Width - rectangle2.Location.X);
|
||||
float y = rectangle1.Location.Y / (rectangle2.Size.Height - rectangle2.Location.Y);
|
||||
Size size = rectangle1.Size / rectangle2.Size;
|
||||
return new Rectangle(new Point(x, y), size);
|
||||
}
|
||||
|
||||
@ -14,9 +14,9 @@ namespace RGB.NET.Core
|
||||
{
|
||||
#region Constants
|
||||
|
||||
private const double TWO_PI = Math.PI * 2.0;
|
||||
private const double RADIANS_DEGREES_CONVERSION = 180.0 / Math.PI;
|
||||
private const double DEGREES_RADIANS_CONVERSION = Math.PI / 180.0;
|
||||
private const float TWO_PI = MathF.PI * 2.0f;
|
||||
private const float RADIANS_DEGREES_CONVERSION = 180.0f / MathF.PI;
|
||||
private const float DEGREES_RADIANS_CONVERSION = MathF.PI / 180.0f;
|
||||
|
||||
#endregion
|
||||
|
||||
@ -25,12 +25,12 @@ namespace RGB.NET.Core
|
||||
/// <summary>
|
||||
/// Gets the angle in degrees.
|
||||
/// </summary>
|
||||
public double Degrees { get; }
|
||||
public float Degrees { get; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets the angle in radians.
|
||||
/// </summary>
|
||||
public double Radians { get; }
|
||||
public float Radians { get; }
|
||||
|
||||
/// <summary>
|
||||
/// 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.
|
||||
/// </summary>
|
||||
/// <param name="scale">The rotation in degrees.</param>
|
||||
public Rotation(double degrees)
|
||||
public Rotation(float degrees)
|
||||
: 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;
|
||||
}
|
||||
|
||||
@ -64,14 +64,14 @@ namespace RGB.NET.Core
|
||||
/// </summary>
|
||||
/// <param name="degrees">The angle in degrees.</param>
|
||||
/// <returns>The new rotation.</returns>
|
||||
public static Rotation FromDegrees(double degrees) => new(degrees);
|
||||
public static Rotation FromDegrees(float degrees) => new(degrees);
|
||||
|
||||
/// <summary>
|
||||
/// Creates a new Rotation out of the given radian-angle.
|
||||
/// </summary>
|
||||
/// <param name="degrees">The angle in radians.</param>
|
||||
/// <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>
|
||||
/// 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="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>
|
||||
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>
|
||||
/// 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="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>
|
||||
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>
|
||||
/// 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="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>
|
||||
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>
|
||||
/// 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="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>
|
||||
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>
|
||||
/// Converts a double to a <see cref="Rotation" />.
|
||||
/// Converts a float to a <see cref="Rotation" />.
|
||||
/// </summary>
|
||||
/// <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>
|
||||
/// 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>
|
||||
/// <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
|
||||
}
|
||||
|
||||
@ -16,12 +16,12 @@ namespace RGB.NET.Core
|
||||
/// <summary>
|
||||
/// Gets the horizontal scaling value.
|
||||
/// </summary>
|
||||
public double Horizontal { get; }
|
||||
public float Horizontal { get; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets the vertical scaling value.
|
||||
/// </summary>
|
||||
public double Vertical { get; }
|
||||
public float Vertical { get; }
|
||||
|
||||
#endregion
|
||||
|
||||
@ -31,7 +31,7 @@ namespace RGB.NET.Core
|
||||
/// Initializes a new instance of the <see cref="Scale"/> class using the provided values.
|
||||
/// </summary>
|
||||
/// <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>
|
||||
@ -39,7 +39,7 @@ namespace RGB.NET.Core
|
||||
/// </summary>
|
||||
/// <param name="horizontal">The value used for horizontal 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.Vertical = vertical;
|
||||
@ -74,7 +74,7 @@ namespace RGB.NET.Core
|
||||
/// </summary>
|
||||
/// <param name="horizontalScale">The horizontal 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;
|
||||
verticalScale = Vertical;
|
||||
@ -106,7 +106,7 @@ namespace RGB.NET.Core
|
||||
/// <param name="scale">The <see cref="Scale"/>.</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>
|
||||
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>
|
||||
/// 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="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>
|
||||
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>
|
||||
/// 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="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>
|
||||
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>
|
||||
/// 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="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>
|
||||
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>
|
||||
/// Converts a double to a <see cref="Scale" />.
|
||||
/// Converts a float to a <see cref="Scale" />.
|
||||
/// </summary>
|
||||
/// <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
|
||||
}
|
||||
|
||||
@ -16,7 +16,7 @@ namespace RGB.NET.Core
|
||||
/// <summary>
|
||||
/// Gets a [NaN,NaN]-Size.
|
||||
/// </summary>
|
||||
public static Size Invalid => new(double.NaN, double.NaN);
|
||||
public static Size Invalid => new(float.NaN, float.NaN);
|
||||
|
||||
#endregion
|
||||
|
||||
@ -25,12 +25,12 @@ namespace RGB.NET.Core
|
||||
/// <summary>
|
||||
/// Gets or sets the width component value of this <see cref="Size"/>.
|
||||
/// </summary>
|
||||
public double Width { get; }
|
||||
public float Width { get; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the height component value of this <see cref="Size"/>.
|
||||
/// </summary>
|
||||
public double Height { get; }
|
||||
public float Height { get; }
|
||||
|
||||
#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.
|
||||
/// </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>
|
||||
public Size(double size)
|
||||
public Size(float size)
|
||||
: this(size, size)
|
||||
{ }
|
||||
|
||||
@ -50,7 +50,7 @@ namespace RGB.NET.Core
|
||||
/// </summary>
|
||||
/// <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>
|
||||
public Size(double width, double height)
|
||||
public Size(float width, float height)
|
||||
{
|
||||
this.Width = width;
|
||||
this.Height = height;
|
||||
@ -75,9 +75,9 @@ namespace RGB.NET.Core
|
||||
{
|
||||
if (!(obj is Size size)) return false;
|
||||
|
||||
(double width, double height) = size;
|
||||
return ((double.IsNaN(Width) && double.IsNaN(width)) || Width.EqualsInTolerance(width))
|
||||
&& ((double.IsNaN(Height) && double.IsNaN(height)) || Height.EqualsInTolerance(height));
|
||||
(float width, float height) = size;
|
||||
return ((float.IsNaN(Width) && float.IsNaN(width)) || Width.EqualsInTolerance(width))
|
||||
&& ((float.IsNaN(Height) && float.IsNaN(height)) || Height.EqualsInTolerance(height));
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@ -99,7 +99,7 @@ namespace RGB.NET.Core
|
||||
/// </summary>
|
||||
/// <param name="width">The width.</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;
|
||||
height = Height;
|
||||
@ -163,7 +163,7 @@ namespace RGB.NET.Core
|
||||
/// <param name="size">The <see cref="Size"/>.</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>
|
||||
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>
|
||||
/// 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="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>
|
||||
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>
|
||||
/// Returns a new <see cref="Size"/> representing the multiplication of the <see cref="Size"/> and the given <see cref="Scale"/>.
|
||||
|
||||
@ -324,7 +324,7 @@ namespace RGB.NET.Core
|
||||
/// </summary>
|
||||
public void AlignDevices()
|
||||
{
|
||||
double posX = 0;
|
||||
float posX = 0;
|
||||
foreach (IRGBDevice device in Devices)
|
||||
{
|
||||
device.Location += new Point(posX, 0);
|
||||
|
||||
@ -23,10 +23,10 @@ namespace RGB.NET.Core
|
||||
public RenderMode CalculationMode { get; set; } = RenderMode.Relative;
|
||||
|
||||
/// <inheritdoc />
|
||||
public double Brightness { get; set; }
|
||||
public float Brightness { get; set; }
|
||||
|
||||
/// <inheritdoc />
|
||||
public double Opacity { get; set; }
|
||||
public float Opacity { get; set; }
|
||||
|
||||
#endregion
|
||||
|
||||
@ -37,7 +37,7 @@ namespace RGB.NET.Core
|
||||
/// </summary>
|
||||
/// <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>
|
||||
protected AbstractBrush(double brightness = 1, double opacity = 1)
|
||||
protected AbstractBrush(float brightness = 1, float opacity = 1)
|
||||
{
|
||||
this.Brightness = brightness;
|
||||
this.Opacity = opacity;
|
||||
|
||||
@ -24,12 +24,12 @@ namespace RGB.NET.Core
|
||||
/// <summary>
|
||||
/// Gets or sets the overall percentage brightness of the <see cref="IBrush"/>.
|
||||
/// </summary>
|
||||
double Brightness { get; set; }
|
||||
float Brightness { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the overall percentage opacity of the <see cref="IBrush"/>.
|
||||
/// </summary>
|
||||
double Opacity { get; set; }
|
||||
float Opacity { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Performs the render pass of the <see cref="IBrush"/> and calculates the raw <see cref="Color"/> for all requested <see cref="RenderTarget"/>.
|
||||
|
||||
@ -1,75 +1,36 @@
|
||||
using System;
|
||||
|
||||
namespace RGB.NET.Core
|
||||
namespace RGB.NET.Core
|
||||
{
|
||||
public class AverageSampler : ISampler
|
||||
{
|
||||
#region Properties & Fields
|
||||
|
||||
private Func<ReadOnlyMemory<Color>, int, int, int, int, Color> _sampleMethod = SampleWithoutAlpha;
|
||||
|
||||
private bool _sampleAlpha;
|
||||
public bool SampleAlpha
|
||||
{
|
||||
get => _sampleAlpha;
|
||||
set
|
||||
{
|
||||
_sampleAlpha = value;
|
||||
_sampleMethod = value ? SampleWithAlpha : SampleWithoutAlpha;
|
||||
}
|
||||
}
|
||||
public bool SampleAlpha { get; set; }
|
||||
|
||||
#endregion
|
||||
|
||||
#region Methods
|
||||
|
||||
public Color SampleColor(in ReadOnlyMemory<Color> data, int x, int y, int width, int height) => _sampleMethod(data, x, y, width, height);
|
||||
|
||||
private static Color SampleWithAlpha(ReadOnlyMemory<Color> data, int x, int y, int width, int height)
|
||||
public Color SampleColor(int x, int y, int width, int height, GetColor getColor)
|
||||
{
|
||||
ReadOnlySpan<Color> span = data.Span;
|
||||
|
||||
int maxX = x + width;
|
||||
int maxY = y + 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++)
|
||||
{
|
||||
ReadOnlySpan<Color> line = span.Slice((yPos * width) + x, width);
|
||||
foreach (Color color in line)
|
||||
for (int xPos = x; xPos < maxX; xPos++)
|
||||
{
|
||||
Color color = getColor(x, y);
|
||||
a += color.A;
|
||||
r += color.R;
|
||||
g += color.G;
|
||||
b += color.B;
|
||||
}
|
||||
}
|
||||
|
||||
if (count == 0) return Color.Transparent;
|
||||
|
||||
return new Color(a / count, 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);
|
||||
return SampleAlpha
|
||||
? new Color(a / count, r / count, g / count, b / count)
|
||||
: new Color(r / count, g / count, b / count);
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
@ -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
|
||||
{
|
||||
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);
|
||||
}
|
||||
}
|
||||
|
||||
@ -8,10 +8,10 @@ namespace RGB.NET.Devices.Corsair
|
||||
internal static Rectangle ToRectangle(this _CorsairLedPosition position)
|
||||
{
|
||||
//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;
|
||||
double height = position.height < 0.5 ? 10 : position.height;
|
||||
double posX = position.left;
|
||||
double posY = position.top;
|
||||
float width = position.width < 0.5f ? 10 : (float)position.width;
|
||||
float height = position.height < 0.5f ? 10 : (float)position.height;
|
||||
float posX = (float)position.left;
|
||||
float posY = (float)position.top;
|
||||
|
||||
return new Rectangle(posX, posY, width, height);
|
||||
}
|
||||
|
||||
@ -59,27 +59,27 @@ namespace RGB.NET.Layout
|
||||
/// Gets or sets the width of the <see cref="DeviceLayout"/>.
|
||||
/// </summary>
|
||||
[XmlElement("Width")]
|
||||
public double Width { get; set; }
|
||||
public float Width { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the height of the <see cref="DeviceLayout"/>.
|
||||
/// </summary>
|
||||
[XmlElement("Height")]
|
||||
public double Height { get; set; }
|
||||
public float Height { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the width of one 'unit' used for the calculation of led positions and sizes.
|
||||
/// </summary>
|
||||
[XmlElement("LedUnitWidth")]
|
||||
[DefaultValue(19.0)]
|
||||
public double LedUnitWidth { get; set; } = 19.0;
|
||||
public float LedUnitWidth { get; set; } = 19.0f;
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the height of one 'unit' used for the calculation of led positions and sizes.
|
||||
/// </summary>
|
||||
[XmlElement("LedUnitHeight")]
|
||||
[DefaultValue(19.0)]
|
||||
public double LedUnitHeight { get; set; } = 19.0;
|
||||
public float LedUnitHeight { get; set; } = 19.0f;
|
||||
|
||||
[XmlArray("Leds")]
|
||||
public List<LedLayout> InternalLeds { get; set; } = new();
|
||||
|
||||
@ -38,12 +38,12 @@ namespace RGB.NET.Layout
|
||||
/// <summary>
|
||||
/// Gets or sets the width of the <see cref="IDeviceLayout"/>.
|
||||
/// </summary>
|
||||
double Width { get; }
|
||||
float Width { get; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the height of the <see cref="IDeviceLayout"/>.
|
||||
/// </summary>
|
||||
double Height { get; }
|
||||
float Height { get; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets a list of <see cref="ILedLayout"/> representing all the <see cref="Led"/> of the <see cref="IDeviceLayout"/>.
|
||||
|
||||
@ -22,22 +22,22 @@ namespace RGB.NET.Layout
|
||||
/// <summary>
|
||||
/// Gets the x-position of the <see cref="LedLayout"/>.
|
||||
/// </summary>
|
||||
double X { get; }
|
||||
float X { get; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets the y-position of the <see cref="LedLayout"/>.
|
||||
/// </summary>
|
||||
double Y { get; }
|
||||
float Y { get; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets the width of the <see cref="LedLayout"/>.
|
||||
/// </summary>
|
||||
double Width { get; }
|
||||
float Width { get; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets the height of the <see cref="LedLayout"/>.
|
||||
/// </summary>
|
||||
double Height { get; }
|
||||
float Height { get; }
|
||||
|
||||
object? CustomData { get; }
|
||||
}
|
||||
|
||||
@ -83,25 +83,25 @@ namespace RGB.NET.Layout
|
||||
/// Gets the x-position of the <see cref="LedLayout"/>.
|
||||
/// </summary>
|
||||
[XmlIgnore]
|
||||
public double X { get; private set; }
|
||||
public float X { get; private set; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets the y-position of the <see cref="LedLayout"/>.
|
||||
/// </summary>
|
||||
[XmlIgnore]
|
||||
public double Y { get; private set; }
|
||||
public float Y { get; private set; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets the width of the <see cref="LedLayout"/>.
|
||||
/// </summary>
|
||||
[XmlIgnore]
|
||||
public double Width { get; private set; }
|
||||
public float Width { get; private set; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets the height of the <see cref="LedLayout"/>.
|
||||
/// </summary>
|
||||
[XmlIgnore]
|
||||
public double Height { get; private set; }
|
||||
public float Height { get; private set; }
|
||||
|
||||
#endregion
|
||||
|
||||
@ -128,7 +128,7 @@ namespace RGB.NET.Layout
|
||||
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
|
||||
{
|
||||
@ -143,21 +143,21 @@ namespace RGB.NET.Layout
|
||||
return lastValue + lastSize;
|
||||
|
||||
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))
|
||||
return lastValue - currentSize;
|
||||
|
||||
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))
|
||||
return (lastValue + lastSize) - currentSize;
|
||||
|
||||
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
|
||||
{
|
||||
@ -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
|
||||
{
|
||||
@ -174,9 +174,9 @@ namespace RGB.NET.Layout
|
||||
value = value.Replace(" ", string.Empty);
|
||||
|
||||
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
|
||||
{
|
||||
|
||||
@ -20,46 +20,46 @@ namespace RGB.NET.Presets.Decorators
|
||||
/// 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)
|
||||
/// </summary>
|
||||
public double Attack { get; set; } = 0.2;
|
||||
public float Attack { get; set; } = 0.2f;
|
||||
|
||||
/// <summary>
|
||||
/// 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)
|
||||
/// </summary>
|
||||
public double Decay { get; set; } = 0;
|
||||
public float Decay { get; set; } = 0;
|
||||
|
||||
/// <summary>
|
||||
/// 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 />
|
||||
/// Note that this value for naming reasons represents the time NOT the level.
|
||||
/// </summary>
|
||||
public double Sustain { get; set; } = 0.3;
|
||||
public float Sustain { get; set; } = 0.3f;
|
||||
|
||||
/// <summary>
|
||||
/// 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)
|
||||
/// </summary>
|
||||
public double Release { get; set; } = 0.2;
|
||||
public float Release { get; set; } = 0.2f;
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the level to which the oppacity (percentage) should raise in the attack-cycle. (default: 1);
|
||||
/// </summary>
|
||||
public double AttackValue { get; set; } = 1;
|
||||
public float AttackValue { get; set; } = 1;
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the level at which the oppacity (percentage) should stay in the sustain-cycle. (default: 1);
|
||||
/// </summary>
|
||||
public double SustainValue { get; set; } = 1;
|
||||
public float SustainValue { get; set; } = 1;
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the level at which the oppacity (percentage) should stay in the pause-cycle. (default: 0);
|
||||
/// </summary>
|
||||
public double PauseValue { get; set; } = 0;
|
||||
public float PauseValue { get; set; } = 0;
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the interval (in seconds) in which the decorator should repeat (if repetition is enabled). (default: 1)
|
||||
/// </summary>
|
||||
public double Interval { get; set; } = 1;
|
||||
public float Interval { get; set; } = 1;
|
||||
|
||||
/// <summary>
|
||||
/// 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;
|
||||
|
||||
private ADSRPhase _currentPhase;
|
||||
private double _currentPhaseValue;
|
||||
private float _currentPhaseValue;
|
||||
private int _repetitionCount;
|
||||
|
||||
private double _currentValue;
|
||||
private float _currentValue;
|
||||
|
||||
#endregion
|
||||
|
||||
@ -90,14 +90,14 @@ namespace RGB.NET.Presets.Decorators
|
||||
/// <inheritdoc />
|
||||
protected override void Update(double deltaTime)
|
||||
{
|
||||
_currentPhaseValue -= deltaTime;
|
||||
_currentPhaseValue -= (float)deltaTime;
|
||||
|
||||
// Using ifs instead of a switch allows to skip phases with time 0.
|
||||
// ReSharper disable InvertIf
|
||||
|
||||
if (_currentPhase == ADSRPhase.Attack)
|
||||
if (_currentPhaseValue > 0)
|
||||
_currentValue = PauseValue + (Math.Min(1, (Attack - _currentPhaseValue) / Attack) * (AttackValue - PauseValue));
|
||||
_currentValue = PauseValue + (MathF.Min(1, (Attack - _currentPhaseValue) / Attack) * (AttackValue - PauseValue));
|
||||
else
|
||||
{
|
||||
_currentPhaseValue = Decay;
|
||||
@ -106,7 +106,7 @@ namespace RGB.NET.Presets.Decorators
|
||||
|
||||
if (_currentPhase == ADSRPhase.Decay)
|
||||
if (_currentPhaseValue > 0)
|
||||
_currentValue = SustainValue + (Math.Min(1, _currentPhaseValue / Decay) * (AttackValue - SustainValue));
|
||||
_currentValue = SustainValue + (MathF.Min(1, _currentPhaseValue / Decay) * (AttackValue - SustainValue));
|
||||
else
|
||||
{
|
||||
_currentPhaseValue = Sustain;
|
||||
@ -124,7 +124,7 @@ namespace RGB.NET.Presets.Decorators
|
||||
|
||||
if (_currentPhase == ADSRPhase.Release)
|
||||
if (_currentPhaseValue > 0)
|
||||
_currentValue = PauseValue + (Math.Min(1, _currentPhaseValue / Release) * (SustainValue - PauseValue));
|
||||
_currentValue = PauseValue + (MathF.Min(1, _currentPhaseValue / Release) * (SustainValue - PauseValue));
|
||||
else
|
||||
{
|
||||
_currentPhaseValue = Interval;
|
||||
|
||||
@ -26,7 +26,7 @@ namespace RGB.NET.Presets.Decorators
|
||||
/// <see cref="LinearGradient"/>: 360 unit = 1 offset.
|
||||
/// <see cref="RainbowGradient"/>: 1 unit = 1 degree.
|
||||
/// </summary>
|
||||
public double Speed { get; set; }
|
||||
public float Speed { get; set; }
|
||||
|
||||
// ReSharper restore MemberCanBePrivate.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>
|
||||
/// <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>
|
||||
public MoveGradientDecorator(RGBSurface surface, double speed = 180.0, bool direction = true)
|
||||
public MoveGradientDecorator(RGBSurface surface, float speed = 180.0f, bool direction = true)
|
||||
: base(surface)
|
||||
{
|
||||
this.Speed = speed;
|
||||
@ -58,7 +58,7 @@ namespace RGB.NET.Presets.Decorators
|
||||
/// <inheritdoc />
|
||||
protected override void Update(double deltaTime)
|
||||
{
|
||||
double movement = Speed * deltaTime;
|
||||
float movement = Speed * (float)deltaTime;
|
||||
|
||||
if (!Direction)
|
||||
movement = -movement;
|
||||
|
||||
@ -20,7 +20,7 @@ namespace RGB.NET.Presets.Helper
|
||||
/// <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>
|
||||
/// <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;
|
||||
if (startPoint.Y.EqualsInTolerance(endPoint.Y)) // Horizontal case
|
||||
@ -31,20 +31,20 @@ namespace RGB.NET.Presets.Helper
|
||||
|
||||
else // Diagonal case
|
||||
{
|
||||
double slope = (endPoint.Y - startPoint.Y) / (endPoint.X - startPoint.X);
|
||||
double orthogonalSlope = -1 / slope;
|
||||
float slope = (endPoint.Y - startPoint.Y) / (endPoint.X - startPoint.X);
|
||||
float orthogonalSlope = -1 / slope;
|
||||
|
||||
double startYIntercept = startPoint.Y - (slope * startPoint.X);
|
||||
double pointYIntercept = point.Y - (orthogonalSlope * point.X);
|
||||
float startYIntercept = startPoint.Y - (slope * startPoint.X);
|
||||
float pointYIntercept = point.Y - (orthogonalSlope * point.X);
|
||||
|
||||
double intersectingPointX = (pointYIntercept - startYIntercept) / (slope - orthogonalSlope);
|
||||
double intersectingPointY = (slope * intersectingPointX) + startYIntercept;
|
||||
float intersectingPointX = (pointYIntercept - startYIntercept) / (slope - orthogonalSlope);
|
||||
float intersectingPointY = (slope * intersectingPointX) + startYIntercept;
|
||||
intersectingPoint = new Point(intersectingPointX, intersectingPointY);
|
||||
}
|
||||
|
||||
// Calculate distances relative to the vector start
|
||||
double intersectDistance = CalculateDistance(intersectingPoint, startPoint, endPoint);
|
||||
double gradientLength = CalculateDistance(endPoint, startPoint, endPoint);
|
||||
float intersectDistance = CalculateDistance(intersectingPoint, startPoint, endPoint);
|
||||
float gradientLength = CalculateDistance(endPoint, startPoint, endPoint);
|
||||
|
||||
return intersectDistance / gradientLength;
|
||||
}
|
||||
@ -57,9 +57,9 @@ namespace RGB.NET.Presets.Helper
|
||||
/// <param name="origin">The origin 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>
|
||||
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))
|
||||
|| ((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="point2">The second <see cref="Point"/>.</param>
|
||||
/// <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;
|
||||
double y = point1.Y - point2.Y;
|
||||
return Math.Sqrt((y * y) + (x * x));
|
||||
float x = point1.X - point2.X;
|
||||
float y = point1.Y - point2.Y;
|
||||
return MathF.Sqrt((y * y) + (x * x));
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
@ -18,23 +18,23 @@ namespace RGB.NET.Presets.Textures
|
||||
{
|
||||
#region Constants
|
||||
|
||||
private const double PI2 = Math.PI * 2;
|
||||
private const float PI2 = MathF.PI * 2.0f;
|
||||
|
||||
#endregion
|
||||
|
||||
#region Properties & Fields
|
||||
|
||||
private double _origin = Math.Atan2(-1, 0);
|
||||
private float _origin = MathF.Atan2(-1, 0);
|
||||
/// <summary>
|
||||
/// Gets or sets the origin (radian-angle) this <see cref="ConicalGradientTexture"/> is drawn to. (default: -π/2)
|
||||
/// </summary>
|
||||
public double Origin
|
||||
public float Origin
|
||||
{
|
||||
get => _origin;
|
||||
set => SetProperty(ref _origin, value);
|
||||
}
|
||||
|
||||
private Point _center = new(0.5, 0.5);
|
||||
private Point _center = new(0.5f, 0.5f);
|
||||
/// <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)
|
||||
/// </summary>
|
||||
@ -86,9 +86,9 @@ namespace RGB.NET.Presets.Textures
|
||||
|
||||
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;
|
||||
double offset = angle / PI2;
|
||||
float offset = angle / PI2;
|
||||
|
||||
return Gradient.GetColor(offset);
|
||||
}
|
||||
|
||||
@ -96,23 +96,23 @@ namespace RGB.NET.Presets.Textures.Gradients
|
||||
/// </summary>
|
||||
/// <param name="offset"></param>
|
||||
/// <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)
|
||||
return max;
|
||||
|
||||
double min = GradientStops.Min(stop => stop.Offset);
|
||||
float min = GradientStops.Min(stop => stop.Offset);
|
||||
return offset < min ? min : offset;
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
public abstract Color GetColor(double offset);
|
||||
public abstract Color GetColor(float offset);
|
||||
|
||||
/// <inheritdoc />
|
||||
public virtual void Move(double offset)
|
||||
public virtual void Move(float offset)
|
||||
{
|
||||
offset /= 360.0;
|
||||
offset /= 360.0f;
|
||||
|
||||
foreach (GradientStop gradientStop in GradientStops)
|
||||
gradientStop.Offset += offset;
|
||||
|
||||
@ -12,11 +12,11 @@ namespace RGB.NET.Presets.Textures.Gradients
|
||||
{
|
||||
#region Properties & Fields
|
||||
|
||||
private double _offset;
|
||||
private float _offset;
|
||||
/// <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.
|
||||
/// </summary>
|
||||
public double Offset
|
||||
public float Offset
|
||||
{
|
||||
get => _offset;
|
||||
set => SetProperty(ref _offset, value);
|
||||
@ -41,7 +41,7 @@ namespace RGB.NET.Presets.Textures.Gradients
|
||||
/// </summary>
|
||||
/// <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>
|
||||
public GradientStop(double offset, Color color)
|
||||
public GradientStop(float offset, Color color)
|
||||
{
|
||||
this.Offset = offset;
|
||||
this.Color = color;
|
||||
|
||||
@ -19,12 +19,12 @@ namespace RGB.NET.Presets.Textures.Gradients
|
||||
/// </summary>
|
||||
/// <param name="offset">The percentage offset to take the <see cref="Color"/> from.</param>
|
||||
/// <returns>The <see cref="Color"/> at the specific offset.</returns>
|
||||
Color GetColor(double offset);
|
||||
Color GetColor(float offset);
|
||||
|
||||
/// <summary>
|
||||
/// Moves the <see cref="IGradient"/> by the provided offset.
|
||||
/// </summary>
|
||||
/// <param name="offset">The offset the <see cref="IGradient"/> should be moved.</param>
|
||||
void Move(double offset);
|
||||
void Move(float offset);
|
||||
}
|
||||
}
|
||||
|
||||
@ -83,7 +83,7 @@ namespace RGB.NET.Presets.Textures.Gradients
|
||||
/// </summary>
|
||||
/// <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>
|
||||
public override Color GetColor(double offset)
|
||||
public override Color GetColor(float offset)
|
||||
{
|
||||
if (GradientStops.Count == 0) return Color.Transparent;
|
||||
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);
|
||||
|
||||
double blendFactor = 0;
|
||||
float blendFactor = 0;
|
||||
if (!gsBefore.Offset.Equals(gsAfter.Offset))
|
||||
blendFactor = ((offset - gsBefore.Offset) / (gsAfter.Offset - gsBefore.Offset));
|
||||
|
||||
double colA = ((gsAfter.Color.A - gsBefore.Color.A) * blendFactor) + gsBefore.Color.A;
|
||||
double colR = ((gsAfter.Color.R - gsBefore.Color.R) * blendFactor) + gsBefore.Color.R;
|
||||
double colG = ((gsAfter.Color.G - gsBefore.Color.G) * blendFactor) + gsBefore.Color.G;
|
||||
double colB = ((gsAfter.Color.B - gsBefore.Color.B) * blendFactor) + gsBefore.Color.B;
|
||||
float colA = ((gsAfter.Color.A - gsBefore.Color.A) * blendFactor) + gsBefore.Color.A;
|
||||
float colR = ((gsAfter.Color.R - gsBefore.Color.R) * blendFactor) + gsBefore.Color.R;
|
||||
float colG = ((gsAfter.Color.G - gsBefore.Color.G) * blendFactor) + gsBefore.Color.G;
|
||||
float colB = ((gsAfter.Color.B - gsBefore.Color.B) * blendFactor) + gsBefore.Color.B;
|
||||
|
||||
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="wrap">Bool indicating if the gradient should be wrapped or not.</param>
|
||||
/// <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);
|
||||
|
||||
|
||||
@ -17,21 +17,21 @@ namespace RGB.NET.Presets.Textures.Gradients
|
||||
{
|
||||
#region Properties & Fields
|
||||
|
||||
private double _startHue;
|
||||
private float _startHue;
|
||||
/// <summary>
|
||||
/// Gets or sets the hue (in degrees) to start from.
|
||||
/// </summary>
|
||||
public double StartHue
|
||||
public float StartHue
|
||||
{
|
||||
get => _startHue;
|
||||
set => SetProperty(ref _startHue, value);
|
||||
}
|
||||
|
||||
private double _endHue;
|
||||
private float _endHue;
|
||||
/// <summary>
|
||||
/// Gets or sets the hue (in degrees) to end the with.
|
||||
/// </summary>
|
||||
public double EndHue
|
||||
public float EndHue
|
||||
{
|
||||
get => _endHue;
|
||||
set => SetProperty(ref _endHue, value);
|
||||
@ -53,7 +53,7 @@ namespace RGB.NET.Presets.Textures.Gradients
|
||||
/// </summary>
|
||||
/// <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>
|
||||
public RainbowGradient(double startHue = 0, double endHue = 360)
|
||||
public RainbowGradient(float startHue = 0, float endHue = 360)
|
||||
{
|
||||
this.StartHue = startHue;
|
||||
this.EndHue = endHue;
|
||||
@ -71,15 +71,15 @@ namespace RGB.NET.Presets.Textures.Gradients
|
||||
/// </summary>
|
||||
/// <param name="offset">The percentage offset to take the color from.</param>
|
||||
/// <returns>The color at the specific offset.</returns>
|
||||
public Color GetColor(double offset)
|
||||
public Color GetColor(float offset)
|
||||
{
|
||||
double range = EndHue - StartHue;
|
||||
double hue = StartHue + (range * offset);
|
||||
float range = EndHue - StartHue;
|
||||
float hue = StartHue + (range * offset);
|
||||
return HSVColor.Create(hue, 1, 1);
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
public void Move(double offset)
|
||||
public void Move(float offset)
|
||||
{
|
||||
// RainbowGradient is calculated inverse
|
||||
offset *= -1;
|
||||
|
||||
@ -19,7 +19,7 @@ namespace RGB.NET.Presets.Textures
|
||||
{
|
||||
#region Properties & Fields
|
||||
|
||||
private Point _startPoint = new(0, 0.5);
|
||||
private Point _startPoint = new(0, 0.5f);
|
||||
/// <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)
|
||||
/// </summary>
|
||||
@ -29,7 +29,7 @@ namespace RGB.NET.Presets.Textures
|
||||
set => SetProperty(ref _startPoint, value);
|
||||
}
|
||||
|
||||
private Point _endPoint = new(1, 0.5);
|
||||
private Point _endPoint = new(1, 0.5f);
|
||||
/// <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)
|
||||
/// </summary>
|
||||
@ -70,7 +70,7 @@ namespace RGB.NET.Presets.Textures
|
||||
|
||||
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);
|
||||
}
|
||||
|
||||
|
||||
@ -16,9 +16,9 @@ namespace RGB.NET.Presets.Textures
|
||||
{
|
||||
#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>
|
||||
/// 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>
|
||||
@ -61,15 +61,15 @@ namespace RGB.NET.Presets.Textures
|
||||
|
||||
private void CalculateReferenceDistance()
|
||||
{
|
||||
double referenceX = Center.X < 0.5 ? 1 : 0;
|
||||
double referenceY = Center.Y < 0.5 ? 1 : 0;
|
||||
float referenceX = Center.X < 0.5f ? 1 : 0;
|
||||
float referenceY = Center.Y < 0.5f ? 1 : 0;
|
||||
_referenceDistance = GradientHelper.CalculateDistance(new Point(referenceX, referenceY), Center);
|
||||
}
|
||||
|
||||
protected override Color GetColor(in Point point)
|
||||
{
|
||||
double distance = GradientHelper.CalculateDistance(point, Center);
|
||||
double offset = distance / _referenceDistance;
|
||||
float distance = GradientHelper.CalculateDistance(point, Center);
|
||||
float offset = distance / _referenceDistance;
|
||||
return Gradient.GetColor(offset);
|
||||
}
|
||||
|
||||
|
||||
@ -221,36 +221,36 @@ namespace RGB.NET.Core.Tests.Color
|
||||
[TestMethod]
|
||||
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(0.25341, color.R, DoubleExtensions.TOLERANCE, "R is not 0.25341");
|
||||
Assert.AreEqual(0.55367, color.G, DoubleExtensions.TOLERANCE, "G is not 0.55367");
|
||||
Assert.AreEqual(1, color.B, DoubleExtensions.TOLERANCE, "B is not 1");
|
||||
Assert.AreEqual(1, color.A, FloatExtensions.TOLERANCE, "A is not 1");
|
||||
Assert.AreEqual(0.25341, color.R, FloatExtensions.TOLERANCE, "R is not 0.25341");
|
||||
Assert.AreEqual(0.55367, color.G, FloatExtensions.TOLERANCE, "G is not 0.55367");
|
||||
Assert.AreEqual(1, color.B, FloatExtensions.TOLERANCE, "B is not 1");
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
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.25341, color.R, DoubleExtensions.TOLERANCE, "R is not 0.25341");
|
||||
Assert.AreEqual(0.55367, color.G, DoubleExtensions.TOLERANCE, "G is not 0.55367");
|
||||
Assert.AreEqual(1, color.B, DoubleExtensions.TOLERANCE, "B is not 1");
|
||||
Assert.AreEqual(0.3315f, color.A, FloatExtensions.TOLERANCE, "A is not 0.3315");
|
||||
Assert.AreEqual(0.25341f, color.R, FloatExtensions.TOLERANCE, "R is not 0.25341");
|
||||
Assert.AreEqual(0.55367f, color.G, FloatExtensions.TOLERANCE, "G is not 0.55367");
|
||||
Assert.AreEqual(1, color.B, FloatExtensions.TOLERANCE, "B is not 1");
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
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.R, "R is not 1");
|
||||
Assert.AreEqual(1, color1.G, "G 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(0, color2.R, "R is not 0");
|
||||
@ -261,14 +261,14 @@ namespace RGB.NET.Core.Tests.Color
|
||||
[TestMethod]
|
||||
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.R, "R is not 1");
|
||||
Assert.AreEqual(1, color1.G, "G 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.R, "R is not 0");
|
||||
|
||||
@ -12,55 +12,55 @@ namespace RGB.NET.Core.Tests.Color
|
||||
[TestMethod]
|
||||
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);
|
||||
|
||||
Assert.AreEqual(HSVColor.Create(210, 0.5, 0.5), result);
|
||||
Assert.AreEqual(HSVColor.Create(210, 0.5f, 0.5f), result);
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
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);
|
||||
|
||||
Assert.AreEqual(HSVColor.Create(40, 0.5, 0.5), result);
|
||||
Assert.AreEqual(HSVColor.Create(40, 0.5f, 0.5f), result);
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
public void AddSaturationTest()
|
||||
{
|
||||
Core.Color baseColor = HSVColor.Create(180, 0.5, 0.5);
|
||||
Core.Color result = baseColor.AddHSV(saturation: 0.3);
|
||||
Core.Color baseColor = HSVColor.Create(180, 0.5f, 0.5f);
|
||||
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]
|
||||
public void AddSaturationClampTest()
|
||||
{
|
||||
Core.Color baseColor = HSVColor.Create(180, 0.5, 0.5);
|
||||
Core.Color result = baseColor.AddHSV(saturation: 0.8);
|
||||
Core.Color baseColor = HSVColor.Create(180, 0.5f, 0.5f);
|
||||
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]
|
||||
public void AddValueTest()
|
||||
{
|
||||
Core.Color baseColor = HSVColor.Create(180, 0.5, 0.5);
|
||||
Core.Color result = baseColor.AddHSV(value: 0.3);
|
||||
Core.Color baseColor = HSVColor.Create(180, 0.5f, 0.5f);
|
||||
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]
|
||||
public void AddValueClampTest()
|
||||
{
|
||||
Core.Color baseColor = HSVColor.Create(180, 0.5, 0.5);
|
||||
Core.Color result = baseColor.AddHSV(value: 0.8);
|
||||
Core.Color baseColor = HSVColor.Create(180, 0.5f, 0.5f);
|
||||
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
|
||||
@ -70,55 +70,55 @@ namespace RGB.NET.Core.Tests.Color
|
||||
[TestMethod]
|
||||
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);
|
||||
|
||||
Assert.AreEqual(HSVColor.Create(150, 0.5, 0.5), result);
|
||||
Assert.AreEqual(HSVColor.Create(150, 0.5f, 0.5f), result);
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
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);
|
||||
|
||||
Assert.AreEqual(HSVColor.Create(320, 0.5, 0.5), result);
|
||||
Assert.AreEqual(HSVColor.Create(320, 0.5f, 0.5f), result);
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
public void SubtractSaturationTest()
|
||||
{
|
||||
Core.Color baseColor = HSVColor.Create(180, 0.5, 0.5);
|
||||
Core.Color result = baseColor.SubtractHSV(saturation: 0.3);
|
||||
Core.Color baseColor = HSVColor.Create(180, 0.5f, 0.5f);
|
||||
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]
|
||||
public void SubtractSaturationClampTest()
|
||||
{
|
||||
Core.Color baseColor = HSVColor.Create(180, 0.5, 0.5);
|
||||
Core.Color result = baseColor.SubtractHSV(saturation: 0.8);
|
||||
Core.Color baseColor = HSVColor.Create(180, 0.5f, 0.5f);
|
||||
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]
|
||||
public void SubtractValueTest()
|
||||
{
|
||||
Core.Color baseColor = HSVColor.Create(180, 0.5, 0.5);
|
||||
Core.Color result = baseColor.SubtractHSV(value: 0.3);
|
||||
Core.Color baseColor = HSVColor.Create(180, 0.5f, 0.5f);
|
||||
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]
|
||||
public void SubtractValueClampTest()
|
||||
{
|
||||
Core.Color baseColor = HSVColor.Create(180, 0.5, 0.5);
|
||||
Core.Color result = baseColor.SubtractHSV(value: .8);
|
||||
Core.Color baseColor = HSVColor.Create(180, 0.5f, 0.5f);
|
||||
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
|
||||
@ -128,55 +128,55 @@ namespace RGB.NET.Core.Tests.Color
|
||||
[TestMethod]
|
||||
public void MultiplyHueTest()
|
||||
{
|
||||
Core.Color baseColor = HSVColor.Create(180, 0.5, 0.5);
|
||||
Core.Color result = baseColor.MultiplyHSV(hue: 1.5);
|
||||
Core.Color baseColor = HSVColor.Create(180, 0.5f, 0.5f);
|
||||
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]
|
||||
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);
|
||||
|
||||
Assert.AreEqual(HSVColor.Create(180, 0.5, 0.5), result);
|
||||
Assert.AreEqual(HSVColor.Create(180, 0.5f, 0.5f), result);
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
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);
|
||||
|
||||
Assert.AreEqual(HSVColor.Create(180, 0.6, 0.2), result);
|
||||
Assert.AreEqual(HSVColor.Create(180,0.6f, 0.2f), result);
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
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);
|
||||
|
||||
Assert.AreEqual(HSVColor.Create(180, 1.0, 0.5), result);
|
||||
Assert.AreEqual(HSVColor.Create(180, 1.0f, 0.5f), result);
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
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);
|
||||
|
||||
Assert.AreEqual(HSVColor.Create(180, 0.2, 0.6), result);
|
||||
Assert.AreEqual(HSVColor.Create(180, 0.2f,0.6f), result);
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
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);
|
||||
|
||||
Assert.AreEqual(HSVColor.Create(180, 0.5, 1.0), result);
|
||||
Assert.AreEqual(HSVColor.Create(180, 0.5f, 1.0f), result);
|
||||
}
|
||||
|
||||
#endregion
|
||||
@ -186,28 +186,28 @@ namespace RGB.NET.Core.Tests.Color
|
||||
[TestMethod]
|
||||
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);
|
||||
|
||||
Assert.AreEqual(HSVColor.Create(6, 0.5, 0.5), result);
|
||||
Assert.AreEqual(HSVColor.Create(6, 0.5f, 0.5f), result);
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
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);
|
||||
|
||||
Assert.AreEqual(HSVColor.Create(180, 0.3, 0.6), result);
|
||||
Assert.AreEqual(HSVColor.Create(180, 0.3f,0.6f), result);
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
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);
|
||||
|
||||
Assert.AreEqual(HSVColor.Create(180, 0.6, 0.3), result);
|
||||
Assert.AreEqual(HSVColor.Create(180,0.6f, 0.3f), result);
|
||||
}
|
||||
|
||||
#endregion
|
||||
@ -217,64 +217,64 @@ namespace RGB.NET.Core.Tests.Color
|
||||
[TestMethod]
|
||||
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);
|
||||
|
||||
Assert.AreEqual(HSVColor.Create(30, 0.5, 0.5), result);
|
||||
Assert.AreEqual(HSVColor.Create(30, 0.5f, 0.5f), result);
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
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);
|
||||
|
||||
Assert.AreEqual(HSVColor.Create(80, 0.5, 0.5), result);
|
||||
Assert.AreEqual(HSVColor.Create(80, 0.5f, 0.5f), result);
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
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);
|
||||
|
||||
Assert.AreEqual(HSVColor.Create(330, 0.5, 0.5), result);
|
||||
Assert.AreEqual(HSVColor.Create(330, 0.5f, 0.5f), result);
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
public void SetSaturationTest()
|
||||
{
|
||||
Core.Color baseColor = HSVColor.Create(180, 0.5, 0.5);
|
||||
Core.Color result = baseColor.SetHSV(saturation: 0.3);
|
||||
Core.Color baseColor = HSVColor.Create(180, 0.5f, 0.5f);
|
||||
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]
|
||||
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);
|
||||
|
||||
Assert.AreEqual(HSVColor.Create(180, 1.0, 0.5), result);
|
||||
Assert.AreEqual(HSVColor.Create(180, 1.0f, 0.5f), result);
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
public void SetValueTest()
|
||||
{
|
||||
Core.Color baseColor = HSVColor.Create(180, 0.5, 0.5);
|
||||
Core.Color result = baseColor.SetHSV(value: 0.3);
|
||||
Core.Color baseColor = HSVColor.Create(180, 0.5f, 0.5f);
|
||||
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]
|
||||
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);
|
||||
|
||||
Assert.AreEqual(HSVColor.Create(180, 0.5, 1.0), result);
|
||||
Assert.AreEqual(HSVColor.Create(180, 0.5f, 1.0f), result);
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
@ -30,19 +30,19 @@ namespace RGB.NET.Core.Tests.Color
|
||||
[TestMethod]
|
||||
public void BlendUpTest()
|
||||
{
|
||||
Core.Color baseColor = new(0.0, 0.0, 0.0);
|
||||
Core.Color blendColor = new(0.5, 1.0, 1.0, 1.0);
|
||||
Core.Color baseColor = new(0.0f, 0.0f, 0.0f);
|
||||
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]
|
||||
public void BlendDownTest()
|
||||
{
|
||||
Core.Color baseColor = new(1.0, 1.0, 1.0);
|
||||
Core.Color blendColor = new(0.5, 0.0, 0.0, 0.0);
|
||||
Core.Color baseColor = new(1.0f, 1.0f, 1.0f);
|
||||
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
|
||||
@ -61,10 +61,10 @@ namespace RGB.NET.Core.Tests.Color
|
||||
[TestMethod]
|
||||
public void AddRGBPercentTest()
|
||||
{
|
||||
Core.Color baseColor = new(0.5, 0.5, 0.5, 0.5);
|
||||
Core.Color result = baseColor.AddRGB(0.2, 0.3, 0.4);
|
||||
Core.Color baseColor = new(0.5f, 0.5f, 0.5f, 0.5f);
|
||||
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]
|
||||
@ -79,10 +79,10 @@ namespace RGB.NET.Core.Tests.Color
|
||||
[TestMethod]
|
||||
public void AddAPercentTest()
|
||||
{
|
||||
Core.Color baseColor = new(0.5, 0.5, 0.5, 0.5);
|
||||
Core.Color result = baseColor.AddA(0.1);
|
||||
Core.Color baseColor = new(0.5f, 0.5f, 0.5f, 0.5f);
|
||||
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]
|
||||
@ -97,10 +97,10 @@ namespace RGB.NET.Core.Tests.Color
|
||||
[TestMethod]
|
||||
public void AddRPercentTest()
|
||||
{
|
||||
Core.Color baseColor = new(0.5, 0.5, 0.5, 0.5);
|
||||
Core.Color result = baseColor.AddRGB(r: 0.1);
|
||||
Core.Color baseColor = new(0.5f, 0.5f, 0.5f, 0.5f);
|
||||
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]
|
||||
@ -115,10 +115,10 @@ namespace RGB.NET.Core.Tests.Color
|
||||
[TestMethod]
|
||||
public void AddGPercentTest()
|
||||
{
|
||||
Core.Color baseColor = new(0.5, 0.5, 0.5, 0.5);
|
||||
Core.Color result = baseColor.AddRGB(g: 0.1);
|
||||
Core.Color baseColor = new(0.5f, 0.5f, 0.5f, 0.5f);
|
||||
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]
|
||||
@ -133,10 +133,10 @@ namespace RGB.NET.Core.Tests.Color
|
||||
[TestMethod]
|
||||
public void AddBPercentTest()
|
||||
{
|
||||
Core.Color baseColor = new(0.5, 0.5, 0.5, 0.5);
|
||||
Core.Color result = baseColor.AddRGB(b: 0.1);
|
||||
Core.Color baseColor = new(0.5f, 0.5f, 0.5f, 0.5f);
|
||||
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
|
||||
@ -155,10 +155,10 @@ namespace RGB.NET.Core.Tests.Color
|
||||
[TestMethod]
|
||||
public void SubtractRGBPercentTest()
|
||||
{
|
||||
Core.Color baseColor = new(0.5, 0.5, 0.5, 0.5);
|
||||
Core.Color result = baseColor.SubtractRGB(0.2, 0.3, 0.4);
|
||||
Core.Color baseColor = new(0.5f, 0.5f, 0.5f, 0.5f);
|
||||
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]
|
||||
@ -173,10 +173,10 @@ namespace RGB.NET.Core.Tests.Color
|
||||
[TestMethod]
|
||||
public void SubtractAPercentTest()
|
||||
{
|
||||
Core.Color baseColor = new(0.5, 0.5, 0.5, 0.5);
|
||||
Core.Color result = baseColor.SubtractA(0.1);
|
||||
Core.Color baseColor = new(0.5f, 0.5f, 0.5f, 0.5f);
|
||||
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]
|
||||
@ -191,10 +191,10 @@ namespace RGB.NET.Core.Tests.Color
|
||||
[TestMethod]
|
||||
public void SubtractRPercentTest()
|
||||
{
|
||||
Core.Color baseColor = new(0.5, 0.5, 0.5, 0.5);
|
||||
Core.Color result = baseColor.SubtractRGB(r: 0.1);
|
||||
Core.Color baseColor = new(0.5f, 0.5f, 0.5f, 0.5f);
|
||||
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]
|
||||
@ -209,10 +209,10 @@ namespace RGB.NET.Core.Tests.Color
|
||||
[TestMethod]
|
||||
public void SubtractGPercentTest()
|
||||
{
|
||||
Core.Color baseColor = new(0.5, 0.5, 0.5, 0.5);
|
||||
Core.Color result = baseColor.SubtractRGB(g: 0.1);
|
||||
Core.Color baseColor = new(0.5f, 0.5f, 0.5f, 0.5f);
|
||||
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]
|
||||
@ -227,10 +227,10 @@ namespace RGB.NET.Core.Tests.Color
|
||||
[TestMethod]
|
||||
public void SubtractBPercentTest()
|
||||
{
|
||||
Core.Color baseColor = new(0.5, 0.5, 0.5, 0.5);
|
||||
Core.Color result = baseColor.SubtractRGB(b: 0.1);
|
||||
Core.Color baseColor = new(0.5f, 0.5f, 0.5f, 0.5f);
|
||||
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
|
||||
@ -240,46 +240,46 @@ namespace RGB.NET.Core.Tests.Color
|
||||
[TestMethod]
|
||||
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);
|
||||
|
||||
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]
|
||||
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);
|
||||
|
||||
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]
|
||||
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);
|
||||
|
||||
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]
|
||||
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);
|
||||
|
||||
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]
|
||||
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);
|
||||
|
||||
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
|
||||
@ -289,46 +289,46 @@ namespace RGB.NET.Core.Tests.Color
|
||||
[TestMethod]
|
||||
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);
|
||||
|
||||
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]
|
||||
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);
|
||||
|
||||
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]
|
||||
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);
|
||||
|
||||
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]
|
||||
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);
|
||||
|
||||
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]
|
||||
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);
|
||||
|
||||
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
|
||||
@ -347,10 +347,10 @@ namespace RGB.NET.Core.Tests.Color
|
||||
[TestMethod]
|
||||
public void SetRGBPercentTest()
|
||||
{
|
||||
Core.Color baseColor = new(0.5, 0.5, 0.5, 0.5);
|
||||
Core.Color result = baseColor.SetRGB(0.2, 0.3, 0.4);
|
||||
Core.Color baseColor = new(0.5f, 0.5f, 0.5f, 0.5f);
|
||||
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]
|
||||
@ -365,10 +365,10 @@ namespace RGB.NET.Core.Tests.Color
|
||||
[TestMethod]
|
||||
public void SetAPercentTest()
|
||||
{
|
||||
Core.Color baseColor = new(0.5, 0.5, 0.5, 0.5);
|
||||
Core.Color result = baseColor.SetA(0.1);
|
||||
Core.Color baseColor = new(0.5f, 0.5f, 0.5f, 0.5f);
|
||||
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]
|
||||
@ -383,10 +383,10 @@ namespace RGB.NET.Core.Tests.Color
|
||||
[TestMethod]
|
||||
public void SetRPercentTest()
|
||||
{
|
||||
Core.Color baseColor = new(0.5, 0.5, 0.5, 0.5);
|
||||
Core.Color result = baseColor.SetRGB(r: 0.1);
|
||||
Core.Color baseColor = new(0.5f, 0.5f, 0.5f, 0.5f);
|
||||
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]
|
||||
@ -401,10 +401,10 @@ namespace RGB.NET.Core.Tests.Color
|
||||
[TestMethod]
|
||||
public void SetGPercentTest()
|
||||
{
|
||||
Core.Color baseColor = new(0.5, 0.5, 0.5, 0.5);
|
||||
Core.Color result = baseColor.SetRGB(g: 0.1);
|
||||
Core.Color baseColor = new(0.5f, 0.5f, 0.5f, 0.5f);
|
||||
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]
|
||||
@ -419,10 +419,10 @@ namespace RGB.NET.Core.Tests.Color
|
||||
[TestMethod]
|
||||
public void SetBPercentTest()
|
||||
{
|
||||
Core.Color baseColor = new(0.5, 0.5, 0.5, 0.5);
|
||||
Core.Color result = baseColor.SetRGB(b: 0.1);
|
||||
Core.Color baseColor = new(0.5f, 0.5f, 0.5f, 0.5f);
|
||||
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
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user