-
Notifications
You must be signed in to change notification settings - Fork 0
/
geo.go
51 lines (40 loc) · 902 Bytes
/
geo.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
package main
import (
"math"
)
func getCenter(in []coordinates) coordinates {
minX := math.Inf(1)
maxX := math.Inf(-1)
minY := math.Inf(1)
maxY := math.Inf(-1)
for _, p := range in {
minX = math.Min(minX, p.x)
maxX = math.Max(maxX, p.x)
minY = math.Min(minY, p.y)
maxY = math.Max(maxY, p.y)
}
x := (minX + maxX) / 2
y := (minY + maxY) / 2
return coordinates{x, y}
}
// assumes rectangular pads
func getSize(in []coordinates) float64 {
minX := math.Inf(1)
maxX := math.Inf(-1)
minY := math.Inf(1)
maxY := math.Inf(-1)
for _, p := range in {
minX = math.Min(minX, p.x)
maxX = math.Max(maxX, p.x)
minY = math.Min(minY, p.y)
maxY = math.Max(maxY, p.y)
}
x := maxX - minX
y := maxY - minY
// best size for area
areaSize := math.Sqrt(x * y)
// max size for smaller dimension
maxSize := math.Min(x, y) * 1.2
size := math.Min(maxSize, areaSize)
return size
}