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

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

Issue 7066010: Fixes rounding bug in transform. This is needed to avoid rounding (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 9 years, 7 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 | Annotate | Revision Log
« no previous file with comments | « no previous file | views/view_unittest.cc » ('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) 2011 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2011 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 #include "ui/gfx/transform.h" 5 #include "ui/gfx/transform.h"
6 6
7 #include <cmath>
8
7 #include "ui/gfx/point.h" 9 #include "ui/gfx/point.h"
8 #include "ui/gfx/rect.h" 10 #include "ui/gfx/rect.h"
9 #include "ui/gfx/skia_util.h" 11 #include "ui/gfx/skia_util.h"
10 12
11 namespace ui { 13 namespace ui {
12 14
13 Transform::Transform() { 15 Transform::Transform() {
14 matrix_.reset(); 16 matrix_.reset();
15 } 17 }
16 18
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after
64 return matrix_.setConcat(transform.matrix_, matrix_); 66 return matrix_.setConcat(transform.matrix_, matrix_);
65 } 67 }
66 68
67 bool Transform::HasChange() const { 69 bool Transform::HasChange() const {
68 return !matrix_.isIdentity(); 70 return !matrix_.isIdentity();
69 } 71 }
70 72
71 bool Transform::TransformPoint(gfx::Point* point) { 73 bool Transform::TransformPoint(gfx::Point* point) {
72 SkPoint skp; 74 SkPoint skp;
73 matrix_.mapXY(SkIntToScalar(point->x()), SkIntToScalar(point->y()), &skp); 75 matrix_.mapXY(SkIntToScalar(point->x()), SkIntToScalar(point->y()), &skp);
74 point->SetPoint(static_cast<int>(skp.fX), static_cast<int>(skp.fY)); 76 point->SetPoint(static_cast<int>(std::floor(skp.fX)),
77 static_cast<int>(std::floor(skp.fY)));
wjmaclean 2011/05/24 12:11:40 Just curious ... for positive values, wouldn't thi
sky 2011/05/24 15:51:49 I'm sure we'll have rounding problems until we use
75 return true; 78 return true;
76 } 79 }
77 80
78 bool Transform::TransformPointReverse(gfx::Point* point) { 81 bool Transform::TransformPointReverse(gfx::Point* point) {
79 SkMatrix inverse; 82 SkMatrix inverse;
80 // TODO(sad): Try to avoid trying to invert the matrix. 83 // TODO(sad): Try to avoid trying to invert the matrix.
81 if (matrix_.invert(&inverse)) { 84 if (matrix_.invert(&inverse)) {
82 SkPoint skp; 85 SkPoint skp;
83 inverse.mapXY(SkIntToScalar(point->x()), SkIntToScalar(point->y()), &skp); 86 inverse.mapXY(SkIntToScalar(point->x()), SkIntToScalar(point->y()), &skp);
84 point->SetPoint(static_cast<int>(skp.fX), static_cast<int>(skp.fY)); 87 point->SetPoint(static_cast<int>(std::floor(skp.fX)),
88 static_cast<int>(std::floor(skp.fY)));
85 return true; 89 return true;
86 } 90 }
87 return false; 91 return false;
88 } 92 }
89 93
90 bool Transform::TransformRect(gfx::Rect* rect) { 94 bool Transform::TransformRect(gfx::Rect* rect) {
91 SkRect src = gfx::RectToSkRect(*rect); 95 SkRect src = gfx::RectToSkRect(*rect);
92 if (!matrix_.mapRect(&src)) 96 if (!matrix_.mapRect(&src))
93 return false; 97 return false;
94 gfx::Rect xrect = gfx::SkRectToRect(src); 98 gfx::Rect xrect = gfx::SkRectToRect(src);
95 rect->SetRect(xrect.x(), xrect.y(), xrect.width(), xrect.height()); 99 rect->SetRect(xrect.x(), xrect.y(), xrect.width(), xrect.height());
96 return true; 100 return true;
97 } 101 }
98 102
99 } // namespace ui 103 } // namespace ui
OLDNEW
« no previous file with comments | « no previous file | views/view_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698