Esempio n. 1
0
        /// <summary>
        /// Processes the VCircleEvent.
        /// </summary>
        /// <param name="e">The VCircleEvent.</param>
        /// <param name="root">The root node.</param>
        /// <param name="vg">The VoronoiGraph.</param>
        /// <param name="circleCheckList">The circle check list.</param>
        /// <returns>The resulting root.</returns>
        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); // abbort because graph changed
            }

            VEdgeNode eu = (VEdgeNode)b.Parent;

            circleCheckList = new[] { a, c };

            // 1. Create the new Vertex
            Vector2 vNew = new(e.Center.X, e.Center.Y);

            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);
            eo.Edge.AddVertex(vNew);

            // 2. Replace eo by new Edge
            VoronoiEdge ve = new() { LeftData = a.DataPoint, RightData = c.DataPoint };

            ve.AddVertex(vNew);
            vg.Edges.Add(ve);

            VEdgeNode ven = new(ve, false) { Left = eo.Left, Right = eo.Right };

            if (eo.Parent == null)
            {
                return(ven);
            }
            eo.Parent.Replace(eo, ven);
            return(root);
        }

        /// <summary>
        /// Will return the new root (unchanged except in start-up).
        /// </summary>
        /// <param name="e">The VDataEvent.</param>
        /// <param name="root">The root node.</param>
        /// <param name="vg">The VoronoiGraph.</param>
        /// <param name="ys">The ys.</param>
        /// <param name="circleCheckList">The circle check list.</param>
        /// <returns>The new root.</returns>
        public static VNode ProcessDataEvent(VDataEvent e, VNode root, VoronoiGraph vg, double ys, out VDataNode[] circleCheckList)