Skip to content

Commit

Permalink
Revert "Use Skia normalize again after Skia precision fix. (flutter#6121
Browse files Browse the repository at this point in the history
)" (flutter#6122)

This reverts commit dc7b5eb.
  • Loading branch information
GaryQian authored Sep 4, 2018
1 parent 137389a commit 593ed59
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 5 deletions.
14 changes: 11 additions & 3 deletions flow/matrix_decomposition.cc
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,14 @@ 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;
Expand Down Expand Up @@ -83,14 +91,14 @@ MatrixDecomposition::MatrixDecomposition(SkMatrix44 matrix) : valid_(false) {

scale_.fX = row[0].length();

row[0].normalize();
SkVector3Normalize(row[0]);

shear_.fX = row[0].dot(row[1]);
row[1] = SkVector3Combine(row[1], 1.0, row[0], -shear_.fX);

scale_.fY = row[1].length();

row[1].normalize();
SkVector3Normalize(row[1]);

shear_.fX /= scale_.fY;

Expand All @@ -101,7 +109,7 @@ MatrixDecomposition::MatrixDecomposition(SkMatrix44 matrix) : valid_(false) {

scale_.fZ = row[2].length();

row[2].normalize();
SkVector3Normalize(row[2]);

shear_.fY /= scale_.fZ;
shear_.fZ /= scale_.fZ;
Expand Down
3 changes: 1 addition & 2 deletions flow/matrix_decomposition_unittests.cc
Original file line number Diff line number Diff line change
Expand Up @@ -95,8 +95,7 @@ TEST(MatrixDecomposition, Combination) {
}

TEST(MatrixDecomposition, ScaleFloatError) {
// Strange behavior under 0.000245 due to underflow issues.
for (float scale = 0.000245f; scale < 2.0f; scale += 0.000001f) {
for (float scale = 0.0001f; scale < 2.0f; scale += 0.000001f) {
SkMatrix44 matrix = SkMatrix44::I();
matrix.setScale(scale, scale, 1.0f);

Expand Down

0 comments on commit 593ed59

Please sign in to comment.