| 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/base/math_util.h" | 5 #include "cc/base/math_util.h" |
| 6 | 6 |
| 7 #include <algorithm> | 7 #include <algorithm> |
| 8 #include <cmath> | 8 #include <cmath> |
| 9 #include <limits> | 9 #include <limits> |
| 10 #ifdef __SSE__ | 10 #ifdef __SSE__ |
| (...skipping 472 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 483 h3.ShouldBeClipped() || h4.ShouldBeClipped(); | 483 h3.ShouldBeClipped() || h4.ShouldBeClipped(); |
| 484 | 484 |
| 485 // Result will be invalid if clipped == true. But, compute it anyway just in | 485 // Result will be invalid if clipped == true. But, compute it anyway just in |
| 486 // case, to emulate existing behavior. | 486 // case, to emulate existing behavior. |
| 487 return gfx::QuadF(h1.CartesianPoint2d(), | 487 return gfx::QuadF(h1.CartesianPoint2d(), |
| 488 h2.CartesianPoint2d(), | 488 h2.CartesianPoint2d(), |
| 489 h3.CartesianPoint2d(), | 489 h3.CartesianPoint2d(), |
| 490 h4.CartesianPoint2d()); | 490 h4.CartesianPoint2d()); |
| 491 } | 491 } |
| 492 | 492 |
| 493 gfx::QuadF MathUtil::MapQuad3d(const gfx::Transform& transform, | |
| 494 const gfx::QuadF& q, | |
| 495 gfx::Point3F* p, | |
| 496 bool* clipped) { | |
| 497 if (transform.IsIdentityOrTranslation()) { | |
| 498 gfx::QuadF mapped_quad(q); | |
| 499 mapped_quad += gfx::Vector2dF(transform.matrix().getFloat(0, 3), | |
| 500 transform.matrix().getFloat(1, 3)); | |
| 501 *clipped = false; | |
| 502 p[0] = gfx::Point3F(mapped_quad.p1().x(), mapped_quad.p1().y(), 0.0f); | |
| 503 p[1] = gfx::Point3F(mapped_quad.p2().x(), mapped_quad.p2().y(), 0.0f); | |
| 504 p[2] = gfx::Point3F(mapped_quad.p3().x(), mapped_quad.p3().y(), 0.0f); | |
| 505 p[3] = gfx::Point3F(mapped_quad.p4().x(), mapped_quad.p4().y(), 0.0f); | |
| 506 return mapped_quad; | |
| 507 } | |
| 508 | |
| 509 HomogeneousCoordinate h1 = | |
| 510 MapHomogeneousPoint(transform, gfx::Point3F(q.p1())); | |
| 511 HomogeneousCoordinate h2 = | |
| 512 MapHomogeneousPoint(transform, gfx::Point3F(q.p2())); | |
| 513 HomogeneousCoordinate h3 = | |
| 514 MapHomogeneousPoint(transform, gfx::Point3F(q.p3())); | |
| 515 HomogeneousCoordinate h4 = | |
| 516 MapHomogeneousPoint(transform, gfx::Point3F(q.p4())); | |
| 517 | |
| 518 *clipped = h1.ShouldBeClipped() || h2.ShouldBeClipped() || | |
| 519 h3.ShouldBeClipped() || h4.ShouldBeClipped(); | |
| 520 | |
| 521 // Result will be invalid if clipped == true. But, compute it anyway just in | |
| 522 // case, to emulate existing behavior. | |
| 523 p[0] = h1.CartesianPoint3d(); | |
| 524 p[1] = h2.CartesianPoint3d(); | |
| 525 p[2] = h3.CartesianPoint3d(); | |
| 526 p[3] = h4.CartesianPoint3d(); | |
| 527 | |
| 528 return gfx::QuadF(h1.CartesianPoint2d(), | |
| 529 h2.CartesianPoint2d(), | |
| 530 h3.CartesianPoint2d(), | |
| 531 h4.CartesianPoint2d()); | |
| 532 } | |
| 533 | |
| 534 gfx::PointF MathUtil::MapPoint(const gfx::Transform& transform, | 493 gfx::PointF MathUtil::MapPoint(const gfx::Transform& transform, |
| 535 const gfx::PointF& p, | 494 const gfx::PointF& p, |
| 536 bool* clipped) { | 495 bool* clipped) { |
| 537 HomogeneousCoordinate h = MapHomogeneousPoint(transform, gfx::Point3F(p)); | 496 HomogeneousCoordinate h = MapHomogeneousPoint(transform, gfx::Point3F(p)); |
| 538 | 497 |
| 539 if (h.w() > 0) { | 498 if (h.w() > 0) { |
| 540 *clipped = false; | 499 *clipped = false; |
| 541 return h.CartesianPoint2d(); | 500 return h.CartesianPoint2d(); |
| 542 } | 501 } |
| 543 | 502 |
| 544 // The cartesian coordinates will be invalid after dividing by w. | 503 // The cartesian coordinates will be invalid after dividing by w. |
| 545 *clipped = true; | 504 *clipped = true; |
| 546 | 505 |
| 547 // Avoid dividing by w if w == 0. | 506 // Avoid dividing by w if w == 0. |
| 548 if (!h.w()) | 507 if (!h.w()) |
| 549 return gfx::PointF(); | 508 return gfx::PointF(); |
| 550 | 509 |
| 551 // This return value will be invalid because clipped == true, but (1) users of | 510 // This return value will be invalid because clipped == true, but (1) users of |
| 552 // this code should be ignoring the return value when clipped == true anyway, | 511 // this code should be ignoring the return value when clipped == true anyway, |
| 553 // and (2) this behavior is more consistent with existing behavior of WebKit | 512 // and (2) this behavior is more consistent with existing behavior of WebKit |
| 554 // transforms if the user really does not ignore the return value. | 513 // transforms if the user really does not ignore the return value. |
| 555 return h.CartesianPoint2d(); | 514 return h.CartesianPoint2d(); |
| 556 } | 515 } |
| 557 | 516 |
| 558 gfx::Point3F MathUtil::MapPoint(const gfx::Transform& transform, | |
| 559 const gfx::Point3F& p, | |
| 560 bool* clipped) { | |
| 561 HomogeneousCoordinate h = MapHomogeneousPoint(transform, p); | |
| 562 | |
| 563 if (h.w() > 0) { | |
| 564 *clipped = false; | |
| 565 return h.CartesianPoint3d(); | |
| 566 } | |
| 567 | |
| 568 // The cartesian coordinates will be invalid after dividing by w. | |
| 569 *clipped = true; | |
| 570 | |
| 571 // Avoid dividing by w if w == 0. | |
| 572 if (!h.w()) | |
| 573 return gfx::Point3F(); | |
| 574 | |
| 575 // This return value will be invalid because clipped == true, but (1) users of | |
| 576 // this code should be ignoring the return value when clipped == true anyway, | |
| 577 // and (2) this behavior is more consistent with existing behavior of WebKit | |
| 578 // transforms if the user really does not ignore the return value. | |
| 579 return h.CartesianPoint3d(); | |
| 580 } | |
| 581 | |
| 582 gfx::QuadF MathUtil::ProjectQuad(const gfx::Transform& transform, | |
| 583 const gfx::QuadF& q, | |
| 584 bool* clipped) { | |
| 585 gfx::QuadF projected_quad; | |
| 586 bool clipped_point; | |
| 587 projected_quad.set_p1(ProjectPoint(transform, q.p1(), &clipped_point)); | |
| 588 *clipped = clipped_point; | |
| 589 projected_quad.set_p2(ProjectPoint(transform, q.p2(), &clipped_point)); | |
| 590 *clipped |= clipped_point; | |
| 591 projected_quad.set_p3(ProjectPoint(transform, q.p3(), &clipped_point)); | |
| 592 *clipped |= clipped_point; | |
| 593 projected_quad.set_p4(ProjectPoint(transform, q.p4(), &clipped_point)); | |
| 594 *clipped |= clipped_point; | |
| 595 | |
| 596 return projected_quad; | |
| 597 } | |
| 598 | |
| 599 gfx::PointF MathUtil::ProjectPoint(const gfx::Transform& transform, | 517 gfx::PointF MathUtil::ProjectPoint(const gfx::Transform& transform, |
| 600 const gfx::PointF& p, | 518 const gfx::PointF& p, |
| 601 bool* clipped) { | 519 bool* clipped) { |
| 602 HomogeneousCoordinate h = ProjectHomogeneousPoint(transform, p, clipped); | 520 HomogeneousCoordinate h = ProjectHomogeneousPoint(transform, p, clipped); |
| 603 // Avoid dividing by w if w == 0. | 521 // Avoid dividing by w if w == 0. |
| 604 if (!h.w()) | 522 if (!h.w()) |
| 605 return gfx::PointF(); | 523 return gfx::PointF(); |
| 606 | 524 |
| 607 // This return value will be invalid if clipped == true, but (1) users of | 525 // This return value will be invalid if clipped == true, but (1) users of |
| 608 // this code should be ignoring the return value when clipped == true anyway, | 526 // this code should be ignoring the return value when clipped == true anyway, |
| (...skipping 298 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 907 const gfx::PointF& right) { | 825 const gfx::PointF& right) { |
| 908 return IsNearlyTheSame(left, right); | 826 return IsNearlyTheSame(left, right); |
| 909 } | 827 } |
| 910 | 828 |
| 911 bool MathUtil::IsNearlyTheSameForTesting(const gfx::Point3F& left, | 829 bool MathUtil::IsNearlyTheSameForTesting(const gfx::Point3F& left, |
| 912 const gfx::Point3F& right) { | 830 const gfx::Point3F& right) { |
| 913 return IsNearlyTheSame(left, right); | 831 return IsNearlyTheSame(left, right); |
| 914 } | 832 } |
| 915 | 833 |
| 916 } // namespace cc | 834 } // namespace cc |
| OLD | NEW |