Exemplo n.º 1
0
        public void Test_S2PaddedCell_GetEntryExitVertices()
        {
            int kIters = 1000;

            for (int iter = 0; iter < kIters; ++iter)
            {
                S2CellId id = S2Testing.GetRandomCellId();
                // Check that entry/exit vertices do not depend on padding.
                Assert.Equal(new S2PaddedCell(id, 0).GetEntryVertex(),
                             new S2PaddedCell(id, 0.5).GetEntryVertex());
                Assert.Equal(new S2PaddedCell(id, 0).GetExitVertex(),
                             new S2PaddedCell(id, 0.5).GetExitVertex());

                // Check that the exit vertex of one cell is the same as the entry vertex
                // of the immediately following cell.  (This also tests wrapping from the
                // end to the start of the S2CellId curve with high probability.)
                Assert.Equal(new S2PaddedCell(id, 0).GetExitVertex(),
                             new S2PaddedCell(id.NextWrap(), 0).GetEntryVertex());

                // Check that the entry vertex of a cell is the same as the entry vertex
                // of its first child, and similarly for the exit vertex.
                if (!id.IsLeaf())
                {
                    Assert.Equal(new S2PaddedCell(id, 0).GetEntryVertex(),
                                 new S2PaddedCell(id.Child(0), 0).GetEntryVertex());
                    Assert.Equal(new S2PaddedCell(id, 0).GetExitVertex(),
                                 new S2PaddedCell(id.Child(3), 0).GetExitVertex());
                }
            }
        }
Exemplo n.º 2
0
        public void Test_S2CellUnion_IsNormalized()
        {
            var id         = new S2CellId(new S2Point(1, 0, 0)).Parent(10);
            var cell_union = S2CellUnion.FromVerbatim(
                new List <S2CellId> {
                id.Child(0), id.Child(1), id.Child(2), id.Child(3)
            });

            Assert.True(cell_union.IsValid());
            Assert.False(cell_union.IsNormalized());
        }
    public void Test_GetReferencePoint_PartiallyDegenerateLoops()
    {
        for (var iter = 0; iter < 100; ++iter)
        {
            // First we construct a long convoluted edge chain that follows the
            // S2CellId Hilbert curve.  At some random point along the curve, we
            // insert a small triangular loop.
            List <List <S2Point> > loops = new(1) { new() };
            var loop         = loops[0];
            int num_vertices = 100;
            var start        = S2Testing.GetRandomCellId(S2.kMaxCellLevel - 1);
            var end          = start.AdvanceWrap(num_vertices);
            var loop_cellid  = start.AdvanceWrap(
                S2Testing.Random.Uniform(num_vertices - 2) + 1);
            var triangle = new List <S2Point>();
            for (var cellid = start; cellid != end; cellid = cellid.NextWrap())
            {
                if (cellid == loop_cellid)
                {
                    // Insert a small triangular loop.  We save the loop so that we can
                    // test whether it contains the origin later.
                    triangle.Add(cellid.Child(0).ToPoint());
                    triangle.Add(cellid.Child(1).ToPoint());
                    triangle.Add(cellid.Child(2).ToPoint());
                    loop.AddRange(triangle);
                    loop.Add(cellid.Child(0).ToPoint());
                }
                else
                {
                    loop.Add(cellid.ToPoint());
                }
            }
            // Now we retrace our steps, except that we skip the three edges that form
            // the triangular loop above.
            for (S2CellId cellid = end; cellid != start; cellid = cellid.PrevWrap())
            {
                if (cellid == loop_cellid)
                {
                    loop.Add(cellid.Child(0).ToPoint());
                }
                else
                {
                    loop.Add(cellid.ToPoint());
                }
            }
            S2LaxPolygonShape shape         = new(loops);
            S2Loop            triangle_loop = new(triangle);
            var rp = shape.GetReferencePoint();
            Assert.Equal(triangle_loop.Contains(rp.Point), rp.Contained);
        }
    }
}
Exemplo n.º 4
0
        public void Test_S2CellId_MaximumTile()
        {
            // This method is tested more thoroughly in s2cell_union_test.cc.
            for (int iter = 0; iter < 1000; ++iter)
            {
                S2CellId id = S2Testing.GetRandomCellId(10);

                // Check that "limit" is returned for tiles at or beyond "limit".
                Assert.Equal(id, id.MaximumTile(id));
                Assert.Equal(id, id.Child(0).MaximumTile(id));
                Assert.Equal(id, id.Child(1).MaximumTile(id));
                Assert.Equal(id, id.Next().MaximumTile(id));
                Assert.Equal(id.Child(0), id.MaximumTile(id.Child(0)));

                // Check that the tile size is increased when possible.
                Assert.Equal(id, id.Child(0).MaximumTile(id.Next()));
                Assert.Equal(id, id.Child(0).MaximumTile(id.Next().Child(0)));
                Assert.Equal(id, id.Child(0).MaximumTile(id.Next().Child(1).Child(0)));
                Assert.Equal(id, id.Child(0).Child(0).MaximumTile(id.Next()));
                Assert.Equal(id, id.Child(0).Child(0).Child(0).MaximumTile(id.Next()));

                // Check that the tile size is decreased when necessary.
                Assert.Equal(id.Child(0), id.MaximumTile(id.Child(0).Next()));
                Assert.Equal(id.Child(0), id.MaximumTile(id.Child(0).Next().Child(0)));
                Assert.Equal(id.Child(0), id.MaximumTile(id.Child(0).Next().Child(1)));
                Assert.Equal(id.Child(0).Child(0),
                             id.MaximumTile(id.Child(0).Child(0).Next()));
                Assert.Equal(id.Child(0).Child(0).Child(0),
                             id.MaximumTile(id.Child(0).Child(0).Child(0).Next()));

                // Check that the tile size is otherwise unchanged.
                Assert.Equal(id, id.MaximumTile(id.Next()));
                Assert.Equal(id, id.MaximumTile(id.Next().Child(0)));
                Assert.Equal(id, id.MaximumTile(id.Next().Child(1).Child(0)));
            }
        }