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); }