Ejemplo n.º 1
0
        public void NormalizedShort2()
        {
            Assert.Equal((uint)0x0, new NormalizedShort2(Vector2.Zero).PackedValue);
            Assert.Equal((uint)0x7FFF7FFF, new NormalizedShort2(Vector2.One).PackedValue);
            Assert.Equal(0x80018001, new NormalizedShort2(-Vector2.One).PackedValue);

            Assert.True(Equal(Vector2.One, new NormalizedShort2(Vector2.One).ToVector2()));
            Assert.True(Equal(Vector2.Zero, new NormalizedShort2(Vector2.Zero).ToVector2()));
            Assert.True(Equal(-Vector2.One, new NormalizedShort2(-Vector2.One).ToVector2()));
            Assert.True(Equal(Vector2.One, new NormalizedShort2(Vector2.One * 1234.0f).ToVector2()));
            Assert.True(Equal(-Vector2.One, new NormalizedShort2(Vector2.One * -1234.0f).ToVector2()));

            Assert.True(Equal(new Vector4(1, 1, 0, 1), (new NormalizedShort2(Vector2.One)).ToVector4()));
            Assert.True(Equal(new Vector4(0, 0, 0, 1), (new NormalizedShort2(Vector2.Zero)).ToVector4()));

            // Test Ordering
            float x = 0.35f;
            float y = -0.2f;

            Assert.Equal(0xE6672CCC, new NormalizedShort2(x, y).PackedValue);
            x = 0.1f;
            y = -0.3f;
            Assert.Equal(3650751693, new NormalizedShort2(x, y).PackedValue);

            byte[] rgb  = new byte[3];
            byte[] rgba = new byte[4];
            byte[] bgr  = new byte[3];
            byte[] bgra = new byte[4];

            NormalizedShort2 n = new NormalizedShort2();

            n.PackFromRgba32(new Rgba32(141, 90, 0, 0));
            n.ToXyzBytes(rgb, 0);
            Assert.Equal(rgb, new byte[] { 141, 90, 0 });

            // TODO: I don't think this can ever pass since the bytes are already truncated.
            // Assert.Equal(3650751693, n.PackedValue);

            new NormalizedShort2(x, y).ToXyzBytes(rgb, 0);
            Assert.Equal(rgb, new byte[] { 141, 90, 0 });

            new NormalizedShort2(x, y).ToXyzwBytes(rgba, 0);
            Assert.Equal(rgba, new byte[] { 141, 90, 0, 255 });

            new NormalizedShort2(x, y).ToZyxBytes(bgr, 0);
            Assert.Equal(bgr, new byte[] { 0, 90, 141 });

            new NormalizedShort2(x, y).ToZyxwBytes(bgra, 0);
            Assert.Equal(bgra, new byte[] { 0, 90, 141, 255 });
        }
Ejemplo n.º 2
0
        public void NormalizedShort2()
        {
            Assert.Equal((uint)0x0, new NormalizedShort2(Vector2.Zero).PackedValue);
            Assert.Equal((uint)0x7FFF7FFF, new NormalizedShort2(Vector2.One).PackedValue);
            Assert.Equal(0x80018001, new NormalizedShort2(-Vector2.One).PackedValue);

            Assert.True(Equal(Vector2.One, new NormalizedShort2(Vector2.One).ToVector2()));
            Assert.True(Equal(Vector2.Zero, new NormalizedShort2(Vector2.Zero).ToVector2()));
            Assert.True(Equal(-Vector2.One, new NormalizedShort2(-Vector2.One).ToVector2()));
            Assert.True(Equal(Vector2.One, new NormalizedShort2(Vector2.One * 1234.0f).ToVector2()));
            Assert.True(Equal(-Vector2.One, new NormalizedShort2(Vector2.One * -1234.0f).ToVector2()));

            Assert.True(Equal(new Vector4(1, 1, 0, 1), (new NormalizedShort2(Vector2.One)).ToVector4()));
            Assert.True(Equal(new Vector4(0, 0, 0, 1), (new NormalizedShort2(Vector2.Zero)).ToVector4()));

            // Test Ordering
            float x = 0.35f;
            float y = -0.2f;

            Assert.Equal(0xE6672CCC, new NormalizedShort2(x, y).PackedValue);
            x = 0.1f;
            y = -0.3f;
            Assert.Equal(3650751693, new NormalizedShort2(x, y).PackedValue);

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

            var n = new NormalizedShort2();

            n.PackFromRgba32(new Rgba32(141, 90, 0, 0));
            n.ToRgb24(ref rgb);
            Assert.Equal(rgb, new Rgb24(141, 90, 0));

            // TODO: I don't think this can ever pass since the bytes are already truncated.
            // Assert.Equal(3650751693, n.PackedValue);

            new NormalizedShort2(x, y).ToRgb24(ref rgb);
            Assert.Equal(rgb, new Rgb24(141, 90, 0));

            new NormalizedShort2(x, y).ToRgba32(ref rgba);
            Assert.Equal(rgba, new Rgba32(141, 90, 0, 255));

            new NormalizedShort2(x, y).ToBgr24(ref bgr);
            Assert.Equal(bgr, new Bgr24(141, 90, 0));

            new NormalizedShort2(x, y).ToBgra32(ref bgra);
            Assert.Equal(bgra, new Bgra32(141, 90, 0, 255));
        }
Ejemplo n.º 3
0
        public void NormalizedShort2_PackFromRgba32_ToRgb24()
        {
            // arrange
            var actual   = default(Rgb24);
            var short2   = new NormalizedShort2();
            var rgba     = new Rgba32(141, 90, 0, 0);
            var expected = new Rgb24(141, 90, 0);

            // act
            short2.PackFromRgba32(rgba);
            short2.ToRgb24(ref actual);

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