Ejemplo n.º 1
0
        public void Short4()
        {
            // Test the limits.
            Assert.Equal((ulong)0x0, new Short4(Vector4.Zero).PackedValue);
            Assert.Equal((ulong)0x7FFF7FFF7FFF7FFF, new Short4(Vector4.One * 0x7FFF).PackedValue);
            Assert.Equal(0x8000800080008000, new Short4(Vector4.One * -0x8000).PackedValue);

            // Test ToVector4.
            Assert.Equal(Vector4.One * 0x7FFF, new Short4(Vector4.One * 0x7FFF).ToVector4());
            Assert.Equal(Vector4.Zero, new Short4(Vector4.Zero).ToVector4());
            Assert.Equal(Vector4.One * -0x8000, new Short4(Vector4.One * -0x8000).ToVector4());
            Assert.Equal(Vector4.UnitX * 0x7FFF, new Short4(Vector4.UnitX * 0x7FFF).ToVector4());
            Assert.Equal(Vector4.UnitY * 0x7FFF, new Short4(Vector4.UnitY * 0x7FFF).ToVector4());
            Assert.Equal(Vector4.UnitZ * 0x7FFF, new Short4(Vector4.UnitZ * 0x7FFF).ToVector4());
            Assert.Equal(Vector4.UnitW * 0x7FFF, new Short4(Vector4.UnitW * 0x7FFF).ToVector4());

            // Test clamping.
            Assert.Equal(Vector4.One * 0x7FFF, new Short4(Vector4.One * 1234567.0f).ToVector4());
            Assert.Equal(Vector4.One * -0x8000, new Short4(Vector4.One * -1234567.0f).ToVector4());

            // Test Ordering
            float x = 0.1f;
            float y = -0.3f;
            float z = 0.5f;
            float w = -0.7f;

            Assert.Equal(18446462598732840960, new Short4(x, y, z, w).PackedValue);

            x = 11547;
            y = 12653;
            z = 29623;
            w = 193;
            Assert.Equal((ulong)0x00c173b7316d2d1b, new Short4(x, y, z, w).PackedValue);

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

            new Short4(x, y, z, w).ToRgb24(ref rgb);
            Assert.Equal(rgb, new Rgb24(172, 177, 243));

            new Short4(x, y, z, w).ToRgba32(ref rgba);
            Assert.Equal(rgba, new Rgba32(172, 177, 243, 128));

            new Short4(x, y, z, w).ToBgr24(ref bgr);
            Assert.Equal(bgr, new Bgr24(172, 177, 243));

            new Short4(x, y, z, w).ToBgra32(ref bgra);
            Assert.Equal(bgra, new Bgra32(172, 177, 243, 128));

            var r = new Short4();

            r.PackFromRgba32(new Rgba32(20, 38, 0, 255));
            r.ToRgba32(ref rgba);
            Assert.Equal(rgba, new Rgba32(20, 38, 0, 255));
        }
        public void Short4()
        {
            // Test the limits.
            Assert.Equal((ulong)0x0, new Short4(Vector4.Zero).PackedValue);
            Assert.Equal((ulong)0x7FFF7FFF7FFF7FFF, new Short4(Vector4.One * 0x7FFF).PackedValue);
            Assert.Equal(0x8000800080008000, new Short4(Vector4.One * -0x8000).PackedValue);

            // Test ToVector4.
            Assert.Equal(Vector4.One * 0x7FFF, new Short4(Vector4.One * 0x7FFF).ToVector4());
            Assert.Equal(Vector4.Zero, new Short4(Vector4.Zero).ToVector4());
            Assert.Equal(Vector4.One * -0x8000, new Short4(Vector4.One * -0x8000).ToVector4());
            Assert.Equal(Vector4.UnitX * 0x7FFF, new Short4(Vector4.UnitX * 0x7FFF).ToVector4());
            Assert.Equal(Vector4.UnitY * 0x7FFF, new Short4(Vector4.UnitY * 0x7FFF).ToVector4());
            Assert.Equal(Vector4.UnitZ * 0x7FFF, new Short4(Vector4.UnitZ * 0x7FFF).ToVector4());
            Assert.Equal(Vector4.UnitW * 0x7FFF, new Short4(Vector4.UnitW * 0x7FFF).ToVector4());

            // Test clamping.
            Assert.Equal(Vector4.One * 0x7FFF, new Short4(Vector4.One * 1234567.0f).ToVector4());
            Assert.Equal(Vector4.One * -0x8000, new Short4(Vector4.One * -1234567.0f).ToVector4());

            // Test Ordering
            float x = 0.1f;
            float y = -0.3f;
            float z = 0.5f;
            float w = -0.7f;

            Assert.Equal(18446462598732840960, new Short4(x, y, z, w).PackedValue);

            x = 11547;
            y = 12653;
            z = 29623;
            w = 193;
            Assert.Equal((ulong)0x00c173b7316d2d1b, new Short4(x, y, z, w).PackedValue);

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

            new Short4(x, y, z, w).ToXyzBytes(rgb, 0);
            Assert.Equal(rgb, new byte[] { 172, 177, 243 });

            new Short4(x, y, z, w).ToXyzwBytes(rgba, 0);
            Assert.Equal(rgba, new byte[] { 172, 177, 243, 128 });

            new Short4(x, y, z, w).ToZyxBytes(bgr, 0);
            Assert.Equal(bgr, new byte[] { 243, 177, 172 });

            new Short4(x, y, z, w).ToZyxwBytes(bgra, 0);
            Assert.Equal(bgra, new byte[] { 243, 177, 172, 128 });

            Short4 r = new Short4();

            r.PackFromBytes(20, 38, 0, 255);
            r.ToXyzwBytes(rgba, 0);
            Assert.Equal(rgba, new byte[] { 20, 38, 0, 255 });
        }
