/// <summary> /// Verifies that all methods of the two S2Shapes return identical results, /// except for id() and type_tag(). /// </summary> public static void ExpectEqual(S2Shape a, S2Shape b) { Assert.True(a.NumEdges() == b.NumEdges()); for (int i = 0; i < a.NumEdges(); ++i) { Assert.Equal(a.GetEdge(i), b.GetEdge(i)); Assert.True(a.GetChainPosition(i) == b.GetChainPosition(i)); } Assert.True(a.Dimension() == b.Dimension()); Assert.True(a.GetReferencePoint() == b.GetReferencePoint()); Assert.True(a.NumChains() == b.NumChains()); for (int i = 0; i < a.NumChains(); ++i) { Assert.True(a.GetChain(i) == b.GetChain(i)); int chain_length = a.GetChain(i).Length; for (int j = 0; j < chain_length; ++j) { Assert.True(a.ChainEdge(i, j) == b.ChainEdge(i, j)); } } }
// Returns true if the given shape contains the given point. Most clients // should not use this method, since its running time is linear in the number // of shape edges. Instead clients should create an S2ShapeIndex and use // S2ContainsPointQuery, since this strategy is much more efficient when many // points need to be tested. // // Polygon boundaries are treated as being semi-open (see S2ContainsPointQuery // and S2VertexModel for other options). // // CAVEAT: Typically this method is only used internally. Its running time is // linear in the number of shape edges. public static bool ContainsBruteForce(this S2Shape shape, S2Point point) { if (shape.Dimension() < 2) { return(false); } var ref_point = shape.GetReferencePoint(); if (ref_point.Point == point) { return(ref_point.Contained); } S2CopyingEdgeCrosser crosser = new(ref_point.Point, point); bool inside = ref_point.Contained; for (int e = 0; e < shape.NumEdges(); ++e) { var edge = shape.GetEdge(e); inside ^= crosser.EdgeOrVertexCrossing(edge.V0, edge.V1); } return(inside); }