slightly optimize Vec.Rotated

This commit is contained in:
faiface 2016-11-20 19:21:20 +01:00
parent 86f0b0f8ca
commit b0f81a6c7d
1 changed files with 3 additions and 2 deletions

5
vec.go
View File

@ -27,7 +27,7 @@ import (
// u := pixel.V(2, 3)
// v := pixel.V(8, 1)
// if u.X() < 0 {
// fmt.Println("this won't happend")
// fmt.Println("this won't happen")
// }
// x := u.Unit().Dot(v.Unit())
type Vec complex128
@ -78,7 +78,8 @@ func (u Vec) Scaled(c float64) Vec {
// Rotated returns a vector u rotated by the given angle in radians.
func (u Vec) Rotated(angle float64) Vec {
return u * V(math.Cos(angle), math.Sin(angle))
sin, cos := math.Sincos(angle)
return u * V(cos, sin)
}
// Dot returns the dot product of vectors u and v.