| 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" |
| 11 #include "SkReduceOrder.h" | 11 #include "SkReduceOrder.h" |
| 12 #include "Test.h" | 12 #include "Test.h" |
| 13 | 13 |
| 14 struct lineCubic { | 14 struct lineCubic { |
| 15 SkDCubic cubic; | 15 CubicPts cubic; |
| 16 SkDLine line; | 16 SkDLine line; |
| 17 }; | 17 }; |
| 18 | 18 |
| 19 static lineCubic failLineCubicTests[] = { | 19 static lineCubic failLineCubicTests[] = { |
| 20 {{{{37.5273438,-1.44140625}, {37.8736992,-1.69921875}, {38.1640625,-2.140625
}, | 20 {{{{37.5273438,-1.44140625}, {37.8736992,-1.69921875}, {38.1640625,-2.140625
}, |
| 21 {38.3984375,-2.765625}}}, | 21 {38.3984375,-2.765625}}}, |
| 22 {{{40.625,-5.7890625}, {37.7109375,1.3515625}}}}, | 22 {{{40.625,-5.7890625}, {37.7109375,1.3515625}}}}, |
| 23 }; | 23 }; |
| 24 | 24 |
| 25 static const size_t failLineCubicTests_count = SK_ARRAY_COUNT(failLineCubicTests
); | 25 static const size_t failLineCubicTests_count = SK_ARRAY_COUNT(failLineCubicTests
); |
| 26 | 26 |
| 27 static void testFail(skiatest::Reporter* reporter, int iIndex) { | 27 static void testFail(skiatest::Reporter* reporter, int iIndex) { |
| 28 const SkDCubic& cubic = failLineCubicTests[iIndex].cubic; | 28 const CubicPts& cuPts = failLineCubicTests[iIndex].cubic; |
| 29 SkDCubic cubic; |
| 30 cubic.debugSet(cuPts.fPts); |
| 29 SkASSERT(ValidCubic(cubic)); | 31 SkASSERT(ValidCubic(cubic)); |
| 30 const SkDLine& line = failLineCubicTests[iIndex].line; | 32 const SkDLine& line = failLineCubicTests[iIndex].line; |
| 31 SkASSERT(ValidLine(line)); | 33 SkASSERT(ValidLine(line)); |
| 32 SkReduceOrder reduce1; | 34 SkReduceOrder reduce1; |
| 33 SkReduceOrder reduce2; | 35 SkReduceOrder reduce2; |
| 34 int order1 = reduce1.reduce(cubic, SkReduceOrder::kNo_Quadratics); | 36 int order1 = reduce1.reduce(cubic, SkReduceOrder::kNo_Quadratics); |
| 35 int order2 = reduce2.reduce(line); | 37 int order2 = reduce2.reduce(line); |
| 36 if (order1 < 4) { | 38 if (order1 < 4) { |
| 37 SkDebugf("[%d] cubic order=%d\n", iIndex, order1); | 39 SkDebugf("[%d] cubic order=%d\n", iIndex, order1); |
| 38 REPORTER_ASSERT(reporter, 0); | 40 REPORTER_ASSERT(reporter, 0); |
| (...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 116 } | 118 } |
| 117 result = intersections.horizontal(cubic, left, right, line[0].fY, flippe
d); | 119 result = intersections.horizontal(cubic, left, right, line[0].fY, flippe
d); |
| 118 } else { | 120 } else { |
| 119 intersections.intersect(cubic, line); | 121 intersections.intersect(cubic, line); |
| 120 result = intersections.used(); | 122 result = intersections.used(); |
| 121 } | 123 } |
| 122 return result; | 124 return result; |
| 123 } | 125 } |
| 124 | 126 |
| 125 static void testOne(skiatest::Reporter* reporter, int iIndex) { | 127 static void testOne(skiatest::Reporter* reporter, int iIndex) { |
| 126 const SkDCubic& cubic = lineCubicTests[iIndex].cubic; | 128 const CubicPts& cuPts = lineCubicTests[iIndex].cubic; |
| 129 SkDCubic cubic; |
| 130 cubic.debugSet(cuPts.fPts); |
| 127 SkASSERT(ValidCubic(cubic)); | 131 SkASSERT(ValidCubic(cubic)); |
| 128 const SkDLine& line = lineCubicTests[iIndex].line; | 132 const SkDLine& line = lineCubicTests[iIndex].line; |
| 129 SkASSERT(ValidLine(line)); | 133 SkASSERT(ValidLine(line)); |
| 130 SkReduceOrder reduce1; | 134 SkReduceOrder reduce1; |
| 131 SkReduceOrder reduce2; | 135 SkReduceOrder reduce2; |
| 132 int order1 = reduce1.reduce(cubic, SkReduceOrder::kNo_Quadratics); | 136 int order1 = reduce1.reduce(cubic, SkReduceOrder::kNo_Quadratics); |
| 133 int order2 = reduce2.reduce(line); | 137 int order2 = reduce2.reduce(line); |
| 134 if (order1 < 4) { | 138 if (order1 < 4) { |
| 135 SkDebugf("[%d] cubic order=%d\n", iIndex, order1); | 139 SkDebugf("[%d] cubic order=%d\n", iIndex, order1); |
| 136 REPORTER_ASSERT(reporter, 0); | 140 REPORTER_ASSERT(reporter, 0); |
| (...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 181 for (size_t index = 0; index < lineCubicTests_count; ++index) { | 185 for (size_t index = 0; index < lineCubicTests_count; ++index) { |
| 182 int iIndex = static_cast<int>(index); | 186 int iIndex = static_cast<int>(index); |
| 183 testOne(reporter, iIndex); | 187 testOne(reporter, iIndex); |
| 184 reporter->bumpTestCount(); | 188 reporter->bumpTestCount(); |
| 185 } | 189 } |
| 186 } | 190 } |
| 187 | 191 |
| 188 DEF_TEST(PathOpsCubicLineIntersectionOneOff, reporter) { | 192 DEF_TEST(PathOpsCubicLineIntersectionOneOff, reporter) { |
| 189 int iIndex = 0; | 193 int iIndex = 0; |
| 190 testOne(reporter, iIndex); | 194 testOne(reporter, iIndex); |
| 191 const SkDCubic& cubic = lineCubicTests[iIndex].cubic; | 195 const CubicPts& cuPts = lineCubicTests[iIndex].cubic; |
| 196 SkDCubic cubic; |
| 197 cubic.debugSet(cuPts.fPts); |
| 192 const SkDLine& line = lineCubicTests[iIndex].line; | 198 const SkDLine& line = lineCubicTests[iIndex].line; |
| 193 SkIntersections i; | 199 SkIntersections i; |
| 194 i.intersect(cubic, line); | 200 i.intersect(cubic, line); |
| 195 SkASSERT(i.used() == 1); | 201 SkASSERT(i.used() == 1); |
| 196 } | 202 } |
| OLD | NEW |