| 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 469 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 480 projected_length * destination.y()); | 480 projected_length * destination.y()); |
| 481 } | 481 } |
| 482 | 482 |
| 483 scoped_ptr<base::Value> MathUtil::AsValue(gfx::Size s) { | 483 scoped_ptr<base::Value> MathUtil::AsValue(gfx::Size s) { |
| 484 scoped_ptr<base::DictionaryValue> res(new base::DictionaryValue()); | 484 scoped_ptr<base::DictionaryValue> res(new base::DictionaryValue()); |
| 485 res->SetDouble("width", s.width()); | 485 res->SetDouble("width", s.width()); |
| 486 res->SetDouble("height", s.height()); | 486 res->SetDouble("height", s.height()); |
| 487 return res.PassAs<base::Value>(); | 487 return res.PassAs<base::Value>(); |
| 488 } | 488 } |
| 489 | 489 |
| 490 scoped_ptr<base::Value> MathUtil::AsValue(gfx::SizeF s) { |
| 491 scoped_ptr<base::DictionaryValue> res(new base::DictionaryValue()); |
| 492 res->SetDouble("width", s.width()); |
| 493 res->SetDouble("height", s.height()); |
| 494 return res.PassAs<base::Value>(); |
| 495 } |
| 496 |
| 490 scoped_ptr<base::Value> MathUtil::AsValue(gfx::Rect r) { | 497 scoped_ptr<base::Value> MathUtil::AsValue(gfx::Rect r) { |
| 491 scoped_ptr<base::ListValue> res(new base::ListValue()); | 498 scoped_ptr<base::ListValue> res(new base::ListValue()); |
| 492 res->AppendInteger(r.x()); | 499 res->AppendInteger(r.x()); |
| 493 res->AppendInteger(r.y()); | 500 res->AppendInteger(r.y()); |
| 494 res->AppendInteger(r.width()); | 501 res->AppendInteger(r.width()); |
| 495 res->AppendInteger(r.height()); | 502 res->AppendInteger(r.height()); |
| 496 return res.PassAs<base::Value>(); | 503 return res.PassAs<base::Value>(); |
| 497 } | 504 } |
| 498 | 505 |
| 499 bool MathUtil::FromValue(const base::Value* raw_value, gfx::Rect* out_rect) { | 506 bool MathUtil::FromValue(const base::Value* raw_value, gfx::Rect* out_rect) { |
| (...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 539 | 546 |
| 540 scoped_ptr<base::Value> MathUtil::AsValue(const gfx::RectF& rect) { | 547 scoped_ptr<base::Value> MathUtil::AsValue(const gfx::RectF& rect) { |
| 541 scoped_ptr<base::ListValue> res(new base::ListValue()); | 548 scoped_ptr<base::ListValue> res(new base::ListValue()); |
| 542 res->AppendDouble(rect.x()); | 549 res->AppendDouble(rect.x()); |
| 543 res->AppendDouble(rect.y()); | 550 res->AppendDouble(rect.y()); |
| 544 res->AppendDouble(rect.width()); | 551 res->AppendDouble(rect.width()); |
| 545 res->AppendDouble(rect.height()); | 552 res->AppendDouble(rect.height()); |
| 546 return res.PassAs<base::Value>(); | 553 return res.PassAs<base::Value>(); |
| 547 } | 554 } |
| 548 | 555 |
| 556 scoped_ptr<base::Value> MathUtil::AsValue(const gfx::Transform& transform) { |
| 557 scoped_ptr<base::ListValue> res(new base::ListValue()); |
| 558 const SkMatrix44& m = transform.matrix(); |
| 559 for (int row = 0; row < 4; ++row) { |
| 560 for (int col = 0; col < 4; ++col) |
| 561 res->AppendDouble(m.getDouble(row, col)); |
| 562 } |
| 563 return res.PassAs<base::Value>(); |
| 564 } |
| 565 |
| 549 scoped_ptr<base::Value> MathUtil::AsValueSafely(double value) { | 566 scoped_ptr<base::Value> MathUtil::AsValueSafely(double value) { |
| 550 return scoped_ptr<base::Value>(base::Value::CreateDoubleValue( | 567 return scoped_ptr<base::Value>(base::Value::CreateDoubleValue( |
| 551 std::min(value, std::numeric_limits<double>::max()))); | 568 std::min(value, std::numeric_limits<double>::max()))); |
| 552 } | 569 } |
| 553 | 570 |
| 554 scoped_ptr<base::Value> MathUtil::AsValueSafely(float value) { | 571 scoped_ptr<base::Value> MathUtil::AsValueSafely(float value) { |
| 555 return scoped_ptr<base::Value>(base::Value::CreateDoubleValue( | 572 return scoped_ptr<base::Value>(base::Value::CreateDoubleValue( |
| 556 std::min(value, std::numeric_limits<float>::max()))); | 573 std::min(value, std::numeric_limits<float>::max()))); |
| 557 } | 574 } |
| 558 | 575 |
| 559 } // namespace cc | 576 } // namespace cc |
| OLD | NEW |