Skip to content

Commit

Permalink
Merge pull request #395 from DarthAffe/SmallPerformanceThings
Browse files Browse the repository at this point in the history
(MAJOR) Removed all in paramters as their performance impact is too h…
  • Loading branch information
DarthAffe authored Jul 21, 2024
2 parents fdfd35e + c398499 commit 0d41314
Show file tree
Hide file tree
Showing 38 changed files with 157 additions and 155 deletions.
10 changes: 5 additions & 5 deletions RGB.NET.Core/Color/Behaviors/DefaultColorBehavior.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,23 +14,23 @@ 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" />.
/// </summary>
/// <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" />.
/// </summary>
/// <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);
Expand All @@ -39,14 +39,14 @@ public bool Equals(in Color color, in Color color2) => color.A.EqualsInTolerance
/// 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;

Expand Down
10 changes: 5 additions & 5 deletions RGB.NET.Core/Color/Behaviors/IColorBehavior.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,34 +10,34 @@ 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" />.
/// </summary>
/// <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" />.
/// </summary>
/// <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);
}
10 changes: 5 additions & 5 deletions RGB.NET.Core/Color/Color.cs
Original file line number Diff line number Diff line change
Expand Up @@ -175,7 +175,7 @@ public Color(float a, float r, float g, float b)
/// 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)
{ }

Expand Down Expand Up @@ -214,7 +214,7 @@ public Color(in Color 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

Expand All @@ -226,23 +226,23 @@ public Color(in Color 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.
/// </summary>
/// <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.
/// </summary>
/// <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"/>.
Expand Down
18 changes: 9 additions & 9 deletions RGB.NET.Core/Color/HSVColor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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"/>.
Expand All @@ -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
Expand All @@ -55,7 +55,7 @@ public static (float hue, float saturation, float value) GetHSV(this in Color co
/// <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);
Expand All @@ -69,7 +69,7 @@ public static Color AddHSV(this in Color color, float hue = 0, float saturation
/// <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);
Expand All @@ -83,7 +83,7 @@ public static Color SubtractHSV(this in Color color, float hue = 0, float satura
/// <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);
Expand All @@ -97,7 +97,7 @@ public static Color MultiplyHSV(this in Color color, float hue = 1, float satura
/// <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);
Expand All @@ -111,7 +111,7 @@ public static Color DivideHSV(this in Color color, float hue = 1, float saturati
/// <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);
Expand Down
18 changes: 9 additions & 9 deletions RGB.NET.Core/Color/HclColor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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"/>.
Expand All @@ -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
Expand All @@ -55,7 +55,7 @@ public static (float h, float c, float l) GetHcl(this in Color color)
/// <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);
Expand All @@ -69,7 +69,7 @@ public static Color AddHcl(this in Color color, float h = 0, float c = 0, float
/// <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);
Expand All @@ -83,7 +83,7 @@ public static Color SubtractHcl(this in Color color, float h = 0, float c = 0, f
/// <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);
Expand All @@ -97,7 +97,7 @@ public static Color MultiplyHcl(this in Color color, float h = 1, float c = 1, f
/// <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);
Expand All @@ -111,7 +111,7 @@ public static Color DivideHcl(this in Color color, float h = 1, float c = 1, flo
/// <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);
Expand Down
Loading

0 comments on commit 0d41314

Please sign in to comment.