Ejemplo n.º 3
0
        public void Short4_PackedValues()
        {
            var shortValue1 = new Short4(11547, 12653, 29623, 193);
            var shortValue2 = new Short4(0.1f, -0.3f, 0.5f, -0.7f);

            Assert.Equal(0x00c173b7316d2d1bUL, shortValue1.PackedValue);
            Assert.Equal(18446462598732840960, shortValue2.PackedValue);
            Assert.Equal(0x0UL, new Short4(Vector4.Zero).PackedValue);
            Assert.Equal(0x7FFF7FFF7FFF7FFFUL, new Short4(Vector4.One * 0x7FFF).PackedValue);
            Assert.Equal(0x8000800080008000, new Short4(Vector4.One * -0x8000).PackedValue);
        }
Ejemplo n.º 4
0
        public void Short4_ToRgba32()
        {
            // arrange
            var shortValue = new Short4(11547, 12653, 29623, 193);
            var actual     = default(Rgba32);
            var expected   = new Rgba32(172, 177, 243, 128);

            // act
            shortValue.ToRgba32(ref actual);

            // assert
            Assert.Equal(expected, actual);
        }
Ejemplo n.º 5
0
        public void Short4_ToBgr24()
        {
            // arrange
            var shortValue = new Short4(11547, 12653, 29623, 193);
            var actual     = default(Bgr24);
            var expected   = new Bgr24(172, 177, 243);

            // act
            shortValue.ToBgr24(ref actual);

            // assert
            Assert.Equal(expected, actual);
        }
Ejemplo n.º 6
0
        public void Short4_Clamping()
        {
            // arrange
            var short1 = new Short4(Vector4.One * 1234567.0f);
            var short2 = new Short4(Vector4.One * -1234567.0f);

            // act
            var vector1 = short1.ToVector4();
            var vector2 = short2.ToVector4();

            // assert
            Assert.Equal(Vector4.One * 0x7FFF, vector1);
            Assert.Equal(Vector4.One * -0x8000, vector2);
        }
