update the geometric obitag

Former-commit-id: acd8fe1c8c1cf443098432d818397b0b5d02df33
This commit is contained in:
2024-01-17 23:38:51 +01:00
parent 13cfebd737
commit f2f7b4574e
5 changed files with 36 additions and 25 deletions

View File

@ -15,14 +15,14 @@ import (
// SquareDist calculates the squared Euclidean distance between
// two vectors 'a' and 'b'.
//
// 'a' and 'b' are slices of float64 values representing
// 'a' and 'b' are slices of float64 or int values representing
// coordinate points in space. It is assumed that both slices
// have the same length.
// Returns the calculated squared distance as a float64.
func SquareDist[T float64 | int](a, b []T) float64 {
sum := 0.0
func SquareDist[T float64 | int](a, b []T) T {
sum := T(0)
for i, v := range a {
diff := float64(v - b[i])
diff := v - b[i]
sum += diff * diff
}
return sum
@ -35,7 +35,7 @@ func SquareDist[T float64 | int](a, b []T) float64 {
// is paired with the corresponding element of `b`.
// Returns the squared sum of the differences.
func EuclideanDist[T float64 | int](a, b []T) float64 {
return math.Sqrt(SquareDist(a, b))
return math.Sqrt(float64(SquareDist(a, b)))
}
// DefaultRG creates and returns a new instance of *rand.Rand.