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

Side by Side Diff: cc/base/math_util.cc

Issue 609663003: cc: Remove use of PassAs() and constructor-casting with scoped_ptr. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: cc-passas: PassAs-presubmit-warning Created 6 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
« no previous file with comments | « cc/animation/timing_function.cc ('k') | cc/base/region.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 675 matching lines...) Expand 10 before | Expand all | Expand 10 after
686 float projected_length = 686 float projected_length =
687 gfx::DotProduct(source, destination) / destination.LengthSquared(); 687 gfx::DotProduct(source, destination) / destination.LengthSquared();
688 return gfx::Vector2dF(projected_length * destination.x(), 688 return gfx::Vector2dF(projected_length * destination.x(),
689 projected_length * destination.y()); 689 projected_length * destination.y());
690 } 690 }
691 691
692 scoped_ptr<base::Value> MathUtil::AsValue(const gfx::Size& s) { 692 scoped_ptr<base::Value> MathUtil::AsValue(const gfx::Size& s) {
693 scoped_ptr<base::DictionaryValue> res(new base::DictionaryValue()); 693 scoped_ptr<base::DictionaryValue> res(new base::DictionaryValue());
694 res->SetDouble("width", s.width()); 694 res->SetDouble("width", s.width());
695 res->SetDouble("height", s.height()); 695 res->SetDouble("height", s.height());
696 return res.PassAs<base::Value>(); 696 return res.Pass();
697 } 697 }
698 698
699 scoped_ptr<base::Value> MathUtil::AsValue(const gfx::Rect& r) { 699 scoped_ptr<base::Value> MathUtil::AsValue(const gfx::Rect& r) {
700 scoped_ptr<base::ListValue> res(new base::ListValue()); 700 scoped_ptr<base::ListValue> res(new base::ListValue());
701 res->AppendInteger(r.x()); 701 res->AppendInteger(r.x());
702 res->AppendInteger(r.y()); 702 res->AppendInteger(r.y());
703 res->AppendInteger(r.width()); 703 res->AppendInteger(r.width());
704 res->AppendInteger(r.height()); 704 res->AppendInteger(r.height());
705 return res.PassAs<base::Value>(); 705 return res.Pass();
706 } 706 }
707 707
708 bool MathUtil::FromValue(const base::Value* raw_value, gfx::Rect* out_rect) { 708 bool MathUtil::FromValue(const base::Value* raw_value, gfx::Rect* out_rect) {
709 const base::ListValue* value = NULL; 709 const base::ListValue* value = NULL;
710 if (!raw_value->GetAsList(&value)) 710 if (!raw_value->GetAsList(&value))
711 return false; 711 return false;
712 712
713 if (value->GetSize() != 4) 713 if (value->GetSize() != 4)
714 return false; 714 return false;
715 715
716 int x, y, w, h; 716 int x, y, w, h;
717 bool ok = true; 717 bool ok = true;
718 ok &= value->GetInteger(0, &x); 718 ok &= value->GetInteger(0, &x);
719 ok &= value->GetInteger(1, &y); 719 ok &= value->GetInteger(1, &y);
720 ok &= value->GetInteger(2, &w); 720 ok &= value->GetInteger(2, &w);
721 ok &= value->GetInteger(3, &h); 721 ok &= value->GetInteger(3, &h);
722 if (!ok) 722 if (!ok)
723 return false; 723 return false;
724 724
725 *out_rect = gfx::Rect(x, y, w, h); 725 *out_rect = gfx::Rect(x, y, w, h);
726 return true; 726 return true;
727 } 727 }
728 728
729 scoped_ptr<base::Value> MathUtil::AsValue(const gfx::PointF& pt) { 729 scoped_ptr<base::Value> MathUtil::AsValue(const gfx::PointF& pt) {
730 scoped_ptr<base::ListValue> res(new base::ListValue()); 730 scoped_ptr<base::ListValue> res(new base::ListValue());
731 res->AppendDouble(pt.x()); 731 res->AppendDouble(pt.x());
732 res->AppendDouble(pt.y()); 732 res->AppendDouble(pt.y());
733 return res.PassAs<base::Value>(); 733 return res.Pass();
734 } 734 }
735 735
736 void MathUtil::AddToTracedValue(const gfx::Size& s, 736 void MathUtil::AddToTracedValue(const gfx::Size& s,
737 base::debug::TracedValue* res) { 737 base::debug::TracedValue* res) {
738 res->SetDouble("width", s.width()); 738 res->SetDouble("width", s.width());
739 res->SetDouble("height", s.height()); 739 res->SetDouble("height", s.height());
740 } 740 }
741 741
742 void MathUtil::AddToTracedValue(const gfx::SizeF& s, 742 void MathUtil::AddToTracedValue(const gfx::SizeF& s,
743 base::debug::TracedValue* res) { 743 base::debug::TracedValue* res) {
(...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after
819 819
820 double MathUtil::AsDoubleSafely(double value) { 820 double MathUtil::AsDoubleSafely(double value) {
821 return std::min(value, std::numeric_limits<double>::max()); 821 return std::min(value, std::numeric_limits<double>::max());
822 } 822 }
823 823
824 float MathUtil::AsFloatSafely(float value) { 824 float MathUtil::AsFloatSafely(float value) {
825 return std::min(value, std::numeric_limits<float>::max()); 825 return std::min(value, std::numeric_limits<float>::max());
826 } 826 }
827 827
828 } // namespace cc 828 } // namespace cc
OLDNEW
« no previous file with comments | « cc/animation/timing_function.cc ('k') | cc/base/region.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698