Skip to content
This repository was archived by the owner on Feb 25, 2025. It is now read-only.
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
Original file line number Diff line number Diff line change
Expand Up @@ -239,7 +239,7 @@ DownsamplePassArgs CalculateDownsamplePassArgs(
// .Contains(coverage_hint.value()))

std::optional<Rect> snapshot_coverage = input_snapshot.GetCoverage();
if (input_snapshot.transform.IsIdentity() &&
if (input_snapshot.transform.Equals(snapshot_entity.GetTransform()) &&
source_expanded_coverage_hint.has_value() &&
snapshot_coverage.has_value() &&
snapshot_coverage->Contains(source_expanded_coverage_hint.value())) {
Expand Down
21 changes: 21 additions & 0 deletions impeller/geometry/matrix.h
Original file line number Diff line number Diff line change
Expand Up @@ -407,6 +407,27 @@ struct Matrix {

std::optional<MatrixDecomposition> Decompose() const;

bool Equals(const Matrix& matrix, Scalar epsilon = 1e-5f) const {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We have an existing scalar nearly equal method you could use instead?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done, I also expanded ScalarNearlyEquals to use fabsf since it will be faster

const Scalar* a = m;
const Scalar* b = matrix.m;
return ScalarNearlyEqual(a[0], b[0], epsilon) &&
ScalarNearlyEqual(a[1], b[1], epsilon) &&
ScalarNearlyEqual(a[2], b[2], epsilon) &&
ScalarNearlyEqual(a[3], b[3], epsilon) &&
ScalarNearlyEqual(a[4], b[4], epsilon) &&
ScalarNearlyEqual(a[5], b[5], epsilon) &&
ScalarNearlyEqual(a[6], b[6], epsilon) &&
ScalarNearlyEqual(a[7], b[7], epsilon) &&
ScalarNearlyEqual(a[8], b[8], epsilon) &&
ScalarNearlyEqual(a[9], b[9], epsilon) &&
ScalarNearlyEqual(a[10], b[10], epsilon) &&
ScalarNearlyEqual(a[11], b[11], epsilon) &&
ScalarNearlyEqual(a[12], b[12], epsilon) &&
ScalarNearlyEqual(a[13], b[13], epsilon) &&
ScalarNearlyEqual(a[14], b[14], epsilon) &&
ScalarNearlyEqual(a[15], b[15], epsilon);
}

constexpr bool operator==(const Matrix& m) const {
// clang-format off
return vec[0] == m.vec[0]
Expand Down
12 changes: 12 additions & 0 deletions impeller/geometry/matrix_unittests.cc
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,18 @@ TEST(MatrixTest, Multiply) {
11.0, 21.0, 0.0, 1.0)));
}

TEST(MatrixTest, Equals) {
Matrix x;
Matrix y = x;
EXPECT_TRUE(x.Equals(y));
}

TEST(MatrixTest, NotEquals) {
Matrix x;
Matrix y = x.Translate({1, 0, 0});
EXPECT_FALSE(x.Equals(y));
}

TEST(MatrixTest, HasPerspective2D) {
EXPECT_FALSE(Matrix().HasPerspective2D());

Expand Down
5 changes: 5 additions & 0 deletions impeller/geometry/scalar.h
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,11 @@ constexpr T Absolute(const T& val) {
return val >= T{} ? val : -val;
}

template <>
constexpr Scalar Absolute<Scalar>(const float& val) {
return fabsf(val);
}

constexpr inline bool ScalarNearlyZero(Scalar x,
Scalar tolerance = kEhCloseEnough) {
return Absolute(x) <= tolerance;
Expand Down