mirror of
https://github.com/DarthAffe/RGB.NET.git
synced 2025-12-12 09:38:31 +00:00
(MAJOR) Removed all in paramters as their performance impact is too hard to predict
This commit is contained in:
parent
6f0711564c
commit
c39849949a
@ -14,7 +14,7 @@ public sealed class DefaultColorBehavior : IColorBehavior
|
||||
/// Converts the individual byte values of this <see cref="Color"/> to a human-readable string.
|
||||
/// </summary>
|
||||
/// <returns>A string that contains the individual byte values of this <see cref="Color"/>. For example "[A: 255, R: 255, G: 0, B: 0]".</returns>
|
||||
public string ToString(in Color color) => $"[A: {color.GetA()}, R: {color.GetR()}, G: {color.GetG()}, B: {color.GetB()}]";
|
||||
public string ToString(Color color) => $"[A: {color.GetA()}, R: {color.GetR()}, G: {color.GetG()}, B: {color.GetB()}]";
|
||||
|
||||
/// <summary>
|
||||
/// Tests whether the specified object is a <see cref="Color" /> and is equivalent to this <see cref="Color" />.
|
||||
@ -22,7 +22,7 @@ public sealed class DefaultColorBehavior : IColorBehavior
|
||||
/// <param name="color">The color to test.</param>
|
||||
/// <param name="obj">The object to test.</param>
|
||||
/// <returns><c>true</c> if <paramref name="obj" /> is a <see cref="Color" /> equivalent to this <see cref="Color" />; otherwise, <c>false</c>.</returns>
|
||||
public bool Equals(in Color color, object? obj) => obj is Color color2 && Equals(color, color2);
|
||||
public bool Equals(Color color, object? obj) => obj is Color color2 && Equals(color, color2);
|
||||
|
||||
/// <summary>
|
||||
/// Tests whether the specified object is a <see cref="Color" /> and is equivalent to this <see cref="Color" />.
|
||||
@ -30,7 +30,7 @@ public sealed class DefaultColorBehavior : IColorBehavior
|
||||
/// <param name="color">The first color to test.</param>
|
||||
/// <param name="color2">The second color to test.</param>
|
||||
/// <returns><c>true</c> if <paramref name="color2" /> equivalent to this <see cref="Color" />; otherwise, <c>false</c>.</returns>
|
||||
public bool Equals(in Color color, in Color color2) => color.A.EqualsInTolerance(color2.A)
|
||||
public bool Equals(Color color, Color color2) => color.A.EqualsInTolerance(color2.A)
|
||||
&& color.R.EqualsInTolerance(color2.R)
|
||||
&& color.G.EqualsInTolerance(color2.G)
|
||||
&& color.B.EqualsInTolerance(color2.B);
|
||||
@ -39,14 +39,14 @@ public sealed class DefaultColorBehavior : IColorBehavior
|
||||
/// Returns a hash code for this <see cref="Color" />.
|
||||
/// </summary>
|
||||
/// <returns>An integer value that specifies the hash code for this <see cref="Color" />.</returns>
|
||||
public int GetHashCode(in Color color) => HashCode.Combine(color.A, color.R, color.G, color.B);
|
||||
public int GetHashCode(Color color) => HashCode.Combine(color.A, color.R, color.G, color.B);
|
||||
|
||||
/// <summary>
|
||||
/// Blends a <see cref="Color"/> over this color.
|
||||
/// </summary>
|
||||
/// <param name="baseColor">The <see cref="Color"/> to to blend over.</param>
|
||||
/// <param name="blendColor">The <see cref="Color"/> to blend.</param>
|
||||
public Color Blend(in Color baseColor, in Color blendColor)
|
||||
public Color Blend(Color baseColor, Color blendColor)
|
||||
{
|
||||
if (blendColor.A.EqualsInTolerance(0)) return baseColor;
|
||||
|
||||
|
||||
@ -10,7 +10,7 @@ public interface IColorBehavior
|
||||
/// </summary>
|
||||
/// <param name="color">The color to convert.</param>
|
||||
/// <returns>The string representation of the specified color.</returns>
|
||||
string ToString(in Color color);
|
||||
string ToString(Color color);
|
||||
|
||||
/// <summary>
|
||||
/// Tests whether the specified object is a <see cref="Color" /> and is equivalent to this <see cref="Color" />.
|
||||
@ -18,7 +18,7 @@ public interface IColorBehavior
|
||||
/// <param name="color">The color to test.</param>
|
||||
/// <param name="obj">The object to test.</param>
|
||||
/// <returns><c>true</c> if <paramref name="obj" /> is a <see cref="Color" /> equivalent to this <see cref="Color" />; otherwise, <c>false</c>.</returns>
|
||||
bool Equals(in Color color, object? obj);
|
||||
bool Equals(Color color, object? obj);
|
||||
|
||||
/// <summary>
|
||||
/// Tests whether the specified object is a <see cref="Color" /> and is equivalent to this <see cref="Color" />.
|
||||
@ -26,18 +26,18 @@ public interface IColorBehavior
|
||||
/// <param name="color">The first color to test.</param>
|
||||
/// <param name="color2">The second color to test.</param>
|
||||
/// <returns><c>true</c> if <paramref name="color2" /> equivalent to this <see cref="Color" />; otherwise, <c>false</c>.</returns>
|
||||
bool Equals(in Color color, in Color color2);
|
||||
bool Equals(Color color, Color color2);
|
||||
|
||||
/// <summary>
|
||||
/// Returns a hash code for this <see cref="Color" />.
|
||||
/// </summary>
|
||||
/// <returns>An integer value that specifies the hash code for this <see cref="Color" />.</returns>
|
||||
int GetHashCode(in Color color);
|
||||
int GetHashCode(Color color);
|
||||
|
||||
/// <summary>
|
||||
/// Blends a <see cref="Color"/> over this color.
|
||||
/// </summary>
|
||||
/// <param name="baseColor">The <see cref="Color"/> to to blend over.</param>
|
||||
/// <param name="blendColor">The <see cref="Color"/> to blend.</param>
|
||||
Color Blend(in Color baseColor, in Color blendColor);
|
||||
Color Blend(Color baseColor, Color blendColor);
|
||||
}
|
||||
@ -175,7 +175,7 @@ public readonly struct Color : IEquatable<Color>
|
||||
/// Initializes a new instance of the <see cref="T:RGB.NET.Core.Color" /> struct by cloning a existing <see cref="T:RGB.NET.Core.Color" />.
|
||||
/// </summary>
|
||||
/// <param name="color">The <see cref="T:RGB.NET.Core.Color" /> the values are copied from.</param>
|
||||
public Color(in Color color)
|
||||
public Color(Color color)
|
||||
: this(color.A, color.R, color.G, color.B)
|
||||
{ }
|
||||
|
||||
@ -214,7 +214,7 @@ public readonly struct Color : IEquatable<Color>
|
||||
/// Blends a <see cref="Color"/> over this color, as defined by the current <see cref="Behavior"/>.
|
||||
/// </summary>
|
||||
/// <param name="color">The <see cref="Color"/> to blend.</param>
|
||||
public Color Blend(in Color color) => Behavior.Blend(this, color);
|
||||
public Color Blend(Color color) => Behavior.Blend(this, color);
|
||||
|
||||
#endregion
|
||||
|
||||
@ -226,7 +226,7 @@ public readonly struct Color : IEquatable<Color>
|
||||
/// <param name="color1">The base color.</param>
|
||||
/// <param name="color2">The color to blend.</param>
|
||||
/// <returns>The blended color.</returns>
|
||||
public static Color operator +(in Color color1, in Color color2) => color1.Blend(color2);
|
||||
public static Color operator +(Color color1, Color color2) => color1.Blend(color2);
|
||||
|
||||
/// <summary>
|
||||
/// Returns a value that indicates whether two specified <see cref="Color" /> are equal.
|
||||
@ -234,7 +234,7 @@ public readonly struct Color : IEquatable<Color>
|
||||
/// <param name="color1">The first <see cref="Color" /> to compare.</param>
|
||||
/// <param name="color2">The second <see cref="Color" /> to compare.</param>
|
||||
/// <returns><c>true</c> if <paramref name="color1" /> and <paramref name="color2" /> are equal; otherwise, <c>false</c>.</returns>
|
||||
public static bool operator ==(in Color color1, in Color color2) => color1.Equals(color2);
|
||||
public static bool operator ==(Color color1, Color color2) => color1.Equals(color2);
|
||||
|
||||
/// <summary>
|
||||
/// Returns a value that indicates whether two specified <see cref="Color" /> are equal.
|
||||
@ -242,7 +242,7 @@ public readonly struct Color : IEquatable<Color>
|
||||
/// <param name="color1">The first <see cref="Color" /> to compare.</param>
|
||||
/// <param name="color2">The second <see cref="Color" /> to compare.</param>
|
||||
/// <returns><c>true</c> if <paramref name="color1" /> and <paramref name="color2" /> are not equal; otherwise, <c>false</c>.</returns>
|
||||
public static bool operator !=(in Color color1, in Color color2) => !(color1 == color2);
|
||||
public static bool operator !=(Color color1, Color color2) => !(color1 == color2);
|
||||
|
||||
/// <summary>
|
||||
/// Converts a <see cref="ValueTuple"/> of ARGB-components to a <see cref="Color"/>.
|
||||
|
||||
@ -16,21 +16,21 @@ public static class HSVColor
|
||||
/// </summary>
|
||||
/// <param name="color">The color to get the value from.</param>
|
||||
/// <returns>The hue component value of the color.</returns>
|
||||
public static float GetHue(this in 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">The color to get the value from.</param>
|
||||
/// <returns>The saturation component value of the color.</returns>
|
||||
public static float GetSaturation(this in 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">The color to get the value from.</param>
|
||||
/// <returns>The value component value of the color.</returns>
|
||||
public static float GetValue(this in 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"/>.
|
||||
@ -40,7 +40,7 @@ public static class HSVColor
|
||||
/// </summary>
|
||||
/// <param name="color">The color to get the value from.</param>
|
||||
/// <returns>A tuple containing the hue, saturation and value component value of the color.</returns>
|
||||
public static (float hue, float saturation, float value) GetHSV(this in Color color)
|
||||
public static (float hue, float saturation, float value) GetHSV(this Color color)
|
||||
=> CaclulateHSVFromRGB(color.R, color.G, color.B);
|
||||
|
||||
#endregion
|
||||
@ -55,7 +55,7 @@ public static class HSVColor
|
||||
/// <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 in Color color, float hue = 0, float saturation = 0, float value = 0)
|
||||
public static Color AddHSV(this Color color, float hue = 0, float saturation = 0, float value = 0)
|
||||
{
|
||||
(float cHue, float cSaturation, float cValue) = color.GetHSV();
|
||||
return Create(color.A, cHue + hue, cSaturation + saturation, cValue + value);
|
||||
@ -69,7 +69,7 @@ public static class HSVColor
|
||||
/// <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 in Color color, float hue = 0, float saturation = 0, float value = 0)
|
||||
public static Color SubtractHSV(this Color color, float hue = 0, float saturation = 0, float value = 0)
|
||||
{
|
||||
(float cHue, float cSaturation, float cValue) = color.GetHSV();
|
||||
return Create(color.A, cHue - hue, cSaturation - saturation, cValue - value);
|
||||
@ -83,7 +83,7 @@ public static class HSVColor
|
||||
/// <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 in Color color, float hue = 1, float saturation = 1, float value = 1)
|
||||
public static Color MultiplyHSV(this Color color, float hue = 1, float saturation = 1, float value = 1)
|
||||
{
|
||||
(float cHue, float cSaturation, float cValue) = color.GetHSV();
|
||||
return Create(color.A, cHue * hue, cSaturation * saturation, cValue * value);
|
||||
@ -97,7 +97,7 @@ public static class HSVColor
|
||||
/// <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 in Color color, float hue = 1, float saturation = 1, float value = 1)
|
||||
public static Color DivideHSV(this Color color, float hue = 1, float saturation = 1, float value = 1)
|
||||
{
|
||||
(float cHue, float cSaturation, float cValue) = color.GetHSV();
|
||||
return Create(color.A, cHue / hue, cSaturation / saturation, cValue / value);
|
||||
@ -111,7 +111,7 @@ public static class HSVColor
|
||||
/// <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 in Color color, float? hue = null, float? saturation = null, float? value = null)
|
||||
public static Color SetHSV(this Color color, float? hue = null, float? saturation = null, float? value = null)
|
||||
{
|
||||
(float cHue, float cSaturation, float cValue) = color.GetHSV();
|
||||
return Create(color.A, hue ?? cHue, saturation ?? cSaturation, value ?? cValue);
|
||||
|
||||
@ -16,21 +16,21 @@ public static class HclColor
|
||||
/// </summary>
|
||||
/// <param name="color">The color to get the value from.</param>
|
||||
/// <returns>The H component value of the color. </returns>
|
||||
public static float GetHclH(this in Color color) => color.GetHcl().h;
|
||||
public static float GetHclH(this Color color) => color.GetHcl().h;
|
||||
|
||||
/// <summary>
|
||||
/// Gets the c component value (Hcl-color space) of this <see cref="Color"/> in the range [0..1].
|
||||
/// </summary>
|
||||
/// <param name="color">The color to get the value from.</param>
|
||||
/// <returns>The c component value of the color. </returns>
|
||||
public static float GetHclC(this in Color color) => color.GetHcl().c;
|
||||
public static float GetHclC(this Color color) => color.GetHcl().c;
|
||||
|
||||
/// <summary>
|
||||
/// Gets the l component value (Hcl-color space) of this <see cref="Color"/> in the range [0..1].
|
||||
/// </summary>
|
||||
/// <param name="color">The color to get the value from.</param>
|
||||
/// <returns>The l component value of the color. </returns>
|
||||
public static float GetHclL(this in Color color) => color.GetHcl().l;
|
||||
public static float GetHclL(this Color color) => color.GetHcl().l;
|
||||
|
||||
/// <summary>
|
||||
/// Gets the H, c and l component values (Hcl-color space) of this <see cref="Color"/>.
|
||||
@ -40,7 +40,7 @@ public static class HclColor
|
||||
/// </summary>
|
||||
/// <param name="color">The color to get the value from.</param>
|
||||
/// <returns>A tuple containing the H, c and l component value of the color.</returns>
|
||||
public static (float h, float c, float l) GetHcl(this in Color color)
|
||||
public static (float h, float c, float l) GetHcl(this Color color)
|
||||
=> CalculateHclFromRGB(color.R, color.G, color.B);
|
||||
|
||||
#endregion
|
||||
@ -55,7 +55,7 @@ public static class HclColor
|
||||
/// <param name="c">The c value to add.</param>
|
||||
/// <param name="l">The l value to add.</param>
|
||||
/// <returns>The new color after the modification.</returns>
|
||||
public static Color AddHcl(this in Color color, float h = 0, float c = 0, float l = 0)
|
||||
public static Color AddHcl(this Color color, float h = 0, float c = 0, float l = 0)
|
||||
{
|
||||
(float cH, float cC, float cL) = color.GetHcl();
|
||||
return Create(color.A, cH + h, cC + c, cL + l);
|
||||
@ -69,7 +69,7 @@ public static class HclColor
|
||||
/// <param name="c">The c value to subtract.</param>
|
||||
/// <param name="l">The l value to subtract.</param>
|
||||
/// <returns>The new color after the modification.</returns>
|
||||
public static Color SubtractHcl(this in Color color, float h = 0, float c = 0, float l = 0)
|
||||
public static Color SubtractHcl(this Color color, float h = 0, float c = 0, float l = 0)
|
||||
{
|
||||
(float cH, float cC, float cL) = color.GetHcl();
|
||||
return Create(color.A, cH - h, cC - c, cL - l);
|
||||
@ -83,7 +83,7 @@ public static class HclColor
|
||||
/// <param name="c">The c value to multiply.</param>
|
||||
/// <param name="l">The l value to multiply.</param>
|
||||
/// <returns>The new color after the modification.</returns>
|
||||
public static Color MultiplyHcl(this in Color color, float h = 1, float c = 1, float l = 1)
|
||||
public static Color MultiplyHcl(this Color color, float h = 1, float c = 1, float l = 1)
|
||||
{
|
||||
(float cH, float cC, float cL) = color.GetHcl();
|
||||
return Create(color.A, cH * h, cC * c, cL * l);
|
||||
@ -97,7 +97,7 @@ public static class HclColor
|
||||
/// <param name="c">The c value to divide.</param>
|
||||
/// <param name="l">The l value to divide.</param>
|
||||
/// <returns>The new color after the modification.</returns>
|
||||
public static Color DivideHcl(this in Color color, float h = 1, float c = 1, float l = 1)
|
||||
public static Color DivideHcl(this Color color, float h = 1, float c = 1, float l = 1)
|
||||
{
|
||||
(float cH, float cC, float cL) = color.GetHcl();
|
||||
return Create(color.A, cH / h, cC / c, cL / l);
|
||||
@ -111,7 +111,7 @@ public static class HclColor
|
||||
/// <param name="c">The c value to set.</param>
|
||||
/// <param name="l">The l value to set.</param>
|
||||
/// <returns>The new color after the modification.</returns>
|
||||
public static Color SetHcl(this in Color color, float? h = null, float? c = null, float? l = null)
|
||||
public static Color SetHcl(this Color color, float? h = null, float? c = null, float? l = null)
|
||||
{
|
||||
(float cH, float cC, float cL) = color.GetHcl();
|
||||
return Create(color.A, h ?? cH, c ?? cC, l ?? cL);
|
||||
|
||||
@ -16,21 +16,21 @@ public static class LabColor
|
||||
/// </summary>
|
||||
/// <param name="color">The color to get the value from.</param>
|
||||
/// <returns>The L component value of the color.</returns>
|
||||
public static float GetLabL(this in Color color) => color.GetLab().l;
|
||||
public static float GetLabL(this Color color) => color.GetLab().l;
|
||||
|
||||
/// <summary>
|
||||
/// Gets the a component value (Lab-color space) of this <see cref="Color"/> in the range [0..1].
|
||||
/// </summary>
|
||||
/// <param name="color">The color to get the value from.</param>
|
||||
/// <returns>The a component value of the color.</returns>
|
||||
public static float GetLabA(this in Color color) => color.GetLab().a;
|
||||
public static float GetLabA(this Color color) => color.GetLab().a;
|
||||
|
||||
/// <summary>
|
||||
/// Gets the b component value (Lab-color space) of this <see cref="Color"/> in the range [0..1].
|
||||
/// </summary>
|
||||
/// <param name="color">The color to get the value from.</param>
|
||||
/// <returns>The b component value of the color.</returns>
|
||||
public static float GetLabB(this in Color color) => color.GetLab().b;
|
||||
public static float GetLabB(this Color color) => color.GetLab().b;
|
||||
|
||||
/// <summary>
|
||||
/// Gets the L, a and b component values (Lab-color space) of this <see cref="Color"/>.
|
||||
@ -40,7 +40,7 @@ public static class LabColor
|
||||
/// </summary>
|
||||
/// <param name="color">The color to get the value from.</param>
|
||||
/// <returns>A tuple containing the L, a and b component value of the color.</returns>
|
||||
public static (float l, float a, float b) GetLab(this in Color color)
|
||||
public static (float l, float a, float b) GetLab(this Color color)
|
||||
=> CalculateLabFromRGB(color.R, color.G, color.B);
|
||||
|
||||
#endregion
|
||||
@ -55,7 +55,7 @@ public static class LabColor
|
||||
/// <param name="a">The a value to add.</param>
|
||||
/// <param name="b">The b value to add.</param>
|
||||
/// <returns>The new color after the modification.</returns>
|
||||
public static Color AddLab(this in Color color, float l = 0, float a = 0, float b = 0)
|
||||
public static Color AddLab(this Color color, float l = 0, float a = 0, float b = 0)
|
||||
{
|
||||
(float cL, float cA, float cB) = color.GetLab();
|
||||
return Create(color.A, cL + l, cA + a, cB + b);
|
||||
@ -69,7 +69,7 @@ public static class LabColor
|
||||
/// <param name="a">The a value to subtract.</param>
|
||||
/// <param name="b">The b value to subtract.</param>
|
||||
/// <returns>The new color after the modification.</returns>
|
||||
public static Color SubtractLab(this in Color color, float l = 0, float a = 0, float b = 0)
|
||||
public static Color SubtractLab(this Color color, float l = 0, float a = 0, float b = 0)
|
||||
{
|
||||
(float cL, float cA, float cB) = color.GetLab();
|
||||
return Create(color.A, cL - l, cA - a, cB - b);
|
||||
@ -83,7 +83,7 @@ public static class LabColor
|
||||
/// <param name="a">The a value to multiply.</param>
|
||||
/// <param name="b">The b value to multiply.</param>
|
||||
/// <returns>The new color after the modification.</returns>
|
||||
public static Color MultiplyLab(this in Color color, float l = 1, float a = 1, float b = 1)
|
||||
public static Color MultiplyLab(this Color color, float l = 1, float a = 1, float b = 1)
|
||||
{
|
||||
(float cL, float cA, float cB) = color.GetLab();
|
||||
return Create(color.A, cL * l, cA * a, cB * b);
|
||||
@ -97,7 +97,7 @@ public static class LabColor
|
||||
/// <param name="a">The a value to divide.</param>
|
||||
/// <param name="b">The b value to divide.</param>
|
||||
/// <returns>The new color after the modification.</returns>
|
||||
public static Color DivideLab(this in Color color, float l = 1, float a = 1, float b = 1)
|
||||
public static Color DivideLab(this Color color, float l = 1, float a = 1, float b = 1)
|
||||
{
|
||||
(float cL, float cA, float cB) = color.GetLab();
|
||||
return Create(color.A, cL / l, cA / a, cB / b);
|
||||
@ -111,7 +111,7 @@ public static class LabColor
|
||||
/// <param name="a">The a value to set.</param>
|
||||
/// <param name="b">The b value to set.</param>
|
||||
/// <returns>The new color after the modification.</returns>
|
||||
public static Color SetLab(this in Color color, float? l = null, float? a = null, float? b = null)
|
||||
public static Color SetLab(this Color color, float? l = null, float? a = null, float? b = null)
|
||||
{
|
||||
(float cL, float cA, float cB) = color.GetLab();
|
||||
return Create(color.A, l ?? cL, a ?? cA, b ?? cB);
|
||||
|
||||
@ -16,35 +16,35 @@ public static class RGBColor
|
||||
/// </summary>
|
||||
/// <param name="color">The color to get the value from.</param>
|
||||
/// <returns>The A component value of the color.</returns>
|
||||
public static byte GetA(this in Color color) => color.A.GetByteValueFromPercentage();
|
||||
public static byte GetA(this Color color) => color.A.GetByteValueFromPercentage();
|
||||
|
||||
/// <summary>
|
||||
/// Gets the R component value of this <see cref="Color"/> as byte in the range [0..255].
|
||||
/// </summary>
|
||||
/// <param name="color">The color to get the value from.</param>
|
||||
/// <returns>The R component value of the color.</returns>
|
||||
public static byte GetR(this in Color color) => color.R.GetByteValueFromPercentage();
|
||||
public static byte GetR(this Color color) => color.R.GetByteValueFromPercentage();
|
||||
|
||||
/// <summary>
|
||||
/// Gets the G component value of this <see cref="Color"/> as byte in the range [0..255].
|
||||
/// </summary>
|
||||
/// <param name="color">The color to get the value from.</param>
|
||||
/// <returns>The G component value of the color.</returns>
|
||||
public static byte GetG(this in Color color) => color.G.GetByteValueFromPercentage();
|
||||
public static byte GetG(this Color color) => color.G.GetByteValueFromPercentage();
|
||||
|
||||
/// <summary>
|
||||
/// Gets the B component value of this <see cref="Color"/> as byte in the range [0..255].
|
||||
/// </summary>
|
||||
/// <param name="color">The color to get the value from.</param>
|
||||
/// <returns>The B component value of the color.</returns>
|
||||
public static byte GetB(this in Color color) => color.B.GetByteValueFromPercentage();
|
||||
public static byte GetB(this Color color) => color.B.GetByteValueFromPercentage();
|
||||
|
||||
/// <summary>
|
||||
/// Gets the A, R, G and B component value of this <see cref="Color"/> as byte in the range [0..255].
|
||||
/// </summary>
|
||||
/// <param name="color">The color to get the value from.</param>
|
||||
/// <returns>A tuple containing the A, R, G and B component value of the color.</returns>
|
||||
public static (byte a, byte r, byte g, byte b) GetRGBBytes(this in Color color)
|
||||
public static (byte a, byte r, byte g, byte b) GetRGBBytes(this Color color)
|
||||
=> (color.GetA(), color.GetR(), color.GetG(), color.GetB());
|
||||
|
||||
/// <summary>
|
||||
@ -52,7 +52,7 @@ public static class RGBColor
|
||||
/// </summary>
|
||||
/// <param name="color">The color to get the value from.</param>
|
||||
/// <returns>A tuple containing the A, R, G and B component value of the color.</returns>
|
||||
public static (float a, float r, float g, float b) GetRGB(this in 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
|
||||
@ -69,7 +69,7 @@ public static class RGBColor
|
||||
/// <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 in Color color, int r = 0, int g = 0, int b = 0)
|
||||
public static Color AddRGB(this Color color, int r = 0, int g = 0, int b = 0)
|
||||
=> new(color.A, color.GetR() + r, color.GetG() + g, color.GetB() + b);
|
||||
|
||||
/// <summary>
|
||||
@ -80,7 +80,7 @@ public static class RGBColor
|
||||
/// <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 in Color color, float r = 0, float g = 0, float 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>
|
||||
@ -89,7 +89,7 @@ public static class RGBColor
|
||||
/// <param name="color">The color to modify.</param>
|
||||
/// <param name="a">The alpha value to add.</param>
|
||||
/// <returns>The new color after the modification.</returns>
|
||||
public static Color AddA(this in Color color, int a)
|
||||
public static Color AddA(this Color color, int a)
|
||||
=> new(color.GetA() + a, color.R, color.G, color.B);
|
||||
|
||||
/// <summary>
|
||||
@ -98,7 +98,7 @@ public static class RGBColor
|
||||
/// <param name="color">The color to modify.</param>
|
||||
/// <param name="a">The alpha value to add.</param>
|
||||
/// <returns>The new color after the modification.</returns>
|
||||
public static Color AddA(this in Color color, float a)
|
||||
public static Color AddA(this Color color, float a)
|
||||
=> new(color.A + a, color.R, color.G, color.B);
|
||||
|
||||
#endregion
|
||||
@ -113,7 +113,7 @@ public static class RGBColor
|
||||
/// <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 in Color color, int r = 0, int g = 0, int b = 0)
|
||||
public static Color SubtractRGB(this Color color, int r = 0, int g = 0, int b = 0)
|
||||
=> new(color.A, color.GetR() - r, color.GetG() - g, color.GetB() - b);
|
||||
|
||||
/// <summary>
|
||||
@ -124,7 +124,7 @@ public static class RGBColor
|
||||
/// <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 in Color color, float r = 0, float g = 0, float 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>
|
||||
@ -133,7 +133,7 @@ public static class RGBColor
|
||||
/// <param name="color">The color to modify.</param>
|
||||
/// <param name="a">The alpha value to subtract.</param>
|
||||
/// <returns>The new color after the modification.</returns>
|
||||
public static Color SubtractA(this in Color color, int a)
|
||||
public static Color SubtractA(this Color color, int a)
|
||||
=> new(color.GetA() - a, color.R, color.G, color.B);
|
||||
|
||||
/// <summary>
|
||||
@ -142,7 +142,7 @@ public static class RGBColor
|
||||
/// <param name="color">The color to modify.</param>
|
||||
/// <param name="aPercent">The alpha value to subtract.</param>
|
||||
/// <returns>The new color after the modification.</returns>
|
||||
public static Color SubtractA(this in Color color, float aPercent)
|
||||
public static Color SubtractA(this Color color, float aPercent)
|
||||
=> new(color.A - aPercent, color.R, color.G, color.B);
|
||||
|
||||
#endregion
|
||||
@ -157,7 +157,7 @@ public static class RGBColor
|
||||
/// <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 in Color color, float r = 1, float g = 1, float 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>
|
||||
@ -166,7 +166,7 @@ public static class RGBColor
|
||||
/// <param name="color">The color to modify.</param>
|
||||
/// <param name="a">The alpha value to multiply.</param>
|
||||
/// <returns>The new color after the modification.</returns>
|
||||
public static Color MultiplyA(this in Color color, float a)
|
||||
public static Color MultiplyA(this Color color, float a)
|
||||
=> new(color.A * a, color.R, color.G, color.B);
|
||||
|
||||
#endregion
|
||||
@ -181,7 +181,7 @@ public static class RGBColor
|
||||
/// <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 in Color color, float r = 1, float g = 1, float 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>
|
||||
@ -190,7 +190,7 @@ public static class RGBColor
|
||||
/// <param name="color">The color to modify.</param>
|
||||
/// <param name="a">The alpha value to divide.</param>
|
||||
/// <returns>The new color after the modification.</returns>
|
||||
public static Color DivideA(this in Color color, float a)
|
||||
public static Color DivideA(this Color color, float a)
|
||||
=> new(color.A / a, color.R, color.G, color.B);
|
||||
|
||||
#endregion
|
||||
@ -205,7 +205,7 @@ public static class RGBColor
|
||||
/// <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 in Color color, byte? r = null, byte? g = null, byte? b = null)
|
||||
public static Color SetRGB(this Color color, byte? r = null, byte? g = null, byte? b = null)
|
||||
=> new(color.A, r ?? color.GetR(), g ?? color.GetG(), b ?? color.GetB());
|
||||
|
||||
/// <summary>
|
||||
@ -216,7 +216,7 @@ public static class RGBColor
|
||||
/// <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 in Color color, int? r = null, int? g = null, int? b = null)
|
||||
public static Color SetRGB(this Color color, int? r = null, int? g = null, int? b = null)
|
||||
=> new(color.A, r ?? color.GetR(), g ?? color.GetG(), b ?? color.GetB());
|
||||
|
||||
/// <summary>
|
||||
@ -227,7 +227,7 @@ public static class RGBColor
|
||||
/// <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 in Color color, float? r = null, float? g = null, float? 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>
|
||||
@ -236,7 +236,7 @@ public static class RGBColor
|
||||
/// <param name="color">The color to modify.</param>
|
||||
/// <param name="a">The alpha value to set.</param>
|
||||
/// <returns>The new color after the modification.</returns>
|
||||
public static Color SetA(this in Color color, int a) => new(a, color.R, color.G, color.B);
|
||||
public static Color SetA(this Color color, int a) => new(a, color.R, color.G, color.B);
|
||||
|
||||
/// <summary>
|
||||
/// Sets the specified alpha value of this color.
|
||||
@ -244,7 +244,7 @@ public static class RGBColor
|
||||
/// <param name="color">The color to modify.</param>
|
||||
/// <param name="a">The alpha value to set.</param>
|
||||
/// <returns>The new color after the modification.</returns>
|
||||
public static Color SetA(this in Color color, float 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
|
||||
|
||||
@ -256,13 +256,13 @@ public static class RGBColor
|
||||
/// Gets the current color as a RGB-HEX-string.
|
||||
/// </summary>
|
||||
/// <returns>The RGB-HEX-string.</returns>
|
||||
public static string AsRGBHexString(this in Color color, bool leadingHash = true) => (leadingHash ? "#" : "") + ConversionHelper.ToHex(color.GetR(), color.GetG(), color.GetB());
|
||||
public static string AsRGBHexString(this Color color, bool leadingHash = true) => (leadingHash ? "#" : "") + ConversionHelper.ToHex(color.GetR(), color.GetG(), color.GetB());
|
||||
|
||||
/// <summary>
|
||||
/// Gets the current color as a ARGB-HEX-string.
|
||||
/// </summary>
|
||||
/// <returns>The ARGB-HEX-string.</returns>
|
||||
public static string AsARGBHexString(this in Color color, bool leadingHash = true) => (leadingHash ? "#" : "") + ConversionHelper.ToHex(color.GetA(), color.GetR(), color.GetG(), color.GetB());
|
||||
public static string AsARGBHexString(this Color color, bool leadingHash = true) => (leadingHash ? "#" : "") + ConversionHelper.ToHex(color.GetA(), color.GetR(), color.GetG(), color.GetB());
|
||||
|
||||
#endregion
|
||||
|
||||
|
||||
@ -16,21 +16,21 @@ public static class XYZColor
|
||||
/// </summary>
|
||||
/// <param name="color">The color to get the value from.</param>
|
||||
/// <returns>The X component value of the color.</returns>
|
||||
public static float GetX(this in Color color) => color.GetXYZ().x;
|
||||
public static float GetX(this Color color) => color.GetXYZ().x;
|
||||
|
||||
/// <summary>
|
||||
/// Gets the Y component value (XYZ-color space) of this <see cref="Color"/> in the range [0..100].
|
||||
/// </summary>
|
||||
/// <param name="color">The color to get the value from.</param>
|
||||
/// <returns>The Y component value of the color.</returns>
|
||||
public static float GetY(this in Color color) => color.GetXYZ().y;
|
||||
public static float GetY(this Color color) => color.GetXYZ().y;
|
||||
|
||||
/// <summary>
|
||||
/// Gets the Z component value (XYZ-color space) of this <see cref="Color"/> in the range [0..108.883].
|
||||
/// </summary>
|
||||
/// <param name="color">The color to get the value from.</param>
|
||||
/// <returns>The Z component value of the color.</returns>
|
||||
public static float GetZ(this in Color color) => color.GetXYZ().z;
|
||||
public static float GetZ(this Color color) => color.GetXYZ().z;
|
||||
|
||||
/// <summary>
|
||||
/// Gets the X, Y and Z component values (XYZ-color space) of this <see cref="Color"/>.
|
||||
@ -40,7 +40,7 @@ public static class XYZColor
|
||||
/// </summary>
|
||||
/// <param name="color">The color to get the value from.</param>
|
||||
/// <returns>A tuple containing the X, Y and Z component value of the color.</returns>
|
||||
public static (float x, float y, float z) GetXYZ(this in Color color)
|
||||
public static (float x, float y, float z) GetXYZ(this Color color)
|
||||
=> CaclulateXYZFromRGB(color.R, color.G, color.B);
|
||||
|
||||
#endregion
|
||||
@ -55,7 +55,7 @@ public static class XYZColor
|
||||
/// <param name="y">The Y value to add.</param>
|
||||
/// <param name="z">The Z value to add.</param>
|
||||
/// <returns>The new color after the modification.</returns>
|
||||
public static Color AddXYZ(this in Color color, float x = 0, float y = 0, float z = 0)
|
||||
public static Color AddXYZ(this Color color, float x = 0, float y = 0, float z = 0)
|
||||
{
|
||||
(float cX, float cY, float cZ) = color.GetXYZ();
|
||||
return Create(color.A, cX + x, cY + y, cZ + z);
|
||||
@ -69,7 +69,7 @@ public static class XYZColor
|
||||
/// <param name="y">The Y value to subtract.</param>
|
||||
/// <param name="z">The Z value to subtract.</param>
|
||||
/// <returns>The new color after the modification.</returns>
|
||||
public static Color SubtractXYZ(this in Color color, float x = 0, float y = 0, float z = 0)
|
||||
public static Color SubtractXYZ(this Color color, float x = 0, float y = 0, float z = 0)
|
||||
{
|
||||
(float cX, float cY, float cZ) = color.GetXYZ();
|
||||
return Create(color.A, cX - x, cY - y, cZ - z);
|
||||
@ -83,7 +83,7 @@ public static class XYZColor
|
||||
/// <param name="y">The Y value to multiply.</param>
|
||||
/// <param name="z">The Z value to multiply.</param>
|
||||
/// <returns>The new color after the modification.</returns>
|
||||
public static Color MultiplyXYZ(this in Color color, float x = 1, float y = 1, float z = 1)
|
||||
public static Color MultiplyXYZ(this Color color, float x = 1, float y = 1, float z = 1)
|
||||
{
|
||||
(float cX, float cY, float cZ) = color.GetXYZ();
|
||||
return Create(color.A, cX * x, cY * y, cZ * z);
|
||||
@ -97,7 +97,7 @@ public static class XYZColor
|
||||
/// <param name="y">The Y value to divide.</param>
|
||||
/// <param name="z">The Z value to divide.</param>
|
||||
/// <returns>The new color after the modification.</returns>
|
||||
public static Color DivideXYZ(this in Color color, float x = 1, float y = 1, float z = 1)
|
||||
public static Color DivideXYZ(this Color color, float x = 1, float y = 1, float z = 1)
|
||||
{
|
||||
(float cX, float cY, float cZ) = color.GetXYZ();
|
||||
return Create(color.A, cX / x, cY / y, cZ / z);
|
||||
@ -111,7 +111,7 @@ public static class XYZColor
|
||||
/// <param name="y">The Y value to set.</param>
|
||||
/// <param name="z">The Z value to set.</param>
|
||||
/// <returns>The new color after the modification.</returns>
|
||||
public static Color SetXYZ(this in Color color, float? x = null, float? y = null, float? z = null)
|
||||
public static Color SetXYZ(this Color color, float? x = null, float? y = null, float? z = null)
|
||||
{
|
||||
(float cX, float cY, float cZ) = color.GetXYZ();
|
||||
return Create(color.A, x ?? cX, y ?? cY, z ?? cZ);
|
||||
|
||||
@ -12,5 +12,5 @@ public interface IBrushDecorator : IDecorator
|
||||
/// <param name="rectangle">The rectangle in which the <see cref="IBrush"/> should be drawn.</param>
|
||||
/// <param name="renderTarget">The target (key/point) from which the <see cref="Color"/> should be taken.</param>
|
||||
/// <param name="color">The <see cref="Color"/> to be modified.</param>
|
||||
void ManipulateColor(in Rectangle rectangle, in RenderTarget renderTarget, ref Color color);
|
||||
void ManipulateColor(Rectangle rectangle, RenderTarget renderTarget, ref Color color);
|
||||
}
|
||||
@ -179,7 +179,7 @@ public abstract class AbstractRGBDevice<TDeviceInfo> : Placeable, IRGBDevice<TDe
|
||||
{ }
|
||||
|
||||
/// <inheritdoc />
|
||||
public virtual Led? AddLed(LedId ledId, in Point location, in Size size, object? customData = null)
|
||||
public virtual Led? AddLed(LedId ledId, Point location, Size size, object? customData = null)
|
||||
{
|
||||
if ((ledId == LedId.Invalid) || LedMapping.ContainsKey(ledId)) return null;
|
||||
|
||||
|
||||
@ -72,7 +72,7 @@ public interface IRGBDevice : IEnumerable<Led>, IPlaceable, IBindable, IDisposab
|
||||
/// <param name="size">The size of the led.</param>
|
||||
/// <param name="customData">Custom data saved on the led.</param>
|
||||
/// <returns>The newly added led or <c>null</c> if a led with this id is already added.</returns>
|
||||
Led? AddLed(LedId ledId, in Point location, in Size size, object? customData = null);
|
||||
Led? AddLed(LedId ledId, Point location, Size size, object? customData = null);
|
||||
|
||||
/// <summary>
|
||||
/// Removes the led with the specified id from the device.
|
||||
|
||||
@ -16,7 +16,7 @@ public static class ColorExtensions
|
||||
/// <param name="color1">The start color of the distance calculation.</param>
|
||||
/// <param name="color2">The end color fot the distance calculation.</param>
|
||||
/// <returns>The redmean distance between the two specified colors.</returns>
|
||||
public static double DistanceTo(this in Color color1, in Color color2)
|
||||
public static double DistanceTo(this Color color1, Color color2)
|
||||
{
|
||||
(_, byte r1, byte g1, byte b1) = color1.GetRGBBytes();
|
||||
(_, byte r2, byte g2, byte b2) = color2.GetRGBBytes();
|
||||
|
||||
@ -91,9 +91,11 @@ public static class FloatExtensions
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public static byte GetByteValueFromPercentage(this float percentage)
|
||||
{
|
||||
// ReSharper disable once ConvertIfStatementToSwitchStatement - This results in a bit more instructions
|
||||
if (float.IsNaN(percentage) || (percentage <= 0)) return 0;
|
||||
if (percentage >= 1.0f) return byte.MaxValue;
|
||||
|
||||
return (byte)(percentage >= 1.0f ? 255 : percentage * 256.0f);
|
||||
return (byte)(percentage * 256.0f);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
|
||||
@ -16,7 +16,7 @@ public static class PointExtensions
|
||||
/// <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 in Point point, float x = 0, float 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 specified amuont around the specified origin.
|
||||
@ -25,7 +25,7 @@ public static class PointExtensions
|
||||
/// <param name="rotation">The rotation.</param>
|
||||
/// <param name="origin">The origin to rotate around. [0,0] if not set.</param>
|
||||
/// <returns>The new location of the point.</returns>
|
||||
public static Point Rotate(this in Point point, in Rotation rotation, in Point origin = new())
|
||||
public static Point Rotate(this Point point, Rotation rotation, Point origin = new())
|
||||
{
|
||||
float sin = MathF.Sin(rotation.Radians);
|
||||
float cos = MathF.Cos(rotation.Radians);
|
||||
|
||||
@ -15,7 +15,7 @@ public static class RectangleExtensions
|
||||
/// <param name="rect">The rectangle to modify.</param>
|
||||
/// <param name="location">The new location of the rectangle.</param>
|
||||
/// <returns>The modified <see cref="Rectangle"/>.</returns>
|
||||
public static Rectangle SetLocation(this in Rectangle rect, in Point location) => new(location, rect.Size);
|
||||
public static Rectangle SetLocation(this Rectangle rect, Point location) => new(location, rect.Size);
|
||||
|
||||
/// <summary>
|
||||
/// Sets the <see cref="Point.X"/> of the <see cref="Rectangle.Location"/> of the specified rectangle.
|
||||
@ -23,7 +23,7 @@ public static class RectangleExtensions
|
||||
/// <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 in Rectangle rect, float 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 specified rectangle.
|
||||
@ -31,7 +31,7 @@ public static class RectangleExtensions
|
||||
/// <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 in Rectangle rect, float 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 specified rectangle.
|
||||
@ -39,7 +39,7 @@ public static class RectangleExtensions
|
||||
/// <param name="rect">The rectangle to modify.</param>
|
||||
/// <param name="size">The new size of the rectangle.</param>
|
||||
/// <returns>The modified <see cref="Rectangle"/>.</returns>
|
||||
public static Rectangle SetSize(this in Rectangle rect, in Size size) => new(rect.Location, size);
|
||||
public static Rectangle SetSize(this Rectangle rect, Size size) => new(rect.Location, size);
|
||||
|
||||
/// <summary>
|
||||
/// Sets the <see cref="Size.Width"/> of the <see cref="Rectangle.Size"/> of the specified rectangle.
|
||||
@ -47,7 +47,7 @@ public static class RectangleExtensions
|
||||
/// <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 in Rectangle rect, float 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 specified rectangle.
|
||||
@ -55,7 +55,7 @@ public static class RectangleExtensions
|
||||
/// <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 in Rectangle rect, float 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.
|
||||
@ -63,7 +63,7 @@ public static class RectangleExtensions
|
||||
/// <param name="rect">The rectangle to calculate the intersection for.</param>
|
||||
/// <param name="intersectingRect">The intersecting rectangle.</param>
|
||||
/// <returns>The percentage of intersection.</returns>
|
||||
public static float CalculateIntersectPercentage(this in Rectangle rect, in Rectangle intersectingRect)
|
||||
public static float CalculateIntersectPercentage(this Rectangle rect, Rectangle intersectingRect)
|
||||
{
|
||||
if (rect.IsEmpty || intersectingRect.IsEmpty) return 0;
|
||||
|
||||
@ -77,7 +77,7 @@ public static class RectangleExtensions
|
||||
/// <param name="rect">The rectangle to calculate the intersection for.</param>
|
||||
/// <param name="intersectingRectangle">The intersecting <see cref="Rectangle"/>.</param>
|
||||
/// <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 in Rectangle rect, in Rectangle intersectingRectangle)
|
||||
public static Rectangle CalculateIntersection(this Rectangle rect, Rectangle intersectingRectangle)
|
||||
{
|
||||
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);
|
||||
@ -97,7 +97,7 @@ public static class RectangleExtensions
|
||||
/// <param name="rect">The containing rectangle.</param>
|
||||
/// <param name="point">The <see cref="Point"/> to test.</param>
|
||||
/// <returns><c>true</c> if the rectangle contains the specified point; otherwise <c>false</c>.</returns>
|
||||
public static bool Contains(this in Rectangle rect, in Point point) => rect.Contains(point.X, point.Y);
|
||||
public static bool Contains(this Rectangle rect, Point point) => rect.Contains(point.X, point.Y);
|
||||
|
||||
/// <summary>
|
||||
/// Determines if the specified location is contained within this <see cref="Rectangle"/>.
|
||||
@ -106,7 +106,7 @@ public static class RectangleExtensions
|
||||
/// <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 specified coordinates; otherwise <c>false</c>.</returns>
|
||||
public static bool Contains(this in Rectangle rect, float x, float 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>
|
||||
@ -115,7 +115,7 @@ public static class RectangleExtensions
|
||||
/// <param name="rect">The containing rectangle.</param>
|
||||
/// <param name="rect2">The <see cref="Rectangle"/> to test.</param>
|
||||
/// <returns><c>true</c> if the rectangle contains the specified rect; otherwise <c>false</c>.</returns>
|
||||
public static bool Contains(this in Rectangle rect, in Rectangle rect2) => (rect.Location.X <= rect2.Location.X) && ((rect2.Location.X + rect2.Size.Width) <= (rect.Location.X + rect.Size.Width))
|
||||
public static bool Contains(this Rectangle rect, Rectangle rect2) => (rect.Location.X <= rect2.Location.X) && ((rect2.Location.X + rect2.Size.Width) <= (rect.Location.X + rect.Size.Width))
|
||||
&& (rect.Location.Y <= rect2.Location.Y) && ((rect2.Location.Y + rect2.Size.Height) <= (rect.Location.Y + rect.Size.Height));
|
||||
|
||||
/// <summary>
|
||||
@ -124,7 +124,7 @@ public static class RectangleExtensions
|
||||
/// <param name="rect">The <see cref="Rectangle"/> to move.</param>
|
||||
/// <param name="point">The amount to move.</param>
|
||||
/// <returns>The moved rectangle.</returns>
|
||||
public static Rectangle Translate(this in Rectangle rect, in Point point) => rect.Translate(point.X, point.Y);
|
||||
public static Rectangle Translate(this Rectangle rect, Point point) => rect.Translate(point.X, point.Y);
|
||||
|
||||
/// <summary>
|
||||
/// Moves the specified <see cref="Rectangle"/> by the specified amount.
|
||||
@ -133,7 +133,7 @@ public static class RectangleExtensions
|
||||
/// <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 in Rectangle rect, float x = 0, float 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 specified amuont around the specified origin.
|
||||
@ -149,7 +149,7 @@ public static class RectangleExtensions
|
||||
/// <param name="rotation">The rotation.</param>
|
||||
/// <param name="origin">The origin to rotate around. [0,0] if not set.</param>
|
||||
/// <returns>A array of <see cref="Point"/> containing the new locations of the corners of the original rectangle.</returns>
|
||||
public static Point[] Rotate(this in Rectangle rect, in Rotation rotation, in Point origin = new())
|
||||
public static Point[] Rotate(this Rectangle rect, Rotation rotation, Point origin = new())
|
||||
{
|
||||
Point[] points =
|
||||
[
|
||||
|
||||
@ -90,7 +90,7 @@ public readonly struct Point : IEquatable<Point>
|
||||
/// <param name="point1">The first <see cref="Point" /> to compare.</param>
|
||||
/// <param name="point2">The second <see cref="Point" /> to compare.</param>
|
||||
/// <returns><c>true</c> if <paramref name="point1" /> and <paramref name="point2" /> are equal; otherwise, <c>false</c>.</returns>
|
||||
public static bool operator ==(in Point point1, in Point point2) => point1.Equals(point2);
|
||||
public static bool operator ==(Point point1, Point point2) => point1.Equals(point2);
|
||||
|
||||
/// <summary>
|
||||
/// Returns a value that indicates whether two specified <see cref="Point" /> are equal.
|
||||
@ -98,7 +98,7 @@ public readonly struct Point : IEquatable<Point>
|
||||
/// <param name="point1">The first <see cref="Point" /> to compare.</param>
|
||||
/// <param name="point2">The second <see cref="Point" /> to compare.</param>
|
||||
/// <returns><c>true</c> if <paramref name="point1" /> and <paramref name="point2" /> are not equal; otherwise, <c>false</c>.</returns>
|
||||
public static bool operator !=(in Point point1, in Point point2) => !(point1 == point2);
|
||||
public static bool operator !=(Point point1, Point point2) => !(point1 == point2);
|
||||
|
||||
/// <summary>
|
||||
/// Returns a new <see cref="Point"/> representing the addition of the two provided <see cref="Point"/>.
|
||||
@ -106,7 +106,7 @@ public readonly struct Point : IEquatable<Point>
|
||||
/// <param name="point1">The first <see cref="Point"/>.</param>
|
||||
/// <param name="point2">The second <see cref="Point"/>.</param>
|
||||
/// <returns>A new <see cref="Point"/> representing the addition of the two provided <see cref="Point"/>.</returns>
|
||||
public static Point operator +(in Point point1, in Point point2) => new(point1.X + point2.X, point1.Y + point2.Y);
|
||||
public static Point operator +(Point point1, Point point2) => new(point1.X + point2.X, point1.Y + point2.Y);
|
||||
|
||||
/// <summary>
|
||||
/// Returns a new <see cref="Rectangle"/> created from the provided <see cref="Point"/> and <see cref="Size"/>.
|
||||
@ -114,7 +114,7 @@ public readonly struct Point : IEquatable<Point>
|
||||
/// <param name="point">The <see cref="Point"/> of the rectangle.</param>
|
||||
/// <param name="size">The <see cref="Size"/> of the rectangle.</param>
|
||||
/// <returns>The rectangle created from the provided <see cref="Point"/> and <see cref="Size"/>.</returns>
|
||||
public static Rectangle operator +(in Point point, in Size size) => new(point, size);
|
||||
public static Rectangle operator +(Point point, Size size) => new(point, size);
|
||||
|
||||
/// <summary>
|
||||
/// Returns a new <see cref="Point"/> representing the subtraction of the two provided <see cref="Point"/>.
|
||||
@ -122,7 +122,7 @@ public readonly struct Point : IEquatable<Point>
|
||||
/// <param name="point1">The first <see cref="Point"/>.</param>
|
||||
/// <param name="point2">The second <see cref="Point"/>.</param>
|
||||
/// <returns>A new <see cref="Point"/> representing the subtraction of the two provided <see cref="Point"/>.</returns>
|
||||
public static Point operator -(in Point point1, in Point point2) => new(point1.X - point2.X, point1.Y - point2.Y);
|
||||
public static Point operator -(Point point1, Point point2) => new(point1.X - point2.X, point1.Y - point2.Y);
|
||||
|
||||
/// <summary>
|
||||
/// Returns a new <see cref="Point"/> representing the multiplication of the two provided <see cref="Point"/>.
|
||||
@ -130,7 +130,7 @@ public readonly struct Point : IEquatable<Point>
|
||||
/// <param name="point1">The first <see cref="Point"/>.</param>
|
||||
/// <param name="point2">The second <see cref="Point"/>.</param>
|
||||
/// <returns>A new <see cref="Point"/> representing the multiplication of the two provided <see cref="Point"/>.</returns>
|
||||
public static Point operator *(in Point point1, in Point point2) => new(point1.X * point2.X, point1.Y * point2.Y);
|
||||
public static Point operator *(Point point1, Point point2) => new(point1.X * point2.X, point1.Y * point2.Y);
|
||||
|
||||
/// <summary>
|
||||
/// Returns a new <see cref="Point"/> representing the division of the two provided <see cref="Point"/>.
|
||||
@ -138,7 +138,7 @@ public readonly struct Point : IEquatable<Point>
|
||||
/// <param name="point1">The first <see cref="Point"/>.</param>
|
||||
/// <param name="point2">The second <see cref="Point"/>.</param>
|
||||
/// <returns>A new <see cref="Point"/> representing the division of the two provided <see cref="Point"/>.</returns>
|
||||
public static Point operator /(in Point point1, in Point point2)
|
||||
public static Point operator /(Point point1, Point point2)
|
||||
{
|
||||
if (point2.X.EqualsInTolerance(0) || point2.Y.EqualsInTolerance(0)) return Invalid;
|
||||
return new Point(point1.X / point2.X, point1.Y / point2.Y);
|
||||
@ -150,7 +150,7 @@ public readonly struct Point : IEquatable<Point>
|
||||
/// <param name="point">The <see cref="Point"/>.</param>
|
||||
/// <param name="scale">The <see cref="Scale"/>.</param>
|
||||
/// <returns>A new <see cref="Point"/> representing the multiplication of the <see cref="Point"/> and the provided <see cref="Scale"/>.</returns>
|
||||
public static Point operator *(in Point point, in Scale scale) => new(point.X * scale.Horizontal, point.Y * scale.Vertical);
|
||||
public static Point operator *(Point point, Scale scale) => new(point.X * scale.Horizontal, point.Y * scale.Vertical);
|
||||
|
||||
#endregion
|
||||
}
|
||||
@ -179,7 +179,7 @@ public readonly struct Rectangle : IEquatable<Rectangle>
|
||||
|
||||
#region Methods
|
||||
|
||||
private static (Point location, Size size) InitializeFromPoints(in Point point1, in Point point2)
|
||||
private static (Point location, Size size) InitializeFromPoints(Point point1, Point point2)
|
||||
{
|
||||
float posX = Math.Min(point1.X, point2.X);
|
||||
float posY = Math.Min(point1.Y, point2.Y);
|
||||
@ -225,7 +225,7 @@ public readonly struct Rectangle : IEquatable<Rectangle>
|
||||
/// <param name="rectangle1">The first <see cref="Rectangle" /> to compare.</param>
|
||||
/// <param name="rectangle2">The second <see cref="Rectangle" /> to compare.</param>
|
||||
/// <returns><c>true</c> if <paramref name="rectangle1" /> and <paramref name="rectangle2" /> are equal; otherwise, <c>false</c>.</returns>
|
||||
public static bool operator ==(in Rectangle rectangle1, in Rectangle rectangle2) => rectangle1.Equals(rectangle2);
|
||||
public static bool operator ==(Rectangle rectangle1, Rectangle rectangle2) => rectangle1.Equals(rectangle2);
|
||||
|
||||
/// <summary>
|
||||
/// Returns a value that indicates whether two specified <see cref="Rectangle" /> are equal.
|
||||
@ -233,7 +233,7 @@ public readonly struct Rectangle : IEquatable<Rectangle>
|
||||
/// <param name="rectangle1">The first <see cref="Rectangle" /> to compare.</param>
|
||||
/// <param name="rectangle2">The second <see cref="Rectangle" /> to compare.</param>
|
||||
/// <returns><c>true</c> if <paramref name="rectangle1" /> and <paramref name="rectangle2" /> are not equal; otherwise, <c>false</c>.</returns>
|
||||
public static bool operator !=(in Rectangle rectangle1, in Rectangle rectangle2) => !(rectangle1 == rectangle2);
|
||||
public static bool operator !=(Rectangle rectangle1, Rectangle rectangle2) => !(rectangle1 == rectangle2);
|
||||
|
||||
// DarthAffe 20.02.2021: Used for normalization
|
||||
/// <summary>
|
||||
@ -242,7 +242,7 @@ public readonly struct Rectangle : IEquatable<Rectangle>
|
||||
/// <param name="rectangle1">The rectangle to nromalize.</param>
|
||||
/// <param name="rectangle2">The reference used for normalization.</param>
|
||||
/// <returns>A normalized rectangle.</returns>
|
||||
public static Rectangle operator /(in Rectangle rectangle1, in Rectangle rectangle2)
|
||||
public static Rectangle operator /(Rectangle rectangle1, Rectangle rectangle2)
|
||||
{
|
||||
float x = rectangle1.Location.X / (rectangle2.Size.Width - rectangle2.Location.X);
|
||||
float y = rectangle1.Location.Y / (rectangle2.Size.Height - rectangle2.Location.Y);
|
||||
|
||||
@ -103,7 +103,7 @@ public readonly struct Rotation : IEquatable<Rotation>
|
||||
/// <param name="rotation1">The first <see cref="Rotation" /> to compare.</param>
|
||||
/// <param name="rotation2">The second <see cref="Rotation" /> to compare.</param>
|
||||
/// <returns><c>true</c> if <paramref name="rotation1" /> and <paramref name="rotation2" /> are equal; otherwise, <c>false</c>.</returns>
|
||||
public static bool operator ==(in Rotation rotation1, in Rotation rotation2) => rotation1.Equals(rotation2);
|
||||
public static bool operator ==(Rotation rotation1, Rotation rotation2) => rotation1.Equals(rotation2);
|
||||
|
||||
/// <summary>
|
||||
/// Returns a value that indicates whether two specified <see cref="Rotation" /> are equal.
|
||||
@ -111,7 +111,7 @@ public readonly struct Rotation : IEquatable<Rotation>
|
||||
/// <param name="rotation1">The first <see cref="Rotation" /> to compare.</param>
|
||||
/// <param name="rotation2">The second <see cref="Rotation" /> to compare.</param>
|
||||
/// <returns><c>true</c> if <paramref name="rotation1" /> and <paramref name="rotation2" /> are not equal; otherwise, <c>false</c>.</returns>
|
||||
public static bool operator !=(in Rotation rotation1, in Rotation rotation2) => !(rotation1 == rotation2);
|
||||
public static bool operator !=(Rotation rotation1, Rotation rotation2) => !(rotation1 == rotation2);
|
||||
|
||||
/// <summary>
|
||||
/// Returns a new <see cref="Rotation"/> representing the addition of the <see cref="Rotation"/> and the provided value.
|
||||
@ -119,7 +119,7 @@ public readonly struct Rotation : IEquatable<Rotation>
|
||||
/// <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 +(in Rotation rotation, float 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 @@ public readonly struct Rotation : IEquatable<Rotation>
|
||||
/// <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 -(in Rotation rotation, float 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 @@ public readonly struct Rotation : IEquatable<Rotation>
|
||||
/// <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 *(in Rotation rotation, float 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,7 +143,7 @@ public readonly struct Rotation : IEquatable<Rotation>
|
||||
/// <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 /(in Rotation rotation, float 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 float to a <see cref="Rotation" />.
|
||||
@ -155,7 +155,7 @@ public readonly struct Rotation : IEquatable<Rotation>
|
||||
/// 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 float(in Rotation rotation) => rotation.Degrees;
|
||||
public static implicit operator float(Rotation rotation) => rotation.Degrees;
|
||||
|
||||
#endregion
|
||||
}
|
||||
@ -110,7 +110,7 @@ public readonly struct Size : IEquatable<Size>
|
||||
/// <param name="size1">The first <see cref="Size" /> to compare.</param>
|
||||
/// <param name="size2">The second <see cref="Size" /> to compare.</param>
|
||||
/// <returns><c>true</c> if <paramref name="size1" /> and <paramref name="size2" /> are equal; otherwise, <c>false</c>.</returns>
|
||||
public static bool operator ==(in Size size1, in Size size2) => size1.Equals(size2);
|
||||
public static bool operator ==(Size size1, Size size2) => size1.Equals(size2);
|
||||
|
||||
/// <summary>
|
||||
/// Returns a value that indicates whether two specified <see cref="Size" /> are equal.
|
||||
@ -118,7 +118,7 @@ public readonly struct Size : IEquatable<Size>
|
||||
/// <param name="size1">The first <see cref="Size" /> to compare.</param>
|
||||
/// <param name="size2">The second <see cref="Size" /> to compare.</param>
|
||||
/// <returns><c>true</c> if <paramref name="size1" /> and <paramref name="size2" /> are not equal; otherwise, <c>false</c>.</returns>
|
||||
public static bool operator !=(in Size size1, in Size size2) => !(size1 == size2);
|
||||
public static bool operator !=(Size size1, Size size2) => !(size1 == size2);
|
||||
|
||||
/// <summary>
|
||||
/// Returns a new <see cref="Size"/> representing the addition of the two provided <see cref="Size"/>.
|
||||
@ -126,7 +126,7 @@ public readonly struct Size : IEquatable<Size>
|
||||
/// <param name="size1">The first <see cref="Size"/>.</param>
|
||||
/// <param name="size2">The second <see cref="Size"/>.</param>
|
||||
/// <returns>A new <see cref="Size"/> representing the addition of the two provided <see cref="Size"/>.</returns>
|
||||
public static Size operator +(in Size size1, in Size size2) => new(size1.Width + size2.Width, size1.Height + size2.Height);
|
||||
public static Size operator +(Size size1, Size size2) => new(size1.Width + size2.Width, size1.Height + size2.Height);
|
||||
|
||||
/// <summary>
|
||||
/// Returns a new <see cref="Rectangle"/> created from the provided <see cref="Point"/> and <see cref="Size"/>.
|
||||
@ -134,7 +134,7 @@ public readonly struct Size : IEquatable<Size>
|
||||
/// <param name="size">The <see cref="Size"/> of the rectangle.</param>
|
||||
/// <param name="point">The <see cref="Point"/> of the rectangle.</param>
|
||||
/// <returns>The rectangle created from the provided <see cref="Point"/> and <see cref="Size"/>.</returns>
|
||||
public static Rectangle operator +(in Size size, in Point point) => new(point, size);
|
||||
public static Rectangle operator +(Size size, Point point) => new(point, size);
|
||||
|
||||
/// <summary>
|
||||
/// Returns a new <see cref="Size"/> representing the subtraction of the two provided <see cref="Size"/>.
|
||||
@ -142,7 +142,7 @@ public readonly struct Size : IEquatable<Size>
|
||||
/// <param name="size1">The first <see cref="Size"/>.</param>
|
||||
/// <param name="size2">The second <see cref="Size"/>.</param>
|
||||
/// <returns>A new <see cref="Size"/> representing the subtraction of the two provided <see cref="Size"/>.</returns>
|
||||
public static Size operator -(in Size size1, in Size size2) => new(size1.Width - size2.Width, size1.Height - size2.Height);
|
||||
public static Size operator -(Size size1, Size size2) => new(size1.Width - size2.Width, size1.Height - size2.Height);
|
||||
|
||||
/// <summary>
|
||||
/// Returns a new <see cref="Size"/> representing the multiplication of the two provided <see cref="Size"/>.
|
||||
@ -150,7 +150,7 @@ public readonly struct Size : IEquatable<Size>
|
||||
/// <param name="size1">The first <see cref="Size"/>.</param>
|
||||
/// <param name="size2">The second <see cref="Size"/>.</param>
|
||||
/// <returns>A new <see cref="Size"/> representing the multiplication of the two provided <see cref="Size"/>.</returns>
|
||||
public static Size operator *(in Size size1, in Size size2) => new(size1.Width * size2.Width, size1.Height * size2.Height);
|
||||
public static Size operator *(Size size1, Size size2) => new(size1.Width * size2.Width, size1.Height * size2.Height);
|
||||
|
||||
/// <summary>
|
||||
/// Returns a new <see cref="Size"/> representing the multiplication of the <see cref="Size"/> and the provided factor.
|
||||
@ -158,7 +158,7 @@ public readonly struct Size : IEquatable<Size>
|
||||
/// <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 *(in Size size, float 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"/>.
|
||||
@ -166,7 +166,7 @@ public readonly struct Size : IEquatable<Size>
|
||||
/// <param name="size1">The first <see cref="Size"/>.</param>
|
||||
/// <param name="size2">The second <see cref="Size"/>.</param>
|
||||
/// <returns>A new <see cref="Size"/> representing the division of the two provided <see cref="Size"/>.</returns>
|
||||
public static Size operator /(in Size size1, in Size size2)
|
||||
public static Size operator /(Size size1, Size size2)
|
||||
=> size2.Width.EqualsInTolerance(0) || size2.Height.EqualsInTolerance(0)
|
||||
? Invalid : new Size(size1.Width / size2.Width, size1.Height / size2.Height);
|
||||
|
||||
@ -176,7 +176,7 @@ public readonly struct Size : IEquatable<Size>
|
||||
/// <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 /(in Size size, float 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 specified <see cref="Scale"/>.
|
||||
@ -184,7 +184,7 @@ public readonly struct Size : IEquatable<Size>
|
||||
/// <param name="size">The <see cref="Size"/> to scale.</param>
|
||||
/// <param name="scale">The scaling factor.</param>
|
||||
/// <returns>A new <see cref="Size"/> representing the multiplication of the <see cref="Size"/> and the specified <see cref="Scale"/>.</returns>
|
||||
public static Size operator *(in Size size, in Scale scale) => new(size.Width * scale.Horizontal, size.Height * scale.Vertical);
|
||||
public static Size operator *(Size size, Scale scale) => new(size.Width * scale.Horizontal, size.Height * scale.Vertical);
|
||||
|
||||
#endregion
|
||||
}
|
||||
@ -69,7 +69,7 @@ public abstract class AbstractBrush : AbstractDecoratable<IBrushDecorator>, IBru
|
||||
/// <param name="rectangle">The rectangle in which the brush should be drawn.</param>
|
||||
/// <param name="renderTarget">The target (key/point) from which the color should be taken.</param>
|
||||
/// <param name="color">The <see cref="Color"/> to be modified.</param>
|
||||
protected virtual void ApplyDecorators(in Rectangle rectangle, in RenderTarget renderTarget, ref Color color)
|
||||
protected virtual void ApplyDecorators(Rectangle rectangle, RenderTarget renderTarget, ref Color color)
|
||||
{
|
||||
if (Decorators.Count == 0) return;
|
||||
|
||||
@ -89,7 +89,7 @@ public abstract class AbstractBrush : AbstractDecoratable<IBrushDecorator>, IBru
|
||||
/// <param name="rectangle">The rectangle in which the brush should be drawn.</param>
|
||||
/// <param name="renderTarget">The target (key/point) from which the color should be taken.</param>
|
||||
/// <returns>The color at the specified point.</returns>
|
||||
protected abstract Color GetColorAtPoint(in Rectangle rectangle, in RenderTarget renderTarget);
|
||||
protected abstract Color GetColorAtPoint(Rectangle rectangle, RenderTarget renderTarget);
|
||||
|
||||
/// <summary>
|
||||
/// Finalizes the color by appliing the overall brightness and opacity.<br/>
|
||||
|
||||
@ -41,7 +41,7 @@ public sealed class SolidColorBrush : AbstractBrush
|
||||
#region Methods
|
||||
|
||||
/// <inheritdoc />
|
||||
protected override Color GetColorAtPoint(in Rectangle rectangle, in RenderTarget renderTarget) => Color;
|
||||
protected override Color GetColorAtPoint(Rectangle rectangle, RenderTarget renderTarget) => Color;
|
||||
|
||||
#endregion
|
||||
|
||||
|
||||
@ -36,7 +36,7 @@ public sealed class TextureBrush : AbstractBrush
|
||||
#region Methods
|
||||
|
||||
/// <inheritdoc />
|
||||
protected override Color GetColorAtPoint(in Rectangle rectangle, in RenderTarget renderTarget)
|
||||
protected override Color GetColorAtPoint(Rectangle rectangle, RenderTarget renderTarget)
|
||||
{
|
||||
Rectangle normalizedRect = renderTarget.Rectangle / rectangle;
|
||||
return Texture[normalizedRect];
|
||||
|
||||
@ -5,8 +5,8 @@ internal sealed class EmptyTexture : ITexture
|
||||
#region Properties & Fields
|
||||
|
||||
public Size Size { get; } = new(0, 0);
|
||||
public Color this[in Point point] => Color.Transparent;
|
||||
public Color this[in Rectangle rectangle] => Color.Transparent;
|
||||
public Color this[Point point] => Color.Transparent;
|
||||
public Color this[Rectangle rectangle] => Color.Transparent;
|
||||
|
||||
#endregion
|
||||
}
|
||||
@ -20,12 +20,12 @@ public interface ITexture
|
||||
/// </summary>
|
||||
/// <param name="point">The location to get the color from.</param>
|
||||
/// <returns>The color at the specified location.</returns>
|
||||
Color this[in Point point] { get; }
|
||||
Color this[Point point] { get; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets the sampled color inside the specified rectangle.
|
||||
/// </summary>
|
||||
/// <param name="rectangle">The rectangle to get the color from.</param>
|
||||
/// <returns>The sampled color.</returns>
|
||||
Color this[in Rectangle rectangle] { get; }
|
||||
Color this[Rectangle rectangle] { get; }
|
||||
}
|
||||
@ -39,7 +39,7 @@ public abstract class PixelTexture<T> : ITexture
|
||||
public Size Size { get; }
|
||||
|
||||
/// <inheritdoc />
|
||||
public virtual Color this[in Point point]
|
||||
public virtual Color this[Point point]
|
||||
{
|
||||
get
|
||||
{
|
||||
@ -52,7 +52,7 @@ public abstract class PixelTexture<T> : ITexture
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
public virtual Color this[in Rectangle rectangle]
|
||||
public virtual Color this[Rectangle rectangle]
|
||||
{
|
||||
get
|
||||
{
|
||||
|
||||
@ -22,7 +22,7 @@ public sealed class AverageColorSampler : ISampler<Color>
|
||||
#region Methods
|
||||
|
||||
/// <inheritdoc />
|
||||
public unsafe void Sample(in SamplerInfo<Color> info, Span<Color> pixelData)
|
||||
public unsafe void Sample(SamplerInfo<Color> info, Span<Color> pixelData)
|
||||
{
|
||||
int count = info.Width * info.Height;
|
||||
if (count == 0) return;
|
||||
|
||||
@ -13,5 +13,5 @@ public interface ISampler<T>
|
||||
/// </summary>
|
||||
/// <param name="info">The information containing the data to sample.</param>
|
||||
/// <param name="pixelData">The buffer used to write the resulting pixel to.</param>
|
||||
void Sample(in SamplerInfo<T> info, Span<T> pixelData);
|
||||
void Sample(SamplerInfo<T> info, Span<T> pixelData);
|
||||
}
|
||||
@ -25,7 +25,7 @@ public sealed class LimitedColorUpdateQueue : MidiUpdateQueue
|
||||
#region Methods
|
||||
|
||||
/// <inheritdoc />
|
||||
protected override ShortMessage CreateMessage(object key, in Color color)
|
||||
protected override ShortMessage CreateMessage(object key, Color color)
|
||||
{
|
||||
(byte mode, byte id) = ((byte, byte))key;
|
||||
return new ShortMessage(mode, id, Convert.ToByte(ConvertColor(color)));
|
||||
@ -37,7 +37,7 @@ public sealed class LimitedColorUpdateQueue : MidiUpdateQueue
|
||||
/// </summary>
|
||||
/// <param name="color">The <see cref="Color"/> to convert.</param>
|
||||
/// <returns>The novation-representation of the <see cref="Color"/>.</returns>
|
||||
private static int ConvertColor(in Color color)
|
||||
private static int ConvertColor(Color color)
|
||||
{
|
||||
(double hue, double _, double value) = color.GetHSV();
|
||||
|
||||
|
||||
@ -68,7 +68,7 @@ public abstract class MidiUpdateQueue : UpdateQueue
|
||||
/// <param name="key">The key used to identify the LED to update.</param>
|
||||
/// <param name="color">The color to send.</param>
|
||||
/// <returns>The message created out of the data set.</returns>
|
||||
protected abstract ShortMessage? CreateMessage(object key, in Color color);
|
||||
protected abstract ShortMessage? CreateMessage(object key, Color color);
|
||||
|
||||
/// <inheritdoc />
|
||||
public override void Dispose()
|
||||
|
||||
@ -151,7 +151,7 @@ public sealed class RGBColorUpdateQueue : MidiUpdateQueue
|
||||
#region Methods
|
||||
|
||||
/// <inheritdoc />
|
||||
protected override ShortMessage? CreateMessage(object key, in Color color)
|
||||
protected override ShortMessage? CreateMessage(object key, Color color)
|
||||
{
|
||||
(byte mode, byte id) = ((byte, byte))key;
|
||||
if (mode == 0x00) return null;
|
||||
@ -165,7 +165,7 @@ public sealed class RGBColorUpdateQueue : MidiUpdateQueue
|
||||
/// </summary>
|
||||
/// <param name="color">The <see cref="Color"/> to convert.</param>
|
||||
/// <returns>The novation-representation of the <see cref="Color"/>.</returns>
|
||||
private static int ConvertColor(in Color color)
|
||||
private static int ConvertColor(Color color)
|
||||
{
|
||||
int bestVelocity = 0;
|
||||
double bestMatchDistance = double.MaxValue;
|
||||
|
||||
@ -90,7 +90,7 @@ public sealed class FlashDecorator : AbstractUpdateAwareDecorator, IBrushDecorat
|
||||
#region Methods
|
||||
|
||||
/// <inheritdoc />
|
||||
public void ManipulateColor(in Rectangle rectangle, in RenderTarget renderTarget, ref Color color) => color = color.SetA(_currentValue);
|
||||
public void ManipulateColor(Rectangle rectangle, RenderTarget renderTarget, ref Color color) => color = color.SetA(_currentValue);
|
||||
|
||||
/// <inheritdoc />
|
||||
protected override void Update(double deltaTime)
|
||||
|
||||
@ -20,7 +20,7 @@ public static class GradientHelper
|
||||
/// <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 float CalculateLinearGradientOffset(in Point startPoint, in Point endPoint, in Point point)
|
||||
public static float CalculateLinearGradientOffset(Point startPoint, Point endPoint, Point point)
|
||||
{
|
||||
Point intersectingPoint;
|
||||
if (startPoint.Y.EqualsInTolerance(endPoint.Y)) // Horizontal case
|
||||
@ -57,7 +57,7 @@ public static class GradientHelper
|
||||
/// <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 float CalculateDistance(in Point point, in Point origin, in Point direction)
|
||||
public static float CalculateDistance(Point point, Point origin, Point direction)
|
||||
{
|
||||
float distance = CalculateDistance(point, origin);
|
||||
|
||||
@ -74,7 +74,7 @@ public static class GradientHelper
|
||||
/// <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 float CalculateDistance(in Point point1, in Point point2)
|
||||
public static float CalculateDistance(Point point1, Point point2)
|
||||
{
|
||||
float x = point1.X - point2.X;
|
||||
float y = point1.Y - point2.Y;
|
||||
|
||||
@ -21,10 +21,10 @@ public abstract class AbstractGradientTexture : AbstractBindable, ITexture
|
||||
public Size Size { get; }
|
||||
|
||||
/// <inheritdoc />
|
||||
public Color this[in Point point] => GetColor(point);
|
||||
public Color this[Point point] => GetColor(point);
|
||||
|
||||
/// <inheritdoc />
|
||||
public Color this[in Rectangle rectangle] => GetColor(rectangle.Center);
|
||||
public Color this[Rectangle rectangle] => GetColor(rectangle.Center);
|
||||
|
||||
#endregion
|
||||
|
||||
@ -50,7 +50,7 @@ public abstract class AbstractGradientTexture : AbstractBindable, ITexture
|
||||
/// </summary>
|
||||
/// <param name="point">The location to get the color from.</param>
|
||||
/// <returns>The color at the specified location.</returns>
|
||||
protected abstract Color GetColor(in Point point);
|
||||
protected abstract Color GetColor(Point point);
|
||||
|
||||
#endregion
|
||||
}
|
||||
@ -88,7 +88,7 @@ public sealed class ConicalGradientTexture : AbstractGradientTexture
|
||||
#region Methods
|
||||
|
||||
/// <inheritdoc />
|
||||
protected override Color GetColor(in Point point)
|
||||
protected override Color GetColor(Point point)
|
||||
{
|
||||
float angle = MathF.Atan2(point.Y - Center.Y, point.X - Center.X) - Origin;
|
||||
if (angle < 0) angle += PI2;
|
||||
|
||||
@ -71,7 +71,7 @@ public sealed class LinearGradientTexture : AbstractGradientTexture
|
||||
#region Methods
|
||||
|
||||
/// <inheritdoc />
|
||||
protected override Color GetColor(in Point point)
|
||||
protected override Color GetColor(Point point)
|
||||
{
|
||||
float offset = GradientHelper.CalculateLinearGradientOffset(StartPoint, EndPoint, point);
|
||||
return Gradient.GetColor(offset);
|
||||
|
||||
@ -69,7 +69,7 @@ public sealed class RadialGradientTexture : AbstractGradientTexture
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
protected override Color GetColor(in Point point)
|
||||
protected override Color GetColor(Point point)
|
||||
{
|
||||
float distance = GradientHelper.CalculateDistance(point, Center);
|
||||
float offset = distance / _referenceDistance;
|
||||
|
||||
@ -18,7 +18,7 @@ public sealed class AverageByteSampler : ISampler<byte>
|
||||
#region Methods
|
||||
|
||||
/// <inheritdoc />
|
||||
public unsafe void Sample(in SamplerInfo<byte> info, Span<byte> pixelData)
|
||||
public unsafe void Sample(SamplerInfo<byte> info, Span<byte> pixelData)
|
||||
{
|
||||
int count = info.Width * info.Height;
|
||||
if (count == 0) return;
|
||||
|
||||
@ -12,7 +12,7 @@ public sealed class AverageFloatSampler : ISampler<float>
|
||||
#region Methods
|
||||
|
||||
/// <inheritdoc />
|
||||
public unsafe void Sample(in SamplerInfo<float> info, Span<float> pixelData)
|
||||
public unsafe void Sample(SamplerInfo<float> info, Span<float> pixelData)
|
||||
{
|
||||
int count = info.Width * info.Height;
|
||||
if (count == 0) return;
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user