Commit b0708fda authored by Xianzhu Wang's avatar Xianzhu Wang Committed by Commit Bot

[PE] Relax TransformationMatrix::IsInvertible

Previously it treated transforms with abs(determinant) less than 1e-8 as
non-invertible. This was too strict that transforms like Scale(9.9e-5)
were treated as non-invertible.

Now just check if determinant is zero, which is consistent with
AffineTransform and SkMatrix[44].

The code was added here:
https://chromium.googlesource.com/chromium/src/+/041f0d1e8d01d8dc0cd2f4fe2579e1f09a9ae27a
in an initial commit of 3D transforms.

Bug: 849382
Change-Id: I01e395f373493f61fcf85851b694be9aed7b41c5
Reviewed-on: https://chromium-review.googlesource.com/1087362
Commit-Queue: Xianzhu Wang <wangxianzhu@chromium.org>
Reviewed-by: default avatarFredrik Söderquist <fs@opera.com>
Reviewed-by: default avatarChris Harrelson <chrishtr@chromium.org>
Cr-Commit-Position: refs/heads/master@{#564680}
parent 090c04d0
......@@ -78,8 +78,6 @@ namespace blink {
typedef double Vector4[4];
typedef double Vector3[3];
const double kSmallNumber = 1.e-8;
// inverse(original_matrix, inverse_matrix)
//
// calculate the inverse of a 4x4 matrix
......@@ -225,7 +223,7 @@ static bool Inverse(const TransformationMatrix::Matrix4& matrix,
// then the inverse matrix is not unique.
double det = Determinant4x4(matrix);
if (fabs(det) < kSmallNumber)
if (det == 0)
return false;
#if defined(ARCH_CPU_ARM64)
......@@ -1651,15 +1649,7 @@ void TransformationMatrix::MultVecMatrix(double x,
}
bool TransformationMatrix::IsInvertible() const {
if (IsIdentityOrTranslation())
return true;
double det = blink::Determinant4x4(matrix_);
if (fabs(det) < kSmallNumber)
return false;
return true;
return IsIdentityOrTranslation() || blink::Determinant4x4(matrix_) != 0;
}
TransformationMatrix TransformationMatrix::Inverse() const {
......
......@@ -285,4 +285,15 @@ TEST(TransformationMatrixTest, ToString) {
column_major_constructor.ToString(true));
}
TEST(TransformationMatrix, IsInvertible) {
EXPECT_FALSE(
TransformationMatrix(0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0)
.IsInvertible());
EXPECT_TRUE(TransformationMatrix().IsInvertible());
EXPECT_TRUE(TransformationMatrix().Translate3d(10, 20, 30).IsInvertible());
EXPECT_TRUE(TransformationMatrix().Scale(1e-8).IsInvertible());
EXPECT_TRUE(TransformationMatrix().Scale3d(1e-8, -1e-8, 1).IsInvertible());
EXPECT_FALSE(TransformationMatrix().Scale(0).IsInvertible());
}
} // namespace blink
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment