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 448 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
459 gfx::Vector2dF bottom_right_diff = | 459 gfx::Vector2dF bottom_right_diff = |
460 scale_inner_rect.bottom_right() - scale_outer_rect.bottom_right(); | 460 scale_inner_rect.bottom_right() - scale_outer_rect.bottom_right(); |
461 output_inner_rect.Inset(top_left_diff.x() / scale_rect_to_input_scale_x, | 461 output_inner_rect.Inset(top_left_diff.x() / scale_rect_to_input_scale_x, |
462 top_left_diff.y() / scale_rect_to_input_scale_y, | 462 top_left_diff.y() / scale_rect_to_input_scale_y, |
463 -bottom_right_diff.x() / scale_rect_to_input_scale_x, | 463 -bottom_right_diff.x() / scale_rect_to_input_scale_x, |
464 -bottom_right_diff.y() / scale_rect_to_input_scale_y); | 464 -bottom_right_diff.y() / scale_rect_to_input_scale_y); |
465 return output_inner_rect; | 465 return output_inner_rect; |
466 } | 466 } |
467 | 467 |
468 static inline float ScaleOnAxis(double a, double b, double c) { | 468 static inline float ScaleOnAxis(double a, double b, double c) { |
| 469 if (!b && !c) |
| 470 return a; |
| 471 if (!a && !c) |
| 472 return b; |
| 473 if (!a && !b) |
| 474 return c; |
| 475 |
469 // Do the sqrt as a double to not lose precision. | 476 // Do the sqrt as a double to not lose precision. |
470 return static_cast<float>(std::sqrt(a * a + b * b + c * c)); | 477 return static_cast<float>(std::sqrt(a * a + b * b + c * c)); |
471 } | 478 } |
472 | 479 |
473 gfx::Vector2dF MathUtil::ComputeTransform2dScaleComponents( | 480 gfx::Vector2dF MathUtil::ComputeTransform2dScaleComponents( |
474 const gfx::Transform& transform, | 481 const gfx::Transform& transform, |
475 float fallback_value) { | 482 float fallback_value) { |
476 if (transform.HasPerspective()) | 483 if (transform.HasPerspective()) |
477 return gfx::Vector2dF(fallback_value, fallback_value); | 484 return gfx::Vector2dF(fallback_value, fallback_value); |
478 float x_scale = ScaleOnAxis(transform.matrix().getDouble(0, 0), | 485 float x_scale = ScaleOnAxis(transform.matrix().getDouble(0, 0), |
(...skipping 108 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
587 return scoped_ptr<base::Value>(base::Value::CreateDoubleValue( | 594 return scoped_ptr<base::Value>(base::Value::CreateDoubleValue( |
588 std::min(value, std::numeric_limits<double>::max()))); | 595 std::min(value, std::numeric_limits<double>::max()))); |
589 } | 596 } |
590 | 597 |
591 scoped_ptr<base::Value> MathUtil::AsValueSafely(float value) { | 598 scoped_ptr<base::Value> MathUtil::AsValueSafely(float value) { |
592 return scoped_ptr<base::Value>(base::Value::CreateDoubleValue( | 599 return scoped_ptr<base::Value>(base::Value::CreateDoubleValue( |
593 std::min(value, std::numeric_limits<float>::max()))); | 600 std::min(value, std::numeric_limits<float>::max()))); |
594 } | 601 } |
595 | 602 |
596 } // namespace cc | 603 } // namespace cc |
OLD | NEW |