circle radius

This commit is contained in:
Ilia Denisov
2026-03-22 19:43:09 +02:00
committed by GitHub
parent ad25845ec0
commit 73a4b0d3ec
7 changed files with 169 additions and 9 deletions
+26
View File
@@ -2,6 +2,32 @@ package util
import "math"
// WrapF maps value into the half-open interval [0, float64(size)).
// It supports negative input values and is used for torus coordinates
// when the coordinate is represented as float64.
//
// size must be greater than zero.
func WrapF(value float64, size int) float64 {
if size <= 0 {
panic("WrapF: size must be > 0")
}
s := float64(size)
r := math.Mod(value, s)
if r < 0 {
r += s
}
// Protect against a possible boundary artifact and keep result in [0, s).
// In normal cases math.Mod already gives a value with |r| < s.
if r >= s {
r -= s
}
return r
}
func ShortDistance(w, h uint32, x1, y1, x2, y2 float64) float64 {
return math.Hypot(deltas(w, h, x1, y1, x2, y2))
}