public void TriangulatePartial() { var sortedVertices = new[] { new Vertex(1, 1), // 0 new Vertex(1, 3), new Vertex(1.5f, 3), // 2 new Vertex(2, 2), new Vertex(2, 4), // 4 new Vertex(2.5f, 1), new Vertex(2.5f, 2), // 6 new Vertex(2.5f, 3), new Vertex(3.5f, 2.5f), // 8 new Vertex(3.5f, 1), new Vertex(4, 1.5f), // 10 new Vertex(4, 3.5f), new Vertex(4, 4), // 12 }; var polygon = Polygon.Build(sortedVertices) .AddVertices(5, 0, 6, 3, 1, 4, 12, 2, 7, 11, 8, 10, 9) .Close(); Assert.AreEqual("5 0 6 3 1 4 12 2 7 11 8 10 9", string.Join(" ", polygon.SubPolygonVertices(0))); var triangluator = new PolygonTriangulator(polygon); var partialEdges = triangluator.GetEdgesAfterPartialTrapezoidation(4).ToArray(); CollectionAssert.AreEqual(new[] { "1>4", "2<12", "2>7", "3<6", "0>6", "0<5" }, partialEdges); }
public string[] BuildTrapezoidationDebug() { var lines = new List <string>(); var trapezoidation = new PolygonTriangulator(this.Polygon); int limit = 0; foreach (var vertexInfo in this.Polygon.OrderedVertices) { try { lines.Add($"{vertexInfo.Prev}>{vertexInfo.Id}>{vertexInfo.Next}"); lines.AddRange(trapezoidation.GetEdgesAfterPartialTrapezoidation(++limit)); lines.Add(string.Empty); } catch (Exception e) { lines.Add(string.Empty); lines.Add(e.ToString()); break; } } return(lines.ToArray()); }