예제 #1
0
        public void ColorRGBF_CastFromColor()
        {
            const double Epsilon = 0.25;

            Random random = new Random();
            double r      = NextComponent(random, 1.0);
            double g      = NextComponent(random, 1.0);
            double b      = NextComponent(random, 1.0);

            Color c = Color.FromArgb(byte.MaxValue, (int)(r * byte.MaxValue), (int)(g * byte.MaxValue), (int)(b * byte.MaxValue));

            ColorRGBF v = (ColorRGBF)c;

            Assert.AreEqual((float)r, v[0], Epsilon);
            Assert.AreEqual((float)g, v[1], Epsilon);
            Assert.AreEqual((float)b, v[2], Epsilon);

            // Not influenced by alpha
            c = Color.FromArgb(0, (int)(r * byte.MaxValue), (int)(g * byte.MaxValue), (int)(b * byte.MaxValue));
            v = (ColorRGBF)c;

            Assert.AreEqual((float)r, v[0], Epsilon);
            Assert.AreEqual((float)g, v[1], Epsilon);
            Assert.AreEqual((float)b, v[2], Epsilon);
        }
예제 #2
0
        public void ColorRGBF_Accessor()
        {
            float r = (float)NextComponent(1.0f);
            float g = (float)NextComponent(1.0f);
            float b = (float)NextComponent(1.0f);

            ColorRGBF v = new ColorRGBF(r, g, b);
            float     c;

            Assert.DoesNotThrow(() => c = v[0]);
            Assert.DoesNotThrow(() => c = v[1]);
            Assert.DoesNotThrow(() => c = v[2]);
            Assert.Throws <IndexOutOfRangeException>(() => c = v[+3]);
            Assert.Throws <IndexOutOfRangeException>(() => c = v[-1]);

            Assert.DoesNotThrow(() => v[0] = 1.0f);
            Assert.DoesNotThrow(() => v[1] = 1.0f);
            Assert.DoesNotThrow(() => v[2] = 1.0f);
            Assert.Throws <IndexOutOfRangeException>(() => v[+3] = 0.0f);
            Assert.Throws <IndexOutOfRangeException>(() => v[-1] = 0.0f);

            Assert.DoesNotThrow(() => v[2] = 0.0f);
            Assert.DoesNotThrow(() => v[2] = 1.0f);
            Assert.Throws <InvalidOperationException>(() => v[2] = -1.0f);
            Assert.Throws <InvalidOperationException>(() => v[2] = +1.1f);
        }
예제 #3
0
        public void ColorRGBF_CastToRGBA()
        {
            float r = (float)NextComponent(1.0f);
            float g = (float)NextComponent(1.0f);
            float b = (float)NextComponent(1.0f);

            ColorRGBF  v     = new ColorRGBF(r, g, b);
            ColorRGBAF vRGBA = v;
        }
예제 #4
0
        public void ColorRGBF_PixelType()
        {
            float r = (float)NextComponent(1.0f);
            float g = (float)NextComponent(1.0f);
            float b = (float)NextComponent(1.0f);

            ColorRGBF v = new ColorRGBF(r, g, b);

            Assert.AreNotEqual(PixelLayout.None, v.PixelType);
        }
예제 #5
0
        public void ColorRGBF_TestConstructor1()
        {
            float r = (float)1.0f;
            float g = (float)1.0f;
            float b = (float)1.0f;

            ColorRGBF v = new ColorRGBF(r, g, b);

            Assert.AreEqual(r, v.Red);
            Assert.AreEqual(g, v.Green);
            Assert.AreEqual(b, v.Blue);
        }
예제 #6
0
        public void ColorRGBF_CastToVertex4()
        {
            float r = (float)NextComponent(1.0f);
            float g = (float)NextComponent(1.0f);
            float b = (float)NextComponent(1.0f);

            ColorRGBF v      = new ColorRGBF(r, g, b);
            Vertex3f  vArray = v;

            Assert.AreEqual(r, vArray.x);
            Assert.AreEqual(g, vArray.y);
            Assert.AreEqual(b, vArray.z);
        }
예제 #7
0
        /// <summary>
        /// Convert a <see cref="Single[]"/> to <see cref="ColorRGBF[]"/>.
        /// </summary>
        /// <param name="array">
        /// The <see cref="Single[]"/> to be converted.
        /// </param>
        /// <returns>
        /// It returns the <see cref="ColorRGBF[]"/> equivalent to <paramref name="array"/>.
        /// </returns>
        public static ColorRGBF[] ToColorRGBF(this float[] array)
        {
            int structArrayLength = array.Length / 3;

            ColorRGBF[] structArray = new ColorRGBF[structArrayLength];

            for (int i = 0, j = 0; i < structArrayLength; i++, j += 3)
            {
                structArray[i] = new ColorRGBF(array[j + 0], array[j + 1], array[j + 2]);
            }

            return(structArray);
        }
예제 #8
0
        public void ColorRGBF_CastToRGBA()
        {
            float r = (float)NextComponent(1.0f);
            float g = (float)NextComponent(1.0f);
            float b = (float)NextComponent(1.0f);

            ColorRGBF  v     = new ColorRGBF(r, g, b);
            ColorRGBAF vRGBA = v;

            Assert.AreEqual(v.Red, vRGBA.Red);
            Assert.AreEqual(v.Green, vRGBA.Green);
            Assert.AreEqual(v.Blue, vRGBA.Blue);
            Assert.AreEqual(1.0f, vRGBA.Alpha);
        }
예제 #9
0
        public void ColorRGBF_CastToArray()
        {
            float r = (float)NextComponent(1.0f);
            float g = (float)NextComponent(1.0f);
            float b = (float)NextComponent(1.0f);

            ColorRGBF v = new ColorRGBF(r, g, b);

            float[] vArray = v;

            Assert.AreEqual(3, vArray.Length);
            Assert.AreEqual(r, vArray[0]);
            Assert.AreEqual(g, vArray[1]);
            Assert.AreEqual(b, vArray[2]);
        }