feat: move func to calc package
This commit is contained in:
+5
-18
@@ -1,6 +1,9 @@
|
||||
package util
|
||||
|
||||
import "math"
|
||||
import (
|
||||
"galaxy/calc"
|
||||
"math"
|
||||
)
|
||||
|
||||
// WrapF maps value into the half-open interval [0, float64(size)).
|
||||
// It supports negative input values and is used for torus coordinates
|
||||
@@ -28,12 +31,8 @@ func WrapF(value float64, size int) float64 {
|
||||
return r
|
||||
}
|
||||
|
||||
func ShortDistance(w, h uint32, x1, y1, x2, y2 float64) float64 {
|
||||
return math.Hypot(deltas(w, h, x1, y1, x2, y2))
|
||||
}
|
||||
|
||||
func NextTravelCoord(w, h uint32, x1, y1, x2, y2, delta float64) (float64, float64, bool) {
|
||||
deltaX, deltaY := deltas(w, h, x1, y1, x2, y2)
|
||||
deltaX, deltaY := calc.Deltas(w, h, x1, y1, x2, y2)
|
||||
distance := math.Hypot(deltaX, deltaY)
|
||||
if distance <= delta {
|
||||
return x2, y2, true
|
||||
@@ -93,15 +92,3 @@ func NextTravelCoord(w, h uint32, x1, y1, x2, y2, delta float64) (float64, float
|
||||
|
||||
return tx, ty, false
|
||||
}
|
||||
|
||||
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
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user