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