OLD | NEW |
1 /* | 1 /* |
2 * Copyright 2011 Google Inc. | 2 * Copyright 2011 Google Inc. |
3 * | 3 * |
4 * Use of this source code is governed by a BSD-style license that can be | 4 * Use of this source code is governed by a BSD-style license that can be |
5 * found in the LICENSE file. | 5 * found in the LICENSE file. |
6 */ | 6 */ |
7 | 7 |
8 #include "SkMatrix44.h" | 8 #include "SkMatrix44.h" |
9 #include "Test.h" | 9 #include "Test.h" |
10 | 10 |
(...skipping 412 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
423 {0.1, 0, 2, -2, | 423 {0.1, 0, 2, -2, |
424 0, 0.05, 3, -3, | 424 0, 0.05, 3, -3, |
425 0, 0, 4.01, -4, | 425 0, 0, 4.01, -4, |
426 0, 0, -1, 1}; | 426 0, 0, -1, 1}; |
427 expected.setRowMajord(expectedInverseAffineAndPerspective); | 427 expected.setRowMajord(expectedInverseAffineAndPerspective); |
428 REPORTER_ASSERT(reporter, nearly_equal(expected, inverse)); | 428 REPORTER_ASSERT(reporter, nearly_equal(expected, inverse)); |
429 | 429 |
430 SkMatrix44 tinyScale(SkMatrix44::kIdentity_Constructor); | 430 SkMatrix44 tinyScale(SkMatrix44::kIdentity_Constructor); |
431 tinyScale.setDouble(0, 0, 1e-39); | 431 tinyScale.setDouble(0, 0, 1e-39); |
432 REPORTER_ASSERT(reporter, tinyScale.getType() == SkMatrix44::kScale_Mask); | 432 REPORTER_ASSERT(reporter, tinyScale.getType() == SkMatrix44::kScale_Mask); |
433 REPORTER_ASSERT(reporter, !tinyScale.invert(NULL)); | 433 REPORTER_ASSERT(reporter, !tinyScale.invert(nullptr)); |
434 REPORTER_ASSERT(reporter, !tinyScale.invert(&inverse)); | 434 REPORTER_ASSERT(reporter, !tinyScale.invert(&inverse)); |
435 | 435 |
436 SkMatrix44 tinyScaleTranslate(SkMatrix44::kIdentity_Constructor); | 436 SkMatrix44 tinyScaleTranslate(SkMatrix44::kIdentity_Constructor); |
437 tinyScaleTranslate.setDouble(0, 0, 1e-38); | 437 tinyScaleTranslate.setDouble(0, 0, 1e-38); |
438 REPORTER_ASSERT(reporter, tinyScaleTranslate.invert(NULL)); | 438 REPORTER_ASSERT(reporter, tinyScaleTranslate.invert(nullptr)); |
439 tinyScaleTranslate.setDouble(0, 3, 10); | 439 tinyScaleTranslate.setDouble(0, 3, 10); |
440 REPORTER_ASSERT( | 440 REPORTER_ASSERT( |
441 reporter, tinyScaleTranslate.getType() == | 441 reporter, tinyScaleTranslate.getType() == |
442 (SkMatrix44::kScale_Mask | SkMatrix44::kTranslate_Mask)); | 442 (SkMatrix44::kScale_Mask | SkMatrix44::kTranslate_Mask)); |
443 REPORTER_ASSERT(reporter, !tinyScaleTranslate.invert(NULL)); | 443 REPORTER_ASSERT(reporter, !tinyScaleTranslate.invert(nullptr)); |
444 REPORTER_ASSERT(reporter, !tinyScaleTranslate.invert(&inverse)); | 444 REPORTER_ASSERT(reporter, !tinyScaleTranslate.invert(&inverse)); |
445 | 445 |
446 SkMatrix44 tinyScalePerspective(SkMatrix44::kIdentity_Constructor); | 446 SkMatrix44 tinyScalePerspective(SkMatrix44::kIdentity_Constructor); |
447 tinyScalePerspective.setDouble(0, 0, 1e-39); | 447 tinyScalePerspective.setDouble(0, 0, 1e-39); |
448 tinyScalePerspective.setDouble(3, 2, -1); | 448 tinyScalePerspective.setDouble(3, 2, -1); |
449 REPORTER_ASSERT(reporter, (tinyScalePerspective.getType() & | 449 REPORTER_ASSERT(reporter, (tinyScalePerspective.getType() & |
450 SkMatrix44::kPerspective_Mask) == | 450 SkMatrix44::kPerspective_Mask) == |
451 SkMatrix44::kPerspective_Mask); | 451 SkMatrix44::kPerspective_Mask); |
452 REPORTER_ASSERT(reporter, !tinyScalePerspective.invert(NULL)); | 452 REPORTER_ASSERT(reporter, !tinyScalePerspective.invert(nullptr)); |
453 REPORTER_ASSERT(reporter, !tinyScalePerspective.invert(&inverse)); | 453 REPORTER_ASSERT(reporter, !tinyScalePerspective.invert(&inverse)); |
454 } | 454 } |
455 | 455 |
456 static void test_transpose(skiatest::Reporter* reporter) { | 456 static void test_transpose(skiatest::Reporter* reporter) { |
457 SkMatrix44 a(SkMatrix44::kUninitialized_Constructor); | 457 SkMatrix44 a(SkMatrix44::kUninitialized_Constructor); |
458 SkMatrix44 b(SkMatrix44::kUninitialized_Constructor); | 458 SkMatrix44 b(SkMatrix44::kUninitialized_Constructor); |
459 | 459 |
460 int i = 0; | 460 int i = 0; |
461 for (int row = 0; row < 4; ++row) { | 461 for (int row = 0; row < 4; ++row) { |
462 for (int col = 0; col < 4; ++col) { | 462 for (int col = 0; col < 4; ++col) { |
(...skipping 365 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
828 REPORTER_ASSERT(reporter, is_identity(iden1)); | 828 REPORTER_ASSERT(reporter, is_identity(iden1)); |
829 | 829 |
830 mat.setScale(SK_MScalar1/2, SK_MScalar1/2, SK_MScalar1/2); | 830 mat.setScale(SK_MScalar1/2, SK_MScalar1/2, SK_MScalar1/2); |
831 mat.invert(&inverse); | 831 mat.invert(&inverse); |
832 iden1.setConcat(mat, inverse); | 832 iden1.setConcat(mat, inverse); |
833 REPORTER_ASSERT(reporter, is_identity(iden1)); | 833 REPORTER_ASSERT(reporter, is_identity(iden1)); |
834 | 834 |
835 mat.setScale(3, 3, 3); | 835 mat.setScale(3, 3, 3); |
836 rot.setRotateDegreesAbout(0, 0, -1, 90); | 836 rot.setRotateDegreesAbout(0, 0, -1, 90); |
837 mat.postConcat(rot); | 837 mat.postConcat(rot); |
838 REPORTER_ASSERT(reporter, mat.invert(NULL)); | 838 REPORTER_ASSERT(reporter, mat.invert(nullptr)); |
839 mat.invert(&inverse); | 839 mat.invert(&inverse); |
840 iden1.setConcat(mat, inverse); | 840 iden1.setConcat(mat, inverse); |
841 REPORTER_ASSERT(reporter, is_identity(iden1)); | 841 REPORTER_ASSERT(reporter, is_identity(iden1)); |
842 iden2.setConcat(inverse, mat); | 842 iden2.setConcat(inverse, mat); |
843 REPORTER_ASSERT(reporter, is_identity(iden2)); | 843 REPORTER_ASSERT(reporter, is_identity(iden2)); |
844 | 844 |
845 // test tiny-valued matrix inverse | 845 // test tiny-valued matrix inverse |
846 mat.reset(); | 846 mat.reset(); |
847 auto v = SkDoubleToMScalar(1.0e-12); | 847 auto v = SkDoubleToMScalar(1.0e-12); |
848 mat.setScale(v,v,v); | 848 mat.setScale(v,v,v); |
849 rot.setRotateDegreesAbout(0, 0, -1, 90); | 849 rot.setRotateDegreesAbout(0, 0, -1, 90); |
850 mat.postConcat(rot); | 850 mat.postConcat(rot); |
851 mat.postTranslate(v,v,v); | 851 mat.postTranslate(v,v,v); |
852 REPORTER_ASSERT(reporter, mat.invert(NULL)); | 852 REPORTER_ASSERT(reporter, mat.invert(nullptr)); |
853 mat.invert(&inverse); | 853 mat.invert(&inverse); |
854 iden1.setConcat(mat, inverse); | 854 iden1.setConcat(mat, inverse); |
855 REPORTER_ASSERT(reporter, is_identity(iden1)); | 855 REPORTER_ASSERT(reporter, is_identity(iden1)); |
856 | 856 |
857 // test mixed-valued matrix inverse | 857 // test mixed-valued matrix inverse |
858 mat.reset(); | 858 mat.reset(); |
859 mat.setScale(SkDoubleToMScalar(1.0e-2), | 859 mat.setScale(SkDoubleToMScalar(1.0e-2), |
860 SkDoubleToMScalar(3.0), | 860 SkDoubleToMScalar(3.0), |
861 SkDoubleToMScalar(1.0e+2)); | 861 SkDoubleToMScalar(1.0e+2)); |
862 rot.setRotateDegreesAbout(0, 0, -1, 90); | 862 rot.setRotateDegreesAbout(0, 0, -1, 90); |
863 mat.postConcat(rot); | 863 mat.postConcat(rot); |
864 mat.postTranslate(SkDoubleToMScalar(1.0e+2), | 864 mat.postTranslate(SkDoubleToMScalar(1.0e+2), |
865 SkDoubleToMScalar(3.0), | 865 SkDoubleToMScalar(3.0), |
866 SkDoubleToMScalar(1.0e-2)); | 866 SkDoubleToMScalar(1.0e-2)); |
867 REPORTER_ASSERT(reporter, mat.invert(NULL)); | 867 REPORTER_ASSERT(reporter, mat.invert(nullptr)); |
868 mat.invert(&inverse); | 868 mat.invert(&inverse); |
869 iden1.setConcat(mat, inverse); | 869 iden1.setConcat(mat, inverse); |
870 REPORTER_ASSERT(reporter, is_identity(iden1)); | 870 REPORTER_ASSERT(reporter, is_identity(iden1)); |
871 | 871 |
872 // test degenerate matrix | 872 // test degenerate matrix |
873 mat.reset(); | 873 mat.reset(); |
874 mat.set3x3(1.0, 1.0, 0.0, 1.0, 0.0, 0.0, 0.0, 1.0, 0.0); | 874 mat.set3x3(1.0, 1.0, 0.0, 1.0, 0.0, 0.0, 0.0, 1.0, 0.0); |
875 REPORTER_ASSERT(reporter, !mat.invert(NULL)); | 875 REPORTER_ASSERT(reporter, !mat.invert(nullptr)); |
876 | 876 |
877 // test rol/col Major getters | 877 // test rol/col Major getters |
878 { | 878 { |
879 mat.setTranslate(2, 3, 4); | 879 mat.setTranslate(2, 3, 4); |
880 float dataf[16]; | 880 float dataf[16]; |
881 double datad[16]; | 881 double datad[16]; |
882 | 882 |
883 mat.asColMajorf(dataf); | 883 mat.asColMajorf(dataf); |
884 assert16<float>(reporter, dataf, | 884 assert16<float>(reporter, dataf, |
885 1, 0, 0, 0, | 885 1, 0, 0, 0, |
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
917 test_get_set_double(reporter); | 917 test_get_set_double(reporter); |
918 test_set_row_col_major(reporter); | 918 test_set_row_col_major(reporter); |
919 test_translate(reporter); | 919 test_translate(reporter); |
920 test_scale(reporter); | 920 test_scale(reporter); |
921 test_map2(reporter); | 921 test_map2(reporter); |
922 test_3x3_conversion(reporter); | 922 test_3x3_conversion(reporter); |
923 test_has_perspective(reporter); | 923 test_has_perspective(reporter); |
924 test_preserves_2d_axis_alignment(reporter); | 924 test_preserves_2d_axis_alignment(reporter); |
925 test_toint(reporter); | 925 test_toint(reporter); |
926 } | 926 } |
OLD | NEW |