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

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

Issue 11316043: Implement unit tests and temporary MathUtil wrappers for transform functionality (Closed) Base URL: http://git.chromium.org/chromium/src.git@master
Patch Set: Created 8 years, 1 month 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 98 matching lines...) Expand 10 before | Expand all | Expand 10 after
109 109
110 void Transform::SetSkewX(double angle) { 110 void Transform::SetSkewX(double angle) {
111 MSET(matrix_, 0, 1, TanDegrees(angle)); 111 MSET(matrix_, 0, 1, TanDegrees(angle));
112 } 112 }
113 113
114 void Transform::SetSkewY(double angle) { 114 void Transform::SetSkewY(double angle) {
115 MSET(matrix_, 1, 0, TanDegrees(angle)); 115 MSET(matrix_, 1, 0, TanDegrees(angle));
116 } 116 }
117 117
118 void Transform::SetPerspectiveDepth(double depth) { 118 void Transform::SetPerspectiveDepth(double depth) {
119 if (depth == 0)
120 return;
Ian Vollick 2012/11/16 13:44:46 Good catch. Thank you!
121
119 SkMatrix44 m; 122 SkMatrix44 m;
120 MSET(m, 3, 2, -1.0 / depth); 123 MSET(m, 3, 2, -1.0 / depth);
121 matrix_ = m; 124 matrix_ = m;
122 } 125 }
123 126
124 void Transform::ConcatRotate(double degree) { 127 void Transform::ConcatRotate(double degree) {
125 SkMatrix44 rot; 128 SkMatrix44 rot;
126 rot.setRotateDegreesAbout(SkDoubleToMScalar(0), 129 rot.setRotateDegreesAbout(SkDoubleToMScalar(0),
127 SkDoubleToMScalar(0), 130 SkDoubleToMScalar(0),
128 SkDoubleToMScalar(1), 131 SkDoubleToMScalar(1),
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after
177 matrix_.postConcat(t.matrix_); 180 matrix_.postConcat(t.matrix_);
178 } 181 }
179 182
180 void Transform::ConcatSkewY(double angle_y) { 183 void Transform::ConcatSkewY(double angle_y) {
181 Transform t; 184 Transform t;
182 t.SetSkewY(angle_y); 185 t.SetSkewY(angle_y);
183 matrix_.postConcat(t.matrix_); 186 matrix_.postConcat(t.matrix_);
184 } 187 }
185 188
186 void Transform::ConcatPerspectiveDepth(double depth) { 189 void Transform::ConcatPerspectiveDepth(double depth) {
190 if (depth == 0)
191 return;
192
187 SkMatrix44 m; 193 SkMatrix44 m;
188 MSET(m, 3, 2, -1.0 / depth); 194 MSET(m, 3, 2, -1.0 / depth);
189 matrix_.postConcat(m); 195 matrix_.postConcat(m);
190 } 196 }
191 197
192 void Transform::PreconcatRotate(double degree) { 198 void Transform::PreconcatRotate(double degree) {
193 SkMatrix44 rot; 199 SkMatrix44 rot;
194 rot.setRotateDegreesAbout(SkDoubleToMScalar(0), 200 rot.setRotateDegreesAbout(SkDoubleToMScalar(0),
195 SkDoubleToMScalar(0), 201 SkDoubleToMScalar(0),
196 SkDoubleToMScalar(1), 202 SkDoubleToMScalar(1),
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after
245 matrix_.preConcat(t.matrix_); 251 matrix_.preConcat(t.matrix_);
246 } 252 }
247 253
248 void Transform::PreconcatSkewY(double angle_y) { 254 void Transform::PreconcatSkewY(double angle_y) {
249 Transform t; 255 Transform t;
250 t.SetSkewY(angle_y); 256 t.SetSkewY(angle_y);
251 matrix_.preConcat(t.matrix_); 257 matrix_.preConcat(t.matrix_);
252 } 258 }
253 259
254 void Transform::PreconcatPerspectiveDepth(double depth) { 260 void Transform::PreconcatPerspectiveDepth(double depth) {
261 if (depth == 0)
262 return;
263
255 SkMatrix44 m; 264 SkMatrix44 m;
256 MSET(m, 3, 2, -1.0 / depth); 265 MSET(m, 3, 2, -1.0 / depth);
257 matrix_.preConcat(m); 266 matrix_.preConcat(m);
258 } 267 }
259 268
260 void Transform::PreconcatTransform(const Transform& transform) { 269 void Transform::PreconcatTransform(const Transform& transform) {
261 if (!transform.matrix_.isIdentity()) { 270 if (!transform.matrix_.isIdentity()) {
262 matrix_.preConcat(transform.matrix_); 271 matrix_.preConcat(transform.matrix_);
263 } 272 }
264 } 273 }
(...skipping 106 matching lines...) Expand 10 before | Expand all | Expand 10 after
371 SkDoubleToMScalar(0), 380 SkDoubleToMScalar(0),
372 SkDoubleToMScalar(1) 381 SkDoubleToMScalar(1)
373 }; 382 };
374 383
375 xform.mapMScalars(p); 384 xform.mapMScalars(p);
376 385
377 point.SetPoint(ToRoundedInt(p[0]), ToRoundedInt(p[1])); 386 point.SetPoint(ToRoundedInt(p[0]), ToRoundedInt(p[1]));
378 } 387 }
379 388
380 } // namespace gfx 389 } // namespace gfx
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698