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/math_util.h" | 5 #include "cc/math_util.h" |
6 | 6 |
7 #include <cmath> | 7 #include <cmath> |
8 #include <limits> | 8 #include <limits> |
9 | 9 |
| 10 #include "base/values.h" |
10 #include "ui/gfx/quad_f.h" | 11 #include "ui/gfx/quad_f.h" |
11 #include "ui/gfx/rect.h" | 12 #include "ui/gfx/rect.h" |
12 #include "ui/gfx/rect_conversions.h" | 13 #include "ui/gfx/rect_conversions.h" |
13 #include "ui/gfx/rect_f.h" | 14 #include "ui/gfx/rect_f.h" |
14 #include "ui/gfx/transform.h" | 15 #include "ui/gfx/transform.h" |
15 #include "ui/gfx/vector2d_f.h" | 16 #include "ui/gfx/vector2d_f.h" |
16 | 17 |
17 namespace cc { | 18 namespace cc { |
18 | 19 |
19 const double MathUtil::PI_DOUBLE = 3.14159265358979323846; | 20 const double MathUtil::PI_DOUBLE = 3.14159265358979323846; |
(...skipping 358 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
378 dotProduct = std::max(-1.0, std::min(1.0, dotProduct)); | 379 dotProduct = std::max(-1.0, std::min(1.0, dotProduct)); |
379 return static_cast<float>(Rad2Deg(std::acos(dotProduct))); | 380 return static_cast<float>(Rad2Deg(std::acos(dotProduct))); |
380 } | 381 } |
381 | 382 |
382 gfx::Vector2dF MathUtil::projectVector(gfx::Vector2dF source, gfx::Vector2dF des
tination) | 383 gfx::Vector2dF MathUtil::projectVector(gfx::Vector2dF source, gfx::Vector2dF des
tination) |
383 { | 384 { |
384 float projectedLength = gfx::DotProduct(source, destination) / destination.L
engthSquared(); | 385 float projectedLength = gfx::DotProduct(source, destination) / destination.L
engthSquared(); |
385 return gfx::Vector2dF(projectedLength * destination.x(), projectedLength * d
estination.y()); | 386 return gfx::Vector2dF(projectedLength * destination.x(), projectedLength * d
estination.y()); |
386 } | 387 } |
387 | 388 |
| 389 scoped_ptr<base::Value> MathUtil::asValue(gfx::Size s) { |
| 390 scoped_ptr<base::DictionaryValue> res(new base::DictionaryValue()); |
| 391 res->SetDouble("width", s.width()); |
| 392 res->SetDouble("height", s.height()); |
| 393 return res.PassAs<base::Value>(); |
| 394 } |
| 395 |
| 396 scoped_ptr<base::Value> MathUtil::asValue(gfx::PointF pt) { |
| 397 scoped_ptr<base::DictionaryValue> res(new base::DictionaryValue()); |
| 398 res->SetDouble("x", pt.x()); |
| 399 res->SetDouble("y", pt.y()); |
| 400 return res.PassAs<base::Value>(); |
| 401 } |
| 402 |
| 403 scoped_ptr<base::Value> MathUtil::asValue(gfx::QuadF q) { |
| 404 scoped_ptr<base::DictionaryValue> res(new base::DictionaryValue()); |
| 405 res->Set("p1", asValue(q.p1()).release()); |
| 406 res->Set("p2", asValue(q.p2()).release()); |
| 407 res->Set("p3", asValue(q.p3()).release()); |
| 408 res->Set("p4", asValue(q.p4()).release()); |
| 409 return res.PassAs<base::Value>(); |
| 410 } |
| 411 |
388 } // namespace cc | 412 } // namespace cc |
OLD | NEW |