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 "FloatSize.h" | 9 #include <cmath> |
| 10 #include <limits> |
| 11 |
10 #include "ui/gfx/quad_f.h" | 12 #include "ui/gfx/quad_f.h" |
11 #include "ui/gfx/rect.h" | 13 #include "ui/gfx/rect.h" |
12 #include "ui/gfx/rect_conversions.h" | 14 #include "ui/gfx/rect_conversions.h" |
13 #include "ui/gfx/rect_f.h" | 15 #include "ui/gfx/rect_f.h" |
14 #include <cmath> | 16 #include "ui/gfx/vector2d_f.h" |
15 #include <public/WebTransformationMatrix.h> | 17 #include <public/WebTransformationMatrix.h> |
16 | 18 |
17 using WebKit::WebTransformationMatrix; | 19 using WebKit::WebTransformationMatrix; |
18 | 20 |
19 namespace cc { | 21 namespace cc { |
20 | 22 |
21 static HomogeneousCoordinate projectHomogeneousPoint(const WebTransformationMatr
ix& transform, const gfx::PointF& p) | 23 static HomogeneousCoordinate projectHomogeneousPoint(const WebTransformationMatr
ix& transform, const gfx::PointF& p) |
22 { | 24 { |
23 // In this case, the layer we are trying to project onto is perpendicular to
ray | 25 // In this case, the layer we are trying to project onto is perpendicular to
ray |
24 // (point p and z-axis direction) that we are trying to project. This happen
s when the | 26 // (point p and z-axis direction) that we are trying to project. This happen
s when the |
(...skipping 346 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
371 | 373 |
372 gfx::Vector2dF MathUtil::computeTransform2dScaleComponents(const WebTransformati
onMatrix& transform) | 374 gfx::Vector2dF MathUtil::computeTransform2dScaleComponents(const WebTransformati
onMatrix& transform) |
373 { | 375 { |
374 if (transform.hasPerspective()) | 376 if (transform.hasPerspective()) |
375 return gfx::Vector2dF(1, 1); | 377 return gfx::Vector2dF(1, 1); |
376 float xScale = scaleOnAxis(transform.m11(), transform.m12(), transform.m13()
); | 378 float xScale = scaleOnAxis(transform.m11(), transform.m12(), transform.m13()
); |
377 float yScale = scaleOnAxis(transform.m21(), transform.m22(), transform.m23()
); | 379 float yScale = scaleOnAxis(transform.m21(), transform.m22(), transform.m23()
); |
378 return gfx::Vector2dF(xScale, yScale); | 380 return gfx::Vector2dF(xScale, yScale); |
379 } | 381 } |
380 | 382 |
381 float MathUtil::smallestAngleBetweenVectors(const FloatSize& v1, const FloatSize
& v2) | 383 static inline double rad2deg(double r) |
382 { | 384 { |
383 float dotProduct = (v1.width() * v2.width() + v1.height() * v2.height()) / (
v1.diagonalLength() * v2.diagonalLength()); | 385 double pi = 3.14159265358979323846; |
384 // Clamp to compensate for rounding errors. | 386 return r * 180.0 / pi; |
385 dotProduct = std::max(-1.f, std::min(1.f, dotProduct)); | |
386 return rad2deg(acosf(dotProduct)); | |
387 } | 387 } |
388 | 388 |
389 FloatSize MathUtil::projectVector(const FloatSize& source, const FloatSize& dest
ination) | 389 float MathUtil::smallestAngleBetweenVectors(gfx::Vector2dF v1, gfx::Vector2dF v2
) |
390 { | 390 { |
391 float sourceDotDestination = source.width() * destination.width() + source.h
eight() * destination.height(); | 391 double dotProduct = gfx::DotProduct(v1, v2) / v1.Length() / v2.Length(); |
392 float projectedLength = sourceDotDestination / destination.diagonalLengthSqu
ared(); | 392 // Clamp to compensate for rounding errors. |
393 return FloatSize(projectedLength * destination.width(), projectedLength * de
stination.height()); | 393 dotProduct = std::max(-1.0, std::min(1.0, dotProduct)); |
| 394 return static_cast<float>(rad2deg(std::acos(dotProduct))); |
| 395 } |
| 396 |
| 397 gfx::Vector2dF MathUtil::projectVector(gfx::Vector2dF source, gfx::Vector2dF des
tination) |
| 398 { |
| 399 float projectedLength = gfx::DotProduct(source, destination) / destination.L
engthSquared(); |
| 400 return gfx::Vector2dF(projectedLength * destination.x(), projectedLength * d
estination.y()); |
394 } | 401 } |
395 | 402 |
396 } // namespace cc | 403 } // namespace cc |
OLD | NEW |