using System; namespace NvAPIWrapper.Display { /// /// Represents a RGB intensity texture pixel /// public class IntensityTexturePixel : IEquatable { /// /// Creates a new instance of . /// /// The intensity of the red light (0-1) /// The intensity of the green light (0-1) /// The intensity of the blue light (0-1) public IntensityTexturePixel(float redIntensity, float greenIntensity, float blueIntensity) { RedIntensity = Math.Max(Math.Min(redIntensity, 1), 0); GreenIntensity = Math.Max(Math.Min(greenIntensity, 1), 0); BlueIntensity = Math.Max(Math.Min(blueIntensity, 1), 0); } /// /// Gets the intensity of the blue light (0-1) /// public float BlueIntensity { get; } /// /// Gets the intensity of the green light (0-1) /// public float GreenIntensity { get; } /// /// Gets the intensity of the red light (0-1) /// public float RedIntensity { get; } /// public bool Equals(IntensityTexturePixel other) { if (other == null) { return false; } if (ReferenceEquals(this, other)) { return true; } return Math.Abs(RedIntensity - other.RedIntensity) < 0.0001 && Math.Abs(GreenIntensity - other.GreenIntensity) < 0.0001 && Math.Abs(BlueIntensity - other.BlueIntensity) < 0.0001; } /// /// Compares two instance of for equality. /// /// The first instance. /// The second instance. /// if both instances are equal, otherwise public static bool operator ==(IntensityTexturePixel left, IntensityTexturePixel right) { return Equals(left, right) || left?.Equals(right) == true; } /// /// Compares two instance of for in-equality. /// /// The first instance. /// The second instance. /// if both instances are not equal, otherwise public static bool operator !=(IntensityTexturePixel left, IntensityTexturePixel right) { return !(left == right); } internal static IntensityTexturePixel FromFloatArray(float[] floats, int index) { return new IntensityTexturePixel(floats[index], floats[index + 1], floats[index + 2]); } /// public override bool Equals(object obj) { if (obj == null) { return false; } if (ReferenceEquals(this, obj)) { return true; } return Equals(obj as IntensityTexturePixel); } /// public override int GetHashCode() { unchecked { var hashCode = RedIntensity.GetHashCode(); hashCode = (hashCode * 397) ^ GreenIntensity.GetHashCode(); hashCode = (hashCode * 397) ^ BlueIntensity.GetHashCode(); return hashCode; } } internal float[] ToFloatArray() { return new[] {RedIntensity, GreenIntensity, BlueIntensity}; } } }