예제 #1
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="other"></param>
        /// <param name="exact"></param>
        /// <returns></returns>
        public bool Equals(IHsbColorModel <float> other, bool exact)
        {
            if (other == null)
            {
                return(false);
            }
            float b;

            if (exact)
            {
                if (other.Alpha != _alpha.ToPercentage())
                {
                    return(false);
                }
                ColorExtensions.RGBtoHSB(_red.ToPercentage(), _green.ToPercentage(), _blue.ToPercentage(), out float h, out float s, out b);
                return(other.Hue == h && other.Saturation == s && other.Brightness == b);
            }

            if (other.Alpha.FromPercentage() != _alpha)
            {
                return(false);
            }

            if (!other.IsNormalized)
            {
                other = other.AsNormalized();
            }

            ColorExtensions.HSBtoRGB(other.Hue, other.Saturation, other.Brightness, out float r, out float g, out b);
            return(_red == r.FromPercentage() && _green == g.FromPercentage() && _blue == b.FromPercentage());
        }
예제 #2
0
 /// <summary>
 ///
 /// </summary>
 /// <param name="value"></param>
 public HsbColorFNormalized(IHsbColorModel <byte> value)
 {
     if (value == null)
     {
         throw new ArgumentNullException();
     }
     if (value.Hue < 0f || value.Hue > ColorExtensions.HUE_MAXVALUE)
     {
         throw new ArgumentOutOfRangeException("hue");
     }
     if (value.Saturation < 0f || value.Saturation > 1f)
     {
         throw new ArgumentOutOfRangeException("saturation");
     }
     if (value.Brightness < 0f || value.Brightness > 1f)
     {
         throw new ArgumentOutOfRangeException("brightness");
     }
     if (value.Alpha < 0f || value.Alpha > 1f)
     {
         throw new ArgumentOutOfRangeException("alpha");
     }
     ColorExtensions.HSBtoRGB((value.Hue == ColorExtensions.HUE_MAXVALUE) ? 0f : value.Hue, value.Saturation, value.Brightness, out float r, out float g, out float b);
     ColorExtensions.RGBtoHSB(r, g, b, out float hue, out float saturation, out float brightness);
     _hue        = hue;
     _saturation = saturation;
     _brightness = brightness;
     _alpha      = value.Alpha;
 }
 /// <summary>
 ///
 /// </summary>
 /// <param name="value"></param>
 public HsbColor32Normalized(IHsbColorModel <float> value)
 {
     if (value == null)
     {
         throw new ArgumentNullException();
     }
     _value = 0;
     if (value.Hue < 0f || value.Hue > ColorExtensions.HUE_MAXVALUE)
     {
         throw new ArgumentOutOfRangeException("hue");
     }
     if (value.Saturation < 0f || value.Saturation > 1f)
     {
         throw new ArgumentOutOfRangeException("saturation");
     }
     if (value.Brightness < 0f || value.Brightness > 1f)
     {
         throw new ArgumentOutOfRangeException("brightness");
     }
     if (value.Alpha < 0f || value.Alpha > 1f)
     {
         throw new ArgumentOutOfRangeException("alpha");
     }
     ColorExtensions.HSBtoRGB(value.Hue, value.Saturation, value.Brightness, out float r, out float g, out float b);
     ColorExtensions.RGBtoHSB(r, g, b, out float hF, out float sF, out float bF);
     _hue        = hF.FromDegrees();
     _brightness = bF.FromPercentage();
     _saturation = sF.FromPercentage();
     _alpha      = value.Alpha.FromPercentage();;
 }
