caryclark@google.com | c682590 | 2012-02-03 22:07:47 +0000 | [diff] [blame] | 1 | #include "CurveIntersection.h" |
caryclark@google.com | 27accef | 2012-01-25 18:57:23 +0000 | [diff] [blame] | 2 | #include "Intersection_Tests.h" |
| 3 | #include "Intersections.h" |
| 4 | #include "QuadraticIntersection_TestData.h" |
| 5 | #include "TestUtilities.h" |
caryclark@google.com | b45a1b4 | 2012-05-18 20:50:33 +0000 | [diff] [blame] | 6 | #include "SkTypes.h" |
caryclark@google.com | 27accef | 2012-01-25 18:57:23 +0000 | [diff] [blame] | 7 | |
| 8 | const int firstQuadIntersectionTest = 9; |
| 9 | |
caryclark@google.com | b45a1b4 | 2012-05-18 20:50:33 +0000 | [diff] [blame] | 10 | static void standardTestCases() { |
caryclark@google.com | 27accef | 2012-01-25 18:57:23 +0000 | [diff] [blame] | 11 | for (size_t index = firstQuadIntersectionTest; index < quadraticTests_count; ++index) { |
| 12 | const Quadratic& quad1 = quadraticTests[index][0]; |
| 13 | const Quadratic& quad2 = quadraticTests[index][1]; |
| 14 | Quadratic reduce1, reduce2; |
| 15 | int order1 = reduceOrder(quad1, reduce1); |
| 16 | int order2 = reduceOrder(quad2, reduce2); |
| 17 | if (order1 < 3) { |
| 18 | printf("[%d] quad1 order=%d\n", (int) index, order1); |
| 19 | } |
| 20 | if (order2 < 3) { |
| 21 | printf("[%d] quad2 order=%d\n", (int) index, order2); |
| 22 | } |
| 23 | if (order1 == 3 && order2 == 3) { |
| 24 | Intersections intersections; |
caryclark@google.com | c682590 | 2012-02-03 22:07:47 +0000 | [diff] [blame] | 25 | intersect(reduce1, reduce2, intersections); |
caryclark@google.com | 27accef | 2012-01-25 18:57:23 +0000 | [diff] [blame] | 26 | if (intersections.intersected()) { |
| 27 | for (int pt = 0; pt < intersections.used(); ++pt) { |
| 28 | double tt1 = intersections.fT[0][pt]; |
| 29 | double tx1, ty1; |
| 30 | xy_at_t(quad1, tt1, tx1, ty1); |
| 31 | double tt2 = intersections.fT[1][pt]; |
| 32 | double tx2, ty2; |
| 33 | xy_at_t(quad2, tt2, tx2, ty2); |
| 34 | if (!approximately_equal(tx1, tx2)) { |
| 35 | printf("%s [%d,%d] x!= t1=%g (%g,%g) t2=%g (%g,%g)\n", |
| 36 | __FUNCTION__, (int)index, pt, tt1, tx1, ty1, tt2, tx2, ty2); |
| 37 | } |
| 38 | if (!approximately_equal(ty1, ty2)) { |
| 39 | printf("%s [%d,%d] y!= t1=%g (%g,%g) t2=%g (%g,%g)\n", |
| 40 | __FUNCTION__, (int)index, pt, tt1, tx1, ty1, tt2, tx2, ty2); |
| 41 | } |
| 42 | } |
| 43 | } |
| 44 | } |
| 45 | } |
| 46 | } |
| 47 | |
caryclark@google.com | b45a1b4 | 2012-05-18 20:50:33 +0000 | [diff] [blame] | 48 | static const Quadratic testSet[] = { |
| 49 | {{8, 8}, {10, 10}, {8, -10}}, |
| 50 | {{8, 8}, {12, 12}, {14, 4}}, |
| 51 | {{8, 8}, {9, 9}, {10, 8}} |
| 52 | }; |
| 53 | |
| 54 | const size_t testSetCount = sizeof(testSet) / sizeof(testSet[0]); |
| 55 | |
| 56 | static void oneOffTest() { |
caryclark@google.com | f25edfe | 2012-06-01 18:20:10 +0000 | [diff] [blame^] | 57 | for (size_t outer = 0; outer < testSetCount - 1; ++outer) { |
| 58 | for (size_t inner = outer + 1; inner < testSetCount; ++inner) { |
caryclark@google.com | b45a1b4 | 2012-05-18 20:50:33 +0000 | [diff] [blame] | 59 | const Quadratic& quad1 = testSet[outer]; |
| 60 | const Quadratic& quad2 = testSet[inner]; |
| 61 | Intersections intersections; |
| 62 | intersect(quad1, quad2, intersections); |
| 63 | if (!intersections.intersected()) { |
| 64 | SkDebugf("%s no intersection!\n", __FUNCTION__); |
| 65 | } |
| 66 | for (int pt = 0; pt < intersections.used(); ++pt) { |
| 67 | double tt1 = intersections.fT[0][pt]; |
| 68 | double tx1, ty1; |
| 69 | xy_at_t(quad1, tt1, tx1, ty1); |
| 70 | double tt2 = intersections.fT[1][pt]; |
| 71 | double tx2, ty2; |
| 72 | xy_at_t(quad2, tt2, tx2, ty2); |
| 73 | if (!approximately_equal(tx1, tx2)) { |
| 74 | SkDebugf("%s [%d,%d] x!= t1=%g (%g,%g) t2=%g (%g,%g)\n", |
| 75 | __FUNCTION__, (int)index, pt, tt1, tx1, ty1, tt2, tx2, ty2); |
| 76 | SkASSERT(0); |
| 77 | } |
| 78 | if (!approximately_equal(ty1, ty2)) { |
| 79 | SkDebugf("%s [%d,%d] y!= t1=%g (%g,%g) t2=%g (%g,%g)\n", |
| 80 | __FUNCTION__, (int)index, pt, tt1, tx1, ty1, tt2, tx2, ty2); |
| 81 | SkASSERT(0); |
| 82 | } |
| 83 | SkDebugf("%s [%d][%d] t1=%1.9g (%1.9g, %1.9g) t2=%1.9g\n", __FUNCTION__, |
| 84 | outer, inner, tt1, tx1, tx2, tt2); |
| 85 | } |
| 86 | } |
| 87 | } |
| 88 | } |
| 89 | |
| 90 | void QuadraticIntersection_Test() { |
| 91 | oneOffTest(); |
| 92 | standardTestCases(); |
caryclark@google.com | a3f05fa | 2012-06-01 17:44:28 +0000 | [diff] [blame] | 93 | } |