static public IEnumerable <Triangle> Triangles(this ITriangulableShape shape) { using (IEnumerator <Vector2> enumerator = shape.TriangulationVertices().GetEnumerator()) { if (!enumerator.MoveNext()) { yield break; } var triangle = new Triangle(); triangle.P0 = enumerator.Current; enumerator.MoveNext(); triangle.P1 = enumerator.Current; enumerator.MoveNext(); triangle.P2 = enumerator.Current; yield return(triangle); if (shape.StripTriangulation) { while (enumerator.MoveNext()) { triangle = new Triangle { P0 = triangle.P2, P1 = triangle.P1, P2 = enumerator.Current }; yield return(triangle); } } while (enumerator.MoveNext()) { triangle = new Triangle(); triangle.P0 = enumerator.Current; enumerator.MoveNext(); triangle.P1 = enumerator.Current; enumerator.MoveNext(); triangle.P2 = enumerator.Current; yield return(triangle); } } }
static public ITriangulableShape InverseTransform(this ITransformer transformer, ITriangulableShape shape) { Vector2[] vertices = shape.Vertices.Select(transformer.InverseTransform).ToArray(); Segment[] edges = shape.Edges.Select(transformer.InverseTransform).ToArray(); return(new IndexedShape(vertices, edges, shape.TriangulationIndices?.ToArray(), shape.StripTriangulation)); }
static public IEnumerable <Vector2> TriangulationVertices(this ITriangulableShape shape) { return(shape.TriangulationIndices?.Select(shape.GetIndexedVertex) ?? shape.Vertices); }