public static VNode ProcessCircleEvent(VCircleEvent e, VNode root, VoronoiGraph vg, out VDataNode[] circleCheckList) { VEdgeNode eo; var b = e.NodeN; var a = LeftDataNode(b); var c = RightDataNode(b); if (a == null || b.Parent == null || c == null || !a.DataPoint.Equals(e.NodeL.DataPoint) || !c.DataPoint.Equals(e.NodeR.DataPoint)) { circleCheckList = new VDataNode[] { }; return(root); // Abbruch da sich der Graph verändert hat } var eu = (VEdgeNode)b.Parent; circleCheckList = new[] { a, c }; //1. Create the new Vertex var vNew = new Vector2((float)e.CenterX, (float)e.CenterY); vg.AddVertex(vNew); //2. Find out if a or c are in a distand part of the tree (the other is then b's sibling) and assign the new vertex if (eu.Left == b) // c is sibling { eo = EdgeToRightDataNode(a); // replace eu by eu's Right eu.Parent.Replace(eu, eu.Right); } else // a is sibling { eo = EdgeToRightDataNode(b); // replace eu by eu's Left eu.Parent.Replace(eu, eu.Left); } eu.Edge.AddVertex(vNew); eo.Edge.AddVertex(vNew); //2. Replace eo by new Edge var ve = new VoronoiEdge { LeftData = a.DataPoint, RightData = c.DataPoint }; ve.AddVertex(vNew); vg.AddEdge(ve); var ven = new VEdgeNode(ve, false) { Left = eo.Left, Right = eo.Right }; if (eo.Parent == null) { return(ven); } eo.Parent.Replace(eo, ven); return(root); }
public static VoronoiGraph FilterVg(VoronoiGraph vg, double minLeftRightDist) { var vgErg = new VoronoiGraph(); foreach (var ve in vg.GetEdges().Select(edge => edge as VoronoiEdge)) { if ((ve.LeftData - ve.RightData).magnitude >= minLeftRightDist) { vgErg.AddEdge(ve); } } foreach (var ve in vgErg.GetEdges()) { vgErg.AddVertex(ve.V1); vgErg.AddVertex(ve.V2); } return(vgErg); }