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

Unified Diff: ui/gfx/transform.cc

Issue 12541006: Use LCD text if the transform IsAlmostIdentityAndIntegerTranslation (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Transform::IsAlmostXXX methods Created 7 years, 9 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
« cc/layer_tree_host_common.cc ('K') | « ui/gfx/transform.h ('k') | no next file » | 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 5e8799841fc4508782958a3aa716e3c5fe30630e..469abc49c409b2e40538b17db15d07b836e78b55 100644
--- a/ui/gfx/transform.cc
+++ b/ui/gfx/transform.cc
@@ -30,6 +30,15 @@ double TanDegrees(double degrees) {
return std::tan(radians);
}
+bool AlmostEqual(double d, double i) {
+ const double kErrorThreshold = 1e-6;
alokp 2013/03/08 19:40:06 The error threshold should really depend on the tr
Xianzhu 2013/03/08 23:36:56 My another thought is not to add these methods but
+ return std::abs(d - i) < kErrorThreshold;
+}
+
+double Round(double d) {
+ return (d > 0.0) ? std::floor(d + 0.5) : std::ceil(d - 0.5);
+}
+
} // namespace
Transform::Transform(
@@ -215,6 +224,28 @@ bool Transform::IsIdentityOrIntegerTranslation() const {
return no_fractional_translation;
}
+
+bool Transform::IsAlmostIdentity() const {
+ return IsAlmostIdentityOrTranslation() &&
+ AlmostEqual(matrix_.getDouble(0, 3), 0) &&
+ AlmostEqual(matrix_.getDouble(1, 3), 0) &&
+ AlmostEqual(matrix_.getDouble(2, 3), 0);
+}
+
+bool Transform::IsAlmostIdentityOrTranslation() const {
+ return IsScaleOrTranslation() &&
+ AlmostEqual(matrix_.getDouble(0, 0), 1) &&
+ AlmostEqual(matrix_.getDouble(1, 1), 1) &&
+ AlmostEqual(matrix_.getDouble(2, 2), 1);
+}
+
+bool Transform::IsAlmostIdentityOrIntegerTranslation() const {
+ return IsAlmostIdentityOrTranslation() &&
+ AlmostEqual(matrix_.getDouble(0, 3), Round(matrix_.getDouble(0, 3))) &&
+ AlmostEqual(matrix_.getDouble(1, 3), Round(matrix_.getDouble(1, 3))) &&
+ AlmostEqual(matrix_.getDouble(2, 3), Round(matrix_.getDouble(2, 3)));
+}
+
bool Transform::IsBackFaceVisible() const {
// Compute whether a layer with a forward-facing normal of (0, 0, 1, 0)
// would have its back face visible after applying the transform.
« cc/layer_tree_host_common.cc ('K') | « ui/gfx/transform.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698