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

Side by Side Diff: tests/PathTest.cpp

Issue 2017313002: Add SkPathPriv::IsSimpleClosedRect (Closed) Base URL: https://chromium.googlesource.com/skia.git@fixaddarc
Patch Set: fix gcc warning 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/SkPathPriv.h ('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 <cmath> 8 #include <cmath>
9 #include "SkCanvas.h" 9 #include "SkCanvas.h"
10 #include "SkGeometry.h" 10 #include "SkGeometry.h"
(...skipping 1957 matching lines...) Expand 10 before | Expand all | Expand 10 after
1968 for (index = 1; index < SkToInt(SK_ARRAY_COUNT(r1)); ++index) { 1968 for (index = 1; index < SkToInt(SK_ARRAY_COUNT(r1)); ++index) {
1969 if (index == 2) { 1969 if (index == 2) {
1970 path1.cubicTo(1, .5f, 1, .5f, 1, .5f); 1970 path1.cubicTo(1, .5f, 1, .5f, 1, .5f);
1971 } 1971 }
1972 path1.lineTo(r1[index].fX, r1[index].fY); 1972 path1.lineTo(r1[index].fX, r1[index].fY);
1973 } 1973 }
1974 path1.close(); 1974 path1.close();
1975 REPORTER_ASSERT(reporter, !path1.isRect(nullptr)); 1975 REPORTER_ASSERT(reporter, !path1.isRect(nullptr));
1976 } 1976 }
1977 1977
1978 static void check_simple_closed_rect(skiatest::Reporter* reporter, const SkPath& path,
1979 const SkRect& rect, SkPath::Direction dir, unsigned start) {
1980 SkRect r = SkRect::MakeEmpty();
1981 SkPath::Direction d = SkPath::kCCW_Direction;
1982 unsigned s = ~0U;
1983
1984 REPORTER_ASSERT(reporter, SkPathPriv::IsSimpleClosedRect(path, &r, &d, &s));
1985 REPORTER_ASSERT(reporter, r == rect);
1986 REPORTER_ASSERT(reporter, d == dir);
1987 REPORTER_ASSERT(reporter, s == start);
1988 }
1989
1990 static void test_is_simple_closed_rect(skiatest::Reporter* reporter) {
1991 SkRect r = SkRect::MakeEmpty();
1992 SkPath::Direction d = SkPath::kCCW_Direction;
1993 unsigned s = ~0U;
1994
1995 const SkRect testRect = SkRect::MakeXYWH(10, 10, 50, 70);
1996 const SkRect emptyRect = SkRect::MakeEmpty();
1997 SkPath path;
1998 for (int start = 0; start < 4; ++start) {
1999 for (auto dir : {SkPath::kCCW_Direction, SkPath::kCW_Direction}) {
2000 SkPath path;
2001 path.addRect(testRect, dir, start);
2002 check_simple_closed_rect(reporter, path, testRect, dir, start);
2003 path.close();
2004 check_simple_closed_rect(reporter, path, testRect, dir, start);
2005 SkPath path2 = path;
2006 path2.lineTo(10, 10);
2007 REPORTER_ASSERT(reporter, !SkPathPriv::IsSimpleClosedRect(path2, &r, &d, &s));
2008 path2 = path;
2009 path2.moveTo(10, 10);
2010 REPORTER_ASSERT(reporter, !SkPathPriv::IsSimpleClosedRect(path2, &r, &d, &s));
2011 path2 = path;
2012 path2.addRect(testRect, dir, start);
2013 REPORTER_ASSERT(reporter, !SkPathPriv::IsSimpleClosedRect(path2, &r, &d, &s));
2014 // Make the path by hand, manually closing it.
2015 path2.reset();
2016 SkPath::RawIter iter(path);
2017 SkPath::Verb v;
2018 SkPoint verbPts[4];
2019 SkPoint firstPt = {0.f, 0.f};
2020 while ((v = iter.next(verbPts)) != SkPath::kDone_Verb) {
2021 switch(v) {
2022 case SkPath::kMove_Verb:
2023 firstPt = verbPts[0];
2024 path2.moveTo(verbPts[0]);
2025 break;
2026 case SkPath::kLine_Verb:
2027 path2.lineTo(verbPts[1]);
2028 break;
2029 default:
2030 break;
2031 }
2032 }
2033 // We haven't closed it yet...
2034 REPORTER_ASSERT(reporter, !SkPathPriv::IsSimpleClosedRect(path2, &r, &d, &s));
2035 // ... now we do and test again.
2036 path2.lineTo(firstPt);
2037 check_simple_closed_rect(reporter, path2, testRect, dir, start);
2038 // A redundant close shouldn't cause a failure.
2039 path2.close();
2040 check_simple_closed_rect(reporter, path2, testRect, dir, start);
2041 // Degenerate point and line rects are not allowed
2042 path2.reset();
2043 path2.addRect(emptyRect, dir, start);
2044 REPORTER_ASSERT(reporter, !SkPathPriv::IsSimpleClosedRect(path2, &r, &d, &s));
2045 SkRect degenRect = testRect;
2046 degenRect.fLeft = degenRect.fRight;
2047 path2.reset();
2048 path2.addRect(degenRect, dir, start);
2049 REPORTER_ASSERT(reporter, !SkPathPriv::IsSimpleClosedRect(path2, &r, &d, &s));
2050 degenRect = testRect;
2051 degenRect.fTop = degenRect.fBottom;
2052 path2.reset();
2053 path2.addRect(degenRect, dir, start);
2054 REPORTER_ASSERT(reporter, !SkPathPriv::IsSimpleClosedRect(path2, &r, &d, &s));
2055 // An inverted rect makes a rect path, but changes the winding dir a nd start point.
2056 SkPath::Direction swapDir = (dir == SkPath::kCW_Direction)
2057 ? SkPath::kCCW_Direction
2058 : SkPath::kCW_Direction;
2059 static constexpr unsigned kXSwapStarts[] = { 1, 0, 3, 2 };
2060 static constexpr unsigned kYSwapStarts[] = { 3, 2, 1, 0 };
2061 SkRect swapRect = testRect;
2062 SkTSwap(swapRect.fLeft, swapRect.fRight);
2063 path2.reset();
2064 path2.addRect(swapRect, dir, start);
2065 check_simple_closed_rect(reporter, path2, testRect, swapDir, kXSwapS tarts[start]);
2066 swapRect = testRect;
2067 SkTSwap(swapRect.fTop, swapRect.fBottom);
2068 path2.reset();
2069 path2.addRect(swapRect, dir, start);
2070 check_simple_closed_rect(reporter, path2, testRect, swapDir, kYSwapS tarts[start]);
2071 }
2072 }
2073 }
2074
1978 static void test_isNestedFillRects(skiatest::Reporter* reporter) { 2075 static void test_isNestedFillRects(skiatest::Reporter* reporter) {
1979 // passing tests (all moveTo / lineTo... 2076 // passing tests (all moveTo / lineTo...
1980 SkPoint r1[] = {{0, 0}, {1, 0}, {1, 1}, {0, 1}}; // CW 2077 SkPoint r1[] = {{0, 0}, {1, 0}, {1, 1}, {0, 1}}; // CW
1981 SkPoint r2[] = {{1, 0}, {1, 1}, {0, 1}, {0, 0}}; 2078 SkPoint r2[] = {{1, 0}, {1, 1}, {0, 1}, {0, 0}};
1982 SkPoint r3[] = {{1, 1}, {0, 1}, {0, 0}, {1, 0}}; 2079 SkPoint r3[] = {{1, 1}, {0, 1}, {0, 0}, {1, 0}};
1983 SkPoint r4[] = {{0, 1}, {0, 0}, {1, 0}, {1, 1}}; 2080 SkPoint r4[] = {{0, 1}, {0, 0}, {1, 0}, {1, 1}};
1984 SkPoint r5[] = {{0, 0}, {0, 1}, {1, 1}, {1, 0}}; // CCW 2081 SkPoint r5[] = {{0, 0}, {0, 1}, {1, 1}, {1, 0}}; // CCW
1985 SkPoint r6[] = {{0, 1}, {1, 1}, {1, 0}, {0, 0}}; 2082 SkPoint r6[] = {{0, 1}, {1, 1}, {1, 0}, {0, 0}};
1986 SkPoint r7[] = {{1, 1}, {1, 0}, {0, 0}, {0, 1}}; 2083 SkPoint r7[] = {{1, 1}, {1, 0}, {0, 0}, {0, 1}};
1987 SkPoint r8[] = {{1, 0}, {0, 0}, {0, 1}, {1, 1}}; 2084 SkPoint r8[] = {{1, 0}, {0, 0}, {0, 1}, {1, 1}};
(...skipping 2155 matching lines...) Expand 10 before | Expand all | Expand 10 after
4143 REPORTER_ASSERT(reporter, r == bounds); 4240 REPORTER_ASSERT(reporter, r == bounds);
4144 // add a moveTo outside of our bounds 4241 // add a moveTo outside of our bounds
4145 p.moveTo(bounds.fLeft + 10, bounds.fBottom + 10); 4242 p.moveTo(bounds.fLeft + 10, bounds.fBottom + 10);
4146 REPORTER_ASSERT(reporter, p.isRect(&r)); 4243 REPORTER_ASSERT(reporter, p.isRect(&r));
4147 REPORTER_ASSERT(reporter, r == bounds); 4244 REPORTER_ASSERT(reporter, r == bounds);
4148 } 4245 }
4149 4246
4150 test_operatorEqual(reporter); 4247 test_operatorEqual(reporter);
4151 test_isLine(reporter); 4248 test_isLine(reporter);
4152 test_isRect(reporter); 4249 test_isRect(reporter);
4250 test_is_simple_closed_rect(reporter);
4153 test_isNestedFillRects(reporter); 4251 test_isNestedFillRects(reporter);
4154 test_zero_length_paths(reporter); 4252 test_zero_length_paths(reporter);
4155 test_direction(reporter); 4253 test_direction(reporter);
4156 test_convexity(reporter); 4254 test_convexity(reporter);
4157 test_convexity2(reporter); 4255 test_convexity2(reporter);
4158 test_conservativelyContains(reporter); 4256 test_conservativelyContains(reporter);
4159 test_close(reporter); 4257 test_close(reporter);
4160 test_segment_masks(reporter); 4258 test_segment_masks(reporter);
4161 test_flattening(reporter); 4259 test_flattening(reporter);
4162 test_transform(reporter); 4260 test_transform(reporter);
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after
4202 PathTest_Private::TestPathTo(reporter); 4300 PathTest_Private::TestPathTo(reporter);
4203 PathRefTest_Private::TestPathRef(reporter); 4301 PathRefTest_Private::TestPathRef(reporter);
4204 PathTest_Private::TestPathrefListeners(reporter); 4302 PathTest_Private::TestPathrefListeners(reporter);
4205 test_dump(reporter); 4303 test_dump(reporter);
4206 test_path_crbug389050(reporter); 4304 test_path_crbug389050(reporter);
4207 test_path_crbugskia2820(reporter); 4305 test_path_crbugskia2820(reporter);
4208 test_skbug_3469(reporter); 4306 test_skbug_3469(reporter);
4209 test_skbug_3239(reporter); 4307 test_skbug_3239(reporter);
4210 test_bounds_crbug_513799(reporter); 4308 test_bounds_crbug_513799(reporter);
4211 } 4309 }
OLDNEW
« no previous file with comments | « src/core/SkPathPriv.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698