/// <summary> /// Removes vertices from the provided vertex sequence. This will scan round all vertices in the contour /// and if the vector to and from each vertex to its neighbours is the same (i.e. 3 vertices are in a straight /// line), then the center vertex is culled. Reducing the amount of vertices in the contour but retaining the shape. /// </summary> /// <param name="vs">The vertex sequence to cull vertices from.</param> private void RemoveVertices(VertexSequence vs) { int count = 0; for (int i = 0; i < vs.Count; i++) { Vector2 a = vs[i - 1]; Vector2 b = vs[i]; Vector2 c = vs[i + 1]; //Remove b if its the same X or same Y as a and c bool abX = UnityEngine.Mathf.Approximately(a.x, b.x); bool bcX = UnityEngine.Mathf.Approximately(b.x, c.x); bool abY = UnityEngine.Mathf.Approximately(a.y, b.y); bool bcY = UnityEngine.Mathf.Approximately(b.y, c.y); if ((abX && bcX) || (abY && bcY)) { count++; vs.Remove(b); i--; } } }