Skip to content
This repository was archived by the owner on Feb 25, 2025. It is now read-only.

Commit 390cb99

Browse files
[Impeller] account for negative scale in max basis xy. (#54630)
Otherwise we get funky negative scales that break tessellation.
1 parent 93e5c81 commit 390cb99

File tree

2 files changed

+11
-1
lines changed

2 files changed

+11
-1
lines changed

impeller/geometry/matrix.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -303,7 +303,7 @@ struct Matrix {
303303
// precision for small and large scales. Instead, check for the common cases
304304
// and directly return the max scaling factor.
305305
if (e[0][1] == 0 && e[1][0] == 0) {
306-
return std::max(e[0][0], e[1][1]);
306+
return std::max(std::abs(e[0][0]), std::abs(e[1][1]));
307307
}
308308
return std::sqrt(std::max(e[0][0] * e[0][0] + e[0][1] * e[0][1],
309309
e[1][0] * e[1][0] + e[1][1] * e[1][1]));

impeller/geometry/matrix_unittests.cc

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -161,6 +161,16 @@ TEST(MatrixTest, TransformHomogenous) {
161161
Vector3(32.0f, 33.0f, 41.0f));
162162
}
163163

164+
TEST(MatrixTest, GetMaxBasisXYNegativeScale) {
165+
Matrix m = Matrix::MakeScale({-2, 1, 1});
166+
167+
EXPECT_EQ(m.GetMaxBasisLengthXY(), 2);
168+
169+
m = Matrix::MakeScale({1, -3, 1});
170+
171+
EXPECT_EQ(m.GetMaxBasisLengthXY(), 3);
172+
}
173+
164174
// Verifies a translate scale matrix doesn't need to compute sqrt(pow(scale, 2))
165175
TEST(MatrixTest, GetMaxBasisXYWithLargeAndSmallScalingFactor) {
166176
Matrix m = Matrix::MakeScale({2.625e+20, 2.625e+20, 1});

0 commit comments

Comments
 (0)