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

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: Move code to gfx::Transform class. 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
Index: ui/gfx/transform.cc
diff --git a/ui/gfx/transform.cc b/ui/gfx/transform.cc
index 59e6a607a8de11558cbec9ac06fd6f1b47c067ab..22818f4e61df2b8acd4fb4c6a1febc165b082f4b 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) &&
danakj 2013/10/17 17:43:18 no extra white space to line things up vertically.
+ 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') | ui/gfx/transform_unittest.cc » ('J')

Powered by Google App Engine
This is Rietveld 408576698