Ejemplo n.º 7
0
        public void Short4_ToScaledVector4()
        {
            // arrange
            var short4 = new Short4(Vector4.One * 0x7FFF);

            // act
            Vector4 actual = short4.ToScaledVector4();

            // assert
            Assert.Equal(1, actual.X);
            Assert.Equal(1, actual.Y);
            Assert.Equal(1, actual.Z);
            Assert.Equal(1, actual.W);
        }
Ejemplo n.º 8
0
        public void Short4_FromScaledVector4()
        {
            // arrange
            var        short4   = new Short4(Vector4.One * 0x7FFF);
            Vector4    scaled   = short4.ToScaledVector4();
            const long expected = 0x7FFF7FFF7FFF7FFF;

            // act
            var pixel = default(Short4);

            pixel.FromScaledVector4(scaled);

            // assert
            Assert.Equal((ulong)expected, pixel.PackedValue);
        }
Ejemplo n.º 9
0
        public void Encode(VertexElement element, XNAV4 value)
        {
            var dstVertex = _Vertex.Slice(element.Offset);

            if (element.VertexElementFormat == VertexElementFormat.Vector4)
            {
                System.Runtime.InteropServices.MemoryMarshal.Write(dstVertex, ref value);
                return;
            }

            if (element.VertexElementFormat == VertexElementFormat.Byte4)
            {
                var c = new Byte4(value);
                System.Runtime.InteropServices.MemoryMarshal.Write(dstVertex, ref c);
                return;
            }

            if (element.VertexElementFormat == VertexElementFormat.Color)
            {
                var c = new Color(value);
                System.Runtime.InteropServices.MemoryMarshal.Write(dstVertex, ref c);
                return;
            }

            if (element.VertexElementFormat == VertexElementFormat.Short4)
            {
                var ns = new Short4(value);
                System.Runtime.InteropServices.MemoryMarshal.Write(dstVertex, ref ns);
                return;
            }

            if (element.VertexElementFormat == VertexElementFormat.NormalizedShort4)
            {
                var ns = new NormalizedShort4(value);
                System.Runtime.InteropServices.MemoryMarshal.Write(dstVertex, ref ns);
                return;
            }

            if (element.VertexElementFormat == VertexElementFormat.HalfVector4)
            {
                var ns = new HalfVector4(value);
                System.Runtime.InteropServices.MemoryMarshal.Write(dstVertex, ref ns);
                return;
            }

            throw new ArgumentException(nameof(element));
        }
Ejemplo n.º 10
0
        public void Short4()
        {
            // Test the limits.
            Assert.AreEqual(0x0, new Short4(Vector4.Zero).PackedValue);
            Assert.AreEqual(0x7FFF7FFF7FFF7FFF, new Short4(Vector4.One * 0x7FFF).PackedValue);
            Assert.AreEqual(0x8000800080008000, new Short4(Vector4.One * -0x8000).PackedValue);

            // Test ToVector4.
            Assert.AreEqual(Vector4.One * 0x7FFF, new Short4(Vector4.One * 0x7FFF).ToVector4());
            Assert.AreEqual(Vector4.Zero, new Short4(Vector4.Zero).ToVector4());
            Assert.AreEqual(Vector4.One * -0x8000, new Short4(Vector4.One * -0x8000).ToVector4());
            Assert.AreEqual(Vector4.UnitX * 0x7FFF, new Short4(Vector4.UnitX * 0x7FFF).ToVector4());
            Assert.AreEqual(Vector4.UnitY * 0x7FFF, new Short4(Vector4.UnitY * 0x7FFF).ToVector4());
            Assert.AreEqual(Vector4.UnitZ * 0x7FFF, new Short4(Vector4.UnitZ * 0x7FFF).ToVector4());
            Assert.AreEqual(Vector4.UnitW * 0x7FFF, new Short4(Vector4.UnitW * 0x7FFF).ToVector4());

            // Test clamping.
            Assert.AreEqual(Vector4.One * 0x7FFF, new Short4(Vector4.One * 1234567.0f).ToVector4());
            Assert.AreEqual(Vector4.One * -0x8000, new Short4(Vector4.One * -1234567.0f).ToVector4());

            //Test Ordering
            float x = 0x2d1b;
            float y = 0x316d;
            float z = 0x73b7;
            float w = 0x00c1;

            Assert.AreEqual(0x00c173b7316d2d1b, new Short4(x, y, z, w).PackedValue);
            x = 0.1f;
            y = -0.3f;
            z = 0.5f;
            w = -0.7f;
            Assert.AreEqual(18446462598732840960, new Short4(x, y, z, w).PackedValue);

            var packed   = new Short4(x, y, z, w).PackedValue;
            var unpacked = new Short4()
            {
                PackedValue = packed
            }.ToVector4();

            Assert.AreEqual(0f, unpacked.X);
            Assert.AreEqual(0f, unpacked.Y);
            Assert.AreEqual(0f, unpacked.Z);
            Assert.AreEqual(-1f, unpacked.W);
        }
