OLD | NEW |
1 /* | 1 /* |
2 * Copyright 2012 Google Inc. | 2 * Copyright 2012 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 "SkMatrix.h" | 8 #include "SkMatrix.h" |
9 #include "SkRRect.h" | 9 #include "SkRRect.h" |
10 #include "Test.h" | 10 #include "Test.h" |
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
53 | 53 |
54 SkRRect rr1; | 54 SkRRect rr1; |
55 rr1.setRect(rect); | 55 rr1.setRect(rect); |
56 | 56 |
57 REPORTER_ASSERT(reporter, SkRRect::kRect_Type == rr1.type()); | 57 REPORTER_ASSERT(reporter, SkRRect::kRect_Type == rr1.type()); |
58 REPORTER_ASSERT(reporter, rr1.rect() == rect); | 58 REPORTER_ASSERT(reporter, rr1.rect() == rect); |
59 | 59 |
60 for (int i = 0; i < 4; ++i) { | 60 for (int i = 0; i < 4; ++i) { |
61 REPORTER_ASSERT(reporter, zeroPt == rr1.radii((SkRRect::Corner) i)); | 61 REPORTER_ASSERT(reporter, zeroPt == rr1.radii((SkRRect::Corner) i)); |
62 } | 62 } |
63 SkRRect rr1_2; // construct the same RR using the most general set function | |
64 SkVector rr1_2_radii[4] = { { 0, 0 }, { 0, 0 }, { 0, 0 }, { 0, 0 } }; | |
65 rr1_2.setRectRadii(rect, rr1_2_radii); | |
66 REPORTER_ASSERT(reporter, rr1_2 == rr1 && rr1_2.getType() == rr1.getType()); | |
67 SkRRect rr1_3; // construct the same RR using the nine patch set function | |
68 rr1_3.setNinePatch(rect, 0, 0, 0, 0); | |
69 REPORTER_ASSERT(reporter, rr1_3 == rr1 && rr1_3.getType() == rr1.getType()); | |
70 | 63 |
71 //---- | 64 //---- |
72 SkPoint halfPoint = { SkScalarHalf(kWidth), SkScalarHalf(kHeight) }; | 65 SkPoint halfPoint = { SkScalarHalf(kWidth), SkScalarHalf(kHeight) }; |
73 SkRRect rr2; | 66 SkRRect rr2; |
74 rr2.setOval(rect); | 67 rr2.setOval(rect); |
75 | 68 |
76 REPORTER_ASSERT(reporter, SkRRect::kOval_Type == rr2.type()); | 69 REPORTER_ASSERT(reporter, SkRRect::kOval_Type == rr2.type()); |
77 REPORTER_ASSERT(reporter, rr2.rect() == rect); | 70 REPORTER_ASSERT(reporter, rr2.rect() == rect); |
78 | 71 |
79 for (int i = 0; i < 4; ++i) { | 72 for (int i = 0; i < 4; ++i) { |
80 REPORTER_ASSERT(reporter, | 73 REPORTER_ASSERT(reporter, |
81 rr2.radii((SkRRect::Corner) i).equalsWithinTolerance(hal
fPoint)); | 74 rr2.radii((SkRRect::Corner) i).equalsWithinTolerance(hal
fPoint)); |
82 } | 75 } |
83 SkRRect rr2_2; // construct the same RR using the most general set function | |
84 SkVector rr2_2_radii[4] = { { halfPoint.fX, halfPoint.fY }, { halfPoint.fX,
halfPoint.fY }, | |
85 { halfPoint.fX, halfPoint.fY }, { halfPoint.fX,
halfPoint.fY } }; | |
86 rr2_2.setRectRadii(rect, rr2_2_radii); | |
87 REPORTER_ASSERT(reporter, rr2_2 == rr2 && rr2_2.getType() == rr2.getType()); | |
88 SkRRect rr2_3; // construct the same RR using the nine patch set function | |
89 rr2_3.setNinePatch(rect, halfPoint.fX, halfPoint.fY, halfPoint.fX, halfPoint
.fY); | |
90 REPORTER_ASSERT(reporter, rr2_3 == rr2 && rr2_3.getType() == rr2.getType()); | |
91 | 76 |
92 //---- | 77 //---- |
93 SkPoint p = { 5, 5 }; | 78 SkPoint p = { 5, 5 }; |
94 SkRRect rr3; | 79 SkRRect rr3; |
95 rr3.setRectXY(rect, p.fX, p.fY); | 80 rr3.setRectXY(rect, p.fX, p.fY); |
96 | 81 |
97 REPORTER_ASSERT(reporter, SkRRect::kSimple_Type == rr3.type()); | 82 REPORTER_ASSERT(reporter, SkRRect::kSimple_Type == rr3.type()); |
98 REPORTER_ASSERT(reporter, rr3.rect() == rect); | 83 REPORTER_ASSERT(reporter, rr3.rect() == rect); |
99 | 84 |
100 for (int i = 0; i < 4; ++i) { | 85 for (int i = 0; i < 4; ++i) { |
101 REPORTER_ASSERT(reporter, p == rr3.radii((SkRRect::Corner) i)); | 86 REPORTER_ASSERT(reporter, p == rr3.radii((SkRRect::Corner) i)); |
102 } | 87 } |
103 SkRRect rr3_2; // construct the same RR using the most general set function | |
104 SkVector rr3_2_radii[4] = { { 5, 5 }, { 5, 5 }, { 5, 5 }, { 5, 5 } }; | |
105 rr3_2.setRectRadii(rect, rr3_2_radii); | |
106 REPORTER_ASSERT(reporter, rr3_2 == rr3 && rr3_2.getType() == rr3.getType()); | |
107 SkRRect rr3_3; // construct the same RR using the nine patch set function | |
108 rr3_3.setNinePatch(rect, 5, 5, 5, 5); | |
109 REPORTER_ASSERT(reporter, rr3_3 == rr3 && rr3_3.getType() == rr3.getType()); | |
110 | 88 |
111 //---- | 89 //---- |
112 SkRect ninePatchRadii = { 10, 9, 8, 7 }; | 90 SkPoint radii[4] = { { 5, 5 }, { 5, 5 }, { 5, 5 }, { 5, 5 } }; |
113 | 91 |
114 SkRRect rr4; | 92 SkRRect rr4; |
115 rr4.setNinePatch(rect, ninePatchRadii.fLeft, ninePatchRadii.fTop, ninePatchR
adii.fRight, | 93 rr4.setRectRadii(rect, radii); |
116 ninePatchRadii.fBottom); | |
117 | 94 |
118 REPORTER_ASSERT(reporter, SkRRect::kNinePatch_Type == rr4.type()); | 95 REPORTER_ASSERT(reporter, SkRRect::kSimple_Type == rr4.type()); |
119 REPORTER_ASSERT(reporter, rr4.rect() == rect); | 96 REPORTER_ASSERT(reporter, rr4.rect() == rect); |
120 | 97 |
121 SkPoint rquad[4]; | |
122 ninePatchRadii.toQuad(rquad); | |
123 for (int i = 0; i < 4; ++i) { | 98 for (int i = 0; i < 4; ++i) { |
124 REPORTER_ASSERT(reporter, rquad[i] == rr4.radii((SkRRect::Corner) i)); | 99 REPORTER_ASSERT(reporter, radii[i] == rr4.radii((SkRRect::Corner) i)); |
125 } | 100 } |
126 SkRRect rr4_2; // construct the same RR using the most general set function | |
127 SkVector rr4_2_radii[4] = { { 10, 9 }, { 8, 9 }, {8, 7 }, { 10, 7 } }; | |
128 rr4_2.setRectRadii(rect, rr4_2_radii); | |
129 REPORTER_ASSERT(reporter, rr4_2 == rr4 && rr4_2.getType() == rr4.getType()); | |
130 | 101 |
131 //---- | 102 //---- |
132 SkPoint radii2[4] = { { 0, 0 }, { 0, 0 }, { 50, 50 }, { 20, 50 } }; | 103 SkPoint radii2[4] = { { 0, 0 }, { 0, 0 }, { 50, 50 }, { 20, 50 } }; |
133 | 104 |
134 SkRRect rr5; | 105 SkRRect rr5; |
135 rr5.setRectRadii(rect, radii2); | 106 rr5.setRectRadii(rect, radii2); |
136 | 107 |
137 REPORTER_ASSERT(reporter, SkRRect::kComplex_Type == rr5.type()); | 108 REPORTER_ASSERT(reporter, SkRRect::kComplex_Type == rr5.type()); |
138 REPORTER_ASSERT(reporter, rr5.rect() == rect); | 109 REPORTER_ASSERT(reporter, rr5.rect() == rect); |
139 | 110 |
140 for (int i = 0; i < 4; ++i) { | 111 for (int i = 0; i < 4; ++i) { |
141 REPORTER_ASSERT(reporter, radii2[i] == rr5.radii((SkRRect::Corner) i)); | 112 REPORTER_ASSERT(reporter, radii2[i] == rr5.radii((SkRRect::Corner) i)); |
142 } | 113 } |
143 | 114 |
144 // Test out == & != | 115 // Test out == & != |
145 REPORTER_ASSERT(reporter, empty != rr3); | 116 REPORTER_ASSERT(reporter, empty != rr3); |
146 REPORTER_ASSERT(reporter, rr3 != rr4); | 117 REPORTER_ASSERT(reporter, rr3 == rr4); |
147 REPORTER_ASSERT(reporter, rr4 != rr5); | 118 REPORTER_ASSERT(reporter, rr4 != rr5); |
148 } | 119 } |
149 | 120 |
150 // Test out the cases when the RR degenerates to a rect | 121 // Test out the cases when the RR degenerates to a rect |
151 static void test_round_rect_rects(skiatest::Reporter* reporter) { | 122 static void test_round_rect_rects(skiatest::Reporter* reporter) { |
152 SkRect r; | 123 SkRect r; |
153 | 124 |
154 //---- | 125 //---- |
155 SkRRect empty; | 126 SkRRect empty; |
156 | 127 |
(...skipping 428 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
585 DEF_TEST(RoundRect, reporter) { | 556 DEF_TEST(RoundRect, reporter) { |
586 test_round_rect_basic(reporter); | 557 test_round_rect_basic(reporter); |
587 test_round_rect_rects(reporter); | 558 test_round_rect_rects(reporter); |
588 test_round_rect_ovals(reporter); | 559 test_round_rect_ovals(reporter); |
589 test_round_rect_general(reporter); | 560 test_round_rect_general(reporter); |
590 test_round_rect_iffy_parameters(reporter); | 561 test_round_rect_iffy_parameters(reporter); |
591 test_inset(reporter); | 562 test_inset(reporter); |
592 test_round_rect_contains_rect(reporter); | 563 test_round_rect_contains_rect(reporter); |
593 test_round_rect_transform(reporter); | 564 test_round_rect_transform(reporter); |
594 } | 565 } |
OLD | NEW |