1 /* 2 * Copyright 2014 Google Inc. 3 * 4 * Use of this source code is governed by a BSD-style license that can be 5 * found in the LICENSE file. 6 */ 7 8 #include "include/core/SkMatrix.h" 9 #include "include/core/SkPoint.h" 10 #include "include/core/SkScalar.h" 11 #include "src/utils/SkMatrix22.h" 12 SkComputeGivensRotation(const SkVector & h,SkMatrix * G)13void SkComputeGivensRotation(const SkVector& h, SkMatrix* G) { 14 const SkScalar& a = h.fX; 15 const SkScalar& b = h.fY; 16 SkScalar c, s; 17 if (0 == b) { 18 c = SkScalarCopySign(SK_Scalar1, a); 19 s = 0; 20 //r = SkScalarAbs(a); 21 } else if (0 == a) { 22 c = 0; 23 s = -SkScalarCopySign(SK_Scalar1, b); 24 //r = SkScalarAbs(b); 25 } else if (SkScalarAbs(b) > SkScalarAbs(a)) { 26 SkScalar t = a / b; 27 SkScalar u = SkScalarCopySign(SkScalarSqrt(SK_Scalar1 + t*t), b); 28 s = -SK_Scalar1 / u; 29 c = -s * t; 30 //r = b * u; 31 } else { 32 SkScalar t = b / a; 33 SkScalar u = SkScalarCopySign(SkScalarSqrt(SK_Scalar1 + t*t), a); 34 c = SK_Scalar1 / u; 35 s = -c * t; 36 //r = a * u; 37 } 38 39 G->setSinCos(s, c); 40 } 41