Exemplo n.º 1
0
        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);
        }
Exemplo n.º 2
0
        /// <summary>
        /// Will return the new root (unchanged except in start-up)
        /// </summary>
        public static VNode ProcessDataEvent(VDataEvent e, VNode root, VoronoiGraph vg, double ys, out VDataNode[] circleCheckList)
        {
            if (root == null)
            {
                root            = new VDataNode(e.DataPoint);
                circleCheckList = new[] { (VDataNode)root };
                return(root);
            }
            //1. Find the node to be replaced
            VNode c = FindDataNode(root, ys, e.DataPoint[0]);
            //2. Create the subtree (ONE Edge, but two VEdgeNodes)
            var ve = new VoronoiEdge
            {
                LeftData  = ((VDataNode)c).DataPoint,
                RightData = e.DataPoint,
                V1        = Edge.GetUnknownVertex(),
                V2        = Edge.GetUnknownVertex()
            };

            vg.AddEdge(ve);

            VNode subRoot;

            if (Math.Abs(ve.LeftData[1] - ve.RightData[1]) < 1e-10)
            {
                if (ve.LeftData[0] < ve.RightData[0])
                {
                    subRoot = new VEdgeNode(ve, false)
                    {
                        Left = new VDataNode(ve.LeftData), Right = new VDataNode(ve.RightData)
                    };
                }
                else
                {
                    subRoot = new VEdgeNode(ve, true)
                    {
                        Left = new VDataNode(ve.RightData), Right = new VDataNode(ve.LeftData)
                    };
                }
                circleCheckList = new[] { (VDataNode)subRoot.Left, (VDataNode)subRoot.Right };
            }
            else
            {
                subRoot = new VEdgeNode(ve, false)
                {
                    Left  = new VDataNode(ve.LeftData),
                    Right = new VEdgeNode(ve, true)
                    {
                        Left = new VDataNode(ve.RightData), Right = new VDataNode(ve.LeftData)
                    }
                };
                circleCheckList = new[] { (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);
        }