Exemplo n.º 1
0
    public void Test_S2ShapeIndexRegion_GetRectBound()
    {
        var id = S2CellId.FromDebugString("3/0123012301230123012301230123");

        // Add a polygon that is slightly smaller than the cell being tested.
        MutableS2ShapeIndex index = new();

        index.Add(NewPaddedCell(id, -kPadding));
        S2LatLngRect cell_bound  = new S2Cell(id).GetRectBound();
        S2LatLngRect index_bound = index.MakeS2ShapeIndexRegion().GetRectBound();

        Assert.Equal(index_bound, cell_bound);
    }
Exemplo n.º 2
0
 public void Test_S2CellId_FromDebugString()
 {
     Assert.Equal(S2CellId.FromFace(3), S2CellId.FromDebugString("3/"));
     Assert.Equal(S2CellId.FromFace(0).Child(2).Child(1),
                  S2CellId.FromDebugString("0/21"));
     Assert.Equal(S2CellId.FromFace(4).RangeMin(),
                  S2CellId.FromDebugString("4/000000000000000000000000000000"));
     Assert.Equal(S2CellId.None,
                  S2CellId.FromDebugString("4/0000000000000000000000000000000"));
     Assert.Equal(S2CellId.None, S2CellId.FromDebugString(""));
     Assert.Equal(S2CellId.None, S2CellId.FromDebugString("7/"));
     Assert.Equal(S2CellId.None, S2CellId.FromDebugString(" /"));
     Assert.Equal(S2CellId.None, S2CellId.FromDebugString("3:0"));
     Assert.Equal(S2CellId.None, S2CellId.FromDebugString("3/ 12"));
     Assert.Equal(S2CellId.None, S2CellId.FromDebugString("3/1241"));
 }
Exemplo n.º 3
0
    public void Test_S2ShapeIndexRegion_GetCapBound()
    {
        var id = S2CellId.FromDebugString("3/0123012301230123012301230123");

        // Add a polygon that is slightly smaller than the cell being tested.
        MutableS2ShapeIndex index = new();

        index.Add(NewPaddedCell(id, -kPadding));
        S2Cap cell_bound  = new S2Cell(id).GetCapBound();
        S2Cap index_bound = index.MakeS2ShapeIndexRegion().GetCapBound();

        Assert.True(index_bound.Contains(cell_bound));

        // Note that S2CellUnion.GetCapBound returns a slightly larger bound than
        // S2Cell.GetBound even when the cell union consists of a single S2CellId.
        Assert.True(index_bound.RadiusAngle() <= 1.00001 * cell_bound.RadiusAngle());
    }
Exemplo n.º 4
0
    public void Test_S2ShapeIndexRegion_IntersectsExactCell()
    {
        var target = S2CellId.FromDebugString("3/0123012301230123012301230123");

        // Adds a polygon that exactly follows a cell boundary.
        MutableS2ShapeIndex index = new();

        index.Add(NewPaddedCell(target, 0.0));
        var region = index.MakeS2ShapeIndexRegion();

        // Check that the index intersects the cell and all of its neighbors.
        List <S2CellId> ids = new(){ target };

        target.AppendAllNeighbors(target.Level(), ids);
        foreach (S2CellId id in ids)
        {
            Assert.True(region.MayIntersect(new S2Cell(id)));
        }
    }
Exemplo n.º 5
0
    public void Test_S2ShapeIndexRegion_IntersectsShrunkenCell()
    {
        var target = S2CellId.FromDebugString("3/0123012301230123012301230123");

        // Add a polygon that is slightly smaller than the cell being tested.
        MutableS2ShapeIndex index = new();

        index.Add(NewPaddedCell(target, -kPadding));
        var region = index.MakeS2ShapeIndexRegion();

        // Check that the index intersects the cell itself, but not any of the
        // neighboring cells.
        Assert.True(region.MayIntersect(new S2Cell(target)));
        var nbrs = new List <S2CellId>();

        target.AppendAllNeighbors(target.Level(), nbrs);
        foreach (var id in nbrs)
        {
            Assert.False(region.MayIntersect(new S2Cell(id)));
        }
    }
Exemplo n.º 6
0
    public void Test_S2ShapeIndexRegion_ContainsCellMultipleShapes()
    {
        Assert.True(false); //TODO

        var id = S2CellId.FromDebugString("3/0123012301230123012301230123");

        // Add a polygon that is slightly smaller than the cell being tested.
        MutableS2ShapeIndex index = new();

        index.Add(NewPaddedCell(id, -kPadding));
        Assert.False(index.MakeS2ShapeIndexRegion().Contains(new S2Cell(id)));

        // Add a second polygon that is slightly larger than the cell being tested.
        // Note that Contains() should return true if *any* shape contains the cell.
        index.Add(NewPaddedCell(id, kPadding));
        Assert.True(index.MakeS2ShapeIndexRegion().Contains(new S2Cell(id)));

        // Verify that all children of the cell are also contained.
        for (var child = id.ChildBegin(); child != id.ChildEnd(); child = child.Next())
        {
            Assert.True(index.MakeS2ShapeIndexRegion().Contains(new S2Cell(child)));
        }
    }
Exemplo n.º 7
0
 private static S2CellId MakeCellId(string str) => S2CellId.FromDebugString(str);