|
1 | 1 | # FortunesAlgorithm |
2 | 2 |
|
| 3 | +`FortunesAlgorithm` is a Swift package for building Voronoi diagrams using Steven Fortune's algorithm. Algorithm guarantees `O(n log n)` worst-case running time and uses `O(n)` space. |
| 4 | + |
| 5 | +# Installing |
| 6 | + |
| 7 | +`FortunesAlgorithm` can be installed as any other Swift package. Add the following to the `dependencies` section of your `Package.swift`: |
| 8 | + |
| 9 | +``` |
| 10 | +.package(url: "https://github.com/fewlinesofcode/FortunesAlgorithm", from: "1.0.0") |
| 11 | +``` |
| 12 | + |
| 13 | +# Basic Usage |
| 14 | + |
| 15 | +1. Add package dependency |
| 16 | +2. Import `import FortunesAlgorithm` |
| 17 | +3. Add diagram computation code in appropriate place: |
| 18 | + |
| 19 | +``` |
| 20 | +let fortuneSweep = FortunesAlgorithm() |
| 21 | +var diagram = Diagram() |
| 22 | +let clippingRect = Rectangle( |
| 23 | + origin: Vertex(x: 20, y: 20), |
| 24 | + size: Size(width: 100, height: 100) |
| 25 | + ) |
| 26 | +var sites = Set<Site>([Site(x: 10, y: 10), Site(x: 50, y: 50)/* Generate sites you need ... */]) |
| 27 | +fortuneSweep.compute( |
| 28 | + sites: sites, |
| 29 | + diagram: &diagram, |
| 30 | + clippingRect: clippingRect |
| 31 | + ) |
| 32 | + |
| 33 | +// `diagram.cells` now contains doubly linked list of `HalfEdges` and their twins allowing you to continue diagram usage drawing. |
| 34 | +``` |
| 35 | + |
| 36 | +# Literature |
| 37 | + |
| 38 | +### Must read: |
| 39 | +1. "Computational Geometry Algorithms and Applications. Third Edition" by Mark de Berg, Otfried Cheong Marc van Kreveld, Mark Overmars (Voronoi diagrams section) |
| 40 | +2. "Introduction to Algorithms. Third Edition" by Thomas H. Cormen, Charles E. Leiserson, Ronald L. Rivest, Clifford Stein (RedBlack Trees section) |
| 41 | +3. [A Sweepline Algorithm for Voronoi Diagrams](http://www.wias-berlin.de/people/si/course/files/Fortune87-SweepLine-Voronoi.pdf) - Steven Fortune's paper |
| 42 | + |
| 43 | +### This project would not be possible without following articles: |
| 44 | + |
| 45 | +1. ([Fortunes Algorithm. Part 1](https://jacquesheunis.com/post/fortunes-algorithm/) and [Fortunes Algorithm Part 2](https://jacquesheunis.com/post/fortunes-algorithm-implementation/) by Jacques Heunis (@jacquesh) |
| 46 | +2. [Fortune's algorithm, the details](https://pvigier.github.io/2018/11/18/fortune-algorithm-details.html) by Pierre Vigier (@pvigier) |
| 47 | + |
0 commit comments