| OLD | NEW |
| 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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 // MSVC++ requires this to be set before any other includes to get M_PI. | 5 // MSVC++ requires this to be set before any other includes to get M_PI. |
| 6 #define _USE_MATH_DEFINES | 6 #define _USE_MATH_DEFINES |
| 7 | 7 |
| 8 #include "ui/gfx/transform.h" | 8 #include "ui/gfx/transform.h" |
| 9 | 9 |
| 10 #include <cmath> | 10 #include <cmath> |
| (...skipping 430 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 441 int x1; | 441 int x1; |
| 442 int y1; | 442 int y1; |
| 443 float tx; | 443 float tx; |
| 444 float ty; | 444 float ty; |
| 445 int x2; | 445 int x2; |
| 446 int y2; | 446 int y2; |
| 447 } test_cases[] = { | 447 } test_cases[] = { |
| 448 { 0, 0, 10.0f, 20.0f, 10, 20}, | 448 { 0, 0, 10.0f, 20.0f, 10, 20}, |
| 449 { 0, 0, -10.0f, -20.0f, 0, 0}, | 449 { 0, 0, -10.0f, -20.0f, 0, 0}, |
| 450 { 0, 0, -10.0f, -20.0f, -10, -20}, | 450 { 0, 0, -10.0f, -20.0f, -10, -20}, |
| 451 { 0, 0, | |
| 452 std::numeric_limits<float>::quiet_NaN(), | |
| 453 std::numeric_limits<float>::quiet_NaN(), | |
| 454 10, 20}, | |
| 455 }; | 451 }; |
| 456 | 452 |
| 457 Transform xform; | 453 Transform xform; |
| 458 for (size_t i = 0; i < arraysize(test_cases); ++i) { | 454 for (size_t i = 0; i < arraysize(test_cases); ++i) { |
| 459 const TestCase& value = test_cases[i]; | 455 const TestCase& value = test_cases[i]; |
| 460 Transform translation; | 456 Transform translation; |
| 461 translation.Translate(value.tx, value.ty); | 457 translation.Translate(value.tx, value.ty); |
| 462 xform = translation * xform; | 458 xform = translation * xform; |
| 463 Point p1(value.x1, value.y1); | 459 Point p1(value.x1, value.y1); |
| 464 Point p2(value.x2, value.y2); | 460 Point p2(value.x2, value.y2); |
| 465 xform.TransformPoint(&p1); | 461 xform.TransformPoint(&p1); |
| 466 if (value.tx == value.tx && | 462 if (value.tx == value.tx && |
| 467 value.ty == value.ty) { | 463 value.ty == value.ty) { |
| 468 EXPECT_EQ(p1.x(), p2.x()); | 464 EXPECT_EQ(p1.x(), p2.x()); |
| 469 EXPECT_EQ(p1.y(), p2.y()); | 465 EXPECT_EQ(p1.y(), p2.y()); |
| 470 } | 466 } |
| 471 } | 467 } |
| 472 } | 468 } |
| 473 | 469 |
| 474 TEST(XFormTest, ConcatScale2D) { | 470 TEST(XFormTest, ConcatScale2D) { |
| 475 static const struct TestCase { | 471 static const struct TestCase { |
| 476 int before; | 472 int before; |
| 477 float scale; | 473 float scale; |
| 478 int after; | 474 int after; |
| 479 } test_cases[] = { | 475 } test_cases[] = { |
| 480 { 1, 10.0f, 10}, | 476 { 1, 10.0f, 10}, |
| 481 { 1, .1f, 1}, | 477 { 1, .1f, 1}, |
| 482 { 1, 100.0f, 100}, | 478 { 1, 100.0f, 100}, |
| 483 { 1, -1.0f, -100}, | 479 { 1, -1.0f, -100}, |
| 484 { 1, std::numeric_limits<float>::quiet_NaN(), 1} | |
| 485 }; | 480 }; |
| 486 | 481 |
| 487 Transform xform; | 482 Transform xform; |
| 488 for (size_t i = 0; i < arraysize(test_cases); ++i) { | 483 for (size_t i = 0; i < arraysize(test_cases); ++i) { |
| 489 const TestCase& value = test_cases[i]; | 484 const TestCase& value = test_cases[i]; |
| 490 Transform scale; | 485 Transform scale; |
| 491 scale.Scale(value.scale, value.scale); | 486 scale.Scale(value.scale, value.scale); |
| 492 xform = scale * xform; | 487 xform = scale * xform; |
| 493 Point p1(value.before, value.before); | 488 Point p1(value.before, value.before); |
| 494 Point p2(value.after, value.after); | 489 Point p2(value.after, value.after); |
| (...skipping 11 matching lines...) Expand all Loading... |
| 506 int y1; | 501 int y1; |
| 507 float degrees; | 502 float degrees; |
| 508 int x2; | 503 int x2; |
| 509 int y2; | 504 int y2; |
| 510 } test_cases[] = { | 505 } test_cases[] = { |
| 511 { 1, 0, 90.0f, 0, 1}, | 506 { 1, 0, 90.0f, 0, 1}, |
| 512 { 1, 0, -90.0f, 1, 0}, | 507 { 1, 0, -90.0f, 1, 0}, |
| 513 { 1, 0, 90.0f, 0, 1}, | 508 { 1, 0, 90.0f, 0, 1}, |
| 514 { 1, 0, 360.0f, 0, 1}, | 509 { 1, 0, 360.0f, 0, 1}, |
| 515 { 1, 0, 0.0f, 0, 1}, | 510 { 1, 0, 0.0f, 0, 1}, |
| 516 { 1, 0, std::numeric_limits<float>::quiet_NaN(), 1, 0} | |
| 517 }; | 511 }; |
| 518 | 512 |
| 519 Transform xform; | 513 Transform xform; |
| 520 for (size_t i = 0; i < arraysize(test_cases); ++i) { | 514 for (size_t i = 0; i < arraysize(test_cases); ++i) { |
| 521 const TestCase& value = test_cases[i]; | 515 const TestCase& value = test_cases[i]; |
| 522 Transform rotation; | 516 Transform rotation; |
| 523 rotation.Rotate(value.degrees); | 517 rotation.Rotate(value.degrees); |
| 524 xform = rotation * xform; | 518 xform = rotation * xform; |
| 525 Point p1(value.x1, value.y1); | 519 Point p1(value.x1, value.y1); |
| 526 Point p2(value.x2, value.y2); | 520 Point p2(value.x2, value.y2); |
| 527 xform.TransformPoint(&p1); | 521 xform.TransformPoint(&p1); |
| 528 if (value.degrees == value.degrees) { | 522 if (value.degrees == value.degrees) { |
| 529 EXPECT_EQ(p1.x(), p2.x()); | 523 EXPECT_EQ(p1.x(), p2.x()); |
| 530 EXPECT_EQ(p1.y(), p2.y()); | 524 EXPECT_EQ(p1.y(), p2.y()); |
| 531 } | 525 } |
| 532 } | 526 } |
| 533 } | 527 } |
| 534 | 528 |
| 535 TEST(XFormTest, SetTranslate2D) { | 529 TEST(XFormTest, SetTranslate2D) { |
| 536 static const struct TestCase { | 530 static const struct TestCase { |
| 537 int x1; int y1; | 531 int x1; int y1; |
| 538 float tx; float ty; | 532 float tx; float ty; |
| 539 int x2; int y2; | 533 int x2; int y2; |
| 540 } test_cases[] = { | 534 } test_cases[] = { |
| 541 { 0, 0, 10.0f, 20.0f, 10, 20}, | 535 { 0, 0, 10.0f, 20.0f, 10, 20}, |
| 542 { 10, 20, 10.0f, 20.0f, 20, 40}, | 536 { 10, 20, 10.0f, 20.0f, 20, 40}, |
| 543 { 10, 20, 0.0f, 0.0f, 10, 20}, | 537 { 10, 20, 0.0f, 0.0f, 10, 20}, |
| 544 { 0, 0, | |
| 545 std::numeric_limits<float>::quiet_NaN(), | |
| 546 std::numeric_limits<float>::quiet_NaN(), | |
| 547 0, 0} | |
| 548 }; | 538 }; |
| 549 | 539 |
| 550 for (size_t i = 0; i < arraysize(test_cases); ++i) { | 540 for (size_t i = 0; i < arraysize(test_cases); ++i) { |
| 551 const TestCase& value = test_cases[i]; | 541 const TestCase& value = test_cases[i]; |
| 552 for (int j = -1; j < 2; ++j) { | 542 for (int j = -1; j < 2; ++j) { |
| 553 for (int k = 0; k < 3; ++k) { | 543 for (int k = 0; k < 3; ++k) { |
| 554 float epsilon = 0.0001f; | 544 float epsilon = 0.0001f; |
| 555 Point p0, p1, p2; | 545 Point p0, p1, p2; |
| 556 Transform xform; | 546 Transform xform; |
| 557 switch (k) { | 547 switch (k) { |
| (...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 590 TEST(XFormTest, SetScale2D) { | 580 TEST(XFormTest, SetScale2D) { |
| 591 static const struct TestCase { | 581 static const struct TestCase { |
| 592 int before; | 582 int before; |
| 593 float s; | 583 float s; |
| 594 int after; | 584 int after; |
| 595 } test_cases[] = { | 585 } test_cases[] = { |
| 596 { 1, 10.0f, 10}, | 586 { 1, 10.0f, 10}, |
| 597 { 1, 1.0f, 1}, | 587 { 1, 1.0f, 1}, |
| 598 { 1, 0.0f, 0}, | 588 { 1, 0.0f, 0}, |
| 599 { 0, 10.0f, 0}, | 589 { 0, 10.0f, 0}, |
| 600 { 1, std::numeric_limits<float>::quiet_NaN(), 0}, | |
| 601 }; | 590 }; |
| 602 | 591 |
| 603 for (size_t i = 0; i < arraysize(test_cases); ++i) { | 592 for (size_t i = 0; i < arraysize(test_cases); ++i) { |
| 604 const TestCase& value = test_cases[i]; | 593 const TestCase& value = test_cases[i]; |
| 605 for (int j = -1; j < 2; ++j) { | 594 for (int j = -1; j < 2; ++j) { |
| 606 for (int k = 0; k < 3; ++k) { | 595 for (int k = 0; k < 3; ++k) { |
| 607 float epsilon = 0.0001f; | 596 float epsilon = 0.0001f; |
| 608 Point p0, p1, p2; | 597 Point p0, p1, p2; |
| 609 Transform xform; | 598 Transform xform; |
| 610 switch (k) { | 599 switch (k) { |
| (...skipping 2093 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2704 // Rounding should only affect 2d translation components. | 2693 // Rounding should only affect 2d translation components. |
| 2705 translation.Translate3d(0.f, 0.f, 0.5f); | 2694 translation.Translate3d(0.f, 0.f, 0.5f); |
| 2706 expected.Translate3d(0.f, 0.f, 0.5f); | 2695 expected.Translate3d(0.f, 0.f, 0.5f); |
| 2707 translation.RoundTranslationComponents(); | 2696 translation.RoundTranslationComponents(); |
| 2708 EXPECT_EQ(expected.ToString(), translation.ToString()); | 2697 EXPECT_EQ(expected.ToString(), translation.ToString()); |
| 2709 } | 2698 } |
| 2710 | 2699 |
| 2711 } // namespace | 2700 } // namespace |
| 2712 | 2701 |
| 2713 } // namespace gfx | 2702 } // namespace gfx |
| OLD | NEW |