Esempio n. 1
0
        public void Run(List <FortuneSite> sites, PoolLinkedList <VEdge> edges, double minX, double minY, double maxX, double maxY)
        {
            eventQueue.Initialize(5 * sites.Count);
            beachLine.Clear();
            deleted.Clear();

            foreach (var s in sites)
            {
                var fEvent = ObjectPool <FortuneSiteEvent> .Get();

                fEvent.Initialize(s);
                eventQueue.Insert(fEvent);
            }

            //init edge list
            while (eventQueue.Count != 0)
            {
                var fEvent = eventQueue.Pop();
                if (fEvent is FortuneSiteEvent)
                {
                    beachLine.AddBeachSection((FortuneSiteEvent)fEvent, eventQueue, deleted, edges);
                    ObjectPool <FortuneSiteEvent> .Recycle((FortuneSiteEvent)fEvent);
                }
                else
                {
                    if (deleted.Contains((FortuneCircleEvent)fEvent))
                    {
                        deleted.Remove((FortuneCircleEvent)fEvent);
                    }
                    else
                    {
                        beachLine.RemoveBeachSection((FortuneCircleEvent)fEvent, eventQueue, deleted, edges);
                    }
                    ObjectPool <FortuneCircleEvent> .Recycle((FortuneCircleEvent)fEvent);
                }
            }


            //clip edges
            var edgeNode = edges.First;

            while (edgeNode != null)
            {
                var edge = edgeNode.Value;
                var next = edgeNode.Next;

                var valid = ClipEdge(edge, minX, minY, maxX, maxY);
                if (!valid)
                {
                    edges.Remove(edgeNode);
                    if (edgeNode.Value.Neighbor != null)
                    {
                        ObjectPool <VEdge> .Recycle(edgeNode.Value.Neighbor);
                    }
                    ObjectPool <VEdge> .Recycle(edgeNode.Value);
                }
                //advance
                edgeNode = next;
            }
        }
Esempio n. 2
0
        public static LinkedList <VEdge> Run(List <FortuneSite> sites, double minX, double minY, double maxX, double maxY)
        {
            var eventQueue = new MinHeap <FortuneEvent>(5 * sites.Count);

            foreach (var s in sites)
            {
                eventQueue.Insert(new FortuneSiteEvent(s));
            }
            //init tree
            var beachLine = new BeachLine();
            var edges     = new LinkedList <VEdge>();
            var deleted   = new HashSet <FortuneCircleEvent>();

            //init edge list
            while (eventQueue.Count != 0)
            {
                var fEvent = eventQueue.Pop();
                if (fEvent is FortuneSiteEvent)
                {
                    beachLine.AddBeachSection((FortuneSiteEvent)fEvent, eventQueue, deleted, edges);
                }
                else
                {
                    if (deleted.Contains((FortuneCircleEvent)fEvent))
                    {
                        deleted.Remove((FortuneCircleEvent)fEvent);
                    }
                    else
                    {
                        beachLine.RemoveBeachSection((FortuneCircleEvent)fEvent, eventQueue, deleted, edges);
                    }
                }
            }


            //clip edges
            var edgeNode = edges.First;

            while (edgeNode != null)
            {
                var edge = edgeNode.Value;
                var next = edgeNode.Next;

                var valid = ClipEdge(edge, minX, minY, maxX, maxY);
                if (!valid)
                {
                    edges.Remove(edgeNode);
                }
                //advance
                edgeNode = next;
            }
            return(edges);
        }