affine: Make GeoM.Rotate faster

This commit is contained in:
Hajime Hoshi 2017-05-28 04:16:11 +09:00
parent 3a58bd7f26
commit 6db96f5442

View File

@ -151,13 +151,23 @@ func (g *GeoM) Translate(tx, ty float64) {
// Rotate rotates the matrix by theta. // Rotate rotates the matrix by theta.
func (g *GeoM) Rotate(theta float64) { func (g *GeoM) Rotate(theta float64) {
sin, cos := math.Sincos(theta) sin, cos := math.Sincos(theta)
g.Concat(&GeoM{ if !g.inited {
a: cos, g.a = cos
b: -sin, g.b = -sin
c: sin, g.c = sin
d: cos, g.d = cos
inited: true, g.tx = 0
}) g.ty = 0
g.inited = true
return
}
a, b, c, d, tx, ty := g.a, g.b, g.c, g.d, g.tx, g.ty
g.a = cos*a - sin*c
g.b = cos*b - sin*d
g.tx = cos*tx - sin*ty
g.c = sin*a + cos*c
g.d = sin*b + cos*d
g.ty = sin*tx + cos*ty
} }
// ScaleGeo is deprecated as of 1.2.0-alpha. Use Scale instead. // ScaleGeo is deprecated as of 1.2.0-alpha. Use Scale instead.