public void ZigZagTest() { var value = ZigZag.Encode(874534L); var result = ZigZag.Decode(value); NUnit.Framework.Assert.AreEqual(874534L, result); }
public void EncodeVertexBuffer(VertexData vData) { // ZigZag Encode Buffer. The quantizing of data I guess ushort _u; ushort _v; ushort _height; ushort prev_u = 0; ushort prev_v = 0; ushort prev_height = 0; 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; vData.v[i] = _v; vData.height[i] = _height; } }
public void Encode() { Assert.Equal(1, ZigZag.Encode(-1)); Assert.Equal(2, ZigZag.Encode(1)); Assert.Equal(3, ZigZag.Encode(-2)); Assert.Equal(4, ZigZag.Encode(2)); }
public void ZigZagTest() { ulong value = ZigZag.Encode(874534L); long result = ZigZag.Decode(value); Xunit.Assert.Equal(874534L, result); }
private static List <uint> EncodePointGeometry(List <List <PointInt> > coordList) { List <uint> geometry = new List <uint>(); PointInt prevCoord = new PointInt() { X = 0, Y = 0 }; foreach (List <PointInt> points in coordList) { if (points.Count == 0) { throw new Exception("Encoding with no points. "); } uint commandInteger = (MoveTo & 0x7) | ((uint)points.Count << 3); geometry.Add(commandInteger); for (int n = 0; n < points.Count; ++n) { int dx = points[n].X - prevCoord.X; int dy = points[n].Y - prevCoord.Y; int parameter = ZigZag.Encode(dx); geometry.Add((uint)parameter); parameter = ZigZag.Encode(dy); geometry.Add((uint)parameter); prevCoord = points[n]; } } return(geometry); }
private void WriteZigZag(ModuleDefinition module, ILProcessor worker, TypeReference fieldType) { var useLong = fieldType.Is <long>(); var encode = useLong ? module.ImportReference((long v) => ZigZag.Encode(v)) : module.ImportReference((int v) => ZigZag.Encode(v)); worker.Append(worker.Create(OpCodes.Call, encode)); }
public void TestZigZagEncode() { // arrange const int inputVar = -2; // act var res = ZigZag.Encode(inputVar); // assert Assert.IsTrue(res == 3); }
private static List <uint> EncodePolygonGeometry(List <List <PointInt> > coordList) { List <uint> geometry = new List <uint>(); PointInt prevCoord = new PointInt() { X = 0, Y = 0 }; foreach (List <PointInt> points in coordList) { if (points.Count == 0) { throw new Exception("Encoding with no points. "); } //start of ring uint commandInteger = (MoveTo & 0x7) | (1 << 3); geometry.Add(commandInteger); int dx = points[0].X - prevCoord.X; int dy = points[0].Y - prevCoord.Y; int parameter = ZigZag.Encode(dx); geometry.Add((uint)parameter); parameter = ZigZag.Encode(dy); geometry.Add((uint)parameter); bool lastPointRepeated = (points[points.Count - 1].X == points[0].X && points[points.Count - 1].Y == points[0].Y); int pointCount = lastPointRepeated ? points.Count - 2 : points.Count - 1; //encode the rest of the points commandInteger = (LineTo & 0x7) | ((uint)(pointCount) << 3); geometry.Add(commandInteger); for (int n = 1; n <= pointCount; ++n) { dx = points[n].X - points[n - 1].X; dy = points[n].Y - points[n - 1].Y; parameter = ZigZag.Encode(dx); geometry.Add((uint)parameter); parameter = ZigZag.Encode(dy); geometry.Add((uint)parameter); } //close path commandInteger = (ClosePath & 0x7) | (1 << 3); geometry.Add(commandInteger); prevCoord = points[pointCount]; } return(geometry); }
public void EncodeZigZag() { var e64_1 = ZigZag.Encode((long)1); var e64_2 = ZigZag.Encode(-1L); var e32_1 = ZigZag.Encode(1); var e32_2 = ZigZag.Encode(-1); NUnit.Framework.Assert.AreEqual((uint)2, e32_1); NUnit.Framework.Assert.AreEqual((uint)1, e32_2); NUnit.Framework.Assert.AreEqual((ulong)2, e64_1); NUnit.Framework.Assert.AreEqual((ulong)1, e64_2); }
public void EncodeZigZag() { ulong e64_1 = ZigZag.Encode((long)1); ulong e64_2 = ZigZag.Encode(-1L); uint e32_1 = ZigZag.Encode(1); uint e32_2 = ZigZag.Encode(-1); Xunit.Assert.Equal((uint)2, e32_1); Xunit.Assert.Equal((uint)1, e32_2); Xunit.Assert.Equal((ulong)2, e64_1); Xunit.Assert.Equal((ulong)1, e64_2); }
private static List <uint> EncodeLineGeometry(List <List <PointInt> > coordList) { List <uint> geometry = new List <uint>(); PointInt prevCoord = new PointInt() { X = 0, Y = 0 }; foreach (List <PointInt> points in coordList) { if (points.Count == 0) { throw new Exception("Encoding with no points. "); } //start of linestring uint commandInteger = (MoveTo & 0x7) | (1 << 3); geometry.Add(commandInteger); int dx = points[0].X - prevCoord.X; int dy = points[0].Y - prevCoord.Y; int parameter = ZigZag.Encode(dx); geometry.Add((uint)parameter); parameter = ZigZag.Encode(dy); geometry.Add((uint)parameter); //encode the rest of the points commandInteger = (LineTo & 0x7) | ((uint)(points.Count - 1) << 3); geometry.Add(commandInteger); for (int n = 1; n < points.Count; ++n) { dx = points[n].X - points[n - 1].X; dy = points[n].Y - points[n - 1].Y; parameter = ZigZag.Encode(dx); geometry.Add((uint)parameter); parameter = ZigZag.Encode(dy); geometry.Add((uint)parameter); } prevCoord = points[points.Count - 1]; } return(geometry); }
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; } }