public void ZigZagTest()
        {
            var value  = ZigZag.Encode(874534L);
            var result = ZigZag.Decode(value);

            NUnit.Framework.Assert.AreEqual(874534L, result);
        }
Beispiel #2
0
 public void Dencode()
 {
     Assert.Equal(-1, ZigZag.Decode(1));
     Assert.Equal(1, ZigZag.Decode(2));
     Assert.Equal(-2, ZigZag.Decode(3));
     Assert.Equal(2, ZigZag.Decode(4));
 }
        public void ZigZagTest()
        {
            ulong value  = ZigZag.Encode(874534L);
            long  result = ZigZag.Decode(value);

            Xunit.Assert.Equal(874534L, result);
        }
Beispiel #4
0
        private static List <List <PointInt> > GetGeometry(List <uint> geom, GeometryType geomType)
        {
            int             x             = 0;
            int             y             = 0;
            var             coordsList    = new List <List <PointInt> >();
            List <PointInt> coords        = null;
            var             geometryCount = geom.Count;
            uint            length        = 0;
            uint            command       = 0;
            var             i             = 0;

            while (i < geometryCount)
            {
                if (length <= 0)
                {
                    length  = geom[i++];
                    command = length & ((1 << 3) - 1);
                    length  = length >> 3;
                }

                if (length > 0)
                {
                    if (command == MoveTo)
                    {
                        coords = new List <PointInt>();
                        coordsList.Add(coords);
                    }
                }

                if (command == ClosePath)
                {
                    if (geomType != GeometryType.Point && !(coords.Count == 0))
                    {
                        coords.Add(coords[0]);
                    }
                    length--;
                    continue;
                }

                var dx = geom[i++];
                var dy = geom[i++];

                length--;

                var ldx = ZigZag.Decode((int)dx);
                var ldy = ZigZag.Decode((int)dy);

                x = x + ldx;
                y = y + ldy;

                var coord = new PointInt()
                {
                    X = x, Y = y
                };
                coords.Add(coord);
            }
            return(coordsList);
        }
Beispiel #5
0
        private void ReadZigZag(ModuleDefinition module, ILProcessor worker, TypeReference fieldType)
        {
            var useLong = fieldType.Is <long>();
            var encode  = useLong
                ? module.ImportReference((ulong v) => ZigZag.Decode(v))
                : module.ImportReference((uint v) => ZigZag.Decode(v));

            worker.Append(worker.Create(OpCodes.Call, encode));
        }
        public void TestZigZagDecode()
        {
            // arrange
            const int inputVar = 1;

            // act
            var res = ZigZag.Decode(inputVar);

            // assert
            Assert.IsTrue(res == -1);
        }
        public void AnotherTestZigZagDecode()
        {
            // arrange
            const int inputVar = 3;

            // act
            var res = ZigZag.Decode(inputVar);

            // assert
            Assert.IsTrue(res == -2);
        }
        public void DecodeZigZag()
        {
            var e64_1 = ZigZag.Decode((ulong)2);
            var e64_2 = ZigZag.Decode((ulong)1);

            var e32_1 = ZigZag.Decode(2);
            var e32_2 = ZigZag.Decode(1);


            NUnit.Framework.Assert.AreEqual(1, e32_1);
            NUnit.Framework.Assert.AreEqual(-1, e32_2);

            NUnit.Framework.Assert.AreEqual(1, e64_1);
            NUnit.Framework.Assert.AreEqual(-1, e64_2);
        }
        public void DecodeZigZag()
        {
            long e64_1 = ZigZag.Decode((ulong)2);
            long e64_2 = ZigZag.Decode((ulong)1);

            int e32_1 = ZigZag.Decode(2);
            int e32_2 = ZigZag.Decode(1);


            Xunit.Assert.Equal(1, e32_1);
            Xunit.Assert.Equal(-1, e32_2);

            Xunit.Assert.Equal(1, e64_1);
            Xunit.Assert.Equal(-1, e64_2);
        }
Beispiel #10
0
        private void button2_Click_1(object sender, EventArgs e)
        {
            ushort     _u;
            ushort     _v;
            ushort     _height;
            ushort     prev_u      = 0;
            ushort     prev_v      = 0;
            ushort     prev_height = 0;
            VertexData vData       = new VertexData(1, 1);

            int k = 0;

            //     vData.AddVertex(k, 0, 0, ConvertRange(0,200,16384));
            vData.AddVertex(k, 0, 0, 16384);
            k = 1;
            vData.AddVertex(k, 0, 32767, 0);
            k = 2;
            vData.AddVertex(k, 32767, 0, 32767);
            k = 3;
            vData.AddVertex(k, 32767, 32767, 6384);
            for (int i = 0; i < vData.u.Length; i++)
            {
                listBox1.Items.Add($"uvh{i}: {vData.u[i]}, {vData.v[i]}, {vData.height[i]}");
            }

            listBox1.Items.Add($"Enccode");


            for (int i = 0; i < vData.u.Length; i++)
            {
                // work out delta of current value minus prev value and encode
                _u      = (ushort)ZigZag.Encode(vData.u[i] - prev_u);
                _v      = (ushort)ZigZag.Encode(vData.v[i] - prev_v);
                _height = (ushort)ZigZag.Encode(vData.height[i] - prev_height);

                prev_u      = vData.u[i];
                prev_v      = vData.v[i];
                prev_height = vData.height[i];

                vData.u[i] = _u;
                listBox1.Items.Add($"uvh{i}: {_u}, {_v}, {_height}");
                vData.v[i]      = _v;
                vData.height[i] = _height;
            }

            listBox1.Items.Add($"Decode");


            //Decode
            // now decode deltas and place true value back into array
            _u      = 0;
            _v      = 0;
            _height = 0;

            for (int i = 0; i < 4; i++)
            {
                _u      += (ushort)ZigZag.Decode(vData.u[i]);
                _v      += (ushort)ZigZag.Decode(vData.v[i]);
                _height += (ushort)ZigZag.Decode(vData.height[i]);

                vData.u[i] = _u;
                listBox1.Items.Add($"uvh{i}: {_u}, {_v}, {_height}");
                vData.v[i]      = _v;
                vData.height[i] = _height;
            }
        }