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

Side by Side Diff: tests/PathTest.cpp

Issue 2006383002: preserve rrect/oval dir (Closed) Base URL: https://chromium.googlesource.com/skia.git@SkTypes
Patch Set: Improve tests Created 4 years, 6 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/SkPathRef.cpp ('k') | tests/RRectInPathTest.cpp » ('j') | 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 "SkGeometry.h" 9 #include "SkGeometry.h"
10 #include "SkPaint.h" 10 #include "SkPaint.h"
(...skipping 2197 matching lines...) Expand 10 before | Expand all | Expand 10 after
2208 SkReader32 reader(storage.get(), size); 2208 SkReader32 reader(storage.get(), size);
2209 2209
2210 SkPath readBack; 2210 SkPath readBack;
2211 REPORTER_ASSERT(reporter, readBack != p); 2211 REPORTER_ASSERT(reporter, readBack != p);
2212 reader.readPath(&readBack); 2212 reader.readPath(&readBack);
2213 REPORTER_ASSERT(reporter, readBack == p); 2213 REPORTER_ASSERT(reporter, readBack == p);
2214 2214
2215 REPORTER_ASSERT(reporter, readBack.getConvexityOrUnknown() == 2215 REPORTER_ASSERT(reporter, readBack.getConvexityOrUnknown() ==
2216 p.getConvexityOrUnknown()); 2216 p.getConvexityOrUnknown());
2217 2217
2218 SkRect oval0, oval1;
2219 SkPath::Direction dir0, dir1;
2220 unsigned start0, start1;
2218 REPORTER_ASSERT(reporter, readBack.isOval(nullptr) == p.isOval(nullptr)); 2221 REPORTER_ASSERT(reporter, readBack.isOval(nullptr) == p.isOval(nullptr));
2219 2222 if (p.isOval(&oval0, &dir0, &start0) && readBack.isOval(&oval1, &dir1, &star t1)) {
2223 REPORTER_ASSERT(reporter, oval0 == oval1);
2224 REPORTER_ASSERT(reporter, dir0 == dir1);
2225 REPORTER_ASSERT(reporter, start0 == start1);
2226 }
2227 REPORTER_ASSERT(reporter, readBack.isRRect(nullptr) == p.isRRect(nullptr));
2228 SkRRect rrect0, rrect1;
2229 if (p.isRRect(&rrect0, &dir0, &start0) && readBack.isRRect(&rrect1, &dir1, & start1)) {
2230 REPORTER_ASSERT(reporter, rrect0 == rrect1);
2231 REPORTER_ASSERT(reporter, dir0 == dir1);
2232 REPORTER_ASSERT(reporter, start0 == start1);
2233 }
2220 const SkRect& origBounds = p.getBounds(); 2234 const SkRect& origBounds = p.getBounds();
2221 const SkRect& readBackBounds = readBack.getBounds(); 2235 const SkRect& readBackBounds = readBack.getBounds();
2222 2236
2223 REPORTER_ASSERT(reporter, origBounds == readBackBounds); 2237 REPORTER_ASSERT(reporter, origBounds == readBackBounds);
2224 } 2238 }
2225 2239
2226 static void test_flattening(skiatest::Reporter* reporter) { 2240 static void test_flattening(skiatest::Reporter* reporter) {
2227 SkPath p; 2241 SkPath p;
2228 2242
2229 static const SkPoint pts[] = { 2243 static const SkPoint pts[] = {
(...skipping 653 matching lines...) Expand 10 before | Expand all | Expand 10 after
2883 REPORTER_ASSERT(reporter, numIterVerbs == numVerbs); 2897 REPORTER_ASSERT(reporter, numIterVerbs == numVerbs);
2884 } 2898 }
2885 } 2899 }
2886 2900
2887 static void check_for_circle(skiatest::Reporter* reporter, 2901 static void check_for_circle(skiatest::Reporter* reporter,
2888 const SkPath& path, 2902 const SkPath& path,
2889 bool expectedCircle, 2903 bool expectedCircle,
2890 SkPathPriv::FirstDirection expectedDir) { 2904 SkPathPriv::FirstDirection expectedDir) {
2891 SkRect rect = SkRect::MakeEmpty(); 2905 SkRect rect = SkRect::MakeEmpty();
2892 REPORTER_ASSERT(reporter, path.isOval(&rect) == expectedCircle); 2906 REPORTER_ASSERT(reporter, path.isOval(&rect) == expectedCircle);
2907 SkPath::Direction isOvalDir;
2908 unsigned isOvalStart;
2909 if (path.isOval(&rect, &isOvalDir, &isOvalStart)) {
2910 REPORTER_ASSERT(reporter, rect.height() == rect.width());
2911 REPORTER_ASSERT(reporter, SkPathPriv::AsFirstDirection(isOvalDir) == exp ectedDir);
2912 SkPath tmpPath;
2913 tmpPath.addOval(rect, isOvalDir, isOvalStart);
2914 REPORTER_ASSERT(reporter, path == tmpPath);
2915 }
2893 REPORTER_ASSERT(reporter, SkPathPriv::CheapIsFirstDirection(path, expectedDi r)); 2916 REPORTER_ASSERT(reporter, SkPathPriv::CheapIsFirstDirection(path, expectedDi r));
2894
2895 if (expectedCircle) {
2896 REPORTER_ASSERT(reporter, rect.height() == rect.width());
2897 }
2898 } 2917 }
2899 2918
2900 static void test_circle_skew(skiatest::Reporter* reporter, 2919 static void test_circle_skew(skiatest::Reporter* reporter,
2901 const SkPath& path, 2920 const SkPath& path,
2902 SkPathPriv::FirstDirection dir) { 2921 SkPathPriv::FirstDirection dir) {
2903 SkPath tmp; 2922 SkPath tmp;
2904 2923
2905 SkMatrix m; 2924 SkMatrix m;
2906 m.setSkew(SkIntToScalar(3), SkIntToScalar(5)); 2925 m.setSkew(SkIntToScalar(3), SkIntToScalar(5));
2907 path.transform(m, &tmp); 2926 path.transform(m, &tmp);
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after
2956 } 2975 }
2957 2976
2958 static void test_circle_mirror_x(skiatest::Reporter* reporter, 2977 static void test_circle_mirror_x(skiatest::Reporter* reporter,
2959 const SkPath& path, 2978 const SkPath& path,
2960 SkPathPriv::FirstDirection dir) { 2979 SkPathPriv::FirstDirection dir) {
2961 SkPath tmp; 2980 SkPath tmp;
2962 SkMatrix m; 2981 SkMatrix m;
2963 m.reset(); 2982 m.reset();
2964 m.setScaleX(-SK_Scalar1); 2983 m.setScaleX(-SK_Scalar1);
2965 path.transform(m, &tmp); 2984 path.transform(m, &tmp);
2966
2967 if (SkPathPriv::kCW_FirstDirection == dir) { 2985 if (SkPathPriv::kCW_FirstDirection == dir) {
2968 dir = SkPathPriv::kCCW_FirstDirection; 2986 dir = SkPathPriv::kCCW_FirstDirection;
2969 } else { 2987 } else {
2970 REPORTER_ASSERT(reporter, SkPathPriv::kCCW_FirstDirection == dir); 2988 REPORTER_ASSERT(reporter, SkPathPriv::kCCW_FirstDirection == dir);
2971 dir = SkPathPriv::kCW_FirstDirection; 2989 dir = SkPathPriv::kCW_FirstDirection;
2972 } 2990 }
2973
2974 check_for_circle(reporter, tmp, true, dir); 2991 check_for_circle(reporter, tmp, true, dir);
2975 } 2992 }
2976 2993
2977 static void test_circle_mirror_y(skiatest::Reporter* reporter, 2994 static void test_circle_mirror_y(skiatest::Reporter* reporter,
2978 const SkPath& path, 2995 const SkPath& path,
2979 SkPathPriv::FirstDirection dir) { 2996 SkPathPriv::FirstDirection dir) {
2980 SkPath tmp; 2997 SkPath tmp;
2981 SkMatrix m; 2998 SkMatrix m;
2982 m.reset(); 2999 m.reset();
2983 m.setScaleY(-SK_Scalar1); 3000 m.setScaleY(-SK_Scalar1);
(...skipping 27 matching lines...) Expand all
3011 const SkPathPriv::FirstDirection dir = SkPathPriv::AsFirstDirection(inDir); 3028 const SkPathPriv::FirstDirection dir = SkPathPriv::AsFirstDirection(inDir);
3012 SkPath path; 3029 SkPath path;
3013 3030
3014 // circle at origin 3031 // circle at origin
3015 path.addCircle(0, 0, SkIntToScalar(20), inDir); 3032 path.addCircle(0, 0, SkIntToScalar(20), inDir);
3016 3033
3017 check_for_circle(reporter, path, true, dir); 3034 check_for_circle(reporter, path, true, dir);
3018 test_circle_rotate(reporter, path, dir); 3035 test_circle_rotate(reporter, path, dir);
3019 test_circle_translate(reporter, path, dir); 3036 test_circle_translate(reporter, path, dir);
3020 test_circle_skew(reporter, path, dir); 3037 test_circle_skew(reporter, path, dir);
3038 test_circle_mirror_x(reporter, path, dir);
3039 test_circle_mirror_y(reporter, path, dir);
3040 test_circle_mirror_xy(reporter, path, dir);
3021 3041
3022 // circle at an offset at (10, 10) 3042 // circle at an offset at (10, 10)
3023 path.reset(); 3043 path.reset();
3024 path.addCircle(SkIntToScalar(10), SkIntToScalar(10), 3044 path.addCircle(SkIntToScalar(10), SkIntToScalar(10),
3025 SkIntToScalar(20), inDir); 3045 SkIntToScalar(20), inDir);
3026 3046
3027 check_for_circle(reporter, path, true, dir); 3047 check_for_circle(reporter, path, true, dir);
3028 test_circle_rotate(reporter, path, dir); 3048 test_circle_rotate(reporter, path, dir);
3029 test_circle_translate(reporter, path, dir); 3049 test_circle_translate(reporter, path, dir);
3030 test_circle_skew(reporter, path, dir); 3050 test_circle_skew(reporter, path, dir);
3031 test_circle_mirror_x(reporter, path, dir); 3051 test_circle_mirror_x(reporter, path, dir);
3032 test_circle_mirror_y(reporter, path, dir); 3052 test_circle_mirror_y(reporter, path, dir);
3033 test_circle_mirror_xy(reporter, path, dir); 3053 test_circle_mirror_xy(reporter, path, dir);
3054
3055 // Try different starting points for the contour.
3056 for (unsigned start = 0; start < 4; ++start) {
3057 path.reset();
3058 path.addOval(SkRect::MakeXYWH(20, 10, 5, 5), inDir, start);
3059 test_circle_rotate(reporter, path, dir);
3060 test_circle_translate(reporter, path, dir);
3061 test_circle_skew(reporter, path, dir);
3062 test_circle_mirror_x(reporter, path, dir);
3063 test_circle_mirror_y(reporter, path, dir);
3064 test_circle_mirror_xy(reporter, path, dir);
3065 }
3034 } 3066 }
3035 3067
3036 static void test_circle_with_add_paths(skiatest::Reporter* reporter) { 3068 static void test_circle_with_add_paths(skiatest::Reporter* reporter) {
3037 SkPath path; 3069 SkPath path;
3038 SkPath circle; 3070 SkPath circle;
3039 SkPath rect; 3071 SkPath rect;
3040 SkPath empty; 3072 SkPath empty;
3041 3073
3042 const SkPath::Direction kCircleDir = SkPath::kCW_Direction; 3074 const SkPath::Direction kCircleDir = SkPath::kCW_Direction;
3043 const SkPath::Direction kCircleDirOpposite = SkPath::kCCW_Direction; 3075 const SkPath::Direction kCircleDirOpposite = SkPath::kCCW_Direction;
3044 3076
3045 circle.addCircle(0, 0, SkIntToScalar(10), kCircleDir); 3077 circle.addCircle(0, 0, SkIntToScalar(10), kCircleDir);
3046 rect.addRect(SkIntToScalar(5), SkIntToScalar(5), 3078 rect.addRect(SkIntToScalar(5), SkIntToScalar(5),
3047 SkIntToScalar(20), SkIntToScalar(20), SkPath::kCW_Direction); 3079 SkIntToScalar(20), SkIntToScalar(20), SkPath::kCW_Direction);
3048 3080
3049 SkMatrix translate; 3081 SkMatrix translate;
3050 translate.setTranslate(SkIntToScalar(12), SkIntToScalar(12)); 3082 translate.setTranslate(SkIntToScalar(12), SkIntToScalar(12));
3051 3083
3052 // Although all the path concatenation related operations leave 3084 // Although all the path concatenation related operations leave
3053 // the path a circle, most mark it as a non-circle for simplicity 3085 // the path a circle, most mark it as a non-circle for simplicity
3054 3086
3055 // empty + circle (translate) 3087 // empty + circle (translate)
3056 path = empty; 3088 path = empty;
3057 path.addPath(circle, translate); 3089 path.addPath(circle, translate);
3058 check_for_circle(reporter, path, false, SkPathPriv::AsFirstDirection(kCircle Dir)); 3090 check_for_circle(reporter, path, false, SkPathPriv::AsFirstDirection(kCircle Dir));
3059 3091
3060 // circle + empty (translate) 3092 // circle + empty (translate)
3061 path = circle; 3093 path = circle;
3062 path.addPath(empty, translate); 3094 path.addPath(empty, translate);
3095
3063 check_for_circle(reporter, path, true, SkPathPriv::AsFirstDirection(kCircleD ir)); 3096 check_for_circle(reporter, path, true, SkPathPriv::AsFirstDirection(kCircleD ir));
3064 3097
3065 // test reverseAddPath 3098 // test reverseAddPath
3066 path = circle; 3099 path = circle;
3067 path.reverseAddPath(rect); 3100 path.reverseAddPath(rect);
3068 check_for_circle(reporter, path, false, SkPathPriv::AsFirstDirection(kCircle DirOpposite)); 3101 check_for_circle(reporter, path, false, SkPathPriv::AsFirstDirection(kCircle DirOpposite));
3069 } 3102 }
3070 3103
3071 static void test_circle(skiatest::Reporter* reporter) { 3104 static void test_circle(skiatest::Reporter* reporter) {
3072 test_circle_with_direction(reporter, SkPath::kCW_Direction); 3105 test_circle_with_direction(reporter, SkPath::kCW_Direction);
(...skipping 22 matching lines...) Expand all
3095 // test negative radius 3128 // test negative radius
3096 path.reset(); 3129 path.reset();
3097 path.addCircle(0, 0, -1, SkPath::kCW_Direction); 3130 path.addCircle(0, 0, -1, SkPath::kCW_Direction);
3098 REPORTER_ASSERT(reporter, path.isEmpty()); 3131 REPORTER_ASSERT(reporter, path.isEmpty());
3099 } 3132 }
3100 3133
3101 static void test_oval(skiatest::Reporter* reporter) { 3134 static void test_oval(skiatest::Reporter* reporter) {
3102 SkRect rect; 3135 SkRect rect;
3103 SkMatrix m; 3136 SkMatrix m;
3104 SkPath path; 3137 SkPath path;
3138 unsigned start;
3139 SkPath::Direction dir;
3105 3140
3106 rect = SkRect::MakeWH(SkIntToScalar(30), SkIntToScalar(50)); 3141 rect = SkRect::MakeWH(SkIntToScalar(30), SkIntToScalar(50));
3107 path.addOval(rect); 3142 path.addOval(rect);
3108 3143
3144 // Defaults to dir = CW and start = 1
3109 REPORTER_ASSERT(reporter, path.isOval(nullptr)); 3145 REPORTER_ASSERT(reporter, path.isOval(nullptr));
3110 3146
3111 m.setRotate(SkIntToScalar(90)); 3147 m.setRotate(SkIntToScalar(90));
3112 SkPath tmp; 3148 SkPath tmp;
3113 path.transform(m, &tmp); 3149 path.transform(m, &tmp);
3114 // an oval rotated 90 degrees is still an oval. 3150 // an oval rotated 90 degrees is still an oval. The start index changes from 1 to 2. Direction
3115 REPORTER_ASSERT(reporter, tmp.isOval(nullptr)); 3151 // is unchanged.
3152 REPORTER_ASSERT(reporter, tmp.isOval(nullptr, &dir, &start));
3153 REPORTER_ASSERT(reporter, 2 == start);
3154 REPORTER_ASSERT(reporter, SkPath::kCW_Direction == dir);
3116 3155
3117 m.reset(); 3156 m.reset();
3118 m.setRotate(SkIntToScalar(30)); 3157 m.setRotate(SkIntToScalar(30));
3119 tmp.reset(); 3158 tmp.reset();
3120 path.transform(m, &tmp); 3159 path.transform(m, &tmp);
3121 // an oval rotated 30 degrees is not an oval anymore. 3160 // an oval rotated 30 degrees is not an oval anymore.
3122 REPORTER_ASSERT(reporter, !tmp.isOval(nullptr)); 3161 REPORTER_ASSERT(reporter, !tmp.isOval(nullptr));
3123 3162
3124 // since empty path being transformed. 3163 // since empty path being transformed.
3125 path.reset(); 3164 path.reset();
(...skipping 17 matching lines...) Expand all
3143 path.reset(); 3182 path.reset();
3144 path.moveTo(0, 0); 3183 path.moveTo(0, 0);
3145 path.addOval(rect); 3184 path.addOval(rect);
3146 REPORTER_ASSERT(reporter, path.isOval(nullptr)); 3185 REPORTER_ASSERT(reporter, path.isOval(nullptr));
3147 3186
3148 // copy path 3187 // copy path
3149 path.reset(); 3188 path.reset();
3150 tmp.reset(); 3189 tmp.reset();
3151 tmp.addOval(rect); 3190 tmp.addOval(rect);
3152 path = tmp; 3191 path = tmp;
3153 REPORTER_ASSERT(reporter, path.isOval(nullptr)); 3192 REPORTER_ASSERT(reporter, path.isOval(nullptr, &dir, &start));
3193 REPORTER_ASSERT(reporter, SkPath::kCW_Direction == dir);
3194 REPORTER_ASSERT(reporter, 1 == start);
3154 } 3195 }
3155 3196
3156 static void test_empty(skiatest::Reporter* reporter, const SkPath& p) { 3197 static void test_empty(skiatest::Reporter* reporter, const SkPath& p) {
3157 SkPath empty; 3198 SkPath empty;
3158 3199
3159 REPORTER_ASSERT(reporter, p.isEmpty()); 3200 REPORTER_ASSERT(reporter, p.isEmpty());
3160 REPORTER_ASSERT(reporter, 0 == p.countPoints()); 3201 REPORTER_ASSERT(reporter, 0 == p.countPoints());
3161 REPORTER_ASSERT(reporter, 0 == p.countVerbs()); 3202 REPORTER_ASSERT(reporter, 0 == p.countVerbs());
3162 REPORTER_ASSERT(reporter, 0 == p.getSegmentMasks()); 3203 REPORTER_ASSERT(reporter, 0 == p.getSegmentMasks());
3163 REPORTER_ASSERT(reporter, p.isConvex()); 3204 REPORTER_ASSERT(reporter, p.isConvex());
(...skipping 931 matching lines...) Expand 10 before | Expand all | Expand 10 after
4095 PathTest_Private::TestPathTo(reporter); 4136 PathTest_Private::TestPathTo(reporter);
4096 PathRefTest_Private::TestPathRef(reporter); 4137 PathRefTest_Private::TestPathRef(reporter);
4097 PathTest_Private::TestPathrefListeners(reporter); 4138 PathTest_Private::TestPathrefListeners(reporter);
4098 test_dump(reporter); 4139 test_dump(reporter);
4099 test_path_crbug389050(reporter); 4140 test_path_crbug389050(reporter);
4100 test_path_crbugskia2820(reporter); 4141 test_path_crbugskia2820(reporter);
4101 test_skbug_3469(reporter); 4142 test_skbug_3469(reporter);
4102 test_skbug_3239(reporter); 4143 test_skbug_3239(reporter);
4103 test_bounds_crbug_513799(reporter); 4144 test_bounds_crbug_513799(reporter);
4104 } 4145 }
OLDNEW
« no previous file with comments | « src/core/SkPathRef.cpp ('k') | tests/RRectInPathTest.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698