| 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 "config.h" | 5 #include "config.h" |
| 6 | 6 |
| 7 #include "cc/math_util.h" | 7 #include "cc/math_util.h" |
| 8 | 8 |
| 9 #include <cmath> | 9 #include <cmath> |
| 10 #include <limits> | 10 #include <limits> |
| 11 | 11 |
| 12 #include "ui/gfx/quad_f.h" | 12 #include "ui/gfx/quad_f.h" |
| 13 #include "ui/gfx/rect.h" | 13 #include "ui/gfx/rect.h" |
| 14 #include "ui/gfx/rect_conversions.h" | 14 #include "ui/gfx/rect_conversions.h" |
| 15 #include "ui/gfx/rect_f.h" | 15 #include "ui/gfx/rect_f.h" |
| 16 #include "ui/gfx/vector2d_f.h" | 16 #include "ui/gfx/vector2d_f.h" |
| 17 #include <public/WebTransformationMatrix.h> | 17 #include <public/WebTransformationMatrix.h> |
| 18 | 18 |
| 19 using WebKit::WebTransformationMatrix; | 19 using WebKit::WebTransformationMatrix; |
| 20 | 20 |
| 21 namespace cc { | 21 namespace cc { |
| 22 | 22 |
| 23 const double MathUtil::PI_DOUBLE = 3.14159265358979323846; |
| 24 const float MathUtil::PI_FLOAT = 3.14159265358979323846f; |
| 25 |
| 23 static HomogeneousCoordinate projectHomogeneousPoint(const WebTransformationMatr
ix& transform, const gfx::PointF& p) | 26 static HomogeneousCoordinate projectHomogeneousPoint(const WebTransformationMatr
ix& transform, const gfx::PointF& p) |
| 24 { | 27 { |
| 25 // In this case, the layer we are trying to project onto is perpendicular to
ray | 28 // In this case, the layer we are trying to project onto is perpendicular to
ray |
| 26 // (point p and z-axis direction) that we are trying to project. This happen
s when the | 29 // (point p and z-axis direction) that we are trying to project. This happen
s when the |
| 27 // layer is rotated so that it is infinitesimally thin, or when it is co-pla
nar with | 30 // layer is rotated so that it is infinitesimally thin, or when it is co-pla
nar with |
| 28 // the camera origin -- i.e. when the layer is invisible anyway. | 31 // the camera origin -- i.e. when the layer is invisible anyway. |
| 29 if (!transform.m33()) | 32 if (!transform.m33()) |
| 30 return HomogeneousCoordinate(0, 0, 0, 1); | 33 return HomogeneousCoordinate(0, 0, 0, 1); |
| 31 | 34 |
| 32 double x = p.x(); | 35 double x = p.x(); |
| (...skipping 340 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 373 | 376 |
| 374 gfx::Vector2dF MathUtil::computeTransform2dScaleComponents(const WebTransformati
onMatrix& transform) | 377 gfx::Vector2dF MathUtil::computeTransform2dScaleComponents(const WebTransformati
onMatrix& transform) |
| 375 { | 378 { |
| 376 if (transform.hasPerspective()) | 379 if (transform.hasPerspective()) |
| 377 return gfx::Vector2dF(1, 1); | 380 return gfx::Vector2dF(1, 1); |
| 378 float xScale = scaleOnAxis(transform.m11(), transform.m12(), transform.m13()
); | 381 float xScale = scaleOnAxis(transform.m11(), transform.m12(), transform.m13()
); |
| 379 float yScale = scaleOnAxis(transform.m21(), transform.m22(), transform.m23()
); | 382 float yScale = scaleOnAxis(transform.m21(), transform.m22(), transform.m23()
); |
| 380 return gfx::Vector2dF(xScale, yScale); | 383 return gfx::Vector2dF(xScale, yScale); |
| 381 } | 384 } |
| 382 | 385 |
| 383 static inline double rad2deg(double r) | |
| 384 { | |
| 385 double pi = 3.14159265358979323846; | |
| 386 return r * 180.0 / pi; | |
| 387 } | |
| 388 | |
| 389 float MathUtil::smallestAngleBetweenVectors(gfx::Vector2dF v1, gfx::Vector2dF v2
) | 386 float MathUtil::smallestAngleBetweenVectors(gfx::Vector2dF v1, gfx::Vector2dF v2
) |
| 390 { | 387 { |
| 391 double dotProduct = gfx::DotProduct(v1, v2) / v1.Length() / v2.Length(); | 388 double dotProduct = gfx::DotProduct(v1, v2) / v1.Length() / v2.Length(); |
| 392 // Clamp to compensate for rounding errors. | 389 // Clamp to compensate for rounding errors. |
| 393 dotProduct = std::max(-1.0, std::min(1.0, dotProduct)); | 390 dotProduct = std::max(-1.0, std::min(1.0, dotProduct)); |
| 394 return static_cast<float>(rad2deg(std::acos(dotProduct))); | 391 return static_cast<float>(Rad2Deg(std::acos(dotProduct))); |
| 395 } | 392 } |
| 396 | 393 |
| 397 gfx::Vector2dF MathUtil::projectVector(gfx::Vector2dF source, gfx::Vector2dF des
tination) | 394 gfx::Vector2dF MathUtil::projectVector(gfx::Vector2dF source, gfx::Vector2dF des
tination) |
| 398 { | 395 { |
| 399 float projectedLength = gfx::DotProduct(source, destination) / destination.L
engthSquared(); | 396 float projectedLength = gfx::DotProduct(source, destination) / destination.L
engthSquared(); |
| 400 return gfx::Vector2dF(projectedLength * destination.x(), projectedLength * d
estination.y()); | 397 return gfx::Vector2dF(projectedLength * destination.x(), projectedLength * d
estination.y()); |
| 401 } | 398 } |
| 402 | 399 |
| 403 } // namespace cc | 400 } // namespace cc |
| OLD | NEW |