| 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 "base/values.h" |
| (...skipping 368 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 379 dotProduct = std::max(-1.0, std::min(1.0, dotProduct)); | 379 dotProduct = std::max(-1.0, std::min(1.0, dotProduct)); |
| 380 return static_cast<float>(Rad2Deg(std::acos(dotProduct))); | 380 return static_cast<float>(Rad2Deg(std::acos(dotProduct))); |
| 381 } | 381 } |
| 382 | 382 |
| 383 gfx::Vector2dF MathUtil::projectVector(gfx::Vector2dF source, gfx::Vector2dF des
tination) | 383 gfx::Vector2dF MathUtil::projectVector(gfx::Vector2dF source, gfx::Vector2dF des
tination) |
| 384 { | 384 { |
| 385 float projectedLength = gfx::DotProduct(source, destination) / destination.L
engthSquared(); | 385 float projectedLength = gfx::DotProduct(source, destination) / destination.L
engthSquared(); |
| 386 return gfx::Vector2dF(projectedLength * destination.x(), projectedLength * d
estination.y()); | 386 return gfx::Vector2dF(projectedLength * destination.x(), projectedLength * d
estination.y()); |
| 387 } | 387 } |
| 388 | 388 |
| 389 bool MathUtil::pointHitsRect(const gfx::PointF& screenSpacePoint, |
| 390 const gfx::Transform& localSpaceToScreenSpaceTransf
orm, |
| 391 gfx::RectF localSpaceRect) |
| 392 { |
| 393 // If the transform is not invertible, then assume that this point doesn't h
it this rect. |
| 394 gfx::Transform inverseLocalSpaceToScreenSpace(gfx::Transform::kSkipInitializ
ation); |
| 395 if (!localSpaceToScreenSpaceTransform.GetInverse(&inverseLocalSpaceToScreenS
pace)) |
| 396 return false; |
| 397 |
| 398 // Transform the hit test point from screen space to the local space of the
given rect. |
| 399 bool clipped = false; |
| 400 gfx::PointF hitTestPointInLocalSpace = projectPoint(inverseLocalSpaceToScree
nSpace, screenSpacePoint, clipped); |
| 401 |
| 402 // If projectPoint could not project to a valid value, then we assume that t
his point doesn't hit this rect. |
| 403 if (clipped) |
| 404 return false; |
| 405 |
| 406 return localSpaceRect.Contains(hitTestPointInLocalSpace); |
| 407 } |
| 408 |
| 389 scoped_ptr<base::Value> MathUtil::asValue(gfx::Size s) { | 409 scoped_ptr<base::Value> MathUtil::asValue(gfx::Size s) { |
| 390 scoped_ptr<base::DictionaryValue> res(new base::DictionaryValue()); | 410 scoped_ptr<base::DictionaryValue> res(new base::DictionaryValue()); |
| 391 res->SetDouble("width", s.width()); | 411 res->SetDouble("width", s.width()); |
| 392 res->SetDouble("height", s.height()); | 412 res->SetDouble("height", s.height()); |
| 393 return res.PassAs<base::Value>(); | 413 return res.PassAs<base::Value>(); |
| 394 } | 414 } |
| 395 | 415 |
| 396 scoped_ptr<base::Value> MathUtil::asValue(gfx::PointF pt) { | 416 scoped_ptr<base::Value> MathUtil::asValue(gfx::PointF pt) { |
| 397 scoped_ptr<base::DictionaryValue> res(new base::DictionaryValue()); | 417 scoped_ptr<base::DictionaryValue> res(new base::DictionaryValue()); |
| 398 res->SetDouble("x", pt.x()); | 418 res->SetDouble("x", pt.x()); |
| (...skipping 14 matching lines...) Expand all Loading... |
| 413 return scoped_ptr<base::Value>(base::Value::CreateDoubleValue( | 433 return scoped_ptr<base::Value>(base::Value::CreateDoubleValue( |
| 414 std::min(value, std::numeric_limits<double>::max()))); | 434 std::min(value, std::numeric_limits<double>::max()))); |
| 415 } | 435 } |
| 416 | 436 |
| 417 scoped_ptr<base::Value> MathUtil::asValueSafely(float value) { | 437 scoped_ptr<base::Value> MathUtil::asValueSafely(float value) { |
| 418 return scoped_ptr<base::Value>(base::Value::CreateDoubleValue( | 438 return scoped_ptr<base::Value>(base::Value::CreateDoubleValue( |
| 419 std::min(value, std::numeric_limits<float>::max()))); | 439 std::min(value, std::numeric_limits<float>::max()))); |
| 420 } | 440 } |
| 421 | 441 |
| 422 } // namespace cc | 442 } // namespace cc |
| OLD | NEW |