OLD | NEW |
(Empty) | |
| 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 "SkMatrix.h" |
| 9 #include "SkPoint.h" |
| 10 #include "SkScalar.h" |
| 11 |
| 12 void SkComputeGivensRotation(const SkVector& h, SkMatrix* G) { |
| 13 const SkScalar& a = h.fX; |
| 14 const SkScalar& b = h.fY; |
| 15 SkScalar c, s; |
| 16 if (0 == b) { |
| 17 c = SkScalarCopySign(SK_Scalar1, a); |
| 18 s = 0; |
| 19 //r = SkScalarAbs(a); |
| 20 } else if (0 == a) { |
| 21 c = 0; |
| 22 s = -SkScalarCopySign(SK_Scalar1, b); |
| 23 //r = SkScalarAbs(b); |
| 24 } else if (SkScalarAbs(b) > SkScalarAbs(a)) { |
| 25 SkScalar t = a / b; |
| 26 SkScalar u = SkScalarCopySign(SkScalarSqrt(SK_Scalar1 + t*t), b); |
| 27 s = -SK_Scalar1 / u; |
| 28 c = -s * t; |
| 29 //r = b * u; |
| 30 } else { |
| 31 SkScalar t = b / a; |
| 32 SkScalar u = SkScalarCopySign(SkScalarSqrt(SK_Scalar1 + t*t), a); |
| 33 c = SK_Scalar1 / u; |
| 34 s = -c * t; |
| 35 //r = a * u; |
| 36 } |
| 37 |
| 38 G->setSinCos(s, c); |
| 39 } |
OLD | NEW |