| 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/base/math_util.h" | 5 #include "cc/base/math_util.h" |
| 6 | 6 |
| 7 #include <algorithm> | 7 #include <algorithm> |
| 8 #include <cmath> | 8 #include <cmath> |
| 9 #include <limits> | 9 #include <limits> |
| 10 | 10 |
| (...skipping 468 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 479 scale_inner_rect.origin() - scale_outer_rect.origin(); | 479 scale_inner_rect.origin() - scale_outer_rect.origin(); |
| 480 gfx::Vector2dF bottom_right_diff = | 480 gfx::Vector2dF bottom_right_diff = |
| 481 scale_inner_rect.bottom_right() - scale_outer_rect.bottom_right(); | 481 scale_inner_rect.bottom_right() - scale_outer_rect.bottom_right(); |
| 482 output_inner_rect.Inset(top_left_diff.x() / scale_rect_to_input_scale_x, | 482 output_inner_rect.Inset(top_left_diff.x() / scale_rect_to_input_scale_x, |
| 483 top_left_diff.y() / scale_rect_to_input_scale_y, | 483 top_left_diff.y() / scale_rect_to_input_scale_y, |
| 484 -bottom_right_diff.x() / scale_rect_to_input_scale_x, | 484 -bottom_right_diff.x() / scale_rect_to_input_scale_x, |
| 485 -bottom_right_diff.y() / scale_rect_to_input_scale_y); | 485 -bottom_right_diff.y() / scale_rect_to_input_scale_y); |
| 486 return output_inner_rect; | 486 return output_inner_rect; |
| 487 } | 487 } |
| 488 | 488 |
| 489 static inline bool NearlyZero(double value) { |
| 490 return std::abs(value) < std::numeric_limits<double>::epsilon(); |
| 491 } |
| 492 |
| 489 static inline float ScaleOnAxis(double a, double b, double c) { | 493 static inline float ScaleOnAxis(double a, double b, double c) { |
| 490 if (!b && !c) | 494 if (NearlyZero(b) && NearlyZero(c)) |
| 491 return a; | 495 return std::abs(a); |
| 492 if (!a && !c) | 496 if (NearlyZero(a) && NearlyZero(c)) |
| 493 return b; | 497 return std::abs(b); |
| 494 if (!a && !b) | 498 if (NearlyZero(a) && NearlyZero(b)) |
| 495 return c; | 499 return std::abs(c); |
| 496 | 500 |
| 497 // Do the sqrt as a double to not lose precision. | 501 // Do the sqrt as a double to not lose precision. |
| 498 return static_cast<float>(std::sqrt(a * a + b * b + c * c)); | 502 return static_cast<float>(std::sqrt(a * a + b * b + c * c)); |
| 499 } | 503 } |
| 500 | 504 |
| 501 gfx::Vector2dF MathUtil::ComputeTransform2dScaleComponents( | 505 gfx::Vector2dF MathUtil::ComputeTransform2dScaleComponents( |
| 502 const gfx::Transform& transform, | 506 const gfx::Transform& transform, |
| 503 float fallback_value) { | 507 float fallback_value) { |
| 504 if (transform.HasPerspective()) | 508 if (transform.HasPerspective()) |
| 505 return gfx::Vector2dF(fallback_value, fallback_value); | 509 return gfx::Vector2dF(fallback_value, fallback_value); |
| (...skipping 127 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 633 return scoped_ptr<base::Value>(base::Value::CreateDoubleValue( | 637 return scoped_ptr<base::Value>(base::Value::CreateDoubleValue( |
| 634 std::min(value, std::numeric_limits<double>::max()))); | 638 std::min(value, std::numeric_limits<double>::max()))); |
| 635 } | 639 } |
| 636 | 640 |
| 637 scoped_ptr<base::Value> MathUtil::AsValueSafely(float value) { | 641 scoped_ptr<base::Value> MathUtil::AsValueSafely(float value) { |
| 638 return scoped_ptr<base::Value>(base::Value::CreateDoubleValue( | 642 return scoped_ptr<base::Value>(base::Value::CreateDoubleValue( |
| 639 std::min(value, std::numeric_limits<float>::max()))); | 643 std::min(value, std::numeric_limits<float>::max()))); |
| 640 } | 644 } |
| 641 | 645 |
| 642 } // namespace cc | 646 } // namespace cc |
| OLD | NEW |