Пример #1
0
        private static void ChooseEdgeNearCell(S2Cell cell, out S2Point a, out S2Point b)
        {
            S2Cap cap = cell.GetCapBound();

            if (S2Testing.Random.OneIn(5))
            {
                // Choose a point anywhere on the sphere.
                a = S2Testing.RandomPoint();
            }
            else
            {
                // Choose a point inside or somewhere near the cell.
                a = S2Testing.SamplePoint(new S2Cap(cap.Center, 1.5 * cap.RadiusAngle()));
            }
            // Now choose a maximum edge length ranging from very short to very long
            // relative to the cell size, and choose the other endpoint.
            double max_length = Math.Min(100 * Math.Pow(1e-4, S2Testing.Random.RandDouble()) *
                                         cap.Radius.Radians(), S2.M_PI_2);

            b = S2Testing.SamplePoint(new S2Cap(a, S1Angle.FromRadians(max_length)));

            if (S2Testing.Random.OneIn(20))
            {
                // Occasionally replace edge with antipodal edge.
                a = -a;
                b = -b;
            }
        }
Пример #2
0
    public void AddEdges(S2Cap index_cap, int num_edges, MutableS2ShapeIndex index)
    {
        var fractal = new S2Testing.Fractal();

        fractal.SetLevelForApproxMaxEdges(num_edges);
        index.Add(new S2Loop.Shape(
                      fractal.MakeLoop(S2Testing.GetRandomFrameAt(index_cap.Center),
                                       index_cap.RadiusAngle())));
    }
Пример #3
0
            public void AddPoints(S2Cap index_cap, int num_points, TestIndex index)
            {
                var points = S2Testing.MakeRegularPoints(
                    index_cap.Center, index_cap.RadiusAngle(), num_points);

                for (int i = 0; i < points.Length; ++i)
                {
                    index.Add(points[i], i);
                }
            }
Пример #4
0
            public void AddPoints(S2Cap index_cap, int num_points, TestIndex index)
            {
                S2Testing.Fractal fractal = new();
                fractal.SetLevelForApproxMaxEdges(num_points);
                fractal.FractalDimension = (1.5);
                var loop = (
                    fractal.MakeLoop(S2Testing.GetRandomFrameAt(index_cap.Center),
                                     index_cap.RadiusAngle()));

                for (int i = 0; i < loop.NumVertices; ++i)
                {
                    index.Add(loop.Vertex(i), i);
                }
            }
Пример #5
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());
    }
Пример #6
0
            public void AddPoints(S2Cap index_cap, int num_points, TestIndex index)
            {
                int            sqrt_num_points = (int)Math.Ceiling(Math.Sqrt(num_points));
                S2PointVector3 frame           = S2Testing.GetRandomFrameAt(index_cap.Center);
                double         radius          = index_cap.RadiusAngle().Radians;
                double         spacing         = 2 * radius / sqrt_num_points;

                for (int i = 0; i < sqrt_num_points; ++i)
                {
                    for (int j = 0; j < sqrt_num_points; ++j)
                    {
                        S2Point point = new(Math.Tan((i + 0.5) * spacing - radius),
                                            Math.Tan((j + 0.5) * spacing - radius), 1.0);
                        index.Add(S2.FromFrame(frame, point.Normalize()),
                                  i * sqrt_num_points + j);
                    }
                }
            }
Пример #7
0
 public void AddEdges(S2Cap index_cap, int num_edges, MutableS2ShapeIndex index)
 {
     index.Add(new S2Loop.Shape(S2Loop.MakeRegularLoop(
                                    index_cap.Center, index_cap.RadiusAngle(), num_edges)));
 }