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); } }
public void Test_GetCrossings_ShapeIdsAreCorrect() { // This tests that when some index cells contain only one shape, the // intersecting edges are returned with the correct shape id. MutableS2ShapeIndex index = new(); index.Add(new S2Polyline.OwningShape( new S2Polyline(S2Testing.MakeRegularPoints( MakePointOrDie("0:0"), S1Angle.FromDegrees(5), 100)))); index.Add(new S2Polyline.OwningShape( new S2Polyline(S2Testing.MakeRegularPoints( MakePointOrDie("0:20"), S1Angle.FromDegrees(5), 100)))); TestPolylineCrossings(index, MakePointOrDie("1:-10"), MakePointOrDie("1:30")); }
public void Test_S2ContainsVertexQuery_CompatibleWithAngleContainsVertex() { var points = S2Testing.MakeRegularPoints(MakePointOrDie("89:1"), S1Angle.FromDegrees(5), 10); S2PointLoopSpan loop = new(points); for (int i = 0; i < loop.Count; ++i) { S2Point a = loop[i]; S2Point b = loop[i + 1]; S2Point c = loop[i + 2]; S2ContainsVertexQuery q = new(b); q.AddEdge(a, -1); q.AddEdge(c, 1); Assert.Equal(q.ContainsSign() > 0, S2.AngleContainsVertex(a, b, c)); } }
public void Test_VisitIntersectingShapes_Polylines() { MutableS2ShapeIndex index = new(); S2Cap center_cap = new(new S2Point(1, 0, 0), S1Angle.FromRadians(0.5)); for (int i = 0; i < 50; ++i) { S2Point center = S2Testing.SamplePoint(center_cap); S2Point[] vertices; if (S2Testing.Random.OneIn(10)) { vertices = new[] { center, center }; // Try a few degenerate polylines. } else { vertices = S2Testing.MakeRegularPoints( center, S1Angle.FromRadians(S2Testing.Random.RandDouble()), S2Testing.Random.Uniform(20) + 3); } index.Add(new S2LaxPolylineShape(vertices)); } new VisitIntersectingShapesTest(index).Run(); }
public void Test_S2LaxPolygonShape_ManyLoopPolygon() { // Test a polygon with enough loops so that binary search is used to find // the loop containing a given edge. var loops = new List <List <S2Point> >(); for (int i = 0; i < 100; ++i) { var center = S2LatLng.FromDegrees(0, i).ToPoint(); var loop = S2Testing.MakeRegularPoints( center, S1Angle.FromDegrees(0.1), S2Testing.Random.Uniform(3)); loops.Add(loop.ToList()); } var shape = new S2LaxPolygonShape(loops); Assert.Equal(loops.Count, shape.NumLoops); int num_vertices = 0; Assert.Equal(loops.Count, shape.NumChains()); for (int i = 0; i < loops.Count; ++i) { Assert.Equal(loops[i].Count, shape.NumLoopVertices(i)); Assert.Equal(num_vertices, shape.GetChain(i).Start); Assert.Equal(loops[i].Count, shape.GetChain(i).Length); for (int j = 0; j < loops[i].Count; ++j) { Assert.Equal(loops[i][j], shape.LoopVertex(i, j)); int e = num_vertices + j; Assert.Equal(shape.GetChainPosition(e), new S2Shape.ChainPosition(i, j)); Assert.Equal(loops[i][j], shape.GetEdge(e).V0); Assert.Equal(loops[i][(j + 1) % loops[i].Count], shape.GetEdge(e).V1); } num_vertices += loops[i].Count; } Assert.Equal(num_vertices, shape.NumVertices); Assert.Equal(num_vertices, shape.NumEdges()); // Now test all the edges in a random order in order to exercise the cases // involving prev_loop_. List <(int, int, int)> edges = new(); for (int i = 0, e = 0; i < loops.Count; ++i) { for (int j = 0; j < loops[i].Count; ++j, ++e) { edges.Add((e, i, j)); } } var mt = new PseudoRandom.MersenneTwister(); edges = edges.Shuffle(mt.genrand_N).ToList(); foreach (var(e, i, j) in edges) { Assert.Equal(shape.GetChainPosition(e), new S2Shape.ChainPosition(i, j)); var v0 = loops[i][j]; var v1 = loops[i][(j + 1) % loops[i].Count]; Assert.Equal(shape.GetEdge(e), new S2Shape.Edge(v0, v1)); } TestEncodedS2LaxPolygonShape(shape); }