OLD | NEW |
1 // Copyright 2012 The Chromium Authors. All rights reserved. | 1 // Copyright 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 "cc/math_util.h" | 5 #include "cc/math_util.h" |
6 | 6 |
7 #include <cmath> | 7 #include <cmath> |
8 #include <limits> | 8 #include <limits> |
9 | 9 |
10 #include "ui/gfx/quad_f.h" | 10 #include "ui/gfx/quad_f.h" |
(...skipping 365 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
376 transform.matrix().setDouble(2, 2, 1); | 376 transform.matrix().setDouble(2, 2, 1); |
377 transform.matrix().setDouble(3, 2, 0); | 377 transform.matrix().setDouble(3, 2, 0); |
378 transform.matrix().setDouble(2, 3, 0); | 378 transform.matrix().setDouble(2, 3, 0); |
379 } | 379 } |
380 | 380 |
381 static inline float scaleOnAxis(double a, double b, double c) | 381 static inline float scaleOnAxis(double a, double b, double c) |
382 { | 382 { |
383 return std::sqrt(a * a + b * b + c * c); | 383 return std::sqrt(a * a + b * b + c * c); |
384 } | 384 } |
385 | 385 |
386 gfx::Vector2dF MathUtil::computeTransform2dScaleComponents(const gfx::Transform&
transform) | 386 gfx::Vector2dF MathUtil::computeTransform2dScaleComponents(const gfx::Transform&
transform, float fallbackValue) |
387 { | 387 { |
388 if (transform.HasPerspective()) | 388 if (transform.HasPerspective()) |
389 return gfx::Vector2dF(1, 1); | 389 return gfx::Vector2dF(fallbackValue, fallbackValue); |
390 float xScale = scaleOnAxis(transform.matrix().getDouble(0, 0), transform.mat
rix().getDouble(1, 0), transform.matrix().getDouble(2, 0)); | 390 float xScale = scaleOnAxis(transform.matrix().getDouble(0, 0), transform.mat
rix().getDouble(1, 0), transform.matrix().getDouble(2, 0)); |
391 float yScale = scaleOnAxis(transform.matrix().getDouble(0, 1), transform.mat
rix().getDouble(1, 1), transform.matrix().getDouble(2, 1)); | 391 float yScale = scaleOnAxis(transform.matrix().getDouble(0, 1), transform.mat
rix().getDouble(1, 1), transform.matrix().getDouble(2, 1)); |
392 return gfx::Vector2dF(xScale, yScale); | 392 return gfx::Vector2dF(xScale, yScale); |
393 } | 393 } |
394 | 394 |
395 float MathUtil::smallestAngleBetweenVectors(gfx::Vector2dF v1, gfx::Vector2dF v2
) | 395 float MathUtil::smallestAngleBetweenVectors(gfx::Vector2dF v1, gfx::Vector2dF v2
) |
396 { | 396 { |
397 double dotProduct = gfx::DotProduct(v1, v2) / v1.Length() / v2.Length(); | 397 double dotProduct = gfx::DotProduct(v1, v2) / v1.Length() / v2.Length(); |
398 // Clamp to compensate for rounding errors. | 398 // Clamp to compensate for rounding errors. |
399 dotProduct = std::max(-1.0, std::min(1.0, dotProduct)); | 399 dotProduct = std::max(-1.0, std::min(1.0, dotProduct)); |
(...skipping 94 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
494 matrix.setDouble(1, 0, b); | 494 matrix.setDouble(1, 0, b); |
495 matrix.setDouble(0, 1, c); | 495 matrix.setDouble(0, 1, c); |
496 matrix.setDouble(1, 1, d); | 496 matrix.setDouble(1, 1, d); |
497 matrix.setDouble(0, 3, e); | 497 matrix.setDouble(0, 3, e); |
498 matrix.setDouble(1, 3, f); | 498 matrix.setDouble(1, 3, f); |
499 | 499 |
500 return result; | 500 return result; |
501 } | 501 } |
502 | 502 |
503 } // namespace cc | 503 } // namespace cc |
OLD | NEW |