fix: color lerp methods fixed

This commit is contained in:
Syntriax 2025-07-26 11:59:04 +03:00
parent 08311acc9a
commit 65eac57fce
3 changed files with 25 additions and 3 deletions

View File

@ -87,7 +87,14 @@ public readonly struct ColorHSV(float hue, float saturation, float value)
/// <param name="to">The ending <see cref="ColorHSV"/> (t = 1).</param>
/// <param name="t">The interpolation parameter.</param>
/// <returns>The interpolated <see cref="ColorHSV"/>.</returns>
public static ColorHSV Lerp(ColorHSV from, ColorHSV to, float t) => from + FromTo(from, to) * t;
public static ColorHSV Lerp(ColorHSV from, ColorHSV to, float t)
{
float hueDiff = to.Hue - from.Hue;
float saturationDiff = to.Saturation - from.Saturation;
float valueDiff = to.Value - from.Value;
return from + new ColorHSV(hueDiff * t, saturationDiff * t, valueDiff * t);
}
/// <summary>
/// Checks if two <see cref="ColorHSV"/>s are approximately equal within a specified epsilon range.

View File

@ -87,7 +87,14 @@ public readonly struct ColorRGB(byte r, byte g, byte b)
/// <param name="to">The ending <see cref="ColorRGB"/> (t = 1).</param>
/// <param name="t">The interpolation parameter.</param>
/// <returns>The interpolated <see cref="ColorRGB"/>.</returns>
public static ColorRGB Lerp(ColorRGB from, ColorRGB to, float t) => from + FromTo(from, to) * t;
public static ColorRGB Lerp(ColorRGB from, ColorRGB to, float t)
{
int redDiff = to.R - from.R;
int greenDiff = to.G - from.G;
int blueDiff = to.B - from.B;
return from + new ColorRGB((byte)(redDiff * t), (byte)(greenDiff * t), (byte)(blueDiff * t));
}
/// <summary>
/// Determines whether the specified object is equal to the current <see cref="ColorRGB"/>.

View File

@ -116,7 +116,15 @@ public readonly struct ColorRGBA(byte r, byte g, byte b, byte a = 255)
/// <param name="to">The ending <see cref="ColorRGBA"/> (t = 1).</param>
/// <param name="t">The interpolation parameter.</param>
/// <returns>The interpolated <see cref="ColorRGBA"/>.</returns>
public static ColorRGBA Lerp(ColorRGBA from, ColorRGBA to, float t) => from + FromTo(from, to) * t;
public static ColorRGBA Lerp(ColorRGBA from, ColorRGBA to, float t)
{
int redDiff = to.R - from.R;
int greenDiff = to.G - from.G;
int blueDiff = to.B - from.B;
int alphaDiff = to.A - from.A;
return from + new ColorRGBA((byte)(redDiff * t), (byte)(greenDiff * t), (byte)(blueDiff * t), (byte)(alphaDiff * t));
}
/// <summary>
/// Determines whether the specified object is equal to the current <see cref="ColorRGBA"/>.