a30cbb19b7
Signed-off-by: Michael Mayer <michael@photoprism.app>
29 lines
505 B
Go
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)
|
|
}
|