| 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 |
| 11 #include "base/debug/trace_event_argument.h" |
| 11 #include "base/values.h" | 12 #include "base/values.h" |
| 12 #include "ui/gfx/quad_f.h" | 13 #include "ui/gfx/quad_f.h" |
| 13 #include "ui/gfx/rect.h" | 14 #include "ui/gfx/rect.h" |
| 14 #include "ui/gfx/rect_conversions.h" | 15 #include "ui/gfx/rect_conversions.h" |
| 15 #include "ui/gfx/rect_f.h" | 16 #include "ui/gfx/rect_f.h" |
| 16 #include "ui/gfx/transform.h" | 17 #include "ui/gfx/transform.h" |
| 17 #include "ui/gfx/vector2d_f.h" | 18 #include "ui/gfx/vector2d_f.h" |
| 18 | 19 |
| 19 namespace cc { | 20 namespace cc { |
| 20 | 21 |
| (...skipping 519 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 540 projected_length * destination.y()); | 541 projected_length * destination.y()); |
| 541 } | 542 } |
| 542 | 543 |
| 543 scoped_ptr<base::Value> MathUtil::AsValue(const gfx::Size& s) { | 544 scoped_ptr<base::Value> MathUtil::AsValue(const gfx::Size& s) { |
| 544 scoped_ptr<base::DictionaryValue> res(new base::DictionaryValue()); | 545 scoped_ptr<base::DictionaryValue> res(new base::DictionaryValue()); |
| 545 res->SetDouble("width", s.width()); | 546 res->SetDouble("width", s.width()); |
| 546 res->SetDouble("height", s.height()); | 547 res->SetDouble("height", s.height()); |
| 547 return res.PassAs<base::Value>(); | 548 return res.PassAs<base::Value>(); |
| 548 } | 549 } |
| 549 | 550 |
| 550 scoped_ptr<base::Value> MathUtil::AsValue(const gfx::SizeF& s) { | |
| 551 scoped_ptr<base::DictionaryValue> res(new base::DictionaryValue()); | |
| 552 res->SetDouble("width", s.width()); | |
| 553 res->SetDouble("height", s.height()); | |
| 554 return res.PassAs<base::Value>(); | |
| 555 } | |
| 556 | |
| 557 scoped_ptr<base::Value> MathUtil::AsValue(const gfx::Rect& r) { | 551 scoped_ptr<base::Value> MathUtil::AsValue(const gfx::Rect& r) { |
| 558 scoped_ptr<base::ListValue> res(new base::ListValue()); | 552 scoped_ptr<base::ListValue> res(new base::ListValue()); |
| 559 res->AppendInteger(r.x()); | 553 res->AppendInteger(r.x()); |
| 560 res->AppendInteger(r.y()); | 554 res->AppendInteger(r.y()); |
| 561 res->AppendInteger(r.width()); | 555 res->AppendInteger(r.width()); |
| 562 res->AppendInteger(r.height()); | 556 res->AppendInteger(r.height()); |
| 563 return res.PassAs<base::Value>(); | 557 return res.PassAs<base::Value>(); |
| 564 } | 558 } |
| 565 | 559 |
| 566 bool MathUtil::FromValue(const base::Value* raw_value, gfx::Rect* out_rect) { | 560 bool MathUtil::FromValue(const base::Value* raw_value, gfx::Rect* out_rect) { |
| (...skipping 17 matching lines...) Expand all Loading... |
| 584 return true; | 578 return true; |
| 585 } | 579 } |
| 586 | 580 |
| 587 scoped_ptr<base::Value> MathUtil::AsValue(const gfx::PointF& pt) { | 581 scoped_ptr<base::Value> MathUtil::AsValue(const gfx::PointF& pt) { |
| 588 scoped_ptr<base::ListValue> res(new base::ListValue()); | 582 scoped_ptr<base::ListValue> res(new base::ListValue()); |
| 589 res->AppendDouble(pt.x()); | 583 res->AppendDouble(pt.x()); |
| 590 res->AppendDouble(pt.y()); | 584 res->AppendDouble(pt.y()); |
| 591 return res.PassAs<base::Value>(); | 585 return res.PassAs<base::Value>(); |
| 592 } | 586 } |
| 593 | 587 |
| 594 scoped_ptr<base::Value> MathUtil::AsValue(const gfx::Point3F& pt) { | 588 void MathUtil::AddToTracedValue(const gfx::Size& s, |
| 595 scoped_ptr<base::ListValue> res(new base::ListValue()); | 589 base::debug::TracedValue* res) { |
| 590 res->SetDouble("width", s.width()); |
| 591 res->SetDouble("height", s.height()); |
| 592 } |
| 593 |
| 594 void MathUtil::AddToTracedValue(const gfx::SizeF& s, |
| 595 base::debug::TracedValue* res) { |
| 596 res->SetDouble("width", s.width()); |
| 597 res->SetDouble("height", s.height()); |
| 598 } |
| 599 |
| 600 void MathUtil::AddToTracedValue(const gfx::Rect& r, |
| 601 base::debug::TracedValue* res) { |
| 602 res->AppendInteger(r.x()); |
| 603 res->AppendInteger(r.y()); |
| 604 res->AppendInteger(r.width()); |
| 605 res->AppendInteger(r.height()); |
| 606 } |
| 607 |
| 608 void MathUtil::AddToTracedValue(const gfx::PointF& pt, |
| 609 base::debug::TracedValue* res) { |
| 610 res->AppendDouble(pt.x()); |
| 611 res->AppendDouble(pt.y()); |
| 612 } |
| 613 |
| 614 void MathUtil::AddToTracedValue(const gfx::Point3F& pt, |
| 615 base::debug::TracedValue* res) { |
| 596 res->AppendDouble(pt.x()); | 616 res->AppendDouble(pt.x()); |
| 597 res->AppendDouble(pt.y()); | 617 res->AppendDouble(pt.y()); |
| 598 res->AppendDouble(pt.z()); | 618 res->AppendDouble(pt.z()); |
| 599 return res.PassAs<base::Value>(); | |
| 600 } | 619 } |
| 601 | 620 |
| 602 scoped_ptr<base::Value> MathUtil::AsValue(const gfx::Vector2d& v) { | 621 void MathUtil::AddToTracedValue(const gfx::Vector2d& v, |
| 603 scoped_ptr<base::ListValue> res(new base::ListValue()); | 622 base::debug::TracedValue* res) { |
| 604 res->AppendInteger(v.x()); | 623 res->AppendInteger(v.x()); |
| 605 res->AppendInteger(v.y()); | 624 res->AppendInteger(v.y()); |
| 606 return res.PassAs<base::Value>(); | |
| 607 } | 625 } |
| 608 | 626 |
| 609 scoped_ptr<base::Value> MathUtil::AsValue(const gfx::QuadF& q) { | 627 void MathUtil::AddToTracedValue(const gfx::QuadF& q, |
| 610 scoped_ptr<base::ListValue> res(new base::ListValue()); | 628 base::debug::TracedValue* res) { |
| 611 res->AppendDouble(q.p1().x()); | 629 res->AppendDouble(q.p1().x()); |
| 612 res->AppendDouble(q.p1().y()); | 630 res->AppendDouble(q.p1().y()); |
| 613 res->AppendDouble(q.p2().x()); | 631 res->AppendDouble(q.p2().x()); |
| 614 res->AppendDouble(q.p2().y()); | 632 res->AppendDouble(q.p2().y()); |
| 615 res->AppendDouble(q.p3().x()); | 633 res->AppendDouble(q.p3().x()); |
| 616 res->AppendDouble(q.p3().y()); | 634 res->AppendDouble(q.p3().y()); |
| 617 res->AppendDouble(q.p4().x()); | 635 res->AppendDouble(q.p4().x()); |
| 618 res->AppendDouble(q.p4().y()); | 636 res->AppendDouble(q.p4().y()); |
| 619 return res.PassAs<base::Value>(); | |
| 620 } | 637 } |
| 621 | 638 |
| 622 scoped_ptr<base::Value> MathUtil::AsValue(const gfx::RectF& rect) { | 639 void MathUtil::AddToTracedValue(const gfx::RectF& rect, |
| 623 scoped_ptr<base::ListValue> res(new base::ListValue()); | 640 base::debug::TracedValue* res) { |
| 624 res->AppendDouble(rect.x()); | 641 res->AppendDouble(rect.x()); |
| 625 res->AppendDouble(rect.y()); | 642 res->AppendDouble(rect.y()); |
| 626 res->AppendDouble(rect.width()); | 643 res->AppendDouble(rect.width()); |
| 627 res->AppendDouble(rect.height()); | 644 res->AppendDouble(rect.height()); |
| 628 return res.PassAs<base::Value>(); | |
| 629 } | 645 } |
| 630 | 646 |
| 631 scoped_ptr<base::Value> MathUtil::AsValue(const gfx::Transform& transform) { | 647 void MathUtil::AddToTracedValue(const gfx::Transform& transform, |
| 632 scoped_ptr<base::ListValue> res(new base::ListValue()); | 648 base::debug::TracedValue* res) { |
| 633 const SkMatrix44& m = transform.matrix(); | 649 const SkMatrix44& m = transform.matrix(); |
| 634 for (int row = 0; row < 4; ++row) { | 650 for (int row = 0; row < 4; ++row) { |
| 635 for (int col = 0; col < 4; ++col) | 651 for (int col = 0; col < 4; ++col) |
| 636 res->AppendDouble(m.getDouble(row, col)); | 652 res->AppendDouble(m.getDouble(row, col)); |
| 637 } | 653 } |
| 638 return res.PassAs<base::Value>(); | |
| 639 } | 654 } |
| 640 | 655 |
| 641 scoped_ptr<base::Value> MathUtil::AsValue(const gfx::BoxF& box) { | 656 void MathUtil::AddToTracedValue(const gfx::BoxF& box, |
| 642 scoped_ptr<base::ListValue> res(new base::ListValue()); | 657 base::debug::TracedValue* res) { |
| 643 res->AppendInteger(box.x()); | 658 res->AppendInteger(box.x()); |
| 644 res->AppendInteger(box.y()); | 659 res->AppendInteger(box.y()); |
| 645 res->AppendInteger(box.z()); | 660 res->AppendInteger(box.z()); |
| 646 res->AppendInteger(box.width()); | 661 res->AppendInteger(box.width()); |
| 647 res->AppendInteger(box.height()); | 662 res->AppendInteger(box.height()); |
| 648 res->AppendInteger(box.depth()); | 663 res->AppendInteger(box.depth()); |
| 649 return res.PassAs<base::Value>(); | |
| 650 } | 664 } |
| 651 | 665 |
| 652 scoped_ptr<base::Value> MathUtil::AsValueSafely(double value) { | 666 double MathUtil::AsDoubleSafely(double value) { |
| 653 return scoped_ptr<base::Value>(new base::FundamentalValue( | 667 return std::min(value, std::numeric_limits<double>::max()); |
| 654 std::min(value, std::numeric_limits<double>::max()))); | |
| 655 } | 668 } |
| 656 | 669 |
| 657 scoped_ptr<base::Value> MathUtil::AsValueSafely(float value) { | 670 float MathUtil::AsFloatSafely(float value) { |
| 658 return scoped_ptr<base::Value>(new base::FundamentalValue( | 671 return std::min(value, std::numeric_limits<float>::max()); |
| 659 std::min(value, std::numeric_limits<float>::max()))); | |
| 660 } | 672 } |
| 661 | 673 |
| 662 } // namespace cc | 674 } // namespace cc |
| OLD | NEW |