Ejemplo n.º 11
0
        public void Encode(VertexElement element, Short4 value)
        {
            var dstVertex = _Vertex.Slice(element.Offset);

            if (element.VertexElementFormat == VertexElementFormat.Vector4)
            {
                var v4 = value.ToVector4();
                System.Runtime.InteropServices.MemoryMarshal.Write(dstVertex, ref v4);
                return;
            }

            if (element.VertexElementFormat == VertexElementFormat.Short4)
            {
                System.Runtime.InteropServices.MemoryMarshal.Write(dstVertex, ref value);
                return;
            }

            throw new ArgumentException(nameof(element));
        }
Ejemplo n.º 12
0
 public void TestMemberFn_GetHashCode_i ()
 {
     HashSet<Int32> hs = new HashSet<Int32>();
     var rand = new System.Random();
     var buff = new Byte[8];
     UInt32 collisions = 0;
     for(Int32 i = 0; i < Settings.NumTests; ++i)
     {
         rand.NextBytes(buff);
         UInt64 packed = BitConverter.ToUInt64(buff, 0);
         var packedObj = new Short4();
         packedObj.PackedValue = packed;
         Int32 hc = packedObj.GetHashCode ();
         if(hs.Contains(hc)) ++collisions;
         hs.Add(hc);
     }
     Assert.That(collisions, Is.LessThan(10));
 }
Ejemplo n.º 13
0
 public void TestMemberFn_ToString_i()
 {
     var testCase = new Short4 ();
     testCase.PackFrom (0.656f, 0.125f, 0.222f, 0.861f);
     String s = testCase.ToString ();
     Assert.That(s, Is.EqualTo ("1000000000001"));
 }
Ejemplo n.º 14
0
        public void TestRandomValues_i()
        {
            var rand = new System.Random();
            var buff = new Byte[8];

            for(Int32 i = 0; i < Settings.NumTests; ++i)
            {
                rand.NextBytes(buff);
                UInt64 packed = BitConverter.ToUInt64(buff, 0);
                var packedObj = new Short4();
                packedObj.PackedValue = packed;
                Single realX, realY, realZ, realW = 0f;
                packedObj.UnpackTo(out realX, out realY, out realZ, out realW);
                var newPackedObj = new Short4(realX, realY, realZ, realW);
                Assert.That(newPackedObj.PackedValue, Is.EqualTo(packedObj.PackedValue));
            }
        }
