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

Side by Side Diff: tests/PathOpsDRectTest.cpp

Issue 1029993002: Revert of pathops version two (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: Created 5 years, 9 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 | « tests/PathOpsDQuadTest.cpp ('k') | tests/PathOpsDTriangleTest.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 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 #include "PathOpsTestCommon.h" 7 #include "PathOpsTestCommon.h"
8 #include "SkPathOpsCubic.h" 8 #include "SkPathOpsCubic.h"
9 #include "SkPathOpsLine.h" 9 #include "SkPathOpsLine.h"
10 #include "SkPathOpsQuad.h" 10 #include "SkPathOpsQuad.h"
11 #include "SkPathOpsRect.h" 11 #include "SkPathOpsRect.h"
12 #include "Test.h" 12 #include "Test.h"
13 13
14 static const SkDLine lineTests[] = {
15 {{{2, 1}, {2, 1}}},
16 {{{2, 1}, {1, 1}}},
17 {{{2, 1}, {2, 2}}},
18 {{{1, 1}, {2, 2}}},
19 {{{3, 0}, {2, 1}}},
20 {{{3, 2}, {1, 1}}},
21 };
22
14 static const SkDQuad quadTests[] = { 23 static const SkDQuad quadTests[] = {
15 {{{1, 1}, {2, 1}, {0, 2}}}, 24 {{{1, 1}, {2, 1}, {0, 2}}},
16 {{{0, 0}, {1, 1}, {3, 1}}}, 25 {{{0, 0}, {1, 1}, {3, 1}}},
17 {{{2, 0}, {1, 1}, {2, 2}}}, 26 {{{2, 0}, {1, 1}, {2, 2}}},
18 {{{4, 0}, {0, 1}, {4, 2}}}, 27 {{{4, 0}, {0, 1}, {4, 2}}},
19 {{{0, 0}, {0, 1}, {1, 1}}}, 28 {{{0, 0}, {0, 1}, {1, 1}}},
20 }; 29 };
21 30
22 static const SkDCubic cubicTests[] = { 31 static const SkDCubic cubicTests[] = {
23 {{{2, 0}, {3, 1}, {2, 2}, {1, 1}}}, 32 {{{2, 0}, {3, 1}, {2, 2}, {1, 1}}},
24 {{{3, 1}, {2, 2}, {1, 1}, {2, 0}}}, 33 {{{3, 1}, {2, 2}, {1, 1}, {2, 0}}},
25 {{{3, 0}, {2, 1}, {3, 2}, {1, 1}}}, 34 {{{3, 0}, {2, 1}, {3, 2}, {1, 1}}},
26 }; 35 };
27 36
37 static const size_t lineTests_count = SK_ARRAY_COUNT(lineTests);
28 static const size_t quadTests_count = SK_ARRAY_COUNT(quadTests); 38 static const size_t quadTests_count = SK_ARRAY_COUNT(quadTests);
29 static const size_t cubicTests_count = SK_ARRAY_COUNT(cubicTests); 39 static const size_t cubicTests_count = SK_ARRAY_COUNT(cubicTests);
30 40
31 static void setRawBounds(const SkDQuad& quad, SkDRect* rect) {
32 rect->set(quad[0]);
33 rect->add(quad[1]);
34 rect->add(quad[2]);
35 }
36
37 static void setRawBounds(const SkDCubic& cubic, SkDRect* rect) {
38 rect->set(cubic[0]);
39 rect->add(cubic[1]);
40 rect->add(cubic[2]);
41 rect->add(cubic[3]);
42 }
43
44 DEF_TEST(PathOpsDRect, reporter) { 41 DEF_TEST(PathOpsDRect, reporter) {
45 size_t index; 42 size_t index;
46 SkDRect rect, rect2; 43 SkDRect rect, rect2;
44 for (index = 0; index < lineTests_count; ++index) {
45 const SkDLine& line = lineTests[index];
46 SkASSERT(ValidLine(line));
47 rect.setBounds(line);
48 REPORTER_ASSERT(reporter, rect.fLeft == SkTMin(line[0].fX, line[1].fX));
49 REPORTER_ASSERT(reporter, rect.fTop == SkTMin(line[0].fY, line[1].fY));
50 REPORTER_ASSERT(reporter, rect.fRight == SkTMax(line[0].fX, line[1].fX)) ;
51 REPORTER_ASSERT(reporter, rect.fBottom == SkTMax(line[0].fY, line[1].fY) );
52 rect2.set(line[0]);
53 rect2.add(line[1]);
54 REPORTER_ASSERT(reporter, rect2.fLeft == SkTMin(line[0].fX, line[1].fX)) ;
55 REPORTER_ASSERT(reporter, rect2.fTop == SkTMin(line[0].fY, line[1].fY));
56 REPORTER_ASSERT(reporter, rect2.fRight == SkTMax(line[0].fX, line[1].fX) );
57 REPORTER_ASSERT(reporter, rect2.fBottom == SkTMax(line[0].fY, line[1].fY ));
58 REPORTER_ASSERT(reporter, rect.contains(line[0]));
59 REPORTER_ASSERT(reporter, rect.intersects(&rect2));
60 }
47 for (index = 0; index < quadTests_count; ++index) { 61 for (index = 0; index < quadTests_count; ++index) {
48 const SkDQuad& quad = quadTests[index]; 62 const SkDQuad& quad = quadTests[index];
49 SkASSERT(ValidQuad(quad)); 63 SkASSERT(ValidQuad(quad));
50 setRawBounds(quad, &rect); 64 rect.setRawBounds(quad);
65 REPORTER_ASSERT(reporter, rect.fLeft == SkTMin(quad[0].fX,
66 SkTMin(quad[1].fX, quad[2].fX)));
67 REPORTER_ASSERT(reporter, rect.fTop == SkTMin(quad[0].fY,
68 SkTMin(quad[1].fY, quad[2].fY)));
69 REPORTER_ASSERT(reporter, rect.fRight == SkTMax(quad[0].fX,
70 SkTMax(quad[1].fX, quad[2].fX)));
71 REPORTER_ASSERT(reporter, rect.fBottom == SkTMax(quad[0].fY,
72 SkTMax(quad[1].fY, quad[2].fY)));
51 rect2.setBounds(quad); 73 rect2.setBounds(quad);
52 REPORTER_ASSERT(reporter, rect.intersects(rect2)); 74 REPORTER_ASSERT(reporter, rect.intersects(&rect2));
53 // FIXME: add a recursive box subdivision method to verify that tight bo unds is correct 75 // FIXME: add a recursive box subdivision method to verify that tight bo unds is correct
54 SkDPoint leftTop = {rect2.fLeft, rect2.fTop}; 76 SkDPoint leftTop = {rect2.fLeft, rect2.fTop};
55 REPORTER_ASSERT(reporter, rect.contains(leftTop)); 77 REPORTER_ASSERT(reporter, rect.contains(leftTop));
56 SkDPoint rightBottom = {rect2.fRight, rect2.fBottom}; 78 SkDPoint rightBottom = {rect2.fRight, rect2.fBottom};
57 REPORTER_ASSERT(reporter, rect.contains(rightBottom)); 79 REPORTER_ASSERT(reporter, rect.contains(rightBottom));
58 } 80 }
59 for (index = 0; index < cubicTests_count; ++index) { 81 for (index = 0; index < cubicTests_count; ++index) {
60 const SkDCubic& cubic = cubicTests[index]; 82 const SkDCubic& cubic = cubicTests[index];
61 SkASSERT(ValidCubic(cubic)); 83 SkASSERT(ValidCubic(cubic));
62 setRawBounds(cubic, &rect); 84 rect.setRawBounds(cubic);
85 REPORTER_ASSERT(reporter, rect.fLeft == SkTMin(cubic[0].fX,
86 SkTMin(cubic[1].fX, SkTMin(cubic[2].fX, cubic[3].fX))));
87 REPORTER_ASSERT(reporter, rect.fTop == SkTMin(cubic[0].fY,
88 SkTMin(cubic[1].fY, SkTMin(cubic[2].fY, cubic[3].fY))));
89 REPORTER_ASSERT(reporter, rect.fRight == SkTMax(cubic[0].fX,
90 SkTMax(cubic[1].fX, SkTMax(cubic[2].fX, cubic[3].fX))));
91 REPORTER_ASSERT(reporter, rect.fBottom == SkTMax(cubic[0].fY,
92 SkTMax(cubic[1].fY, SkTMax(cubic[2].fY, cubic[3].fY))));
63 rect2.setBounds(cubic); 93 rect2.setBounds(cubic);
64 REPORTER_ASSERT(reporter, rect.intersects(rect2)); 94 REPORTER_ASSERT(reporter, rect.intersects(&rect2));
65 // FIXME: add a recursive box subdivision method to verify that tight bo unds is correct 95 // FIXME: add a recursive box subdivision method to verify that tight bo unds is correct
66 SkDPoint leftTop = {rect2.fLeft, rect2.fTop}; 96 SkDPoint leftTop = {rect2.fLeft, rect2.fTop};
67 REPORTER_ASSERT(reporter, rect.contains(leftTop)); 97 REPORTER_ASSERT(reporter, rect.contains(leftTop));
68 SkDPoint rightBottom = {rect2.fRight, rect2.fBottom}; 98 SkDPoint rightBottom = {rect2.fRight, rect2.fBottom};
69 REPORTER_ASSERT(reporter, rect.contains(rightBottom)); 99 REPORTER_ASSERT(reporter, rect.contains(rightBottom));
70 } 100 }
71 } 101 }
OLDNEW
« no previous file with comments | « tests/PathOpsDQuadTest.cpp ('k') | tests/PathOpsDTriangleTest.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698