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

[Impeller] account for negative scale in max basis xy. #54630

Merged
merged 1 commit into from
Aug 19, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion impeller/geometry/matrix.h
Original file line number Diff line number Diff line change
Expand Up @@ -303,7 +303,7 @@ struct Matrix {
// precision for small and large scales. Instead, check for the common cases
// and directly return the max scaling factor.
if (e[0][1] == 0 && e[1][0] == 0) {
return std::max(e[0][0], e[1][1]);
return std::max(std::abs(e[0][0]), std::abs(e[1][1]));
}
return std::sqrt(std::max(e[0][0] * e[0][0] + e[0][1] * e[0][1],
e[1][0] * e[1][0] + e[1][1] * e[1][1]));
Expand Down
10 changes: 10 additions & 0 deletions impeller/geometry/matrix_unittests.cc
Original file line number Diff line number Diff line change
Expand Up @@ -161,6 +161,16 @@ TEST(MatrixTest, TransformHomogenous) {
Vector3(32.0f, 33.0f, 41.0f));
}

TEST(MatrixTest, GetMaxBasisXYNegativeScale) {
Matrix m = Matrix::MakeScale({-2, 1, 1});

EXPECT_EQ(m.GetMaxBasisLengthXY(), 2);

m = Matrix::MakeScale({1, -3, 1});

EXPECT_EQ(m.GetMaxBasisLengthXY(), 3);
}

// Verifies a translate scale matrix doesn't need to compute sqrt(pow(scale, 2))
TEST(MatrixTest, GetMaxBasisXYWithLargeAndSmallScalingFactor) {
Matrix m = Matrix::MakeScale({2.625e+20, 2.625e+20, 1});
Expand Down