예제 #4
0
 /// <summary>
 ///
 /// </summary>
 /// <param name="value"></param>
 public RgbColorF(IHsbColorModel <byte> value)
 {
     if (value == null)
     {
         throw new ArgumentNullException();
     }
     ColorExtensions.HSBtoRGB(value.Hue.ToDegrees(), value.Saturation.ToPercentage(), value.Brightness.ToPercentage(), out float r, out float g, out float b);
     _red   = r;
     _green = g;
     _blue  = b;
     _alpha = value.Alpha.ToPercentage();
 }
 /// <summary>
 /// Indicates whether the current value is equal to another color model object.
 /// </summary>
 /// <param name="other">A color model to compare with this value.</param>
 /// <param name="exact"><c>true</c> to compare exact values; otherwise, <c>false</c> to compare normalized values.</param>
 /// <returns><c>true</c> if the current value is equal to another color model object; otherwise, <c>false</c>.</returns>
 public bool Equals(IHsbColorModel <float> other, bool exact)
 {
     if (other == null)
     {
         return(false);
     }
     if (exact)
     {
         return(_alpha.ToPercentage() == other.Alpha && _hue.ToDegrees() == other.Hue && _saturation.ToPercentage() == other.Saturation && _brightness.ToPercentage() == other.Brightness);
     }
     if (!other.IsNormalized)
     {
         other = other.AsNormalized();
     }
     return(_alpha == other.Alpha.FromPercentage() && _hue == other.Hue.FromDegrees() && _saturation == other.Saturation.FromPercentage() && _brightness == other.Brightness.FromPercentage());
 }
예제 #6
0
 /// <summary>
 ///
 /// </summary>
 /// <param name="value"></param>
 public RgbColorF(IHsbColorModel <float> value)
 {
     if (value == null)
     {
         throw new ArgumentNullException();
     }
     if (value.Alpha < 0f || value.Alpha > 1f)
     {
         throw new ArgumentOutOfRangeException("value", "Value for alpha is out of range");
     }
     try
     {
         ColorExtensions.HSBtoRGB(value.Hue, value.Saturation, value.Brightness, out float r, out float g, out float b);
         _red   = r;
         _green = g;
         _blue  = b;
     }
     catch (ArgumentOutOfRangeException exc) { throw new ArgumentOutOfRangeException("value", "Value for " + exc.ParamName + " is out of range"); }
     _alpha = value.Alpha;
 }
예제 #7
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="other"></param>
        /// <param name="exact"></param>
        /// <returns></returns>
        public bool Equals(IHsbColorModel <float> other, bool exact)
        {
            if (other == null || _alpha != other.Alpha)
            {
                return(false);
            }

            float b;

            if (exact)
            {
                ColorExtensions.RGBtoHSB(_red, _green, _blue, out float h, out float s, out b);
                return(other.Hue == h && other.Saturation == s && other.Brightness == b);
            }

            if (!other.IsNormalized)
            {
                other = other.AsNormalized();
            }

            ColorExtensions.HSBtoRGB(other.Hue, other.Saturation, other.Brightness, out float r, out float g, out b);
            return(_red == r && _green == g && _blue == b);
        }
예제 #8
0
 /// <summary>
 /// Merges a source <see cref="IColorModel"/> with 1 or more <seealso cref="IColorModel"/> objects by averaging average their values.
 /// </summary>
 /// <typeparam name="T">Value component type.</typeparam>
 /// <param name="source"></param>
 /// <param name="other"></param>
 /// <param name="additionalColors"></param>
 /// <returns></returns>
 public static IHsbColorModel <T> MergeAverage <T>(this IHsbColorModel <T> source, IHsbColorModel <T> other, params IHsbColorModel <T>[] additionalColors)
     where T : struct, IComparable, IFormattable, IConvertible, IComparable <T>, IEquatable <T>
 {
     throw new NotImplementedException();
 }
 /// <summary>
 /// Indicates whether the current value is equal to another color model object.
 /// </summary>
 /// <param name="other">A color model to compare with this value.</param>
 /// <returns><c>true</c> if the current value is equal to another color model object; otherwise, <c>false</c>.</returns>
 public bool Equals(IHsbColorModel <byte> other)
 {
     return(other.Alpha == _alpha && other.Hue == _hue && other.Saturation == _saturation && other.Brightness == _brightness);
 }
 /// <summary>
 /// Indicates whether the current value is equal to another color model object.
 /// </summary>
 /// <param name="other">A color model to compare with this value.</param>
 /// <returns><c>true</c> if the current value is equal to another color model object; otherwise, <c>false</c>.</returns>
 public bool Equals(IHsbColorModel <float> other)
 {
     return(Equals(other, false));
 }