circle radius
This commit is contained in:
@@ -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))
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user