Exemplo n.º 1
0
        public void Test_S2CellId_ParentChildRelationships()
        {
            S2CellId id = S2CellId.FromFacePosLevel(3, 0x12345678, S2.kMaxCellLevel - 4);

            Assert.True(id.IsValid());
            Assert.Equal(3UL, id.Face());
            Assert.Equal(0x12345700UL, id.Pos());
            Assert.Equal(S2.kMaxCellLevel - 4, id.Level());
            Assert.False(id.IsLeaf());

            Assert.Equal(0x12345610UL, id.ChildBegin(id.Level() + 2).Pos());
            Assert.Equal(0x12345640UL, id.ChildBegin().Pos());
            Assert.Equal(0x12345400UL, id.Parent().Pos());
            Assert.Equal(0x12345000UL, id.Parent(id.Level() - 2).Pos());

            // Check ordering of children relative to parents.
            Assert.True(id.ChildBegin() < id);
            Assert.True(id.ChildEnd() > id);
            Assert.Equal(id.ChildEnd(), id.ChildBegin().Next().Next().Next().Next());
            Assert.Equal(id.RangeMin(), id.ChildBegin(S2.kMaxCellLevel));
            Assert.Equal(id.RangeMax().Next(), id.ChildEnd(S2.kMaxCellLevel));

            // Check that cells are represented by the position of their center
            // along the Hilbert curve.
            Assert.Equal(2 * id.Id, id.RangeMin().Id + id.RangeMax().Id);
        }
Exemplo n.º 2
0
 // Adds the given (cell_id, label) pair to the index.  Note that the index
 // is not valid until Build() is called.
 //
 // The S2CellIds in the index may overlap (including duplicate values).
 // Duplicate (cell_id, label) pairs are also allowed, although be aware that
 // S2ClosestCellQuery will eliminate such duplicates anyway.
 //
 // REQUIRES: cell_id.IsValid
 public void Add(S2CellId cell_id, Int32 label)
 {
     System.Diagnostics.Debug.Assert(cell_id.IsValid());
     System.Diagnostics.Debug.Assert(label >= 0);
     cell_tree_.Add(new CellNode(cell_id, label, -1));
 }