Exemple #1
0
 public void CellsPerBlockTest()
 {
     Assert.Equal(1UL, ZCurve.CellsPerBlock(0));
     Assert.Equal(4UL, ZCurve.CellsPerBlock(1));
     Assert.Equal(16UL, ZCurve.CellsPerBlock(2));
     Assert.Equal(64UL, ZCurve.CellsPerBlock(3));
     Assert.Equal(256UL, ZCurve.CellsPerBlock(4));
     Assert.Equal(1024UL, ZCurve.CellsPerBlock(5));
     Assert.Equal(0x0400000000000000UL, ZCurve.CellsPerBlock(29));
     Assert.Equal(0x1000000000000000UL, ZCurve.CellsPerBlock(30));
     Assert.Equal(0x4000000000000000UL, ZCurve.CellsPerBlock(31));
     Assert.Equal(0UL, ZCurve.CellsPerBlock(32));             // wrap around
 }
Exemple #2
0
        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}");
        }
Exemple #3
0
        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);
        }