photoprism/internal/frame/point.go
Michael Mayer a30cbb19b7 Albums: Regenerate share preview after one hour and after changes #3658
Signed-off-by: Michael Mayer <michael@photoprism.app>
2023-09-08 17:36:56 +02:00

29 lines
505 B
Go

package frame
import (
"image"
"math/rand"
)
// RandomPoint returns a random image position within the specified range.
func RandomPoint(xMin, yMin, xMax, yMax int) image.Point {
if xMin == 0 && yMin == 0 && xMax == 0 && yMax == 0 {
return image.Pt(0, 0)
}
if xMin > xMax {
xMin = xMax
}
xDiff := float64(xMax - xMin)
x := xMin + int(rand.Float64()*xDiff)
if yMin > yMax {
yMin = yMax
}
yDiff := float64(yMax - yMin)
y := yMin + int(rand.Float64()*yDiff)
return image.Pt(x, y)
}