github.com/joshvarga/voronoi@v0.0.0-20180211004454-2fd26fbdfffb/README.md (about) 1 # Voronoi diagrams in Go 2 3 A Implementation of of Steven J. Fortune's algorithm to 4 efficiently compute Voronoi diagrams in Go language. Based on 5 a Raymond Hill's javascript implementation 6 (https://raw.github.com/gorhill/Javascript-Voronoi). 7 8 ## Usage 9 10 ``` 11 import "github.com/pzsz/voronoi" 12 13 func main() { 14 // Sites of Voronoi diagram 15 sites := []voronoi.Vertex{ 16 {X: 4.0, Y: 5.0}, 17 {X: 6.0, Y: 5.0}, 18 ... 19 } 20 21 // Create bounding box of [0, 20] in X axis 22 // and [0, 10] in Y axis 23 bbox := voronoi.NewBBox(0, 20, 0, 10) 24 25 // Compute diagram and close cells (add half edges from bounding box) 26 diagram := voronoi.ComputeDiagram(sites, bbox, true) 27 28 // Iterate over cells 29 for _, cell := range diagram.Cells { 30 for _, hedge := range cell.Halfedges { 31 ... 32 } 33 } 34 35 // Iterate over all edges 36 for _, edge := range diagram.Edges { 37 if edge.LeftCell != nil && edge.RightCell != nil { 38 ... 39 } 40 } 41 }