cmd: send group

This commit is contained in:
Ilia Denisov
2026-01-04 21:43:16 +02:00
parent c6e1cb5cdf
commit a6093a1c29
12 changed files with 266 additions and 15 deletions
+16
View File
@@ -0,0 +1,16 @@
package util
import "math"
func ShortDistance(w, h uint32, x1, y1, x2, y2 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 math.Sqrt(math.Pow(dx, 2) + math.Pow(dy, 2))
}
+27
View File
@@ -0,0 +1,27 @@
package util_test
import (
"fmt"
"testing"
"github.com/iliadenisov/galaxy/internal/number"
"github.com/iliadenisov/galaxy/internal/util"
"github.com/stretchr/testify/assert"
)
func TestShortDistance(t *testing.T) {
for i, tc := range []struct {
w, h uint32
x1, y1, x2, y2, d float64
}{
{10, 10, 0, 0, 5, 5, 7.071},
{10, 10, 0, 0, 5.01, 5.01, 7.057},
{10, 10, 2, 2, 8, 2, 4.},
{10, 10, 8, 7, 1, 7, 3.},
} {
t.Run(fmt.Sprint(i), func(t *testing.T) {
d := util.ShortDistance(tc.w, tc.h, tc.x1, tc.y1, tc.x2, tc.y2)
assert.Equal(t, tc.d, number.Fixed3(d))
})
}
}