コード例 #1
0
ファイル: S2PaddedCellTests.cs プロジェクト: alas/s2geometry
        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());
                }
            }
        }
コード例 #2
0
        public void Test_S2CellId_Continuity()
        {
            // Make sure that sequentially increasing cell ids form a continuous
            // path over the surface of the sphere, i.e. there are no
            // discontinuous jumps from one region to another.

            double   max_dist = S2.kMaxEdge.GetValue(kMaxWalkLevel);
            S2CellId end      = S2CellId.End(kMaxWalkLevel);
            S2CellId id       = S2CellId.Begin(kMaxWalkLevel);

            for (; id != end; id = id.Next())
            {
                Assert.True(id.ToPointRaw().Angle(id.NextWrap().ToPointRaw()) <= max_dist);
                Assert.Equal(id.NextWrap(), id.AdvanceWrap(1));
                Assert.Equal(id, id.NextWrap().AdvanceWrap(-1));

                // Check that the ToPointRaw() returns the center of each cell
                // in (s,t) coordinates.
                S2.XYZtoFaceUV(id.ToPointRaw(), out var u, out var v);
                Assert2.Near(Math.IEEERemainder(S2.UVtoST(u), 0.5 * kCellSize), 0.0, S2.DoubleError);
                Assert2.Near(Math.IEEERemainder(S2.UVtoST(v), 0.5 * kCellSize), 0.0, S2.DoubleError);
            }
        }