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

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

Issue 1372253002: gfx: Make conversions from gfx::Point to PointF explicit. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: pointfconvert-gfx: . Created 5 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 #include "ui/gfx/transform_util.h" 5 #include "ui/gfx/transform_util.h"
6 6
7 #include <algorithm> 7 #include <algorithm>
8 #include <cmath> 8 #include <cmath>
9 #include <string> 9 #include <string>
10 10
(...skipping 213 matching lines...) Expand 10 before | Expand all | Expand 10 after
224 matrix.preConcat(translation); 224 matrix.preConcat(translation);
225 matrix.preConcat(rotation); 225 matrix.preConcat(rotation);
226 matrix.preConcat(skew); 226 matrix.preConcat(skew);
227 matrix.preConcat(scale); 227 matrix.preConcat(scale);
228 228
229 Transform to_return; 229 Transform to_return;
230 to_return.matrix() = matrix; 230 to_return.matrix() = matrix;
231 return to_return; 231 return to_return;
232 } 232 }
233 233
234 bool CheckViewportPointMapsWithinOnePixel(const Point& point, 234 bool CheckViewportPointMapsWithinOnePixel(const PointF& point,
235 const Transform& transform) { 235 const Transform& transform) {
236 Point3F point_original(point); 236 Point3F point_original(point);
237 Point3F point_transformed(point); 237 Point3F point_transformed(point);
238 238
239 // Can't use TransformRect here since it would give us the axis-aligned 239 // Can't use TransformRect here since it would give us the axis-aligned
240 // bounding rect of the 4 points in the initial rectable which is not what we 240 // bounding rect of the 4 points in the initial rectable which is not what we
241 // want. 241 // want.
242 transform.TransformPoint(&point_transformed); 242 transform.TransformPoint(&point_transformed);
243 243
244 if ((point_transformed - point_original).Length() > 1.f) { 244 if ((point_transformed - point_original).Length() > 1.f) {
245 // The changed distance should not be more than 1 pixel. 245 // The changed distance should not be more than 1 pixel.
246 return false; 246 return false;
247 } 247 }
248 return true; 248 return true;
249 } 249 }
250 250
251 bool CheckTransformsMapsIntViewportWithinOnePixel(const Rect& viewport, 251 bool CheckTransformsMapsIntViewportWithinOnePixel(const Rect& viewport,
252 const Transform& original, 252 const Transform& original,
253 const Transform& snapped) { 253 const Transform& snapped) {
254 254
255 Transform original_inv(Transform::kSkipInitialization); 255 Transform original_inv(Transform::kSkipInitialization);
256 bool invertible = true; 256 bool invertible = true;
257 invertible &= original.GetInverse(&original_inv); 257 invertible &= original.GetInverse(&original_inv);
258 DCHECK(invertible) << "Non-invertible transform, cannot snap."; 258 DCHECK(invertible) << "Non-invertible transform, cannot snap.";
259 259
260 Transform combined = snapped * original_inv; 260 Transform combined = snapped * original_inv;
261 261
262 return CheckViewportPointMapsWithinOnePixel(viewport.origin(), combined) && 262 return CheckViewportPointMapsWithinOnePixel(gfx::PointF(viewport.origin()),
263 CheckViewportPointMapsWithinOnePixel(viewport.top_right(), combined) &&
264 CheckViewportPointMapsWithinOnePixel(viewport.bottom_left(),
265 combined) && 263 combined) &&
266 CheckViewportPointMapsWithinOnePixel(viewport.bottom_right(), 264 CheckViewportPointMapsWithinOnePixel(gfx::PointF(viewport.top_right()),
267 combined); 265 combined) &&
266 CheckViewportPointMapsWithinOnePixel(
267 gfx::PointF(viewport.bottom_left()), combined) &&
268 CheckViewportPointMapsWithinOnePixel(
269 gfx::PointF(viewport.bottom_right()), combined);
268 } 270 }
269 271
270 } // namespace 272 } // namespace
271 273
272 Transform GetScaleTransform(const Point& anchor, float scale) { 274 Transform GetScaleTransform(const Point& anchor, float scale) {
273 Transform transform; 275 Transform transform;
274 transform.Translate(anchor.x() * (1 - scale), 276 transform.Translate(anchor.x() * (1 - scale),
275 anchor.y() * (1 - scale)); 277 anchor.y() * (1 - scale));
276 transform.Scale(scale, scale); 278 transform.Scale(scale, scale);
277 return transform; 279 return transform;
(...skipping 230 matching lines...) Expand 10 before | Expand all | Expand 10 after
508 perspective[1], 510 perspective[1],
509 perspective[2], 511 perspective[2],
510 perspective[3], 512 perspective[3],
511 quaternion[0], 513 quaternion[0],
512 quaternion[1], 514 quaternion[1],
513 quaternion[2], 515 quaternion[2],
514 quaternion[3]); 516 quaternion[3]);
515 } 517 }
516 518
517 } // namespace gfx 519 } // namespace gfx
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698