Пример #1
0
        /// <summary>
        /// Get of set color components.
        /// </summary>
        /// <param name="c">
        /// A <see cref="Int32"/> indicating the color component index.
        /// </param>
        /// <returns>
        /// The color component converted from a normalized floating point number.
        /// </returns>
        /// <exception cref="IndexOutOfRangeException">
        /// Exception thrown when <paramref name="c"/> is less than 0 or greater than the number of components of this IColor implementation.
        /// </exception>
        public float this[int c]
        {
            get
            {
                switch (c)
                {
                case 0: return(r);

                default:
                    throw new IndexOutOfRangeException();
                }
            }
            set
            {
                if (value < 0.0f || value > 1.0f)
                {
                    throw new InvalidOperationException("value out of range");
                }
                switch (c)
                {
                case 0: r = (HalfFloat)value; break;

                default:
                    throw new IndexOutOfRangeException();
                }
            }
        }
Пример #2
0
 /// <summary>
 /// Construct a ColorRGBAHF specifying RGBA components.
 /// </summary>
 /// <param name="r">
 /// A <see cref="HalfFloat"/> that specify the red component.
 /// </param>
 /// <param name="g">
 /// A <see cref="HalfFloat"/> that specify the green component.
 /// </param>
 /// <param name="b">
 /// A <see cref="HalfFloat"/> that specify the blue component.
 /// </param>
 /// <param name="a">
 /// A <see cref="HalfFloat"/> that specify the alpha component.
 /// </param>
 public ColorRGBAHF(HalfFloat r, HalfFloat g, HalfFloat b, HalfFloat a)
 {
     this.r = r;
     this.g = g;
     this.b = b;
     this.a = a;
 }
Пример #3
0
        /// <summary>
        /// Indicates whether the this ColorRGBAHF is equal to another ColorRGBAHF, tolerating an absolute error.
        /// </summary>
        /// <param name="other">
        /// The <see cref="ColorRGBAHF"/> to compare with this ColorRGBAHF.
        /// </param>
        /// <param name="precision">
        /// The <see cref="HalfFloat"/> that specifies the maximum absolute error tollerance.
        /// </param>
        /// <returns>
        /// It returns true if the this ColorRGBAHF is equal to <paramref name="other"/>; otherwise, false.
        /// </returns>
        public bool Equals(ColorRGBAHF other, HalfFloat precision)
        {
            if (Math.Abs(r - other.r) > precision)
            {
                return(false);
            }
            if (Math.Abs(g - other.g) > precision)
            {
                return(false);
            }
            if (Math.Abs(b - other.b) > precision)
            {
                return(false);
            }
            if (Math.Abs(a - other.a) > precision)
            {
                return(false);
            }

            return(true);
        }
Пример #4
0
 /// <summary>
 /// Construct a ColorRHF specifying R component.
 /// </summary>
 /// <param name="r">
 /// A <see cref="HalfFloat"/> that specify the red component.
 /// </param>
 public ColorRHF(HalfFloat r)
 {
     // Setup R components
     this.r = r;
 }
Пример #5
0
 /// <summary>
 /// Construct a ColorRGBAHF specifying RGB components.
 /// </summary>
 /// <param name="r">
 /// A <see cref="HalfFloat"/> that specify the red component.
 /// </param>
 /// <param name="g">
 /// A <see cref="HalfFloat"/> that specify the green component.
 /// </param>
 /// <param name="b">
 /// A <see cref="HalfFloat"/> that specify the blue component.
 /// </param>
 public ColorRGBAHF(HalfFloat r, HalfFloat g, HalfFloat b) :
     this(r, g, b, (HalfFloat)1.0f)
 {
 }