public static VCircleEvent CircleCheckDataNode(VDataNode n, double ys) { VDataNode l = LeftDataNode(n); VDataNode r = RightDataNode(n); if (l == null || r == null || l.DataPoint == r.DataPoint || l.DataPoint == n.DataPoint || n.DataPoint == r.DataPoint) return null; if (MathTools.Ccw(l.DataPoint.X, l.DataPoint.Y, n.DataPoint.X, n.DataPoint.Y, r.DataPoint.X, r.DataPoint.Y, false) <= 0) return null; Vector2 center = Fortune.CircumCircleCenter(l.DataPoint, n.DataPoint, r.DataPoint); VCircleEvent vc = new VCircleEvent(); vc.NodeN = n; vc.NodeL = l; vc.NodeR = r; vc.Center = center; vc.Valid = true; if (vc.Y >= ys) return vc; return null; }
public static VNode ProcessCircleEvent(VCircleEvent e, VNode root, VoronoiGraph vg, out VDataNode[] circleCheckList) { VEdgeNode eo; VDataNode b = e.NodeN; VDataNode a = LeftDataNode(b); VDataNode 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 } VEdgeNode eu = (VEdgeNode)b.Parent; circleCheckList = new[] { a, c }; //1. Create the new Vertex Vector2 vNew = new Vector2(e.Center.X, e.Center.Y); // VNew[0] = Fortune.ParabolicCut(a.DataPoint[0],a.DataPoint[1],c.DataPoint[0],c.DataPoint[1],ys); // VNew[1] = (ys + a.DataPoint[1])/2 - 1/(2*(ys-a.DataPoint[1]))*(VNew[0]-a.DataPoint[0])*(VNew[0]-a.DataPoint[0]); vg.Vertices.Add(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); // ///////////////////// uncertain // if(eo==eu) // return root; // ///////////////////// eo.Edge.AddVertex(vNew); //2. Replace eo by new Edge VoronoiEdge ve = new VoronoiEdge(); ve.LeftData = a.DataPoint; ve.RightData = c.DataPoint; ve.AddVertex(vNew); vg.Edges.Add(ve); VEdgeNode ven = new VEdgeNode(ve, false); ven.Left = eo.Left; ven.Right = eo.Right; if (eo.Parent == null) return ven; eo.Parent.Replace(eo, ven); return root; }