示例#1
0
        public void Byte4()
        {
            // Test the limits.
            Assert.Equal((uint)0x0, new Byte4(Vector4.Zero).PackedValue);
            Assert.Equal(0xFFFFFFFF, new Byte4(Vector4.One * 255).PackedValue);

            // Test ToVector4.
            Assert.True(Equal(Vector4.One * 255, new Byte4(Vector4.One * 255).ToVector4()));
            Assert.True(Equal(Vector4.Zero, new Byte4(Vector4.Zero).ToVector4()));
            Assert.True(Equal(Vector4.UnitX * 255, new Byte4(Vector4.UnitX * 255).ToVector4()));
            Assert.True(Equal(Vector4.UnitY * 255, new Byte4(Vector4.UnitY * 255).ToVector4()));
            Assert.True(Equal(Vector4.UnitZ * 255, new Byte4(Vector4.UnitZ * 255).ToVector4()));
            Assert.True(Equal(Vector4.UnitW * 255, new Byte4(Vector4.UnitW * 255).ToVector4()));

            // Test clamping.
            Assert.True(Equal(Vector4.Zero, new Byte4(Vector4.One * -1234.0f).ToVector4()));
            Assert.True(Equal(Vector4.One * 255, new Byte4(Vector4.One * 1234.0f).ToVector4()));

            // Test ordering
            float x = 0x2d;
            float y = 0x36;
            float z = 0x7b;
            float w = 0x1a;

            Assert.Equal((uint)0x1a7b362d, new Byte4(x, y, z, w).PackedValue);

            x = 127.5f;
            y = -12.3f;
            z = 0.5f;
            w = -0.7f;
            Assert.Equal((uint)128, new Byte4(x, y, z, w).PackedValue);

            // Test ordering
            var rgb  = default(Rgb24);
            var rgba = default(Rgba32);
            var bgr  = default(Bgr24);
            var bgra = default(Bgra32);

            new Byte4(x, y, z, w).ToRgb24(ref rgb);
            Assert.Equal(rgb, new Rgb24(128, 0, 0));

            new Byte4(x, y, z, w).ToRgba32(ref rgba);
            Assert.Equal(rgba, new Rgba32(128, 0, 0, 0));

            new Byte4(x, y, z, w).ToBgr24(ref bgr);
            Assert.Equal(bgr, new Bgr24(128, 0, 0));

            new Byte4(x, y, z, w).ToBgra32(ref bgra);
            Assert.Equal(bgra, new Bgra32(128, 0, 0, 0));

            var r = new Byte4();

            r.PackFromRgba32(new Rgba32(20, 38, 0, 255));
            r.ToRgba32(ref rgba);
            Assert.Equal(rgba, new Rgba32(20, 38, 0, 255));
        }
示例#2
0
        public void Byte4_ToRgba32()
        {
            // arrange
            var byte4    = new Byte4(byte.MaxValue, byte.MaxValue, byte.MaxValue, byte.MaxValue);
            var expected = new Rgba32(Vector4.One);
            var actual   = default(Rgba32);

            // act
            byte4.ToRgba32(ref actual);

            Assert.Equal(expected, actual);
        }
示例#3
0
        public void Byte4_Rgba32()
        {
            // arrange
            var byte4    = new Byte4(127.5f, -12.3f, 0.5f, -0.7f);
            var actual   = default(Rgba32);
            var expected = new Rgba32(128, 0, 0, 0);

            // act
            byte4.ToRgba32(ref actual);

            // assert
            Assert.Equal(expected, actual);
        }