示例#1
0
    public LinkedList <Edge> GenerateVoronoi(List <FortuneSite> sites, double minX, double minY, double maxX, double maxY)
    {
        MinHeap <FortuneEvent> eventQueue = new MinHeap <FortuneEvent>(5 * sites.Count);

        foreach (FortuneSite site in sites)
        {
            eventQueue.Insert(new FortuneSiteEvent(site));
        }

        BeachLine                    beachLine = new BeachLine();
        LinkedList <Edge>            edges     = new LinkedList <Edge>();
        HashSet <FortuneCircleEvent> deleted   = new HashSet <FortuneCircleEvent>();

        while (eventQueue.count != 0)
        {
            FortuneEvent fortuneEvent = eventQueue.Pop();

            if (fortuneEvent is FortuneSiteEvent)
            {
                beachLine.AddSection((FortuneSiteEvent)fortuneEvent, eventQueue, deleted, edges);
            }
            else
            {
                if (deleted.Contains((FortuneCircleEvent)fortuneEvent))
                {
                    deleted.Remove((FortuneCircleEvent)fortuneEvent);
                }
                else
                {
                    beachLine.RemoveBeachSection((FortuneCircleEvent)fortuneEvent, eventQueue, deleted, edges);
                }
            }
        }

        LinkedListNode <Edge> edgeNode = edges.First;

        while (edgeNode != null)
        {
            Edge edge = edgeNode.Value;
            LinkedListNode <Edge> nextNode = edgeNode.Next;

            if (!ClipEdge(edge, minX, minY, maxX, maxY))
            {
                edges.Remove(edgeNode);
            }

            edgeNode = nextNode;
        }

        return(edges);
    }
示例#2
0
        public int CompareTo(FortuneEvent other)
        {
            var c = Y.CompareTo(other.Y);

            return(c == 0 ? X.CompareTo(other.X) : c);
        }
示例#3
0
    public int CompareTo(FortuneEvent other)
    {
        int comparison = this.y.CompareTo(other.y);

        return(comparison == 0 ? this.x.CompareTo(other.x) : comparison);
    }