private static Vertex AddVertex(WeVertex vtx, RayedMesh mesh) { // ReSharper disable once ConvertIfStatementToNullCoalescingExpression if (vtx.HalfEdgeVertex == null) { vtx.HalfEdgeVertex = vtx.FAtInfinity ? mesh.AddRayedVertex(vtx.Pt) : mesh.AddVertex(vtx.Pt); } return(vtx.HalfEdgeVertex); }
private static void ProcessPolygonEdges(FortunePoly poly, RayedMesh mesh) { poly.SortEdges(); var edges = AddEdgeAtInfinity(poly); WeVertex vtxNext; // If this poly is a rayed polygon then we need an extra spot in the vertex array for the // edge at infinity which HalfEdge needs but isn't present in the FortunePolygon. var polyVertices = new Vertex[edges.Count]; // We have to prime the pump here if (edges[0].VtxStart == edges[1].VtxStart || edges[0].VtxStart == edges[1].VtxEnd) { vtxNext = edges[0].VtxStart; polyVertices[0] = AddVertex(edges[0].VtxEnd, mesh); } else { vtxNext = edges[0].VtxEnd; polyVertices[0] = AddVertex(edges[0].VtxStart, mesh); } // We skip the first edge since it's already been added in the pump priming above for (var ivtx = 1; ivtx < edges.Count; ivtx++) { var edge = edges[ivtx]; // Add in the leading vertex for this edge polyVertices[ivtx] = AddVertex(vtxNext, mesh); if (!edge.FZeroLength()) { // What about when we traverse this edge from the other direction? // We don't want to add one vertex going CW and another going CCW. // I think maybe we have to check if the end or start has already // been inserted and use that vertex if so. Still - won't that fail // if there are more than one zero length edge converging? // TODO: think about this vtxNext = edge.VtxStart == vtxNext ? edge.VtxEnd : edge.VtxStart; } } // Now add the Polygon var newFace = mesh.AddFace(polyVertices); // ReSharper disable once PossibleNullReferenceException // ReSharper disable once SuspiciousTypeConversion.Global (newFace as IVoronoi).VoronoiPoint = poly.VoronoiPoint; }