OLD | NEW |
1 /* | 1 /* |
2 * Copyright 2013 Google Inc. | 2 * Copyright 2013 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 "SkOpSegment.h" | 7 #include "SkOpSegment.h" |
8 #include "Test.h" | 8 #include "Test.h" |
9 | 9 |
10 static const SkPoint cubics[][4] = { | 10 static const SkPoint cubics[][4] = { |
11 {{0, 1}, {2, 6}, {4, 2}, {5, 3}} | 11 {{0, 1}, {2, 6}, {4, 2}, {5, 3}}, |
| 12 {{10, 234}, {10, 229.581726f}, {13.5817204f, 226}, {18, 226}}, |
| 13 }; |
| 14 |
| 15 static const SkPoint quads[][3] = { |
| 16 {{12.3423996f, 228.342407f}, {10, 230.686295f}, {10, 234}}, |
12 }; | 17 }; |
13 | 18 |
14 static const SkPoint lines[][2] = { | 19 static const SkPoint lines[][2] = { |
15 {{6, 2}, {2, 4}} | 20 {{6, 2}, {2, 4}}, |
16 }; | 21 }; |
17 | 22 |
18 struct SortSet { | 23 struct SortSet { |
19 const SkPoint* ptData; | 24 const SkPoint* ptData; |
20 int ptCount; | 25 int ptCount; |
21 double tStart; | 26 double tStart; |
22 double tEnd; | 27 double tEnd; |
23 }; | 28 }; |
24 | 29 |
25 static const SortSet set1[] = { | 30 static const SortSet set1[] = { |
26 {cubics[0], 4, 0.66666987081928919, 0.875}, | 31 {cubics[0], 4, 0.66666987081928919, 0.875}, |
27 {lines[0], 2, 0.574070336, 0.388888889}, | 32 {lines[0], 2, 0.574070336, 0.388888889}, |
28 {cubics[0], 4, 0.66666987081928919, 0.4050371120499307 }, | 33 {cubics[0], 4, 0.66666987081928919, 0.4050371120499307 }, |
29 {lines[0], 2, 0.574070336, 0.9140625}, | 34 {lines[0], 2, 0.574070336, 0.9140625}, |
30 }; | 35 }; |
31 | 36 |
32 static const SortSet set2[] = { | 37 static const SortSet set2[] = { |
33 {cubics[0], 4, 0.666666667, 0.875}, | 38 {cubics[0], 4, 0.666666667, 0.875}, |
34 {lines[0], 2, 0.574074074, 0.388888889}, | 39 {lines[0], 2, 0.574074074, 0.388888889}, |
35 {cubics[0], 4, 0.666666667, 0.405037112}, | 40 {cubics[0], 4, 0.666666667, 0.405037112}, |
36 {lines[0], 2, 0.574074074, 0.9140625}, | 41 {lines[0], 2, 0.574074074, 0.9140625}, |
37 }; | 42 }; |
38 | 43 |
| 44 static const SortSet set3[] = { |
| 45 {cubics[1], 4, 0, 1}, |
| 46 {quads[0], 3, 1, 0}, |
| 47 }; |
| 48 |
39 struct SortSetTests { | 49 struct SortSetTests { |
40 const SortSet* set; | 50 const SortSet* set; |
41 size_t count; | 51 size_t count; |
42 }; | 52 }; |
43 | 53 |
44 static const SortSetTests tests[] = { | 54 static const SortSetTests tests[] = { |
| 55 { set3, SK_ARRAY_COUNT(set3) }, |
45 { set2, SK_ARRAY_COUNT(set2) }, | 56 { set2, SK_ARRAY_COUNT(set2) }, |
46 { set1, SK_ARRAY_COUNT(set1) } | 57 { set1, SK_ARRAY_COUNT(set1) }, |
47 }; | 58 }; |
48 | 59 |
49 static void setup(const SortSet* set, const size_t idx, SkPoint const ** data, | 60 static void setup(const SortSet* set, const size_t idx, SkPoint const ** data, |
50 SkOpSegment* seg, int* ts) { | 61 SkOpSegment* seg, int* ts) { |
51 SkPoint start, end; | 62 SkPoint start, end; |
52 if (set[idx].ptCount == 2) { | 63 *data = set[idx].ptData; |
53 *data = set[idx].ptData; | 64 switch(set[idx].ptCount) { |
54 seg->addLine(*data, false, false); | 65 case 2: { |
55 SkDLine dLine; | 66 seg->addLine(*data, false, false); |
56 dLine.set(set[idx].ptData); | 67 SkDLine dLine; |
57 start = dLine.xyAtT(set[idx].tStart).asSkPoint(); | 68 dLine.set(set[idx].ptData); |
58 end = dLine.xyAtT(set[idx].tEnd).asSkPoint(); | 69 start = dLine.xyAtT(set[idx].tStart).asSkPoint(); |
59 } else if (set[idx].ptCount == 4) { | 70 end = dLine.xyAtT(set[idx].tEnd).asSkPoint(); |
60 *data = set[idx].ptData; | 71 } break; |
61 seg->addCubic(*data, false, false); | 72 case 3: { |
62 SkDCubic dCubic; | 73 seg->addQuad(*data, false, false); |
63 dCubic.set(set[idx].ptData); | 74 SkDQuad dQuad; |
64 start = dCubic.xyAtT(set[idx].tStart).asSkPoint(); | 75 dQuad.set(set[idx].ptData); |
65 end = dCubic.xyAtT(set[idx].tEnd).asSkPoint(); | 76 start = dQuad.xyAtT(set[idx].tStart).asSkPoint(); |
| 77 end = dQuad.xyAtT(set[idx].tEnd).asSkPoint(); |
| 78 } break; |
| 79 case 4: { |
| 80 seg->addCubic(*data, false, false); |
| 81 SkDCubic dCubic; |
| 82 dCubic.set(set[idx].ptData); |
| 83 start = dCubic.xyAtT(set[idx].tStart).asSkPoint(); |
| 84 end = dCubic.xyAtT(set[idx].tEnd).asSkPoint(); |
| 85 } break; |
66 } | 86 } |
67 seg->addT(NULL, start, set[idx].tStart); | 87 double tStart = set[idx].tStart; |
68 seg->addT(NULL, end, set[idx].tEnd); | 88 double tEnd = set[idx].tEnd; |
69 seg->addT(NULL, set[idx].ptData[0], 0); | 89 seg->addT(NULL, start, tStart); |
70 seg->addT(NULL, set[idx].ptData[set[idx].ptCount - 1], 1); | 90 seg->addT(NULL, end, tEnd); |
| 91 double tLeft = tStart < tEnd ? 0 : 1; |
| 92 if (tStart != tLeft && tEnd != tLeft) { |
| 93 seg->addT(NULL, set[idx].ptData[0], tLeft); |
| 94 } |
| 95 double tRight = tStart < tEnd ? 1 : 0; |
| 96 if (tStart != tRight && tEnd != tRight) { |
| 97 seg->addT(NULL, set[idx].ptData[set[idx].ptCount - 1], tRight); |
| 98 } |
71 int tIndex = 0; | 99 int tIndex = 0; |
72 do { | 100 do { |
73 if (seg->t(tIndex) == set[idx].tStart) { | 101 if (seg->t(tIndex) == set[idx].tStart) { |
74 ts[0] = tIndex; | 102 ts[0] = tIndex; |
75 } | 103 } |
76 if (seg->t(tIndex) == set[idx].tEnd) { | 104 if (seg->t(tIndex) == set[idx].tEnd) { |
77 ts[1] = tIndex; | 105 ts[1] = tIndex; |
78 } | 106 } |
79 if (seg->t(tIndex) >= 1) { | 107 if (seg->t(tIndex) >= 1) { |
80 break; | 108 break; |
(...skipping 22 matching lines...) Expand all Loading... |
103 SkDebugf("%s test[%d]: lesser[%d] > greater[%d]\n", __FUNCTION_
_, | 131 SkDebugf("%s test[%d]: lesser[%d] > greater[%d]\n", __FUNCTION_
_, |
104 index, idxL, idxG); | 132 index, idxL, idxG); |
105 } | 133 } |
106 REPORTER_ASSERT(reporter, compare); | 134 REPORTER_ASSERT(reporter, compare); |
107 } | 135 } |
108 } | 136 } |
109 } | 137 } |
110 | 138 |
111 #include "TestClassDef.h" | 139 #include "TestClassDef.h" |
112 DEFINE_TESTCLASS_SHORT(PathOpsAngleTest) | 140 DEFINE_TESTCLASS_SHORT(PathOpsAngleTest) |
OLD | NEW |