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 "SkMath.h" | 8 #include "SkMath.h" |
9 #include "SkMatrix.h" | 9 #include "SkMatrix.h" |
10 #include "SkMatrixUtils.h" | 10 #include "SkMatrixUtils.h" |
(...skipping 935 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
946 a.setTranslate(10, 20); | 946 a.setTranslate(10, 20); |
947 | 947 |
948 SkMatrix b; | 948 SkMatrix b; |
949 b.setScale(3, 5); | 949 b.setScale(3, 5); |
950 | 950 |
951 SkMatrix expected; | 951 SkMatrix expected; |
952 expected.setConcat(a,b); | 952 expected.setConcat(a,b); |
953 | 953 |
954 REPORTER_ASSERT(r, expected == SkMatrix::Concat(a, b)); | 954 REPORTER_ASSERT(r, expected == SkMatrix::Concat(a, b)); |
955 } | 955 } |
| 956 |
| 957 // Test that all variants of maprect are correct. |
| 958 DEF_TEST(Matrix_maprects, r) { |
| 959 const SkScalar scale = 1000; |
| 960 |
| 961 SkMatrix mat; |
| 962 mat.setScale(2, 3); |
| 963 mat.postTranslate(1, 4); |
| 964 |
| 965 SkRandom rand; |
| 966 for (int i = 0; i < 10000; ++i) { |
| 967 SkRect src = SkRect::MakeLTRB(rand.nextSScalar1() * scale, |
| 968 rand.nextSScalar1() * scale, |
| 969 rand.nextSScalar1() * scale, |
| 970 rand.nextSScalar1() * scale); |
| 971 SkRect dst[3]; |
| 972 |
| 973 mat.mapPoints((SkPoint*)&dst[0].fLeft, (SkPoint*)&src.fLeft, 2); |
| 974 dst[0].sort(); |
| 975 mat.mapRect(&dst[1], src); |
| 976 mat.mapRectScaleTranslate(&dst[2], src); |
| 977 |
| 978 REPORTER_ASSERT(r, dst[0] == dst[1]); |
| 979 REPORTER_ASSERT(r, dst[0] == dst[2]); |
| 980 } |
| 981 } |
OLD | NEW |