Commit 4a48937e authored by shengxinjing's avatar shengxinjing Committed by Michael Yang
Browse files

refactor: use builtin max and min

parent 967a82f5
...@@ -73,7 +73,7 @@ func (p ImageProcessor) bestResolution(img image.Point, possibleResolutions []im ...@@ -73,7 +73,7 @@ func (p ImageProcessor) bestResolution(img image.Point, possibleResolutions []im
for i, res := range possibleResolutions { for i, res := range possibleResolutions {
scaleW := float64(res.X) / float64(w) scaleW := float64(res.X) / float64(w)
scaleH := float64(res.Y) / float64(h) scaleH := float64(res.Y) / float64(h)
scale := math.Min(scaleW, scaleH) scale := min(scaleW, scaleH)
scales[i] = scale scales[i] = scale
} }
...@@ -124,11 +124,11 @@ func (p ImageProcessor) maxResolution(imageRes, targetRes image.Point) image.Poi ...@@ -124,11 +124,11 @@ func (p ImageProcessor) maxResolution(imageRes, targetRes image.Point) image.Poi
if scaleW < scaleH { if scaleW < scaleH {
newRes = image.Point{ newRes = image.Point{
targetRes.X, targetRes.X,
int(math.Min(math.Floor(float64(imageRes.Y)*scaleW), float64(targetRes.Y))), int(math.Floor(float64(imageRes.Y)*scaleW), float64(targetRes.Y))),
} }
} else { } else {
newRes = image.Point{ newRes = image.Point{
int(math.Min(math.Floor(float64(imageRes.X)*scaleH), float64(targetRes.X))), int(min(math.Floor(float64(imageRes.X)*scaleH), float64(targetRes.X))),
targetRes.Y, targetRes.Y,
} }
} }
......
...@@ -53,7 +53,7 @@ func (p ImageProcessor) fitToCanvas(imageSize, canvasSize image.Point) image.Poi ...@@ -53,7 +53,7 @@ func (p ImageProcessor) fitToCanvas(imageSize, canvasSize image.Point) image.Poi
tw := min(max(imageSize.X, p.imageSize), canvasSize.X) tw := min(max(imageSize.X, p.imageSize), canvasSize.X)
th := min(max(imageSize.Y, p.imageSize), canvasSize.Y) th := min(max(imageSize.Y, p.imageSize), canvasSize.Y)
r := math.Min( r := min(
float64(tw)/float64(imageSize.X), float64(tw)/float64(imageSize.X),
float64(th)/float64(imageSize.Y), float64(th)/float64(imageSize.Y),
) )
...@@ -89,10 +89,10 @@ func (p ImageProcessor) optimalTiledCanvas(imageSize image.Point) image.Point { ...@@ -89,10 +89,10 @@ func (p ImageProcessor) optimalTiledCanvas(imageSize image.Point) image.Point {
if minUpscale == 0 { if minUpscale == 0 {
minUpscale = s minUpscale = s
} else { } else {
minUpscale = math.Min(minUpscale, s) minUpscale = min(minUpscale, s)
} }
} else { } else {
maxDownscale = math.Max(maxDownscale, s) maxDownscale = max(maxDownscale, s)
} }
} }
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment