OLD | NEW |
(Empty) | |
| 1 /* |
| 2 * Copyright 2012 Google Inc. |
| 3 * |
| 4 * Use of this source code is governed by a BSD-style license that can be |
| 5 * found in the LICENSE file. |
| 6 */ |
| 7 #include "PathOpsCubicIntersectionTestData.h" |
| 8 #include "PathOpsQuadIntersectionTestData.h" |
| 9 #include "PathOpsTestCommon.h" |
| 10 #include "SkGeometry.h" |
| 11 #include "SkIntersections.h" |
| 12 #include "SkPathOpsRect.h" |
| 13 #include "SkReduceOrder.h" |
| 14 #include "Test.h" |
| 15 |
| 16 static void test(skiatest::Reporter* reporter, const SkDCubic* cubics, const cha
r* name, |
| 17 int firstTest, size_t testCount) { |
| 18 for (size_t index = firstTest; index < testCount; ++index) { |
| 19 const SkDCubic& cubic = cubics[index]; |
| 20 double precision = cubic.calcPrecision(); |
| 21 SkTDArray<SkDQuad> quads; |
| 22 CubicToQuads(cubic, precision, quads); |
| 23 if (quads.count() != 1) { |
| 24 SkDebugf("%s [%d] cubic to quadratics failed count=%d\n", name, stat
ic_cast<int>(index), |
| 25 quads.count()); |
| 26 } |
| 27 REPORTER_ASSERT(reporter, quads.count() == 1); |
| 28 } |
| 29 } |
| 30 |
| 31 static void test(skiatest::Reporter* reporter, const SkDQuad* quadTests, const c
har* name, |
| 32 int firstTest, size_t testCount) { |
| 33 for (size_t index = firstTest; index < testCount; ++index) { |
| 34 const SkDQuad& quad = quadTests[index]; |
| 35 SkDCubic cubic = quad.toCubic(); |
| 36 double precision = cubic.calcPrecision(); |
| 37 SkTDArray<SkDQuad> quads; |
| 38 CubicToQuads(cubic, precision, quads); |
| 39 if (quads.count() != 1) { |
| 40 SkDebugf("%s [%d] cubic to quadratics failed count=%d\n", name, stat
ic_cast<int>(index), |
| 41 quads.count()); |
| 42 } |
| 43 REPORTER_ASSERT(reporter, quads.count() == 1); |
| 44 } |
| 45 } |
| 46 |
| 47 static void testC(skiatest::Reporter* reporter, const SkDCubic* cubics, const ch
ar* name, |
| 48 int firstTest, size_t testCount) { |
| 49 // test if computed line end points are valid |
| 50 for (size_t index = firstTest; index < testCount; ++index) { |
| 51 const SkDCubic& cubic = cubics[index]; |
| 52 double precision = cubic.calcPrecision(); |
| 53 SkTDArray<SkDQuad> quads; |
| 54 CubicToQuads(cubic, precision, quads); |
| 55 if (!AlmostEqualUlps(cubic[0].fX, quads[0][0].fX) |
| 56 || !AlmostEqualUlps(cubic[0].fY, quads[0][0].fY)) { |
| 57 SkDebugf("[%d] unmatched start\n", static_cast<int>(index)); |
| 58 REPORTER_ASSERT(reporter, 0); |
| 59 } |
| 60 int last = quads.count() - 1; |
| 61 if (!AlmostEqualUlps(cubic[3].fX, quads[last][2].fX) |
| 62 || !AlmostEqualUlps(cubic[3].fY, quads[last][2].fY)) { |
| 63 SkDebugf("[%d] unmatched end\n", static_cast<int>(index)); |
| 64 REPORTER_ASSERT(reporter, 0); |
| 65 } |
| 66 } |
| 67 } |
| 68 |
| 69 static void testC(skiatest::Reporter* reporter, const SkDCubic(* cubics)[2], con
st char* name, |
| 70 int firstTest, size_t testCount) { |
| 71 for (size_t index = firstTest; index < testCount; ++index) { |
| 72 for (int idx2 = 0; idx2 < 2; ++idx2) { |
| 73 const SkDCubic& cubic = cubics[index][idx2]; |
| 74 double precision = cubic.calcPrecision(); |
| 75 SkTDArray<SkDQuad> quads; |
| 76 CubicToQuads(cubic, precision, quads); |
| 77 if (!AlmostEqualUlps(cubic[0].fX, quads[0][0].fX) |
| 78 || !AlmostEqualUlps(cubic[0].fY, quads[0][0].fY)) { |
| 79 SkDebugf("[%d][%d] unmatched start\n", static_cast<int>(index),
idx2); |
| 80 REPORTER_ASSERT(reporter, 0); |
| 81 } |
| 82 int last = quads.count() - 1; |
| 83 if (!AlmostEqualUlps(cubic[3].fX, quads[last][2].fX) |
| 84 || !AlmostEqualUlps(cubic[3].fY, quads[last][2].fY)) { |
| 85 SkDebugf("[%d][%d] unmatched end\n", static_cast<int>(index), id
x2); |
| 86 REPORTER_ASSERT(reporter, 0); |
| 87 } |
| 88 } |
| 89 } |
| 90 } |
| 91 |
| 92 static void CubicToQuads_Test(skiatest::Reporter* reporter) { |
| 93 enum { |
| 94 RunAll, |
| 95 RunPointDegenerates, |
| 96 RunNotPointDegenerates, |
| 97 RunLines, |
| 98 RunNotLines, |
| 99 RunModEpsilonLines, |
| 100 RunLessEpsilonLines, |
| 101 RunNegEpsilonLines, |
| 102 RunQuadraticLines, |
| 103 RunQuadraticModLines, |
| 104 RunComputedLines, |
| 105 RunComputedTests, |
| 106 RunNone |
| 107 } run = RunAll; |
| 108 int firstTestIndex = 0; |
| 109 #if 0 |
| 110 run = RunComputedLines; |
| 111 firstTestIndex = 18; |
| 112 #endif |
| 113 int firstPointDegeneratesTest = run == RunAll ? 0 : run == RunPointDegenerat
es |
| 114 ? firstTestIndex : SK_MaxS32; |
| 115 int firstNotPointDegeneratesTest = run == RunAll ? 0 : run == RunNotPointDeg
enerates |
| 116 ? firstTestIndex : SK_MaxS32; |
| 117 int firstLinesTest = run == RunAll ? 0 : run == RunLines ? firstTestIndex :
SK_MaxS32; |
| 118 int firstNotLinesTest = run == RunAll ? 0 : run == RunNotLines ? firstTestIn
dex : SK_MaxS32; |
| 119 int firstModEpsilonTest = run == RunAll ? 0 : run == RunModEpsilonLines |
| 120 ? firstTestIndex : SK_MaxS32; |
| 121 int firstLessEpsilonTest = run == RunAll ? 0 : run == RunLessEpsilonLines |
| 122 ? firstTestIndex : SK_MaxS32; |
| 123 int firstNegEpsilonTest = run == RunAll ? 0 : run == RunNegEpsilonLines |
| 124 ? firstTestIndex : SK_MaxS32; |
| 125 int firstQuadraticLineTest = run == RunAll ? 0 : run == RunQuadraticLines |
| 126 ? firstTestIndex : SK_MaxS32; |
| 127 int firstQuadraticModLineTest = run == RunAll ? 0 : run == RunQuadraticModLi
nes |
| 128 ? firstTestIndex : SK_MaxS32; |
| 129 int firstComputedLinesTest = run == RunAll ? 0 : run == RunComputedLines |
| 130 ? firstTestIndex : SK_MaxS32; |
| 131 int firstComputedCubicsTest = run == RunAll ? 0 : run == RunComputedTests |
| 132 ? firstTestIndex : SK_MaxS32; |
| 133 |
| 134 test(reporter, pointDegenerates, "pointDegenerates", firstPointDegeneratesTe
st, |
| 135 pointDegenerates_count); |
| 136 testC(reporter, notPointDegenerates, "notPointDegenerates", firstNotPointDeg
eneratesTest, |
| 137 notPointDegenerates_count); |
| 138 test(reporter, lines, "lines", firstLinesTest, lines_count); |
| 139 testC(reporter, notLines, "notLines", firstNotLinesTest, notLines_count); |
| 140 testC(reporter, modEpsilonLines, "modEpsilonLines", firstModEpsilonTest, mod
EpsilonLines_count); |
| 141 test(reporter, lessEpsilonLines, "lessEpsilonLines", firstLessEpsilonTest, |
| 142 lessEpsilonLines_count); |
| 143 test(reporter, negEpsilonLines, "negEpsilonLines", firstNegEpsilonTest, negE
psilonLines_count); |
| 144 test(reporter, quadraticLines, "quadraticLines", firstQuadraticLineTest, qua
draticLines_count); |
| 145 test(reporter, quadraticModEpsilonLines, "quadraticModEpsilonLines", firstQu
adraticModLineTest, |
| 146 quadraticModEpsilonLines_count); |
| 147 testC(reporter, lines, "computed lines", firstComputedLinesTest, lines_count
); |
| 148 testC(reporter, tests, "computed tests", firstComputedCubicsTest, tests_coun
t); |
| 149 } |
| 150 |
| 151 static SkDCubic locals[] = { |
| 152 {{{0, 1}, {1.9274705288631189e-19, 1.0000000000000002}, |
| 153 {0.0017190297609673323, 0.99828097023903239}, |
| 154 {0.0053709083094631276, 0.99505672974365911}}}, |
| 155 {{{14.5975863, 41.632436}, {16.3518929, 26.2639684}, {18.5165519, 7.68775139
}, |
| 156 {8.03767257, 89.1628526}}}, |
| 157 {{{69.7292014, 38.6877352}, {24.7648688, 23.1501713}, {84.9283191, 90.258844
1}, |
| 158 {80.392774, 61.3533852}}}, |
| 159 {{{60.776536520932126, 71.249307306133829}, {87.107894191103014, 22.37766986
8235323}, |
| 160 {1.4974754310666936, 68.069569937917208}, {45.261946574441133, 17.53
6076632112298}}}, |
| 161 }; |
| 162 |
| 163 static size_t localsCount = sizeof(locals) / sizeof(locals[0]); |
| 164 |
| 165 #define DEBUG_CRASH 0 |
| 166 #define TEST_AVERAGE_END_POINTS 0 // must take const off to test |
| 167 extern const bool AVERAGE_END_POINTS; |
| 168 |
| 169 static void oneOff(skiatest::Reporter* reporter, size_t x) { |
| 170 const SkDCubic& cubic = locals[x]; |
| 171 const SkPoint skcubic[4] = { |
| 172 {static_cast<float>(cubic[0].fX), static_cast<float>(cubic[0].fY)}, |
| 173 {static_cast<float>(cubic[1].fX), static_cast<float>(cubic[1].fY)}, |
| 174 {static_cast<float>(cubic[2].fX), static_cast<float>(cubic[2].fY)}, |
| 175 {static_cast<float>(cubic[3].fX), static_cast<float>(cubic[3].fY)}}; |
| 176 SkScalar skinflect[2]; |
| 177 int skin = SkFindCubicInflections(skcubic, skinflect); |
| 178 if (false) SkDebugf("%s %d %1.9g\n", __FUNCTION__, skin, skinflect[0]); |
| 179 SkTDArray<SkDQuad> quads; |
| 180 double precision = cubic.calcPrecision(); |
| 181 CubicToQuads(cubic, precision, quads); |
| 182 if (false) SkDebugf("%s quads=%d\n", __FUNCTION__, quads.count()); |
| 183 } |
| 184 |
| 185 static void CubicsToQuadratics_OneOffTests(skiatest::Reporter* reporter) { |
| 186 for (size_t x = 0; x < localsCount; ++x) { |
| 187 oneOff(reporter, x); |
| 188 } |
| 189 } |
| 190 |
| 191 static void CubicsToQuadratics_OneOffTest(skiatest::Reporter* reporter) { |
| 192 oneOff(reporter, 0); |
| 193 } |
| 194 |
| 195 static void TestCubicToQuads(skiatest::Reporter* reporter) { |
| 196 CubicToQuads_Test(reporter); |
| 197 CubicsToQuadratics_OneOffTest(reporter); |
| 198 CubicsToQuadratics_OneOffTests(reporter); |
| 199 } |
| 200 |
| 201 #include "TestClassDef.h" |
| 202 DEFINE_TESTCLASS("PathOpsCubicToQuads", PathOpsCubicToQuads, TestCubicToQuads) |
OLD | NEW |