| 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 "PathOpsTestCommon.h" | 7 #include "PathOpsTestCommon.h" |
| 8 #include "SkIntersections.h" | 8 #include "SkIntersections.h" |
| 9 #include "SkPathOpsCubic.h" | 9 #include "SkPathOpsCubic.h" |
| 10 #include "SkPathOpsLine.h" | 10 #include "SkPathOpsLine.h" |
| (...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 42 REPORTER_ASSERT(reporter, 0); | 42 REPORTER_ASSERT(reporter, 0); |
| 43 } | 43 } |
| 44 if (order1 == 4 && order2 == 2) { | 44 if (order1 == 4 && order2 == 2) { |
| 45 SkIntersections i; | 45 SkIntersections i; |
| 46 int roots = i.intersect(cubic, line); | 46 int roots = i.intersect(cubic, line); |
| 47 REPORTER_ASSERT(reporter, roots == 0); | 47 REPORTER_ASSERT(reporter, roots == 0); |
| 48 } | 48 } |
| 49 } | 49 } |
| 50 | 50 |
| 51 static lineCubic lineCubicTests[] = { | 51 static lineCubic lineCubicTests[] = { |
| 52 {{{{-634.60540771484375, -481.262939453125}, {266.2696533203125, -752.708679
19921875}, |
| 53 {-751.8370361328125, -317.37921142578125}, {-969.7427978515625, 824.
7255859375}}}, |
| 54 {{{-287.9506133720805678, -557.1376476615772617}, |
| 55 {-285.9506133720805678, -557.1376476615772617}}}}, |
| 56 |
| 57 {{{{36.7184372,0.888650894}, {36.7184372,0.888650894}, {35.1233864,0.5540154
58}, |
| 58 {34.5114098,-0.115255356}}}, {{{35.4531212,0}, {31.9375,0}}}}, |
| 52 | 59 |
| 53 {{{{421, 378}, {421, 380.209137f}, {418.761414f, 382}, {416, 382}}}, | 60 {{{{421, 378}, {421, 380.209137f}, {418.761414f, 382}, {416, 382}}}, |
| 54 {{{320, 378}, {421, 378.000031f}}}}, | 61 {{{320, 378}, {421, 378.000031f}}}}, |
| 55 | 62 |
| 56 {{{{416, 383}, {418.761414f, 383}, {421, 380.761414f}, {421, 378}}}, | 63 {{{{416, 383}, {418.761414f, 383}, {421, 380.761414f}, {421, 378}}}, |
| 57 {{{320, 378}, {421, 378.000031f}}}}, | 64 {{{320, 378}, {421, 378.000031f}}}}, |
| 58 | 65 |
| 59 {{{{154,715}, {151.238571,715}, {149,712.761414}, {149,710}}}, | 66 {{{{154,715}, {151.238571,715}, {149,712.761414}, {149,710}}}, |
| 60 {{{149,675}, {149,710.001465}}}}, | 67 {{{149,675}, {149,710.001465}}}}, |
| 61 | 68 |
| (...skipping 14 matching lines...) Expand all Loading... |
| 76 {{{979.30487060546875,561}, {1036.695068359375,291}}}}, | 83 {{{979.30487060546875,561}, {1036.695068359375,291}}}}, |
| 77 {{{{259.30487060546875,561}, {242.73631286621094,561}, {232.15980529785156,5
47.56854248046875}, | 84 {{{{259.30487060546875,561}, {242.73631286621094,561}, {232.15980529785156,5
47.56854248046875}, |
| 78 {235.68154907226562,531}}}, | 85 {235.68154907226562,531}}}, |
| 79 {{{286.69512939453125,291}, {229.30485534667969,561}}}}, | 86 {{{286.69512939453125,291}, {229.30485534667969,561}}}}, |
| 80 {{{{1, 2}, {2, 6}, {2, 0}, {1, 0}}}, {{{1, 0}, {1, 2}}}}, | 87 {{{{1, 2}, {2, 6}, {2, 0}, {1, 0}}}, {{{1, 0}, {1, 2}}}}, |
| 81 {{{{0, 0}, {0, 1}, {0, 1}, {1, 1}}}, {{{0, 1}, {1, 0}}}}, | 88 {{{{0, 0}, {0, 1}, {0, 1}, {1, 1}}}, {{{0, 1}, {1, 0}}}}, |
| 82 }; | 89 }; |
| 83 | 90 |
| 84 static const size_t lineCubicTests_count = SK_ARRAY_COUNT(lineCubicTests); | 91 static const size_t lineCubicTests_count = SK_ARRAY_COUNT(lineCubicTests); |
| 85 | 92 |
| 93 static int doIntersect(SkIntersections& intersections, const SkDCubic& cubic, co
nst SkDLine& line) { |
| 94 int result; |
| 95 bool flipped = false; |
| 96 if (line[0].fX == line[1].fX) { |
| 97 double top = line[0].fY; |
| 98 double bottom = line[1].fY; |
| 99 flipped = top > bottom; |
| 100 if (flipped) { |
| 101 SkTSwap<double>(top, bottom); |
| 102 } |
| 103 result = intersections.vertical(cubic, top, bottom, line[0].fX, flipped)
; |
| 104 } else if (line[0].fY == line[1].fY) { |
| 105 double left = line[0].fX; |
| 106 double right = line[1].fX; |
| 107 flipped = left > right; |
| 108 if (flipped) { |
| 109 SkTSwap<double>(left, right); |
| 110 } |
| 111 result = intersections.horizontal(cubic, left, right, line[0].fY, flippe
d); |
| 112 } else { |
| 113 intersections.intersect(cubic, line); |
| 114 result = intersections.used(); |
| 115 } |
| 116 return result; |
| 117 } |
| 118 |
| 86 static void testOne(skiatest::Reporter* reporter, int iIndex) { | 119 static void testOne(skiatest::Reporter* reporter, int iIndex) { |
| 87 const SkDCubic& cubic = lineCubicTests[iIndex].cubic; | 120 const SkDCubic& cubic = lineCubicTests[iIndex].cubic; |
| 88 SkASSERT(ValidCubic(cubic)); | 121 SkASSERT(ValidCubic(cubic)); |
| 89 const SkDLine& line = lineCubicTests[iIndex].line; | 122 const SkDLine& line = lineCubicTests[iIndex].line; |
| 90 SkASSERT(ValidLine(line)); | 123 SkASSERT(ValidLine(line)); |
| 91 SkReduceOrder reduce1; | 124 SkReduceOrder reduce1; |
| 92 SkReduceOrder reduce2; | 125 SkReduceOrder reduce2; |
| 93 int order1 = reduce1.reduce(cubic, SkReduceOrder::kNo_Quadratics); | 126 int order1 = reduce1.reduce(cubic, SkReduceOrder::kNo_Quadratics); |
| 94 int order2 = reduce2.reduce(line); | 127 int order2 = reduce2.reduce(line); |
| 95 if (order1 < 4) { | 128 if (order1 < 4) { |
| 96 SkDebugf("[%d] cubic order=%d\n", iIndex, order1); | 129 SkDebugf("[%d] cubic order=%d\n", iIndex, order1); |
| 97 REPORTER_ASSERT(reporter, 0); | 130 REPORTER_ASSERT(reporter, 0); |
| 98 } | 131 } |
| 99 if (order2 < 2) { | 132 if (order2 < 2) { |
| 100 SkDebugf("[%d] line order=%d\n", iIndex, order2); | 133 SkDebugf("[%d] line order=%d\n", iIndex, order2); |
| 101 REPORTER_ASSERT(reporter, 0); | 134 REPORTER_ASSERT(reporter, 0); |
| 102 } | 135 } |
| 103 if (order1 == 4 && order2 == 2) { | 136 if (order1 == 4 && order2 == 2) { |
| 104 SkIntersections i; | 137 SkIntersections i; |
| 105 int roots = i.intersect(cubic, line); | 138 int roots = doIntersect(i, cubic, line); |
| 106 for (int pt = 0; pt < roots; ++pt) { | 139 for (int pt = 0; pt < roots; ++pt) { |
| 107 double tt1 = i[0][pt]; | 140 double tt1 = i[0][pt]; |
| 108 SkDPoint xy1 = cubic.ptAtT(tt1); | 141 SkDPoint xy1 = cubic.ptAtT(tt1); |
| 109 double tt2 = i[1][pt]; | 142 double tt2 = i[1][pt]; |
| 110 SkDPoint xy2 = line.ptAtT(tt2); | 143 SkDPoint xy2 = line.ptAtT(tt2); |
| 111 if (!xy1.approximatelyEqual(xy2)) { | 144 if (!xy1.approximatelyEqual(xy2)) { |
| 112 SkDebugf("%s [%d,%d] x!= t1=%g (%g,%g) t2=%g (%g,%g)\n", | 145 SkDebugf("%s [%d,%d] x!= t1=%g (%g,%g) t2=%g (%g,%g)\n", |
| 113 __FUNCTION__, iIndex, pt, tt1, xy1.fX, xy1.fY, tt2, xy2.fX,
xy2.fY); | 146 __FUNCTION__, iIndex, pt, tt1, xy1.fX, xy1.fY, tt2, xy2.fX,
xy2.fY); |
| 114 } | 147 } |
| 115 REPORTER_ASSERT(reporter, xy1.approximatelyEqual(xy2)); | 148 REPORTER_ASSERT(reporter, xy1.approximatelyEqual(xy2)); |
| (...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 150 | 183 |
| 151 DEF_TEST(PathOpsCubicLineIntersectionOneOff, reporter) { | 184 DEF_TEST(PathOpsCubicLineIntersectionOneOff, reporter) { |
| 152 int iIndex = 0; | 185 int iIndex = 0; |
| 153 testOne(reporter, iIndex); | 186 testOne(reporter, iIndex); |
| 154 const SkDCubic& cubic = lineCubicTests[iIndex].cubic; | 187 const SkDCubic& cubic = lineCubicTests[iIndex].cubic; |
| 155 const SkDLine& line = lineCubicTests[iIndex].line; | 188 const SkDLine& line = lineCubicTests[iIndex].line; |
| 156 SkIntersections i; | 189 SkIntersections i; |
| 157 i.intersect(cubic, line); | 190 i.intersect(cubic, line); |
| 158 SkASSERT(i.used() == 1); | 191 SkASSERT(i.used() == 1); |
| 159 } | 192 } |
| OLD | NEW |