public void Replace(VNode ChildOld, VNode ChildNew) { if (Left == ChildOld) Left = ChildNew; else if (Right == ChildOld) Right = ChildNew; else throw new Exception("Child not found!"); ChildOld.Parent = null; }
/// <summary> /// Will return the new root (unchanged except in start-up) /// </summary> public static VNode ProcessDataEvent(VDataEvent e, VNode Root, VoronoiGraph VG, float ys, out VDataNode[] CircleCheckList) { if (Root == null) { Root = new VDataNode(e.DataPoint); CircleCheckList = new VDataNode[] { (VDataNode)Root }; return Root; } //1. Find the node to be replaced VNode C = VNode.FindDataNode(Root, ys, e.DataPoint.x); //2. Create the subtree (ONE Edge, but two VEdgeNodes) VoronoiEdge VE = new VoronoiEdge(); VE.Left = ((VDataNode)C).DataPoint; VE.Right = e.DataPoint; VE.VVertexA = Fortune.VVUnkown; VE.VVertexB = Fortune.VVUnkown; VG.Edges.Add(VE); VNode SubRoot; if (Math.Abs(VE.Left.y - VE.Right.y) < 1e-10) { if (VE.Left.x < VE.Right.x) { SubRoot = new VEdgeNode(VE, false); SubRoot.Left = new VDataNode(VE.Left); SubRoot.Right = new VDataNode(VE.Right); } else { SubRoot = new VEdgeNode(VE, true); SubRoot.Left = new VDataNode(VE.Right); SubRoot.Right = new VDataNode(VE.Left); } CircleCheckList = new VDataNode[] { (VDataNode)SubRoot.Left, (VDataNode)SubRoot.Right }; } else { SubRoot = new VEdgeNode(VE, false); SubRoot.Left = new VDataNode(VE.Left); SubRoot.Right = new VEdgeNode(VE, true); SubRoot.Right.Left = new VDataNode(VE.Right); SubRoot.Right.Right = new VDataNode(VE.Left); CircleCheckList = new VDataNode[] { (VDataNode)SubRoot.Left, (VDataNode)SubRoot.Right.Left, (VDataNode)SubRoot.Right.Right }; } //3. Apply subtree if (C.Parent == null) return SubRoot; C.Parent.Replace(C, SubRoot); return Root; }
public static VDataNode FirstDataNode(VNode Root) { VNode C = Root; while (C.Left != null) C = C.Left; return (VDataNode)C; }
public static VNode ProcessCircleEvent(VCircleEvent e, VNode Root, VoronoiGraph VG, float ys, out VDataNode[] CircleCheckList) { VDataNode a, b, c; VEdgeNode eu, eo; b = e.NodeN; a = VNode.LeftDataNode(b); c = VNode.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 } eu = (VEdgeNode)b.Parent; CircleCheckList = new VDataNode[] { 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 = VNode.EdgeToRightDataNode(a); // replace eu by eu's Right eu.Parent.Replace(eu, eu.Right); } else // a is sibling { eo = VNode.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.Left = a.DataPoint; VE.Right = 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; }
public static VDataNode FindDataNode(VNode Root, float ys, float x) { VNode C = Root; do { if (C is VDataNode) return (VDataNode)C; if (((VEdgeNode)C).Cut(ys, x) < 0) C = C.Left; else C = C.Right; } while (true); }