OLD | NEW |
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 "PathOpsExtendedTest.h" | 7 #include "PathOpsExtendedTest.h" |
8 #include "PathOpsTestCommon.h" | 8 #include "PathOpsTestCommon.h" |
9 #include "SkIntersections.h" | 9 #include "SkIntersections.h" |
10 #include "SkPathOpsLine.h" | 10 #include "SkPathOpsLine.h" |
11 #include "SkPathOpsQuad.h" | 11 #include "SkPathOpsQuad.h" |
12 #include "SkReduceOrder.h" | 12 #include "SkReduceOrder.h" |
13 #include "Test.h" | 13 #include "Test.h" |
14 | 14 |
15 static struct lineQuad { | 15 static struct lineQuad { |
16 SkDQuad quad; | 16 QuadPts quad; |
17 SkDLine line; | 17 SkDLine line; |
18 int result; | 18 int result; |
19 SkDPoint expected[2]; | 19 SkDPoint expected[2]; |
20 } lineQuadTests[] = { | 20 } lineQuadTests[] = { |
21 // quad line results | 21 // quad line results |
22 {{{{1, 1}, {2, 1}, {0, 2}}}, {{{0, 0}, {1, 1}}}, 1, {{1, 1}, {0, 0}} }, | 22 {{{{1, 1}, {2, 1}, {0, 2}}}, {{{0, 0}, {1, 1}}}, 1, {{1, 1}, {0, 0}} }, |
23 {{{{0, 0}, {1, 1}, {3, 1}}}, {{{0, 0}, {3, 1}}}, 2, {{0, 0}, {3, 1}} }, | 23 {{{{0, 0}, {1, 1}, {3, 1}}}, {{{0, 0}, {3, 1}}}, 2, {{0, 0}, {3, 1}} }, |
24 {{{{2, 0}, {1, 1}, {2, 2}}}, {{{0, 0}, {0, 2}}}, 0, {{0, 0}, {0, 0}} }, | 24 {{{{2, 0}, {1, 1}, {2, 2}}}, {{{0, 0}, {0, 2}}}, 0, {{0, 0}, {0, 0}} }, |
25 {{{{4, 0}, {0, 1}, {4, 2}}}, {{{3, 1}, {4, 1}}}, 0, {{0, 0}, {0, 0}} }, | 25 {{{{4, 0}, {0, 1}, {4, 2}}}, {{{3, 1}, {4, 1}}}, 0, {{0, 0}, {0, 0}} }, |
26 {{{{0, 0}, {0, 1}, {1, 1}}}, {{{0, 1}, {1, 0}}}, 1, {{.25, .75}, {0, 0}} }
, | 26 {{{{0, 0}, {0, 1}, {1, 1}}}, {{{0, 1}, {1, 0}}}, 1, {{.25, .75}, {0, 0}} }
, |
(...skipping 22 matching lines...) Expand all Loading... |
49 } | 49 } |
50 result = intersections.horizontal(quad, left, right, line[0].fY, flipped
); | 50 result = intersections.horizontal(quad, left, right, line[0].fY, flipped
); |
51 } else { | 51 } else { |
52 intersections.intersect(quad, line); | 52 intersections.intersect(quad, line); |
53 result = intersections.used(); | 53 result = intersections.used(); |
54 } | 54 } |
55 return result; | 55 return result; |
56 } | 56 } |
57 | 57 |
58 static struct oneLineQuad { | 58 static struct oneLineQuad { |
59 SkDQuad quad; | 59 QuadPts quad; |
60 SkDLine line; | 60 SkDLine line; |
61 } oneOffs[] = { | 61 } oneOffs[] = { |
62 {{{{97.9337616,100}, {88,112.94265}, {88,130}}}, | 62 {{{{97.9337616,100}, {88,112.94265}, {88,130}}}, |
63 {{{88.919838,120}, {107.058823,120}}}}, | 63 {{{88.919838,120}, {107.058823,120}}}}, |
64 {{{{447.96701049804687, 894.4381103515625}, {448.007080078125, 894.423950195
3125}, | 64 {{{{447.96701049804687, 894.4381103515625}, {448.007080078125, 894.423950195
3125}, |
65 {448.0140380859375, 894.4215087890625}}}, | 65 {448.0140380859375, 894.4215087890625}}}, |
66 {{{490.43548583984375, 879.40740966796875}, {405.59262084960937, 909.435546
875}}}}, | 66 {{{490.43548583984375, 879.40740966796875}, {405.59262084960937, 909.435546
875}}}}, |
67 {{{{142.589081, 102.283646}, {149.821579, 100}, {158, 100}}}, | 67 {{{{142.589081, 102.283646}, {149.821579, 100}, {158, 100}}}, |
68 {{{90, 230}, {160, 60}}}}, | 68 {{{90, 230}, {160, 60}}}}, |
69 {{{{1101, 10}, {1101, 8.3431453704833984}, {1099.828857421875, 7.17119979858
39844}}}, | 69 {{{{1101, 10}, {1101, 8.3431453704833984}, {1099.828857421875, 7.17119979858
39844}}}, |
70 {{{1099.828857421875,7.1711711883544922}, {1099.121337890625,7.878678321
8383789}}}}, | 70 {{{1099.828857421875,7.1711711883544922}, {1099.121337890625,7.878678321
8383789}}}}, |
71 {{{{973, 507}, {973, 508.24264526367187}, {972.12158203125, 509.121612548828
12}}}, | 71 {{{{973, 507}, {973, 508.24264526367187}, {972.12158203125, 509.121612548828
12}}}, |
72 {{{930, 467}, {973, 510}}}}, | 72 {{{930, 467}, {973, 510}}}}, |
73 {{{{369.848602, 145.680267}, {382.360413, 121.298294}, {406.207703, 121.2982
94}}}, | 73 {{{{369.848602, 145.680267}, {382.360413, 121.298294}, {406.207703, 121.2982
94}}}, |
74 {{{406.207703, 121.298294}, {348.781738, 123.864815}}}}, | 74 {{{406.207703, 121.298294}, {348.781738, 123.864815}}}}, |
75 }; | 75 }; |
76 | 76 |
77 static size_t oneOffs_count = SK_ARRAY_COUNT(oneOffs); | 77 static size_t oneOffs_count = SK_ARRAY_COUNT(oneOffs); |
78 | 78 |
79 static void testOneOffs(skiatest::Reporter* reporter) { | 79 static void testOneOffs(skiatest::Reporter* reporter) { |
80 bool flipped = false; | 80 bool flipped = false; |
81 for (size_t index = 0; index < oneOffs_count; ++index) { | 81 for (size_t index = 0; index < oneOffs_count; ++index) { |
82 const SkDQuad& quad = oneOffs[index].quad; | 82 const QuadPts& q = oneOffs[index].quad; |
| 83 SkDQuad quad; |
| 84 quad.debugSet(q.fPts); |
83 SkASSERT(ValidQuad(quad)); | 85 SkASSERT(ValidQuad(quad)); |
84 const SkDLine& line = oneOffs[index].line; | 86 const SkDLine& line = oneOffs[index].line; |
85 SkASSERT(ValidLine(line)); | 87 SkASSERT(ValidLine(line)); |
86 SkIntersections intersections; | 88 SkIntersections intersections; |
87 int result = doIntersect(intersections, quad, line, flipped); | 89 int result = doIntersect(intersections, quad, line, flipped); |
88 for (int inner = 0; inner < result; ++inner) { | 90 for (int inner = 0; inner < result; ++inner) { |
89 double quadT = intersections[0][inner]; | 91 double quadT = intersections[0][inner]; |
90 SkDPoint quadXY = quad.ptAtT(quadT); | 92 SkDPoint quadXY = quad.ptAtT(quadT); |
91 double lineT = intersections[1][inner]; | 93 double lineT = intersections[1][inner]; |
92 SkDPoint lineXY = line.ptAtT(lineT); | 94 SkDPoint lineXY = line.ptAtT(lineT); |
93 if (!quadXY.approximatelyEqual(lineXY)) { | 95 if (!quadXY.approximatelyEqual(lineXY)) { |
94 quadXY.approximatelyEqual(lineXY); | 96 quadXY.approximatelyEqual(lineXY); |
95 SkDebugf(""); | 97 SkDebugf(""); |
96 } | 98 } |
97 REPORTER_ASSERT(reporter, quadXY.approximatelyEqual(lineXY)); | 99 REPORTER_ASSERT(reporter, quadXY.approximatelyEqual(lineXY)); |
98 } | 100 } |
99 } | 101 } |
100 } | 102 } |
101 | 103 |
102 DEF_TEST(PathOpsQuadLineIntersectionOneOff, reporter) { | 104 DEF_TEST(PathOpsQuadLineIntersectionOneOff, reporter) { |
103 testOneOffs(reporter); | 105 testOneOffs(reporter); |
104 } | 106 } |
105 | 107 |
106 DEF_TEST(PathOpsQuadLineIntersection, reporter) { | 108 DEF_TEST(PathOpsQuadLineIntersection, reporter) { |
107 for (size_t index = 0; index < lineQuadTests_count; ++index) { | 109 for (size_t index = 0; index < lineQuadTests_count; ++index) { |
108 int iIndex = static_cast<int>(index); | 110 int iIndex = static_cast<int>(index); |
109 const SkDQuad& quad = lineQuadTests[index].quad; | 111 const QuadPts& q = lineQuadTests[index].quad; |
| 112 SkDQuad quad; |
| 113 quad.debugSet(q.fPts); |
110 SkASSERT(ValidQuad(quad)); | 114 SkASSERT(ValidQuad(quad)); |
111 const SkDLine& line = lineQuadTests[index].line; | 115 const SkDLine& line = lineQuadTests[index].line; |
112 SkASSERT(ValidLine(line)); | 116 SkASSERT(ValidLine(line)); |
113 SkReduceOrder reducer1, reducer2; | 117 SkReduceOrder reducer1, reducer2; |
114 int order1 = reducer1.reduce(quad); | 118 int order1 = reducer1.reduce(quad); |
115 int order2 = reducer2.reduce(line); | 119 int order2 = reducer2.reduce(line); |
116 if (order1 < 3) { | 120 if (order1 < 3) { |
117 SkDebugf("%s [%d] quad order=%d\n", __FUNCTION__, iIndex, order1); | 121 SkDebugf("%s [%d] quad order=%d\n", __FUNCTION__, iIndex, order1); |
118 REPORTER_ASSERT(reporter, 0); | 122 REPORTER_ASSERT(reporter, 0); |
119 } | 123 } |
(...skipping 22 matching lines...) Expand all Loading... |
142 } | 146 } |
143 if (!t1.approximatelyEqual(lineQuadTests[index].expected[0]) | 147 if (!t1.approximatelyEqual(lineQuadTests[index].expected[0]) |
144 && (lineQuadTests[index].result == 1 | 148 && (lineQuadTests[index].result == 1 |
145 || !t1.approximatelyEqual(lineQuadTests[index].expected[1]))
) { | 149 || !t1.approximatelyEqual(lineQuadTests[index].expected[1]))
) { |
146 SkDebugf("%s t1=(%1.9g,%1.9g)\n", __FUNCTION__, t1.fX, t1.fY); | 150 SkDebugf("%s t1=(%1.9g,%1.9g)\n", __FUNCTION__, t1.fX, t1.fY); |
147 REPORTER_ASSERT(reporter, 0); | 151 REPORTER_ASSERT(reporter, 0); |
148 } | 152 } |
149 } | 153 } |
150 } | 154 } |
151 } | 155 } |
OLD | NEW |