FortunesAlgorithm
Fortunes algorithm implementation in Swift
Install / Use
/learn @fewlinesofcode/FortunesAlgorithmREADME
FortunesAlgorithm
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.
You can learn more about the project using Documentation
Installing
FortunesAlgorithm can be installed as any other Swift package. Add the following to the dependencies section of your Package.swift:
.package(url: "https://github.com/fewlinesofcode/FortunesAlgorithm", from: "1.0.0")
Basic Usage
- Add package dependency
- Import
import FortunesAlgorithm - Add diagram computation code in appropriate place:
let fortuneSweep = FortunesAlgorithm()
var diagram = Diagram()
let clippingRect = Rectangle(
origin: Vertex(x: 20, y: 20),
size: Size(width: 100, height: 100)
)
var sites = Set<Site>([Site(x: 10, y: 10), Site(x: 50, y: 50)/* Generate sites you need ... */])
fortuneSweep.compute(
sites: sites,
diagram: &diagram,
clippingRect: clippingRect
)
// `diagram.cells` now contains doubly linked list of `HalfEdges` and their twins allowing you to continue diagram usage drawing.
Literature
Must read:
- "Computational Geometry Algorithms and Applications. Third Edition" by Mark de Berg, Otfried Cheong Marc van Kreveld, Mark Overmars (Voronoi diagrams section)
- "Introduction to Algorithms. Third Edition" by Thomas H. Cormen, Charles E. Leiserson, Ronald L. Rivest, Clifford Stein (RedBlack Trees section)
- A Sweepline Algorithm for Voronoi Diagrams - Steven Fortune's paper
This project would not be possible without following articles:
- (Fortunes Algorithm. Part 1 and Fortunes Algorithm Part 2 by Jacques Heunis (@jacquesh)
- Fortune's algorithm, the details by Pierre Vigier (@pvigier)
Contact
Feel free to ask questions, report bugs and submit pull requests!
You can contact me by email: oglagoliev@gmail.com or follow me on Twitter: @fewlinesofcode
Related Skills
node-connect
346.4kDiagnose OpenClaw node connection and pairing failures for Android, iOS, and macOS companion apps
frontend-design
107.2kCreate distinctive, production-grade frontend interfaces with high design quality. Use this skill when the user asks to build web components, pages, or applications. Generates creative, polished code that avoids generic AI aesthetics.
openai-whisper-api
346.4kTranscribe audio via OpenAI Audio Transcriptions API (Whisper).
qqbot-media
346.4kQQBot 富媒体收发能力。使用 <qqmedia> 标签,系统根据文件扩展名自动识别类型(图片/语音/视频/文件)。
