public void Test_EncodedS2PointVectorTest_SnappedFractalLoops() { S2Testing.Random.Reset(S2Testing.Random.RandomSeed); #if DEBUG const int kMaxPoints = 3 << 10; #else const int kMaxPoints = 3 << 14; #endif for (int num_points = 3; num_points <= kMaxPoints; num_points *= 4) { int s2polygon_size = 0, lax_polygon_size = 0; for (int i = 0; i < 10; ++i) { S2Testing.Fractal fractal = new(); fractal.SetLevelForApproxMaxEdges(num_points); var frame = S2Testing.GetRandomFrame(); var loop = fractal.MakeLoop(frame, S2Testing.KmToAngle(10)); List <S2Point> points = new(); for (int j = 0; j < loop.NumVertices; ++j) { points.Add(new S2CellId(loop.Vertex(j)).ToPoint()); } S2Polygon s2polygon = new(new S2Loop(points)); Encoder encoder = new(); s2polygon.Encode(encoder); s2polygon_size += encoder.Length(); // S2LaxPolygonShape has 2 extra bytes of overhead to encode one loop. lax_polygon_size += TestEncodedS2PointVector(points.ToArray(), CodingHint.COMPACT, -1) + 2; } _logger.WriteLine($"n={num_points:d5} s2={s2polygon_size:d9} lax={lax_polygon_size:9}"); } }
public void Test_S2ContainsPointQuery_GetContainingShapes() { // Also tests ShapeContains(). int kNumVerticesPerLoop = 10; S1Angle kMaxLoopRadius = S2Testing.KmToAngle(10); S2Cap center_cap = new(S2Testing.RandomPoint(), kMaxLoopRadius); MutableS2ShapeIndex index = new(); for (int i = 0; i < 100; ++i) { var loop = S2Loop.MakeRegularLoop( S2Testing.SamplePoint(center_cap), S2Testing.Random.RandDouble() * kMaxLoopRadius, kNumVerticesPerLoop); index.Add(new S2Loop.Shape(loop)); } var query = index.MakeS2ContainsPointQuery(); for (int i = 0; i < 100; ++i) { S2Point p = S2Testing.SamplePoint(center_cap); List <S2Shape> expected = new(); foreach (var shape in index) { var loop = ((S2Loop.Shape)shape).Loop; if (loop.Contains(p)) { Assert.True(query.ShapeContains(shape, p)); expected.Add(shape); } else { Assert.False(query.ShapeContains(shape, p)); } } var actual = query.GetContainingShapes(p); Assert.Equal(expected, actual); } }