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

Side by Side Diff: ui/gfx/transform.cc

Issue 935333002: Update from https://crrev.com/316786 (Closed) Base URL: git@github.com:domokit/mojo.git@master
Patch Set: Created 5 years, 10 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
« no previous file with comments | « ui/gfx/transform.h ('k') | ui/gfx/transform_util.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 22 matching lines...) Expand all
33 } 33 }
34 34
35 inline bool ApproximatelyZero(SkMScalar x, SkMScalar tolerance) { 35 inline bool ApproximatelyZero(SkMScalar x, SkMScalar tolerance) {
36 return std::abs(x) <= tolerance; 36 return std::abs(x) <= tolerance;
37 } 37 }
38 38
39 inline bool ApproximatelyOne(SkMScalar x, SkMScalar tolerance) { 39 inline bool ApproximatelyOne(SkMScalar x, SkMScalar tolerance) {
40 return std::abs(x - SkDoubleToMScalar(1.0)) <= tolerance; 40 return std::abs(x - SkDoubleToMScalar(1.0)) <= tolerance;
41 } 41 }
42 42
43 static float Round(float f) {
44 if (f == 0.f)
45 return f;
46 return (f > 0.f) ? std::floor(f + 0.5f) : std::ceil(f - 0.5f);
47 }
48
43 } // namespace 49 } // namespace
44 50
45 Transform::Transform(SkMScalar col1row1, 51 Transform::Transform(SkMScalar col1row1,
46 SkMScalar col2row1, 52 SkMScalar col2row1,
47 SkMScalar col3row1, 53 SkMScalar col3row1,
48 SkMScalar col4row1, 54 SkMScalar col4row1,
49 SkMScalar col1row2, 55 SkMScalar col1row2,
50 SkMScalar col2row2, 56 SkMScalar col2row2,
51 SkMScalar col3row2, 57 SkMScalar col3row2,
52 SkMScalar col4row2, 58 SkMScalar col4row2,
(...skipping 433 matching lines...) Expand 10 before | Expand all | Expand 10 after
486 !DecomposeTransform(&from_decomp, from)) 492 !DecomposeTransform(&from_decomp, from))
487 return false; 493 return false;
488 494
489 if (!BlendDecomposedTransforms(&to_decomp, to_decomp, from_decomp, progress)) 495 if (!BlendDecomposedTransforms(&to_decomp, to_decomp, from_decomp, progress))
490 return false; 496 return false;
491 497
492 matrix_ = ComposeTransform(to_decomp).matrix(); 498 matrix_ = ComposeTransform(to_decomp).matrix();
493 return true; 499 return true;
494 } 500 }
495 501
502 void Transform::RoundTranslationComponents() {
503 matrix_.set(0, 3, Round(matrix_.get(0, 3)));
504 matrix_.set(1, 3, Round(matrix_.get(1, 3)));
505 }
506
507
496 void Transform::TransformPointInternal(const SkMatrix44& xform, 508 void Transform::TransformPointInternal(const SkMatrix44& xform,
497 Point3F* point) const { 509 Point3F* point) const {
498 if (xform.isIdentity()) 510 if (xform.isIdentity())
499 return; 511 return;
500 512
501 SkMScalar p[4] = {SkFloatToMScalar(point->x()), SkFloatToMScalar(point->y()), 513 SkMScalar p[4] = {SkFloatToMScalar(point->x()), SkFloatToMScalar(point->y()),
502 SkFloatToMScalar(point->z()), 1}; 514 SkFloatToMScalar(point->z()), 1};
503 515
504 xform.mapMScalars(p); 516 xform.mapMScalars(p);
505 517
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after
542 matrix_.get(2, 1), 554 matrix_.get(2, 1),
543 matrix_.get(2, 2), 555 matrix_.get(2, 2),
544 matrix_.get(2, 3), 556 matrix_.get(2, 3),
545 matrix_.get(3, 0), 557 matrix_.get(3, 0),
546 matrix_.get(3, 1), 558 matrix_.get(3, 1),
547 matrix_.get(3, 2), 559 matrix_.get(3, 2),
548 matrix_.get(3, 3)); 560 matrix_.get(3, 3));
549 } 561 }
550 562
551 } // namespace gfx 563 } // namespace gfx
OLDNEW
« no previous file with comments | « ui/gfx/transform.h ('k') | ui/gfx/transform_util.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698