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 "Test.h" | 8 #include "Test.h" |
9 #include "TestClassDef.h" | 9 #include "TestClassDef.h" |
10 #include "SkCanvas.h" | 10 #include "SkCanvas.h" |
(...skipping 2661 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2672 static const SkPath::Direction kCircleDir = SkPath::kCW_Direction; | 2672 static const SkPath::Direction kCircleDir = SkPath::kCW_Direction; |
2673 static const SkPath::Direction kCircleDirOpposite = SkPath::kCCW_Direction; | 2673 static const SkPath::Direction kCircleDirOpposite = SkPath::kCCW_Direction; |
2674 | 2674 |
2675 circle.addCircle(0, 0, SkIntToScalar(10), kCircleDir); | 2675 circle.addCircle(0, 0, SkIntToScalar(10), kCircleDir); |
2676 rect.addRect(SkIntToScalar(5), SkIntToScalar(5), | 2676 rect.addRect(SkIntToScalar(5), SkIntToScalar(5), |
2677 SkIntToScalar(20), SkIntToScalar(20), SkPath::kCW_Direction); | 2677 SkIntToScalar(20), SkIntToScalar(20), SkPath::kCW_Direction); |
2678 | 2678 |
2679 SkMatrix translate; | 2679 SkMatrix translate; |
2680 translate.setTranslate(SkIntToScalar(12), SkIntToScalar(12)); | 2680 translate.setTranslate(SkIntToScalar(12), SkIntToScalar(12)); |
2681 | 2681 |
2682 // For simplicity, all the path concatenation related operations | 2682 // Although all the path concatenation related operations leave |
2683 // would mark it non-circle, though in theory it's still a circle. | 2683 // the path a circle, most mark it as a non-circle for simplicity |
2684 | 2684 |
2685 // empty + circle (translate) | 2685 // empty + circle (translate) |
2686 path = empty; | 2686 path = empty; |
2687 path.addPath(circle, translate); | 2687 path.addPath(circle, translate); |
2688 check_for_circle(reporter, path, false, kCircleDir); | 2688 check_for_circle(reporter, path, false, kCircleDir); |
2689 | 2689 |
2690 // circle + empty (translate) | 2690 // circle + empty (translate) |
2691 path = circle; | 2691 path = circle; |
2692 path.addPath(empty, translate); | 2692 path.addPath(empty, translate); |
2693 check_for_circle(reporter, path, false, kCircleDir); | 2693 check_for_circle(reporter, path, true, kCircleDir); |
2694 | 2694 |
2695 // test reverseAddPath | 2695 // test reverseAddPath |
2696 path = circle; | 2696 path = circle; |
2697 path.reverseAddPath(rect); | 2697 path.reverseAddPath(rect); |
2698 check_for_circle(reporter, path, false, kCircleDirOpposite); | 2698 check_for_circle(reporter, path, false, kCircleDirOpposite); |
2699 } | 2699 } |
2700 | 2700 |
2701 static void test_circle(skiatest::Reporter* reporter) { | 2701 static void test_circle(skiatest::Reporter* reporter) { |
2702 test_circle_with_direction(reporter, SkPath::kCW_Direction); | 2702 test_circle_with_direction(reporter, SkPath::kCW_Direction); |
2703 test_circle_with_direction(reporter, SkPath::kCCW_Direction); | 2703 test_circle_with_direction(reporter, SkPath::kCCW_Direction); |
(...skipping 427 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3131 p.setFillType(SkPath::kEvenOdd_FillType); | 3131 p.setFillType(SkPath::kEvenOdd_FillType); |
3132 p.moveTo(pts[i].fX, pts[i].fY); | 3132 p.moveTo(pts[i].fX, pts[i].fY); |
3133 p.cubicTo(pts[i + 1].fX, pts[i + 1].fY, pts[i + 2].fX, pts[i + 2].fY, pt
s[i + 3].fX, pts[i + 3].fY); | 3133 p.cubicTo(pts[i + 1].fX, pts[i + 1].fY, pts[i + 2].fX, pts[i + 2].fY, pt
s[i + 3].fX, pts[i + 3].fY); |
3134 p.cubicTo(pts[i + 4].fX, pts[i + 4].fY, pts[i + 5].fX, pts[i + 5].fY, pt
s[i + 6].fX, pts[i + 6].fY); | 3134 p.cubicTo(pts[i + 4].fX, pts[i + 4].fY, pts[i + 5].fX, pts[i + 5].fY, pt
s[i + 6].fX, pts[i + 6].fY); |
3135 p.close(); | 3135 p.close(); |
3136 REPORTER_ASSERT(reporter, p.contains(5.5f, 5.5f)); | 3136 REPORTER_ASSERT(reporter, p.contains(5.5f, 5.5f)); |
3137 REPORTER_ASSERT(reporter, !p.contains(4.5f, 5.5f)); | 3137 REPORTER_ASSERT(reporter, !p.contains(4.5f, 5.5f)); |
3138 } | 3138 } |
3139 } | 3139 } |
3140 | 3140 |
3141 static void test_pathref(skiatest::Reporter* reporter) { | 3141 class PathRefTest_Private { |
3142 static const int kRepeatCnt = 10; | 3142 public: |
| 3143 static void TestPathRef(skiatest::Reporter* reporter) { |
| 3144 static const int kRepeatCnt = 10; |
3143 | 3145 |
3144 SkPathRef* pathRef = SkPathRef::CreateEmpty(); | 3146 SkAutoTUnref<SkPathRef> pathRef(SkNEW(SkPathRef)); |
3145 SkAutoTUnref<SkPathRef> pathRef2(SkPathRef::CreateEmpty()); | |
3146 SkMatrix mat; | |
3147 | 3147 |
3148 mat.setTranslate(10, 10); | 3148 SkPathRef::Editor ed(&pathRef); |
3149 | 3149 |
3150 SkPathRef::CreateTransformedCopy(&pathRef2, *pathRef, mat); | 3150 { |
| 3151 ed.growForRepeatedVerb(SkPath::kMove_Verb, kRepeatCnt); |
| 3152 REPORTER_ASSERT(reporter, kRepeatCnt == pathRef->countVerbs()); |
| 3153 REPORTER_ASSERT(reporter, kRepeatCnt == pathRef->countPoints()); |
| 3154 REPORTER_ASSERT(reporter, 0 == pathRef->getSegmentMasks()); |
| 3155 for (int i = 0; i < kRepeatCnt; ++i) { |
| 3156 REPORTER_ASSERT(reporter, SkPath::kMove_Verb == pathRef->atVerb(
i)); |
| 3157 } |
| 3158 ed.resetToSize(0, 0, 0); |
| 3159 } |
3151 | 3160 |
3152 SkPathRef::Editor ed(&pathRef2); | 3161 { |
| 3162 ed.growForRepeatedVerb(SkPath::kLine_Verb, kRepeatCnt); |
| 3163 REPORTER_ASSERT(reporter, kRepeatCnt == pathRef->countVerbs()); |
| 3164 REPORTER_ASSERT(reporter, kRepeatCnt == pathRef->countPoints()); |
| 3165 REPORTER_ASSERT(reporter, SkPath::kLine_SegmentMask == pathRef->getS
egmentMasks()); |
| 3166 for (int i = 0; i < kRepeatCnt; ++i) { |
| 3167 REPORTER_ASSERT(reporter, SkPath::kLine_Verb == pathRef->atVerb(
i)); |
| 3168 } |
| 3169 ed.resetToSize(0, 0, 0); |
| 3170 } |
3153 | 3171 |
3154 { | 3172 { |
3155 ed.growForRepeatedVerb(SkPath::kMove_Verb, kRepeatCnt); | 3173 ed.growForRepeatedVerb(SkPath::kQuad_Verb, kRepeatCnt); |
3156 REPORTER_ASSERT(reporter, kRepeatCnt == pathRef2->countVerbs()); | 3174 REPORTER_ASSERT(reporter, kRepeatCnt == pathRef->countVerbs()); |
3157 REPORTER_ASSERT(reporter, kRepeatCnt == pathRef2->countPoints()); | 3175 REPORTER_ASSERT(reporter, 2*kRepeatCnt == pathRef->countPoints()); |
3158 REPORTER_ASSERT(reporter, 0 == pathRef2->getSegmentMasks()); | 3176 REPORTER_ASSERT(reporter, SkPath::kQuad_SegmentMask == pathRef->getS
egmentMasks()); |
3159 for (int i = 0; i < kRepeatCnt; ++i) { | 3177 for (int i = 0; i < kRepeatCnt; ++i) { |
3160 REPORTER_ASSERT(reporter, SkPath::kMove_Verb == pathRef2->atVerb(i))
; | 3178 REPORTER_ASSERT(reporter, SkPath::kQuad_Verb == pathRef->atVerb(
i)); |
| 3179 } |
| 3180 ed.resetToSize(0, 0, 0); |
3161 } | 3181 } |
3162 ed.resetToSize(0, 0, 0); | 3182 |
| 3183 { |
| 3184 SkScalar* weights = NULL; |
| 3185 ed.growForRepeatedVerb(SkPath::kConic_Verb, kRepeatCnt, &weights); |
| 3186 REPORTER_ASSERT(reporter, kRepeatCnt == pathRef->countVerbs()); |
| 3187 REPORTER_ASSERT(reporter, 2*kRepeatCnt == pathRef->countPoints()); |
| 3188 REPORTER_ASSERT(reporter, kRepeatCnt == pathRef->countWeights()); |
| 3189 REPORTER_ASSERT(reporter, SkPath::kConic_SegmentMask == pathRef->get
SegmentMasks()); |
| 3190 REPORTER_ASSERT(reporter, NULL != weights); |
| 3191 for (int i = 0; i < kRepeatCnt; ++i) { |
| 3192 REPORTER_ASSERT(reporter, SkPath::kConic_Verb == pathRef->atVerb
(i)); |
| 3193 } |
| 3194 ed.resetToSize(0, 0, 0); |
| 3195 } |
| 3196 |
| 3197 { |
| 3198 ed.growForRepeatedVerb(SkPath::kCubic_Verb, kRepeatCnt); |
| 3199 REPORTER_ASSERT(reporter, kRepeatCnt == pathRef->countVerbs()); |
| 3200 REPORTER_ASSERT(reporter, 3*kRepeatCnt == pathRef->countPoints()); |
| 3201 REPORTER_ASSERT(reporter, SkPath::kCubic_SegmentMask == pathRef->get
SegmentMasks()); |
| 3202 for (int i = 0; i < kRepeatCnt; ++i) { |
| 3203 REPORTER_ASSERT(reporter, SkPath::kCubic_Verb == pathRef->atVerb
(i)); |
| 3204 } |
| 3205 ed.resetToSize(0, 0, 0); |
| 3206 } |
3163 } | 3207 } |
3164 | 3208 }; |
3165 { | |
3166 ed.growForRepeatedVerb(SkPath::kLine_Verb, kRepeatCnt); | |
3167 REPORTER_ASSERT(reporter, kRepeatCnt == pathRef2->countVerbs()); | |
3168 REPORTER_ASSERT(reporter, kRepeatCnt == pathRef2->countPoints()); | |
3169 REPORTER_ASSERT(reporter, SkPath::kLine_SegmentMask == pathRef2->getSegm
entMasks()); | |
3170 for (int i = 0; i < kRepeatCnt; ++i) { | |
3171 REPORTER_ASSERT(reporter, SkPath::kLine_Verb == pathRef2->atVerb(i))
; | |
3172 } | |
3173 ed.resetToSize(0, 0, 0); | |
3174 } | |
3175 | |
3176 { | |
3177 ed.growForRepeatedVerb(SkPath::kQuad_Verb, kRepeatCnt); | |
3178 REPORTER_ASSERT(reporter, kRepeatCnt == pathRef2->countVerbs()); | |
3179 REPORTER_ASSERT(reporter, 2*kRepeatCnt == pathRef2->countPoints()); | |
3180 REPORTER_ASSERT(reporter, SkPath::kQuad_SegmentMask == pathRef2->getSegm
entMasks()); | |
3181 for (int i = 0; i < kRepeatCnt; ++i) { | |
3182 REPORTER_ASSERT(reporter, SkPath::kQuad_Verb == pathRef2->atVerb(i))
; | |
3183 } | |
3184 ed.resetToSize(0, 0, 0); | |
3185 } | |
3186 | |
3187 { | |
3188 SkScalar* weights = NULL; | |
3189 ed.growForRepeatedVerb(SkPath::kConic_Verb, kRepeatCnt, &weights); | |
3190 REPORTER_ASSERT(reporter, kRepeatCnt == pathRef2->countVerbs()); | |
3191 REPORTER_ASSERT(reporter, 2*kRepeatCnt == pathRef2->countPoints()); | |
3192 REPORTER_ASSERT(reporter, kRepeatCnt == pathRef2->countWeights()); | |
3193 REPORTER_ASSERT(reporter, SkPath::kConic_SegmentMask == pathRef2->getSeg
mentMasks()); | |
3194 REPORTER_ASSERT(reporter, NULL != weights); | |
3195 for (int i = 0; i < kRepeatCnt; ++i) { | |
3196 REPORTER_ASSERT(reporter, SkPath::kConic_Verb == pathRef2->atVerb(i)
); | |
3197 } | |
3198 ed.resetToSize(0, 0, 0); | |
3199 } | |
3200 | |
3201 { | |
3202 ed.growForRepeatedVerb(SkPath::kCubic_Verb, kRepeatCnt); | |
3203 REPORTER_ASSERT(reporter, kRepeatCnt == pathRef2->countVerbs()); | |
3204 REPORTER_ASSERT(reporter, 3*kRepeatCnt == pathRef2->countPoints()); | |
3205 REPORTER_ASSERT(reporter, SkPath::kCubic_SegmentMask == pathRef2->getSeg
mentMasks()); | |
3206 for (int i = 0; i < kRepeatCnt; ++i) { | |
3207 REPORTER_ASSERT(reporter, SkPath::kCubic_Verb == pathRef2->atVerb(i)
); | |
3208 } | |
3209 ed.resetToSize(0, 0, 0); | |
3210 } | |
3211 } | |
3212 | 3209 |
3213 static void test_operatorEqual(skiatest::Reporter* reporter) { | 3210 static void test_operatorEqual(skiatest::Reporter* reporter) { |
3214 SkPath a; | 3211 SkPath a; |
3215 SkPath b; | 3212 SkPath b; |
3216 REPORTER_ASSERT(reporter, a == a); | 3213 REPORTER_ASSERT(reporter, a == a); |
3217 REPORTER_ASSERT(reporter, a == b); | 3214 REPORTER_ASSERT(reporter, a == b); |
3218 a.setFillType(SkPath::kInverseWinding_FillType); | 3215 a.setFillType(SkPath::kInverseWinding_FillType); |
3219 REPORTER_ASSERT(reporter, a != b); | 3216 REPORTER_ASSERT(reporter, a != b); |
3220 a.reset(); | 3217 a.reset(); |
3221 REPORTER_ASSERT(reporter, a == b); | 3218 REPORTER_ASSERT(reporter, a == b); |
(...skipping 140 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3362 test_gen_id(reporter); | 3359 test_gen_id(reporter); |
3363 test_path_close_issue1474(reporter); | 3360 test_path_close_issue1474(reporter); |
3364 test_path_to_region(reporter); | 3361 test_path_to_region(reporter); |
3365 test_rrect(reporter); | 3362 test_rrect(reporter); |
3366 test_arc(reporter); | 3363 test_arc(reporter); |
3367 test_arcTo(reporter); | 3364 test_arcTo(reporter); |
3368 test_addPath(reporter); | 3365 test_addPath(reporter); |
3369 test_conicTo_special_case(reporter); | 3366 test_conicTo_special_case(reporter); |
3370 test_get_point(reporter); | 3367 test_get_point(reporter); |
3371 test_contains(reporter); | 3368 test_contains(reporter); |
3372 test_pathref(reporter); | |
3373 PathTest_Private::TestPathTo(reporter); | 3369 PathTest_Private::TestPathTo(reporter); |
| 3370 PathRefTest_Private::TestPathRef(reporter); |
3374 } | 3371 } |
OLD | NEW |