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

Side by Side 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 unified diff | Download patch
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 // MSVC++ requires this to be set before any other includes to get M_PI. 5 // MSVC++ requires this to be set before any other includes to get M_PI.
6 #define _USE_MATH_DEFINES 6 #define _USE_MATH_DEFINES
7 7
8 #include "ui/gfx/transform.h" 8 #include "ui/gfx/transform.h"
9 9
10 #include <cmath> 10 #include <cmath>
(...skipping 14 matching lines...) Expand all
25 namespace { 25 namespace {
26 26
27 // Taken from SkMatrix44. 27 // Taken from SkMatrix44.
28 const SkMScalar kEpsilon = 1e-8f; 28 const SkMScalar kEpsilon = 1e-8f;
29 29
30 SkMScalar TanDegrees(double degrees) { 30 SkMScalar TanDegrees(double degrees) {
31 double radians = degrees * M_PI / 180; 31 double radians = degrees * M_PI / 180;
32 return SkDoubleToMScalar(std::tan(radians)); 32 return SkDoubleToMScalar(std::tan(radians));
33 } 33 }
34 34
35 inline bool ApproximatelyZero(SkMScalar x, SkMScalar tolerance) {
36 return std::abs(x) <= tolerance;
37 }
38
39 inline bool ApproximatelyOne(SkMScalar x, SkMScalar tolerance) {
40 return std::abs(x - SkDoubleToMScalar(1.0)) <= tolerance;
41 }
42
35 } // namespace 43 } // namespace
36 44
37 Transform::Transform(SkMScalar col1row1, 45 Transform::Transform(SkMScalar col1row1,
38 SkMScalar col2row1, 46 SkMScalar col2row1,
39 SkMScalar col3row1, 47 SkMScalar col3row1,
40 SkMScalar col4row1, 48 SkMScalar col4row1,
41 SkMScalar col1row2, 49 SkMScalar col1row2,
42 SkMScalar col2row2, 50 SkMScalar col2row2,
43 SkMScalar col3row2, 51 SkMScalar col3row2,
44 SkMScalar col4row2, 52 SkMScalar col4row2,
(...skipping 158 matching lines...) Expand 10 before | Expand all | Expand 10 after
203 } 211 }
204 212
205 void Transform::PreconcatTransform(const Transform& transform) { 213 void Transform::PreconcatTransform(const Transform& transform) {
206 matrix_.preConcat(transform.matrix_); 214 matrix_.preConcat(transform.matrix_);
207 } 215 }
208 216
209 void Transform::ConcatTransform(const Transform& transform) { 217 void Transform::ConcatTransform(const Transform& transform) {
210 matrix_.postConcat(transform.matrix_); 218 matrix_.postConcat(transform.matrix_);
211 } 219 }
212 220
221 bool Transform::IsApproximatelyIdentityOrTranslation(
222 SkMScalar tolerance) const {
223 DCHECK_GE(tolerance, 0);
224 return
225 ApproximatelyOne (matrix_.get(0, 0), tolerance) &&
danakj 2013/10/17 17:43:18 no extra white space to line things up vertically.
226 ApproximatelyZero(matrix_.get(1, 0), tolerance) &&
227 ApproximatelyZero(matrix_.get(2, 0), tolerance) &&
228 matrix_.get(3, 0) == 0 &&
229 ApproximatelyZero(matrix_.get(0, 1), tolerance) &&
230 ApproximatelyOne (matrix_.get(1, 1), tolerance) &&
231 ApproximatelyZero(matrix_.get(2, 1), tolerance) &&
232 matrix_.get(3, 1) == 0 &&
233 ApproximatelyZero(matrix_.get(0, 2), tolerance) &&
234 ApproximatelyZero(matrix_.get(1, 2), tolerance) &&
235 ApproximatelyOne (matrix_.get(2, 2), tolerance) &&
236 matrix_.get(3, 2) == 0 &&
237 matrix_.get(3, 3) == 1;
238 }
239
213 bool Transform::IsIdentityOrIntegerTranslation() const { 240 bool Transform::IsIdentityOrIntegerTranslation() const {
214 if (!IsIdentityOrTranslation()) 241 if (!IsIdentityOrTranslation())
215 return false; 242 return false;
216 243
217 bool no_fractional_translation = 244 bool no_fractional_translation =
218 static_cast<int>(matrix_.get(0, 3)) == matrix_.get(0, 3) && 245 static_cast<int>(matrix_.get(0, 3)) == matrix_.get(0, 3) &&
219 static_cast<int>(matrix_.get(1, 3)) == matrix_.get(1, 3) && 246 static_cast<int>(matrix_.get(1, 3)) == matrix_.get(1, 3) &&
220 static_cast<int>(matrix_.get(2, 3)) == matrix_.get(2, 3); 247 static_cast<int>(matrix_.get(2, 3)) == matrix_.get(2, 3);
221 248
222 return no_fractional_translation; 249 return no_fractional_translation;
(...skipping 295 matching lines...) Expand 10 before | Expand all | Expand 10 after
518 matrix_.get(2, 1), 545 matrix_.get(2, 1),
519 matrix_.get(2, 2), 546 matrix_.get(2, 2),
520 matrix_.get(2, 3), 547 matrix_.get(2, 3),
521 matrix_.get(3, 0), 548 matrix_.get(3, 0),
522 matrix_.get(3, 1), 549 matrix_.get(3, 1),
523 matrix_.get(3, 2), 550 matrix_.get(3, 2),
524 matrix_.get(3, 3)); 551 matrix_.get(3, 3));
525 } 552 }
526 553
527 } // namespace gfx 554 } // namespace gfx
OLDNEW
« 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