Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1995)

Unified Diff: ui/gfx/transform.cc

Issue 27223008: Provide approximate type functions for SkMatrix44. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Pass constants as float not double in unit test. Created 7 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « ui/gfx/transform.h ('k') | ui/gfx/transform_unittest.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: ui/gfx/transform.cc
diff --git a/ui/gfx/transform.cc b/ui/gfx/transform.cc
index 057c93c60b8cd2746ed7b75ab1c3d18200856c31..e129af520640f35bef1fc47718f01f4351e67e40 100644
--- a/ui/gfx/transform.cc
+++ b/ui/gfx/transform.cc
@@ -32,6 +32,14 @@ SkMScalar TanDegrees(double degrees) {
return SkDoubleToMScalar(std::tan(radians));
}
+inline bool ApproximatelyZero(SkMScalar x, SkMScalar tolerance) {
+ return std::abs(x) <= tolerance;
+}
+
+inline bool ApproximatelyOne(SkMScalar x, SkMScalar tolerance) {
+ return std::abs(x - SkDoubleToMScalar(1.0)) <= tolerance;
+}
+
} // namespace
Transform::Transform(SkMScalar col1row1,
@@ -210,6 +218,25 @@ void Transform::ConcatTransform(const Transform& transform) {
matrix_.postConcat(transform.matrix_);
}
+bool Transform::IsApproximatelyIdentityOrTranslation(
+ SkMScalar tolerance) const {
+ DCHECK_GE(tolerance, 0);
+ return
+ ApproximatelyOne(matrix_.get(0, 0), tolerance) &&
+ ApproximatelyZero(matrix_.get(1, 0), tolerance) &&
+ ApproximatelyZero(matrix_.get(2, 0), tolerance) &&
+ matrix_.get(3, 0) == 0 &&
+ ApproximatelyZero(matrix_.get(0, 1), tolerance) &&
+ ApproximatelyOne(matrix_.get(1, 1), tolerance) &&
+ ApproximatelyZero(matrix_.get(2, 1), tolerance) &&
+ matrix_.get(3, 1) == 0 &&
+ ApproximatelyZero(matrix_.get(0, 2), tolerance) &&
+ ApproximatelyZero(matrix_.get(1, 2), tolerance) &&
+ ApproximatelyOne(matrix_.get(2, 2), tolerance) &&
+ matrix_.get(3, 2) == 0 &&
+ matrix_.get(3, 3) == 1;
+}
+
bool Transform::IsIdentityOrIntegerTranslation() const {
if (!IsIdentityOrTranslation())
return false;
« no previous file with comments | « ui/gfx/transform.h ('k') | ui/gfx/transform_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698