Skip to content

Commit dc7b5eb

Browse files
authored
Use Skia normalize again after Skia precision fix. (flutter#6121)
* Fix tilt by using custom normalize impl to avoid strange skia normalize behavior * Use Skia normalize again after Skia fix.
1 parent 1c76824 commit dc7b5eb

File tree

2 files changed

+5
-12
lines changed

2 files changed

+5
-12
lines changed

flow/matrix_decomposition.cc

Lines changed: 3 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -28,14 +28,6 @@ static inline SkVector3 SkVector3Cross(const SkVector3& a, const SkVector3& b) {
2828
MatrixDecomposition::MatrixDecomposition(const SkMatrix& matrix)
2929
: MatrixDecomposition(SkMatrix44{matrix}) {}
3030

31-
// TODO(garyq): use skia row[x].normalize() when skia fixes it
32-
static inline void SkVector3Normalize(SkVector3& v) {
33-
float mag = sqrt(v.fX * v.fX + v.fY * v.fY + v.fZ * v.fZ);
34-
v.fX /= mag;
35-
v.fY /= mag;
36-
v.fZ /= mag;
37-
}
38-
3931
MatrixDecomposition::MatrixDecomposition(SkMatrix44 matrix) : valid_(false) {
4032
if (matrix.get(3, 3) == 0) {
4133
return;
@@ -91,14 +83,14 @@ MatrixDecomposition::MatrixDecomposition(SkMatrix44 matrix) : valid_(false) {
9183

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

94-
SkVector3Normalize(row[0]);
86+
row[0].normalize();
9587

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

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

101-
SkVector3Normalize(row[1]);
93+
row[1].normalize();
10294

10395
shear_.fX /= scale_.fY;
10496

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

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

112-
SkVector3Normalize(row[2]);
104+
row[2].normalize();
113105

114106
shear_.fY /= scale_.fZ;
115107
shear_.fZ /= scale_.fZ;

flow/matrix_decomposition_unittests.cc

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,8 @@ TEST(MatrixDecomposition, Combination) {
9595
}
9696

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

0 commit comments

Comments
 (0)