feat: move func to calc package

This commit is contained in:
Ilia Denisov
2026-05-10 14:55:14 +02:00
parent 92413575f3
commit 408097e3aa
11 changed files with 21214 additions and 38 deletions
+20
View File
@@ -0,0 +1,20 @@
package calc
import "math"
// shortest distance between points on torus map
func ShortDistance(w, h uint32, x1, y1, x2, y2 float64) float64 {
return math.Hypot(Deltas(w, h, x1, y1, x2, y2))
}
func Deltas(w, h uint32, x1, y1, x2, y2 float64) (float64, float64) {
dx := math.Abs(x2 - x1)
dy := math.Abs(y2 - y1)
if dx > float64(w/2) {
dx = float64(h) - dx
}
if dy > float64(h/2) {
dy = float64(h) - dy
}
return dx, dy
}