Ejemplo n.º 15
0
        public void Short4()
        {
            // Test the limits.
            Assert.Equal(0x0UL, new Short4(Vector4.Zero).PackedValue);
            Assert.Equal(0x7FFF7FFF7FFF7FFFUL, new Short4(Vector4.One * 0x7FFF).PackedValue);
            Assert.Equal(0x8000800080008000, new Short4(Vector4.One * -0x8000).PackedValue);

            // Test ToVector4.
            Assert.Equal(Vector4.One * 0x7FFF, new Short4(Vector4.One * 0x7FFF).ToVector4());
            Assert.Equal(Vector4.Zero, new Short4(Vector4.Zero).ToVector4());
            Assert.Equal(Vector4.One * -0x8000, new Short4(Vector4.One * -0x8000).ToVector4());
            Assert.Equal(Vector4.UnitX * 0x7FFF, new Short4(Vector4.UnitX * 0x7FFF).ToVector4());
            Assert.Equal(Vector4.UnitY * 0x7FFF, new Short4(Vector4.UnitY * 0x7FFF).ToVector4());
            Assert.Equal(Vector4.UnitZ * 0x7FFF, new Short4(Vector4.UnitZ * 0x7FFF).ToVector4());
            Assert.Equal(Vector4.UnitW * 0x7FFF, new Short4(Vector4.UnitW * 0x7FFF).ToVector4());

            // Test ToScaledVector4.
            Vector4 scaled = new Short4(Vector4.One * 0x7FFF).ToScaledVector4();

            Assert.Equal(1, scaled.X);
            Assert.Equal(1, scaled.Y);
            Assert.Equal(1, scaled.Z);
            Assert.Equal(1, scaled.W);

            // Test FromScaledVector4.
            var pixel = default(Short4);

            pixel.FromScaledVector4(scaled);
            Assert.Equal(0x7FFF7FFF7FFF7FFFUL, pixel.PackedValue);

            // Test clamping.
            Assert.Equal(Vector4.One * 0x7FFF, new Short4(Vector4.One * 1234567.0f).ToVector4());
            Assert.Equal(Vector4.One * -0x8000, new Short4(Vector4.One * -1234567.0f).ToVector4());

            // Test Ordering
            float x = 0.1f;
            float y = -0.3f;
            float z = 0.5f;
            float w = -0.7f;

            Assert.Equal(18446462598732840960, new Short4(x, y, z, w).PackedValue);

            x = 11547;
            y = 12653;
            z = 29623;
            w = 193;
            Assert.Equal(0x00c173b7316d2d1bUL, new Short4(x, y, z, w).PackedValue);

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

            // new Short4(x, y, z, w).ToRgb24(ref rgb);
            // Assert.Equal(rgb, new Rgb24(172, 177, 243)); // this assert fails in Release build on linux (#594)

            // new Short4(x, y, z, w).ToRgba32(ref rgba);
            // Assert.Equal(rgba, new Rgba32(172, 177, 243, 128));

            // new Short4(x, y, z, w).ToBgr24(ref bgr);
            // Assert.Equal(bgr, new Bgr24(172, 177, 243));

            // new Short4(x, y, z, w).ToBgra32(ref bgra);
            // Assert.Equal(bgra, new Bgra32(172, 177, 243, 128));

            // new Short4(x, y, z, w).ToArgb32(ref argb);
            // Assert.Equal(argb, new Argb32(172, 177, 243, 128));

            // var r = default(Short4);
            // r.FromRgba32(new Rgba32(20, 38, 0, 255));
            // r.ToRgba32(ref rgba);
            // Assert.Equal(rgba, new Rgba32(20, 38, 0, 255));

            // r = default(Short4);
            // r.FromBgra32(new Bgra32(20, 38, 0, 255));
            // r.ToBgra32(ref bgra);
            // Assert.Equal(bgra, new Bgra32(20, 38, 0, 255));

            // r = default(Short4);
            // r.FromArgb32(new Argb32(20, 38, 0, 255));
            // r.ToArgb32(ref argb);
            // Assert.Equal(argb, new Argb32(20, 38, 0, 255));
        }
Ejemplo n.º 16
0
 public IntVertexPositionTexture(Short4 position, NormalizedShort2 textureCoordinate)
 {
     this.Position          = position;
     this.TextureCoordinate = textureCoordinate;
 }