blob: a13b72939f8e2ea051c2bb617b6dd6e268b09d79 [file] [log] [blame]
bungeman@google.comd3fbd342014-04-15 15:52:07 +00001/*
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.org2cfa3202014-04-19 22:00:40 +00009#include "SkMatrix22.h"
bungeman@google.comd3fbd342014-04-15 15:52:07 +000010#include "SkPoint.h"
11#include "SkScalar.h"
12
13void 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}