...
1 package geo
2
3 import "math"
4
5 func EuclideanDistance(x1, y1, x2, y2 float64) float64 {
6 if x1 == x2 {
7 return math.Abs(y1 - y2)
8 } else if y1 == y2 {
9 return math.Abs(x1 - x2)
10 } else {
11 return math.Sqrt((x1-x2)*(x1-x2) + (y1-y2)*(y1-y2))
12 }
13 }
14
15
16
17 func PrecisionCompare(a, b, e float64) int {
18 if math.Abs(a-b) < e {
19 return 0
20 }
21 if a < b {
22 return -1
23 }
24 return 1
25 }
26
27
28
29 func TruncateDecimals(v float64) float64 {
30 return float64(int(v*1000)) / 1000
31 }
32
33 func Sign(i float64) int {
34 if i < 0 {
35 return -1
36 }
37 if i > 0 {
38 return 1
39 }
40 return 0
41 }
42
View as plain text