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