@@ -66,15 +66,16 @@ func Rotate(img image.Image, angle float64, options *RotationOptions) *image.RGB
66
66
angleRadians := - angle * (math .Pi / 180 )
67
67
68
68
var dstW , dstH int
69
+ var sin , cos = math .Sincos (angleRadians )
69
70
if resizeBounds {
70
71
// Reserve larger size in destination image for full image bounds rotation
71
72
// If not preserving size, always take image center as pivot
72
73
pivotX , pivotY = float64 (srcW )/ 2 , float64 (srcH )/ 2
73
74
74
- a := math .Abs (float64 (srcW ) * math . Sin ( angleRadians ) )
75
- b := math .Abs (float64 (srcW ) * math . Cos ( angleRadians ) )
76
- c := math .Abs (float64 (srcH ) * math . Sin ( angleRadians ) )
77
- d := math .Abs (float64 (srcH ) * math . Cos ( angleRadians ) )
75
+ a := math .Abs (float64 (srcW ) * sin )
76
+ b := math .Abs (float64 (srcW ) * cos )
77
+ c := math .Abs (float64 (srcH ) * sin )
78
+ d := math .Abs (float64 (srcH ) * cos )
78
79
79
80
dstW , dstH = int (c + b + 0.5 ), int (a + d + 0.5 )
80
81
} else {
@@ -100,8 +101,8 @@ func Rotate(img image.Image, angle float64, options *RotationOptions) *image.RGB
100
101
for x := xStart ; x < xEnd ; x ++ {
101
102
dx := float64 (x ) - pivotX + 0.5
102
103
103
- ix := int ((math . Cos ( angleRadians ) * dx - math . Sin ( angleRadians ) * dy + pivotX ))
104
- iy := int ((math . Sin ( angleRadians ) * dx + math . Cos ( angleRadians ) * dy + pivotY ))
104
+ ix := int ((cos * dx - sin * dy + pivotX ))
105
+ iy := int ((sin * dx + cos * dy + pivotY ))
105
106
106
107
if ix < 0 || ix >= srcW || iy < 0 || iy >= srcH {
107
108
continue
0 commit comments