Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(2)

Side by Side Diff: tests/PathTest.cpp

Issue 151353006: Adding new 'extend' mode to SkPath::addPath (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: Added test and fix for empty path case Created 6 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « src/core/SkPath.cpp ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 "SkCanvas.h" 8 #include "SkCanvas.h"
9 #include "SkPaint.h" 9 #include "SkPaint.h"
10 #include "SkParse.h" 10 #include "SkParse.h"
(...skipping 3042 matching lines...) Expand 10 before | Expand all | Expand 10 after
3053 q.close(); 3053 q.close();
3054 p.addPath(q, -4, -4); 3054 p.addPath(q, -4, -4);
3055 SkRect expected = {0, 0, 4, 4}; 3055 SkRect expected = {0, 0, 4, 4};
3056 REPORTER_ASSERT(reporter, p.getBounds() == expected); 3056 REPORTER_ASSERT(reporter, p.getBounds() == expected);
3057 p.reset(); 3057 p.reset();
3058 p.reverseAddPath(q); 3058 p.reverseAddPath(q);
3059 SkRect reverseExpected = {4, 4, 8, 8}; 3059 SkRect reverseExpected = {4, 4, 8, 8};
3060 REPORTER_ASSERT(reporter, p.getBounds() == reverseExpected); 3060 REPORTER_ASSERT(reporter, p.getBounds() == reverseExpected);
3061 } 3061 }
3062 3062
3063 static void test_addPathMode(skiatest::Reporter* reporter, bool explicitMoveTo, bool extend) {
3064 SkPath p, q;
3065 if (explicitMoveTo) {
3066 p.moveTo(1, 1);
3067 }
3068 p.lineTo(1, 2);
3069 if (explicitMoveTo) {
3070 q.moveTo(2, 1);
3071 }
3072 q.lineTo(2, 2);
3073 p.addPath(q, extend ? SkPath::kExtend_AddPathMode : SkPath::kAppend_AddPathM ode);
3074 uint8_t verbs[4];
3075 int verbcount = p.getVerbs(verbs, 4);
3076 REPORTER_ASSERT(reporter, verbcount == 4);
3077 REPORTER_ASSERT(reporter, verbs[0] == SkPath::kMove_Verb);
3078 REPORTER_ASSERT(reporter, verbs[1] == SkPath::kLine_Verb);
3079 REPORTER_ASSERT(reporter, verbs[2] == (extend ? SkPath::kLine_Verb : SkPath: :kMove_Verb));
3080 REPORTER_ASSERT(reporter, verbs[3] == SkPath::kLine_Verb);
3081 }
3082
3083 static void test_extendClosedPath(skiatest::Reporter* reporter) {
3084 SkPath p, q;
3085 p.moveTo(1, 1);
3086 p.lineTo(1, 2);
3087 p.lineTo(2, 2);
3088 p.close();
3089 q.moveTo(2, 1);
3090 q.lineTo(2, 3);
3091 p.addPath(q, SkPath::kExtend_AddPathMode);
3092 uint8_t verbs[7];
3093 int verbcount = p.getVerbs(verbs, 7);
3094 REPORTER_ASSERT(reporter, verbcount == 7);
3095 REPORTER_ASSERT(reporter, verbs[0] == SkPath::kMove_Verb);
3096 REPORTER_ASSERT(reporter, verbs[1] == SkPath::kLine_Verb);
3097 REPORTER_ASSERT(reporter, verbs[2] == SkPath::kLine_Verb);
3098 REPORTER_ASSERT(reporter, verbs[3] == SkPath::kClose_Verb);
3099 REPORTER_ASSERT(reporter, verbs[4] == SkPath::kMove_Verb);
3100 REPORTER_ASSERT(reporter, verbs[5] == SkPath::kLine_Verb);
3101 REPORTER_ASSERT(reporter, verbs[6] == SkPath::kLine_Verb);
3102
3103 SkPoint pt;
3104 REPORTER_ASSERT(reporter, p.getLastPt(&pt));
3105 REPORTER_ASSERT(reporter, pt == SkPoint::Make(2, 3));
3106 REPORTER_ASSERT(reporter, p.getPoint(3) == SkPoint::Make(1, 1));
3107 }
3108
3109 static void test_addEmptyPath(skiatest::Reporter* reporter, SkPath::AddPathMode mode) {
3110 SkPath p, q, r;
3111 // case 1: dst is empty
3112 p.moveTo(2, 1);
3113 p.lineTo(2, 3);
3114 q.addPath(p, mode);
3115 REPORTER_ASSERT(reporter, q == p);
3116 // case 2: src is empty
3117 p.addPath(r, mode);
3118 REPORTER_ASSERT(reporter, q == p);
3119 // case 3: src and dst are empty
3120 q.reset();
3121 q.addPath(r, mode);
3122 REPORTER_ASSERT(reporter, q.isEmpty());
3123 }
3124
3063 static void test_conicTo_special_case(skiatest::Reporter* reporter) { 3125 static void test_conicTo_special_case(skiatest::Reporter* reporter) {
3064 SkPath p; 3126 SkPath p;
3065 p.conicTo(1, 2, 3, 4, -1); 3127 p.conicTo(1, 2, 3, 4, -1);
3066 check_path_is_line_and_reset(reporter, &p, 3, 4); 3128 check_path_is_line_and_reset(reporter, &p, 3, 4);
3067 p.conicTo(1, 2, 3, 4, SK_ScalarInfinity); 3129 p.conicTo(1, 2, 3, 4, SK_ScalarInfinity);
3068 check_path_is_line_pair_and_reset(reporter, &p, 1, 2, 3, 4); 3130 check_path_is_line_pair_and_reset(reporter, &p, 1, 2, 3, 4);
3069 p.conicTo(1, 2, 3, 4, 1); 3131 p.conicTo(1, 2, 3, 4, 1);
3070 check_path_is_quad_and_reset(reporter, &p, 1, 2, 3, 4); 3132 check_path_is_quad_and_reset(reporter, &p, 1, 2, 3, 4);
3071 } 3133 }
3072 3134
(...skipping 297 matching lines...) Expand 10 before | Expand all | Expand 10 after
3370 test_bad_cubic_crbug229478(); 3432 test_bad_cubic_crbug229478();
3371 test_bad_cubic_crbug234190(); 3433 test_bad_cubic_crbug234190();
3372 test_android_specific_behavior(reporter); 3434 test_android_specific_behavior(reporter);
3373 test_gen_id(reporter); 3435 test_gen_id(reporter);
3374 test_path_close_issue1474(reporter); 3436 test_path_close_issue1474(reporter);
3375 test_path_to_region(reporter); 3437 test_path_to_region(reporter);
3376 test_rrect(reporter); 3438 test_rrect(reporter);
3377 test_arc(reporter); 3439 test_arc(reporter);
3378 test_arcTo(reporter); 3440 test_arcTo(reporter);
3379 test_addPath(reporter); 3441 test_addPath(reporter);
3442 test_addPathMode(reporter, false, false);
3443 test_addPathMode(reporter, true, false);
3444 test_addPathMode(reporter, false, true);
3445 test_addPathMode(reporter, true, true);
3446 test_extendClosedPath(reporter);
3447 test_addEmptyPath(reporter, SkPath::kExtend_AddPathMode);
3448 test_addEmptyPath(reporter, SkPath::kAppend_AddPathMode);
3380 test_conicTo_special_case(reporter); 3449 test_conicTo_special_case(reporter);
3381 test_get_point(reporter); 3450 test_get_point(reporter);
3382 test_contains(reporter); 3451 test_contains(reporter);
3383 PathTest_Private::TestPathTo(reporter); 3452 PathTest_Private::TestPathTo(reporter);
3384 PathRefTest_Private::TestPathRef(reporter); 3453 PathRefTest_Private::TestPathRef(reporter);
3385 } 3454 }
OLDNEW
« no previous file with comments | « src/core/SkPath.cpp ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698