// Copyright (c) Six Labors and contributors.
// Licensed under the Apache License, Version 2.0.
using System;
using System.Numerics;
using System.Runtime.CompilerServices;
namespace SixLabors.ImageSharp.ColorSpaces
{
///
/// Represents an CMYK (cyan, magenta, yellow, keyline) color.
///
public readonly struct Cmyk : IEquatable
{
private static readonly Vector4 Min = Vector4.Zero;
private static readonly Vector4 Max = Vector4.One;
///
/// Gets the cyan color component.
/// A value ranging between 0 and 1.
///
public readonly float C;
///
/// Gets the magenta color component.
/// A value ranging between 0 and 1.
///
public readonly float M;
///
/// Gets the yellow color component.
/// A value ranging between 0 and 1.
///
public readonly float Y;
///
/// Gets the keyline black color component.
/// A value ranging between 0 and 1.
///
public readonly float K;
///
/// Initializes a new instance of the struct.
///
/// The cyan component.
/// The magenta component.
/// The yellow component.
/// The keyline black component.
[MethodImpl(InliningOptions.ShortMethod)]
public Cmyk(float c, float m, float y, float k)
: this(new Vector4(c, m, y, k))
{
}
///
/// Initializes a new instance of the struct.
///
/// The vector representing the c, m, y, k components.
[MethodImpl(InliningOptions.ShortMethod)]
public Cmyk(Vector4 vector)
{
vector = Vector4.Clamp(vector, Min, Max);
this.C = vector.X;
this.M = vector.Y;
this.Y = vector.Z;
this.K = vector.W;
}
///
/// Compares two objects for equality.
///
/// The on the left side of the operand.
/// The on the right side of the operand.
///
/// True if the current left is equal to the parameter; otherwise, false.
///
[MethodImpl(InliningOptions.ShortMethod)]
public static bool operator ==(Cmyk left, Cmyk right) => left.Equals(right);
///
/// Compares two objects for inequality
///
/// The on the left side of the operand.
/// The on the right side of the operand.
///
/// True if the current left is unequal to the parameter; otherwise, false.
///
[MethodImpl(InliningOptions.ShortMethod)]
public static bool operator !=(Cmyk left, Cmyk right) => !left.Equals(right);
///
[MethodImpl(InliningOptions.ShortMethod)]
public override int GetHashCode() => HashCode.Combine(this.C, this.M, this.Y, this.K);
///
public override string ToString() => FormattableString.Invariant($"Cmyk({this.C:#0.##}, {this.M:#0.##}, {this.Y:#0.##}, {this.K:#0.##})");
///
public override bool Equals(object obj) => obj is Cmyk other && this.Equals(other);
///
[MethodImpl(InliningOptions.ShortMethod)]
public bool Equals(Cmyk other)
{
return this.C.Equals(other.C)
&& this.M.Equals(other.M)
&& this.Y.Equals(other.Y)
&& this.K.Equals(other.K);
}
}
}