//////////////////////////////////////////////////////////////////////////////////////////////////// /// <summary> Insert a new LeafNode into the tree. </summary> /// <remarks> Darrellp, 2/19/2011. </remarks> /// <param name="lfn"> Place to put the new leaf node. </param> /// <param name="evt"> The event to insert. </param> /// <returns> . </returns> //////////////////////////////////////////////////////////////////////////////////////////////////// private static InternalNode NdCreateInsertionSubtree(LeafNode lfn, SiteEvent evt) { // Initialize locals var innParent = lfn.NdParent; var lfnNewParabola = new LeafNode(evt.Poly); var innSubRoot = new InternalNode(evt.Poly, lfn.Poly); var fLeftChild = true; // If this isn't on the root node, shuffle things around a bit if (innParent != null) { fLeftChild = lfn.IsLeftChild; lfn.SnipFromParent(); if (fLeftChild) { innParent.LeftChild = innSubRoot; } else { innParent.RightChild = innSubRoot; } } // Watch for the odd corner case of the top n generators having the same y coordinate. See comments // on NdInsertAtSameY(). if (Geometry2D.FCloseEnough(evt.Pt.Y, lfn.Poly.VoronoiPoint.Y)) { NdInsertAtSameY(lfn, lfnNewParabola, innParent, innSubRoot, fLeftChild); } else { InsertAtDifferentY(lfn, lfnNewParabola, innSubRoot); } return(innSubRoot); }
/// <summary> /// Compare two events. We order them using y coordinate first and then x coordinate. /// </summary> /// <param name="obj"></param> /// <returns></returns> int IComparable.CompareTo(object obj) { // Get our Vector var ptCompare = ((FortuneEvent)obj).Pt; // If two events have essentially the same Y coordinate, we defer to the X coordinate if (Geometry2D.FCloseEnough(Pt.Y, ptCompare.Y)) { if (Pt.X > ptCompare.X) { return(-1); } if (Pt.X < ptCompare.X) { return(1); } // If we are a site event and the compared object is a circle event if (GetType() == typeof(SiteEvent) && obj.GetType() == typeof(CircleEvent)) { // Site events are bigger than circle events at the same point return(-1); } return(0); } if (Pt.Y > ptCompare.Y) { return(-1); } return(1); }