bungeman@google.com | d3fbd34 | 2014-04-15 15:52:07 +0000 | [diff] [blame] | 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" |
commit-bot@chromium.org | 2cfa320 | 2014-04-19 22:00:40 +0000 | [diff] [blame] | 9 | #include "SkMatrix22.h" |
bungeman@google.com | d3fbd34 | 2014-04-15 15:52:07 +0000 | [diff] [blame] | 10 | #include "SkPoint.h" |
| 11 | #include "SkScalar.h" |
| 12 | |
| 13 | void 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 | } |