caryclark@google.com | 6d0032a | 2013-01-04 19:41:13 +0000 | [diff] [blame^] | 1 | #include "CubicIntersection_TestData.h" |
| 2 | #include "CubicUtilities.h" |
| 3 | #include "Intersection_Tests.h" |
| 4 | #include "QuadraticIntersection_TestData.h" |
| 5 | #include "TestUtilities.h" |
| 6 | |
| 7 | void CubicToQuadratics_Test() { |
| 8 | size_t index; |
| 9 | enum { |
| 10 | RunAll, |
| 11 | RunPointDegenerates, |
| 12 | RunNotPointDegenerates, |
| 13 | RunLines, |
| 14 | RunNotLines, |
| 15 | RunModEpsilonLines, |
| 16 | RunLessEpsilonLines, |
| 17 | RunNegEpsilonLines, |
| 18 | RunQuadraticLines, |
| 19 | RunQuadraticModLines, |
| 20 | RunComputedLines, |
| 21 | RunNone |
| 22 | } run = RunAll; |
| 23 | int firstTestIndex = 0; |
| 24 | #if 0 |
| 25 | run = RunComputedLines; |
| 26 | firstTestIndex = 18; |
| 27 | #endif |
| 28 | int firstPointDegeneratesTest = run == RunAll ? 0 : run == RunPointDegenerates ? firstTestIndex : INT_MAX; |
| 29 | int firstNotPointDegeneratesTest = run == RunAll ? 0 : run == RunNotPointDegenerates ? firstTestIndex : INT_MAX; |
| 30 | int firstLinesTest = run == RunAll ? 0 : run == RunLines ? firstTestIndex : INT_MAX; |
| 31 | int firstNotLinesTest = run == RunAll ? 0 : run == RunNotLines ? firstTestIndex : INT_MAX; |
| 32 | int firstModEpsilonTest = run == RunAll ? 0 : run == RunModEpsilonLines ? firstTestIndex : INT_MAX; |
| 33 | int firstLessEpsilonTest = run == RunAll ? 0 : run == RunLessEpsilonLines ? firstTestIndex : INT_MAX; |
| 34 | int firstNegEpsilonTest = run == RunAll ? 0 : run == RunNegEpsilonLines ? firstTestIndex : INT_MAX; |
| 35 | int firstQuadraticLineTest = run == RunAll ? 0 : run == RunQuadraticLines ? firstTestIndex : INT_MAX; |
| 36 | int firstQuadraticModLineTest = run == RunAll ? 0 : run == RunQuadraticModLines ? firstTestIndex : INT_MAX; |
| 37 | int firstComputedLinesTest = run == RunAll ? 0 : run == RunComputedLines ? firstTestIndex : INT_MAX; |
| 38 | SkTDArray<Quadratic> quads; |
| 39 | for (index = firstPointDegeneratesTest; index < pointDegenerates_count; ++index) { |
| 40 | const Cubic& cubic = pointDegenerates[index]; |
| 41 | cubic_to_quadratics(cubic, quads); |
| 42 | if (quads.count() != 1) { |
| 43 | printf("[%d] pointDegenerates count=%d\n", (int) index, quads.count()); |
| 44 | } |
| 45 | } |
| 46 | for (index = firstNotPointDegeneratesTest; index < notPointDegenerates_count; ++index) { |
| 47 | const Cubic& cubic = notPointDegenerates[index]; |
| 48 | cubic_to_quadratics(cubic, quads); |
| 49 | if (quads.count() != 1) { |
| 50 | printf("[%d] notPointDegenerates count=%d\n", (int) index, quads.count()); |
| 51 | } |
| 52 | } |
| 53 | for (index = firstLinesTest; index < lines_count; ++index) { |
| 54 | const Cubic& cubic = lines[index]; |
| 55 | cubic_to_quadratics(cubic, quads); |
| 56 | if (quads.count() != 1) { |
| 57 | printf("[%d] lines count=%d\n", (int) index, quads.count()); |
| 58 | } |
| 59 | } |
| 60 | for (index = firstNotLinesTest; index < notLines_count; ++index) { |
| 61 | const Cubic& cubic = notLines[index]; |
| 62 | cubic_to_quadratics(cubic, quads); |
| 63 | if (quads.count() != 1) { |
| 64 | printf("[%d] notLines order=%d\n", (int) index, quads.count()); |
| 65 | } |
| 66 | } |
| 67 | for (index = firstModEpsilonTest; index < modEpsilonLines_count; ++index) { |
| 68 | const Cubic& cubic = modEpsilonLines[index]; |
| 69 | cubic_to_quadratics(cubic, quads); |
| 70 | if (quads.count() != 1) { |
| 71 | printf("[%d] line mod by epsilon order=%d\n", (int) index, quads.count()); |
| 72 | } |
| 73 | } |
| 74 | for (index = firstLessEpsilonTest; index < lessEpsilonLines_count; ++index) { |
| 75 | const Cubic& cubic = lessEpsilonLines[index]; |
| 76 | cubic_to_quadratics(cubic, quads); |
| 77 | if (quads.count() != 1) { |
| 78 | printf("[%d] line less by epsilon/2 order=%d\n", (int) index, quads.count()); |
| 79 | } |
| 80 | } |
| 81 | for (index = firstNegEpsilonTest; index < negEpsilonLines_count; ++index) { |
| 82 | const Cubic& cubic = negEpsilonLines[index]; |
| 83 | cubic_to_quadratics(cubic, quads); |
| 84 | if (quads.count() != 1) { |
| 85 | printf("[%d] line neg by epsilon/2 order=%d\n", (int) index, quads.count()); |
| 86 | } |
| 87 | } |
| 88 | for (index = firstQuadraticLineTest; index < quadraticLines_count; ++index) { |
| 89 | const Quadratic& quad = quadraticLines[index]; |
| 90 | Cubic cubic; |
| 91 | quad_to_cubic(quad, cubic); |
| 92 | cubic_to_quadratics(cubic, quads); |
| 93 | if (quads.count() != 1) { |
| 94 | printf("[%d] line quad order=%d\n", (int) index, quads.count()); |
| 95 | } |
| 96 | } |
| 97 | for (index = firstQuadraticModLineTest; index < quadraticModEpsilonLines_count; ++index) { |
| 98 | const Quadratic& quad = quadraticModEpsilonLines[index]; |
| 99 | Cubic cubic; |
| 100 | quad_to_cubic(quad, cubic); |
| 101 | cubic_to_quadratics(cubic, quads); |
| 102 | if (quads.count() != 1) { |
| 103 | printf("[%d] line mod quad order=%d\n", (int) index, quads.count()); |
| 104 | } |
| 105 | } |
| 106 | |
| 107 | // test if computed line end points are valid |
| 108 | for (index = firstComputedLinesTest; index < lines_count; ++index) { |
| 109 | const Cubic& cubic = lines[index]; |
| 110 | cubic_to_quadratics(cubic, quads); |
| 111 | if (cubic[0].x != quads[0][0].x && cubic[0].y != quads[0][0].y) { |
| 112 | printf("[%d] unmatched start\n", (int) index); |
| 113 | } |
| 114 | int last = quads.count() - 1; |
| 115 | if (cubic[3].x != quads[last][2].x && cubic[3].y != quads[last][2].y) { |
| 116 | printf("[%d] unmatched end\n", (int) index); |
| 117 | } |
| 118 | } |
| 119 | } |