public DEdge[] GetEdgesConnectedTo(Centroid edgeConnection) { DEdge[] dEdges = new DEdge[2]; int i = 0; foreach (var edge in edges) { if (edge.end == edgeConnection || edge.start == edgeConnection) { dEdges[i++] = edge; } } return(dEdges); }
/// <summary> /// Based off of https://www.redblobgames.com/maps/noisy-edges/ /// </summary> public void CreateNoisyEdge(int subdivisions) { if (segments != null) // already noisified this edge { return; } if (polygons.Count != 2) { // probably on the map edge if (polygons.Count > 2 || polygons.Count == 0) { throw new Exception("Invalid polygon count in edge " + id + ". Count: " + polygons.Count); } CreateSimpleBorder(); return; } segments = new List <Vector3>(); pairedEdge = polygons[0].centroid.GetConnectingEdge(polygons[1].centroid); if (pairedEdge == null) { throw new Exception("Invalid delaunay edge"); } Vector3 control1 = pairedEdge.start.position; Vector3 control2 = pairedEdge.end.position; if (!VoronoiGenerator.TryGetLineIntersections( control1, control2, start.position, end.position, out Vector2 intersectPoint, out float tMid, out float t2)) { Debug.LogWarning("SPECIAL CASE: voronoi and delaunay edges do not meet"); CreateSimpleBorder(); return; } segments.Add(start.position); segments.AddRange( CreateSegments(start.position, end.position, control1, control2, subdivisions, -tMid)); segments.Add(end.position); }
/// <summary> /// Returns any edges that have not been found yet (i.e. new edges). /// </summary> public List <DEdge> CalculateEdges() { List <DEdge> newEdges = new List <DEdge>(); edges = new List <DEdge>(); bool edgeFound = false; foreach (var edge in p1.connectedEdges) { if (edge.Contains(p2)) { edges.Add(edge); edgeFound = true; break; } } if (!edgeFound) { DEdge edge = new DEdge(p1, p2); newEdges.Add(edge); edges.Add(edge); } else { edgeFound = false; } foreach (var edge in p1.connectedEdges) { if (edge.Contains(p3)) { edges.Add(edge); edgeFound = true; break; } } if (!edgeFound) { DEdge edge = new DEdge(p1, p3); newEdges.Add(edge); edges.Add(edge); } else { edgeFound = false; } foreach (var edge in p2.connectedEdges) { if (edge.Contains(p3)) { edges.Add(edge); edgeFound = true; break; } } if (!edgeFound) { DEdge edge = new DEdge(p2, p3); newEdges.Add(edge); edges.Add(edge); } return(newEdges); }