caryclark@google.com | c682590 | 2012-02-03 22:07:47 +0000 | [diff] [blame] | 1 | #include "CurveIntersection.h" |
caryclark@google.com | 8dcf114 | 2012-07-02 20:27:02 +0000 | [diff] [blame] | 2 | #include "CurveUtilities.h" |
caryclark@google.com | 639df89 | 2012-01-10 21:46:10 +0000 | [diff] [blame] | 3 | #include "CubicIntersection_TestData.h" |
caryclark@google.com | 27accef | 2012-01-25 18:57:23 +0000 | [diff] [blame] | 4 | #include "Intersection_Tests.h" |
caryclark@google.com | 639df89 | 2012-01-10 21:46:10 +0000 | [diff] [blame] | 5 | #include "Intersections.h" |
| 6 | #include "TestUtilities.h" |
| 7 | |
| 8 | const int firstCubicIntersectionTest = 9; |
| 9 | |
| 10 | void CubicIntersection_Test() { |
| 11 | for (size_t index = firstCubicIntersectionTest; index < tests_count; ++index) { |
| 12 | const Cubic& cubic1 = tests[index][0]; |
| 13 | const Cubic& cubic2 = tests[index][1]; |
| 14 | Cubic reduce1, reduce2; |
| 15 | int order1 = reduceOrder(cubic1, reduce1, kReduceOrder_NoQuadraticsAllowed); |
| 16 | int order2 = reduceOrder(cubic2, reduce2, kReduceOrder_NoQuadraticsAllowed); |
| 17 | if (order1 < 4) { |
caryclark@google.com | 27accef | 2012-01-25 18:57:23 +0000 | [diff] [blame] | 18 | printf("%s [%d] cubic1 order=%d\n", __FUNCTION__, (int) index, order1); |
| 19 | continue; |
caryclark@google.com | 639df89 | 2012-01-10 21:46:10 +0000 | [diff] [blame] | 20 | } |
| 21 | if (order2 < 4) { |
caryclark@google.com | 27accef | 2012-01-25 18:57:23 +0000 | [diff] [blame] | 22 | printf("%s [%d] cubic2 order=%d\n", __FUNCTION__, (int) index, order2); |
| 23 | continue; |
caryclark@google.com | 639df89 | 2012-01-10 21:46:10 +0000 | [diff] [blame] | 24 | } |
caryclark@google.com | 27accef | 2012-01-25 18:57:23 +0000 | [diff] [blame] | 25 | if (implicit_matches(reduce1, reduce2)) { |
| 26 | printf("%s [%d] coincident\n", __FUNCTION__, (int) index); |
| 27 | continue; |
| 28 | } |
| 29 | Intersections tIntersections; |
caryclark@google.com | c682590 | 2012-02-03 22:07:47 +0000 | [diff] [blame] | 30 | intersect(reduce1, reduce2, tIntersections); |
caryclark@google.com | 27accef | 2012-01-25 18:57:23 +0000 | [diff] [blame] | 31 | if (!tIntersections.intersected()) { |
| 32 | printf("%s [%d] no intersection\n", __FUNCTION__, (int) index); |
| 33 | continue; |
| 34 | } |
| 35 | for (int pt = 0; pt < tIntersections.used(); ++pt) { |
| 36 | double tt1 = tIntersections.fT[0][pt]; |
| 37 | double tx1, ty1; |
| 38 | xy_at_t(cubic1, tt1, tx1, ty1); |
| 39 | double tt2 = tIntersections.fT[1][pt]; |
| 40 | double tx2, ty2; |
| 41 | xy_at_t(cubic2, 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 | 639df89 | 2012-01-10 21:46:10 +0000 | [diff] [blame] | 49 | } |
| 50 | } |
| 51 | } |
| 52 | } |