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 "LineUtilities.h" |
| 5 | #include "TestUtilities.h" |
| 6 | |
| 7 | struct lineCubic { |
| 8 | Cubic cubic; |
| 9 | _Line line; |
| 10 | } lineCubicTests[] = { |
| 11 | {{{0, 0}, {0, 1}, {0, 1}, {1, 1}}, {{0, 1}, {1, 0}}} |
| 12 | }; |
| 13 | |
| 14 | size_t lineCubicTests_count = sizeof(lineCubicTests) / sizeof(lineCubicTests[0]); |
| 15 | |
| 16 | const int firstLineCubicIntersectionTest = 0; |
| 17 | |
| 18 | void LineCubicIntersection_Test() { |
| 19 | for (size_t index = firstLineCubicIntersectionTest; index < lineCubicTests_count; ++index) { |
| 20 | const Cubic& cubic = lineCubicTests[index].cubic; |
| 21 | const _Line& line = lineCubicTests[index].line; |
| 22 | Cubic reduce1; |
| 23 | _Line reduce2; |
| 24 | int order1 = reduceOrder(cubic, reduce1, kReduceOrder_NoQuadraticsAllowed); |
| 25 | int order2 = reduceOrder(line, reduce2); |
| 26 | if (order1 < 4) { |
| 27 | printf("[%d] cubic order=%d\n", (int) index, order1); |
| 28 | } |
| 29 | if (order2 < 2) { |
| 30 | printf("[%d] line order=%d\n", (int) index, order2); |
| 31 | } |
| 32 | if (order1 == 4 && order2 == 2) { |
caryclark@google.com | c682590 | 2012-02-03 22:07:47 +0000 | [diff] [blame] | 33 | double range1[2], range2[2]; |
| 34 | int roots = intersect(reduce1, reduce2, range1, range2); |
| 35 | for (int pt = 0; pt < roots; ++pt) { |
| 36 | double tt1 = range1[pt]; |
| 37 | double tx1, ty1; |
| 38 | xy_at_t(cubic, tt1, tx1, ty1); |
| 39 | double tt2 = range2[pt]; |
| 40 | double tx2, ty2; |
| 41 | xy_at_t(line, tt2, tx2, ty2); |
| 42 | if (!approximately_equal(tx1, tx2)) { |
| 43 | printf("%s [%d,%d] x!= t1=%g (%g,%g) t2=%g (%g,%g)\n", |
| 44 | __FUNCTION__, (int)index, pt, tt1, tx1, ty1, tt2, tx2, ty2); |
| 45 | } |
| 46 | if (!approximately_equal(ty1, ty2)) { |
| 47 | printf("%s [%d,%d] y!= t1=%g (%g,%g) t2=%g (%g,%g)\n", |
| 48 | __FUNCTION__, (int)index, pt, tt1, tx1, ty1, tt2, tx2, ty2); |
caryclark@google.com | 27accef | 2012-01-25 18:57:23 +0000 | [diff] [blame] | 49 | } |
| 50 | } |
| 51 | } |
| 52 | } |
| 53 | } |