/
borders.go
72 lines (67 loc) · 1.87 KB
/
borders.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
package genmapvoronoi
import (
"github.com/pzsz/voronoi"
)
// getBorders returns the outlines of political territories by identifying neighboring
// territories and returning the voronoi cell sites of all neighbors that do not have
// the same territory ID.
//
// TODO: Dedup this with getCityBorders.
func getBorders(render *Terrain) [][]voronoi.Vertex {
terr := render.terr
h := render.h
var edges [][2]voronoi.Vertex
for i := 0; i < len(h.Edges); i++ {
e := h.Edges[i]
if e.Right == nil {
continue
}
//if isnearedge(h.Mesh, e.IdxA) || isnearedge(h.Mesh, e.IdxB){
// continue
//}
if h.Values[e.IdxA] < 0 || h.Values[e.IdxB] < 0 {
continue
}
if terr[e.IdxA] != terr[e.IdxB] {
edges = append(edges, [2]voronoi.Vertex{e.Left.Site, e.Right.Site})
}
}
// Merge all segments into continuous outlines of political territories.
mergedSegs := mergeSegments(edges)
for i := range mergedSegs {
// Relax the outlines.
mergedSegs[i] = relaxPath(mergedSegs[i])
}
return mergedSegs
}
// getCityBorders is virtually identical to getBorders but instead of the national
// territories, we return the outlines of the cities.
//
// TODO: Dedup this with getBorders.
func getCityBorders(render *Terrain) [][]voronoi.Vertex {
terr := render.cityTerritories
h := render.h
var edges [][2]voronoi.Vertex
for i := 0; i < len(h.Edges); i++ {
e := h.Edges[i]
if e.Right == nil {
continue
}
//if isnearedge(h.Mesh, e.IdxA) || isnearedge(h.Mesh, e.IdxB){
// continue
//}
if h.Values[e.IdxA] < 0 || h.Values[e.IdxB] < 0 {
continue
}
if terr[e.IdxA] != terr[e.IdxB] {
edges = append(edges, [2]voronoi.Vertex{e.Left.Site, e.Right.Site})
}
}
// Merge all segments into continuous outlines of city territories.
mergedSegs := mergeSegments(edges)
for i := range mergedSegs {
// Relax the outlines.
mergedSegs[i] = relaxPath(mergedSegs[i])
}
return mergedSegs
}