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