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