public void LargestLevel2Test() { Assert.Equal(0, ZCurve.LargestLevel(48, 48)); Assert.Equal(2, ZCurve.LargestLevel(0, 49)); Assert.Equal(0, ZCurve.LargestLevel(1, 49)); Assert.Equal(0, ZCurve.LargestLevel(2, 49)); Assert.Equal(0, ZCurve.LargestLevel(3, 49)); Assert.Equal(1, ZCurve.LargestLevel(4, 49)); Assert.Equal(0, ZCurve.LargestLevel(5, 49)); Assert.Equal(3, ZCurve.LargestLevel(0, 192)); Assert.Equal(0, ZCurve.LargestLevel(3, 192)); Assert.Equal(1, ZCurve.LargestLevel(12, 192)); Assert.Equal(0, ZCurve.LargestLevel(15, 192)); Assert.Equal(2, ZCurve.LargestLevel(48, 192)); Assert.Equal(0, ZCurve.LargestLevel(51, 192)); Assert.Equal(1, ZCurve.LargestLevel(60, 192)); Assert.Equal(0, ZCurve.LargestLevel(63, 192)); Assert.Equal(0, ZCurve.LargestLevel(192, 192)); // bad args (z>zmax) give level 0: Assert.Equal(0, ZCurve.LargestLevel(60, 48)); Assert.Equal(0, ZCurve.LargestLevel(195, 192)); }
public void BlockPropertyTest(ulong z, int level, ulong first, ulong last) { int i = ZCurve.LargestLevel(z); ulong f = ZCurve.FirstInBlock(z, i); ulong l = ZCurve.LastInBlock(z, i); ulong n = ZCurve.CellsPerBlock(i); Assert.Equal(level, i); Assert.Equal(first, f); Assert.Equal(last, l); _output.WriteLine($"z={z} i={i} first={f:X8} last={l:X8} cells_in_block={n}"); }
public void LargestLevel1Test() { Assert.Equal(32, ZCurve.LargestLevel(0)); Assert.Equal(0, ZCurve.LargestLevel(1)); Assert.Equal(0, ZCurve.LargestLevel(2)); Assert.Equal(0, ZCurve.LargestLevel(3)); Assert.Equal(1, ZCurve.LargestLevel(4)); Assert.Equal(2, ZCurve.LargestLevel(16)); Assert.Equal(3, ZCurve.LargestLevel(64)); Assert.Equal(4, ZCurve.LargestLevel(256)); Assert.Equal(0, ZCurve.LargestLevel(long.MaxValue)); Assert.Equal(30, ZCurve.LargestLevel(1UL << 60)); // 0x100... Assert.Equal(30, ZCurve.LargestLevel(2UL << 60)); // 0x200... Assert.Equal(30, ZCurve.LargestLevel(3UL << 60)); // 0x300... Assert.Equal(31, ZCurve.LargestLevel(1UL << 62)); // 0x400... Assert.Equal(31, ZCurve.LargestLevel(2UL << 62)); // 0x800... Assert.Equal(31, ZCurve.LargestLevel(3UL << 62)); // 0xC00... Assert.Equal(0, ZCurve.LargestLevel(ulong.MaxValue)); // 0xFF...FF }
public void QueryBlocksTrial() { // Expect shortest ordered sequence of blocks covering query box // Query box: ulong qlo = ZCurve.Encode(1U, 1U); // 3 ulong qhi = ZCurve.Encode(5U, 4U); // 49 // Expected result: 3 6 7 9 11 (12..15) 18 19 (24..27) 33 36 37 48 49 var starts = new ulong[] { 3, 6, 7, 9, 11, 12, 18, 19, 24, 33, 36, 37, 48, 49 }; var levels = new[] { 0, 0, 0, 0, 0, 1, 0, 0, 1, 0, 0, 0, 0, 0 }; var expected = starts.Zip(levels, (s, l) => new ZCurve.Block(s, l)).ToList(); var actual = new List <ZCurve.Block>(); ulong first = ZCurve.FirstInBlock(qlo, 0); ulong last = ZCurve.FirstInBlock(qhi, 0); for (ulong cursor = first; ;) { int level = ZCurve.LargestLevel(cursor, last); ulong increment = ZCurve.CellsPerBlock(level); actual.Add(new ZCurve.Block(cursor, level)); cursor += increment; if (cursor > last) { break; } if (!ZCurve.IsInsideBox(cursor, first, last)) { cursor = ZCurve.NextInsideBox(cursor, first, last); } } Assert.Equal(expected, actual); }
public void LargestLevel3Test() { var levels12 = new[] { 1, 2 }; Assert.Equal(1, ZCurve.LargestLevel(48, 48, levels12)); Assert.Equal(1, ZCurve.LargestLevel(60, 48, levels12)); Assert.Equal(2, ZCurve.LargestLevel(0, 49, levels12)); Assert.Equal(1, ZCurve.LargestLevel(1, 49, levels12)); Assert.Equal(1, ZCurve.LargestLevel(2, 49, levels12)); Assert.Equal(1, ZCurve.LargestLevel(3, 49, levels12)); Assert.Equal(1, ZCurve.LargestLevel(4, 49, levels12)); Assert.Equal(1, ZCurve.LargestLevel(5, 49, levels12)); Assert.Equal(1, ZCurve.LargestLevel(48, 49, levels12)); Assert.Equal(2, ZCurve.LargestLevel(48, 63, levels12)); var levels24 = new[] { 2, 4 }; Assert.Equal(4, ZCurve.LargestLevel(0, 768, levels24)); Assert.Equal(2, ZCurve.LargestLevel(128, 768, levels24)); Assert.Equal(2, ZCurve.LargestLevel(31, 31, levels24)); }