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