From dc7b5eb89da31cddc2abc91aa5b30bcc6d66e70c Mon Sep 17 00:00:00 2001 From: Gary Qian Date: Thu, 30 Aug 2018 11:18:01 -0700 Subject: [PATCH] Use Skia normalize again after Skia precision fix. (#6121) * Fix tilt by using custom normalize impl to avoid strange skia normalize behavior * Use Skia normalize again after Skia fix. --- flow/matrix_decomposition.cc | 14 +++----------- flow/matrix_decomposition_unittests.cc | 3 ++- 2 files changed, 5 insertions(+), 12 deletions(-) diff --git a/flow/matrix_decomposition.cc b/flow/matrix_decomposition.cc index e1ac11a92..73a774b4d 100644 --- a/flow/matrix_decomposition.cc +++ b/flow/matrix_decomposition.cc @@ -28,14 +28,6 @@ static inline SkVector3 SkVector3Cross(const SkVector3& a, const SkVector3& b) { MatrixDecomposition::MatrixDecomposition(const SkMatrix& matrix) : MatrixDecomposition(SkMatrix44{matrix}) {} -// TODO(garyq): use skia row[x].normalize() when skia fixes it -static inline void SkVector3Normalize(SkVector3& v) { - float mag = sqrt(v.fX * v.fX + v.fY * v.fY + v.fZ * v.fZ); - v.fX /= mag; - v.fY /= mag; - v.fZ /= mag; -} - MatrixDecomposition::MatrixDecomposition(SkMatrix44 matrix) : valid_(false) { if (matrix.get(3, 3) == 0) { return; @@ -91,14 +83,14 @@ MatrixDecomposition::MatrixDecomposition(SkMatrix44 matrix) : valid_(false) { scale_.fX = row[0].length(); - SkVector3Normalize(row[0]); + row[0].normalize(); shear_.fX = row[0].dot(row[1]); row[1] = SkVector3Combine(row[1], 1.0, row[0], -shear_.fX); scale_.fY = row[1].length(); - SkVector3Normalize(row[1]); + row[1].normalize(); shear_.fX /= scale_.fY; @@ -109,7 +101,7 @@ MatrixDecomposition::MatrixDecomposition(SkMatrix44 matrix) : valid_(false) { scale_.fZ = row[2].length(); - SkVector3Normalize(row[2]); + row[2].normalize(); shear_.fY /= scale_.fZ; shear_.fZ /= scale_.fZ; diff --git a/flow/matrix_decomposition_unittests.cc b/flow/matrix_decomposition_unittests.cc index 3b9f8ed81..3c1b7d6c9 100644 --- a/flow/matrix_decomposition_unittests.cc +++ b/flow/matrix_decomposition_unittests.cc @@ -95,7 +95,8 @@ TEST(MatrixDecomposition, Combination) { } TEST(MatrixDecomposition, ScaleFloatError) { - for (float scale = 0.0001f; scale < 2.0f; scale += 0.000001f) { + // Strange behavior under 0.000245 due to underflow issues. + for (float scale = 0.000245f; scale < 2.0f; scale += 0.000001f) { SkMatrix44 matrix = SkMatrix44::I(); matrix.setScale(scale, scale, 1.0f); -- GitLab