using System.Runtime.CompilerServices;
namespace Peridot;
///
/// Provides static methods to manipulation.
///
public partial struct ColorB
{
#region Math
///
/// Negates the specified color.
///
/// The color to negate.
/// The negated vector.
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static ColorB Negate(ColorB color)
{
var r = -color.R;
var g = -color.G;
var b = -color.B;
var a = -color.A;
return new((byte)r, (byte)g, (byte)b, (byte)a);
}
///
/// Adds two colors together.
///
/// The first color.
/// The second color.
/// The summed color.
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static ColorB Add(ColorB left, ColorB right)
{
var r = left.R + right.R;
var g = left.G + right.G;
var b = left.B + right.B;
var a = left.A + right.A;
return new((byte)r, (byte)g, (byte)b, (byte)a);
}
///
/// Subtracts the second color from the first.
///
/// The first color.
/// The second color.
/// The color that results from subracting from .
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static ColorB Subtract(ColorB left, ColorB right)
{
var r = left.R - right.R;
var g = left.G - right.G;
var b = left.B - right.B;
var a = left.A - right.A;
return new((byte)r, (byte)g, (byte)b, (byte)a);
}
///
/// Multiplies two colors together.
///
/// The first color.
/// The second color.
/// The product color.
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static ColorB Multiply(ColorB left, ColorB right)
{
var r = left.R * right.R;
var g = left.G * right.G;
var b = left.B * right.B;
var a = left.A * right.A;
return new((byte)r, (byte)g, (byte)b, (byte)a);
}
///
/// Divides the first color by the second.
///
/// The first color.
/// The second color.
/// The color that results from dividing by .
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static ColorB Divide(ColorB left, ColorB right)
{
var r = left.R / right.R;
var g = left.G / right.G;
var b = left.B / right.B;
var a = left.A / right.A;
return new((byte)r, (byte)g, (byte)b, (byte)a);
}
///
/// Multiples the specified color by the specified scalar value.
///
/// The color.
/// The scalar value.
/// The scaled color.
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static ColorB Multiply(ColorB left, float right)
{
var r = left.R * right;
var g = left.G * right;
var b = left.B * right;
var a = left.A * right;
return new((byte)r, (byte)g, (byte)b, (byte)a);
}
///
/// Divides the specified color by a specified scalar value.
///
/// The color.
/// The scalar value.
/// The result of the division.
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static ColorB Divide(ColorB left, float right)
{
var r = left.R / right;
var g = left.G / right;
var b = left.B / right;
var a = left.A / right;
return new((byte)r, (byte)g, (byte)b, (byte)a);
}
///
/// Multiples the specified color by the specified scalar value.
///
/// The scalar value.
/// The color.
/// The scaled color.
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static ColorB Multiply(float left, ColorB right) => Multiply(right, left);
///
/// Linearly interpolates between two colors.
///
/// The first color.
/// The second color.
/// Influence of the second color on the final result.
/// * (255 - ) + * .
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static ColorB Lerp(in ColorB a, in ColorB b, float t) =>
a + (b - a) * t;
#endregion
#region Operators
///
/// Element-wise equality.
///
/// The first value.
/// The second value.
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static bool operator ==(ColorB left, ColorB right) =>
left.Equals(right);
///
/// Element-wise inequality.
///
/// The first value.
/// The second value.
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static bool operator !=(ColorB left, ColorB right) =>
!left.Equals(right);
///
/// Negates the specified color.
///
/// The color to negate.
/// The negated vector.
public static ColorB operator -(ColorB color) => Negate(color);
///
/// Adds two colors together.
///
/// The first color.
/// The second color.
/// The summed color.
public static ColorB operator +(ColorB left, ColorB right) => Add(left, right);
///
/// Subtracts the second color from the first.
///
/// The first color.
/// The second color.
/// The color that results from subracting from .
public static ColorB operator -(ColorB left, ColorB right) => Subtract(left, right);
///
/// Multiplies two colors together.
///
/// The first color.
/// The second color.
/// The product color.
public static ColorB operator *(ColorB left, ColorB right) => Multiply(left, right);
///
/// Divides the first color by the second.
///
/// The first color.
/// The second color.
/// The color that results from dividing by .
public static ColorB operator /(ColorB left, ColorB right) => Divide(left, right);
///
/// Multiples the specified color by the specified scalar value.
///
/// The color.
/// The scalar value.
/// The scaled color.
public static ColorB operator *(ColorB left, float right) => Multiply(left, right);
///
/// Divides the specified color by a specified scalar value.
///
/// The color.
/// The scalar value.
/// The result of the division.
public static ColorB operator /(ColorB left, float right) => Divide(left, right);
///
/// Multiples the specified color by the specified scalar value.
///
/// The scalar value.
/// The color.
/// The scaled color.
public static ColorB operator *(float left, ColorB right) => Multiply(left, right);
#endregion
#region Colors
///
/// Red (255, 0, 0, 255)
///
public static readonly ColorB Red = new(255, 0, 0, 255);
///
/// Transparent (0, 0, 0, 0)
///
public static readonly ColorB Transparent = new(0, 0, 0, 0);
///
/// Dark Red (139, 0, 0, 255)
///
public static readonly ColorB DarkRed = new(139, 0, 0, 255);
///
/// Green (0, 255, 0, 255)
///
public static readonly ColorB Green = new(0, 255, 0, 255);
///
/// Blue (0, 0, 255, 255)
///
public static readonly ColorB Blue = new(0, 0, 255, 255);
///
/// Yellow (255, 255, 0, 255)
///
public static readonly ColorB Yellow = new(255, 255, 0, 255);
///
/// Grey (128, 128, 128 / 255f, 255)
///
public static readonly ColorB Grey = new(128, 128, 128, 255);
///
/// Light Grey (211, 211, 211, 255)
///
public static readonly ColorB LightGrey = new(211, 211, 211, 255);
///
/// Cyan (0, 255, 255, 255)
///
public static readonly ColorB Cyan = new(0, 255, 255, 255);
///
/// White (255, 255, 255, 255)
///
public static readonly ColorB White = new(255, 255, 255, 255);
///
/// Cornflower Blue (100, 149, 237, 255)
///
public static readonly ColorB CornflowerBlue = new(100, 149, 237, 255);
///
/// Clear (0, 0, 0, 0)
///
public static readonly ColorB Clear = new(0, 0, 0, 0);
///
/// Black (0, 0, 0, 255)
///
public static readonly ColorB Black = new(0, 0, 0, 255);
///
/// Pink (255, 192, 203, 255)
///
public static readonly ColorB Pink = new(255, 192, 203, 255);
///
/// Orange (255, 165, 0, 255)
///
public static readonly ColorB Orange = new(255, 165, 0, 255);
#endregion
}