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 687 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
698 } | 698 } |
699 | 699 |
700 gfx::Vector2dF MathUtil::ProjectVector(const gfx::Vector2dF& source, | 700 gfx::Vector2dF MathUtil::ProjectVector(const gfx::Vector2dF& source, |
701 const gfx::Vector2dF& destination) { | 701 const gfx::Vector2dF& destination) { |
702 float projected_length = | 702 float projected_length = |
703 gfx::DotProduct(source, destination) / destination.LengthSquared(); | 703 gfx::DotProduct(source, destination) / destination.LengthSquared(); |
704 return gfx::Vector2dF(projected_length * destination.x(), | 704 return gfx::Vector2dF(projected_length * destination.x(), |
705 projected_length * destination.y()); | 705 projected_length * destination.y()); |
706 } | 706 } |
707 | 707 |
708 scoped_ptr<base::Value> MathUtil::AsValue(const gfx::Size& s) { | 708 std::unique_ptr<base::Value> MathUtil::AsValue(const gfx::Size& s) { |
709 scoped_ptr<base::DictionaryValue> res(new base::DictionaryValue()); | 709 std::unique_ptr<base::DictionaryValue> res(new base::DictionaryValue()); |
710 res->SetDouble("width", s.width()); | 710 res->SetDouble("width", s.width()); |
711 res->SetDouble("height", s.height()); | 711 res->SetDouble("height", s.height()); |
712 return std::move(res); | 712 return std::move(res); |
713 } | 713 } |
714 | 714 |
715 scoped_ptr<base::Value> MathUtil::AsValue(const gfx::Rect& r) { | 715 std::unique_ptr<base::Value> MathUtil::AsValue(const gfx::Rect& r) { |
716 scoped_ptr<base::ListValue> res(new base::ListValue()); | 716 std::unique_ptr<base::ListValue> res(new base::ListValue()); |
717 res->AppendInteger(r.x()); | 717 res->AppendInteger(r.x()); |
718 res->AppendInteger(r.y()); | 718 res->AppendInteger(r.y()); |
719 res->AppendInteger(r.width()); | 719 res->AppendInteger(r.width()); |
720 res->AppendInteger(r.height()); | 720 res->AppendInteger(r.height()); |
721 return std::move(res); | 721 return std::move(res); |
722 } | 722 } |
723 | 723 |
724 bool MathUtil::FromValue(const base::Value* raw_value, gfx::Rect* out_rect) { | 724 bool MathUtil::FromValue(const base::Value* raw_value, gfx::Rect* out_rect) { |
725 const base::ListValue* value = nullptr; | 725 const base::ListValue* value = nullptr; |
726 if (!raw_value->GetAsList(&value)) | 726 if (!raw_value->GetAsList(&value)) |
727 return false; | 727 return false; |
728 | 728 |
729 if (value->GetSize() != 4) | 729 if (value->GetSize() != 4) |
730 return false; | 730 return false; |
731 | 731 |
732 int x, y, w, h; | 732 int x, y, w, h; |
733 bool ok = true; | 733 bool ok = true; |
734 ok &= value->GetInteger(0, &x); | 734 ok &= value->GetInteger(0, &x); |
735 ok &= value->GetInteger(1, &y); | 735 ok &= value->GetInteger(1, &y); |
736 ok &= value->GetInteger(2, &w); | 736 ok &= value->GetInteger(2, &w); |
737 ok &= value->GetInteger(3, &h); | 737 ok &= value->GetInteger(3, &h); |
738 if (!ok) | 738 if (!ok) |
739 return false; | 739 return false; |
740 | 740 |
741 *out_rect = gfx::Rect(x, y, w, h); | 741 *out_rect = gfx::Rect(x, y, w, h); |
742 return true; | 742 return true; |
743 } | 743 } |
744 | 744 |
745 scoped_ptr<base::Value> MathUtil::AsValue(const gfx::PointF& pt) { | 745 std::unique_ptr<base::Value> MathUtil::AsValue(const gfx::PointF& pt) { |
746 scoped_ptr<base::ListValue> res(new base::ListValue()); | 746 std::unique_ptr<base::ListValue> res(new base::ListValue()); |
747 res->AppendDouble(pt.x()); | 747 res->AppendDouble(pt.x()); |
748 res->AppendDouble(pt.y()); | 748 res->AppendDouble(pt.y()); |
749 return std::move(res); | 749 return std::move(res); |
750 } | 750 } |
751 | 751 |
752 void MathUtil::AddToTracedValue(const char* name, | 752 void MathUtil::AddToTracedValue(const char* name, |
753 const gfx::Size& s, | 753 const gfx::Size& s, |
754 base::trace_event::TracedValue* res) { | 754 base::trace_event::TracedValue* res) { |
755 res->BeginDictionary(name); | 755 res->BeginDictionary(name); |
756 res->SetDouble("width", s.width()); | 756 res->SetDouble("width", s.width()); |
(...skipping 141 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
898 transform.matrix().getFloat(2, 0)); | 898 transform.matrix().getFloat(2, 0)); |
899 } | 899 } |
900 | 900 |
901 gfx::Vector3dF MathUtil::GetYAxis(const gfx::Transform& transform) { | 901 gfx::Vector3dF MathUtil::GetYAxis(const gfx::Transform& transform) { |
902 return gfx::Vector3dF(transform.matrix().getFloat(0, 1), | 902 return gfx::Vector3dF(transform.matrix().getFloat(0, 1), |
903 transform.matrix().getFloat(1, 1), | 903 transform.matrix().getFloat(1, 1), |
904 transform.matrix().getFloat(2, 1)); | 904 transform.matrix().getFloat(2, 1)); |
905 } | 905 } |
906 | 906 |
907 } // namespace cc | 907 } // namespace cc |
OLD | NEW |