Exemple #1
0
    private readonly int orientation_;  // Hilbert curve orientation of this cell (see s2coords.h)

    #region Constructors

    // Construct an S2PaddedCell for the given cell id and padding.
    public S2PaddedCell(S2CellId id, double padding)
    {
        ij_lo_  = new int[2];
        Id      = id;
        Padding = padding;
        if (Id.IsFace())
        {
            // Fast path for constructing a top-level face (the most common case).
            double limit = 1 + padding;
            Bound = new R2Rect(new R1Interval(-limit, limit),
                               new R1Interval(-limit, limit));
            middle_ = new R2Rect(new R1Interval(-padding, padding),
                                 new R1Interval(-padding, padding));
            ij_lo_[0]    = ij_lo_[1] = 0;
            orientation_ = (int)(Id.Face() & 1);
            Level        = 0;
        }
        else
        {
            var ij = new int[2];
            id.ToFaceIJOrientation(out ij[0], out ij[1], out orientation_, true);
            Level = id.Level();
            Bound = S2CellId.IJLevelToBoundUV(ij, Level).Expanded(padding);
            int ij_size = S2CellId.SizeIJ(Level);
            ij_lo_[0] = ij[0] & -ij_size;
            ij_lo_[1] = ij[1] & -ij_size;
        }
    }
Exemple #2
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);
        }