blob: 0ae174964a28c58e8ea5804c9921a778998ef2ae [file] [log] [blame]
caryclark@google.com639df892012-01-10 21:46:10 +00001#include "CubicIntersection.h"
2#include "CubicIntersection_TestData.h"
3#include "CubicIntersection_Tests.h"
4#include "Intersections.h"
5#include "TestUtilities.h"
6
7const int firstCubicIntersectionTest = 9;
8
9void CubicIntersection_Test() {
10 for (size_t index = firstCubicIntersectionTest; index < tests_count; ++index) {
11 const Cubic& cubic1 = tests[index][0];
12 const Cubic& cubic2 = tests[index][1];
13 Cubic reduce1, reduce2;
14 int order1 = reduceOrder(cubic1, reduce1, kReduceOrder_NoQuadraticsAllowed);
15 int order2 = reduceOrder(cubic2, reduce2, kReduceOrder_NoQuadraticsAllowed);
16 if (order1 < 4) {
17 printf("[%d] cubic1 order=%d\n", (int) index, order1);
18 }
19 if (order2 < 4) {
20 printf("[%d] cubic2 order=%d\n", (int) index, order2);
21 }
22 if (order1 == 4 && order2 == 4) {
23 Intersections tIntersections;
24 intersectStartT(reduce1, reduce2, tIntersections);
25#ifdef COMPUTE_BY_CUBIC_SUBDIVISION
26 Intersections intersections;
27 intersectStart(reduce1, reduce2, intersections);
28#endif
29 if (tIntersections.intersected()) {
30 for (int pt = 0; pt < tIntersections.used(); ++pt) {
31#ifdef COMPUTE_BY_CUBIC_SUBDIVISION
32 double t1 = intersections.fT[0][pt];
33 double x1, y1;
34 xy_at_t(cubic1, t1, x1, y1);
35 double t2 = intersections.fT[1][pt];
36 double x2, y2;
37 xy_at_t(cubic2, t2, x2, y2);
38 if (!approximately_equal(x1, x2)) {
39 printf("%s [%d] (1) t1=%g (%g,%g) t2=%g (%g,%g)\n",
40 __FUNCTION__, pt, t1, x1, y1, t2, x2, y2);
41 }
42 if (!approximately_equal(y1, y2)) {
43 printf("%s [%d] (2) t1=%g (%g,%g) t2=%g (%g,%g)\n",
44 __FUNCTION__, pt, t1, x1, y1, t2, x2, y2);
45 }
46#endif
47 double tt1 = tIntersections.fT[0][pt];
48 double tx1, ty1;
49 xy_at_t(cubic1, tt1, tx1, ty1);
50 double tt2 = tIntersections.fT[1][pt];
51 double tx2, ty2;
52 xy_at_t(cubic2, tt2, tx2, ty2);
53 if (!approximately_equal(tx1, tx2)) {
54 printf("%s [%d,%d] x!= t1=%g (%g,%g) t2=%g (%g,%g)\n",
55 __FUNCTION__, (int)index, pt, tt1, tx1, ty1, tt2, tx2, ty2);
56 }
57 if (!approximately_equal(ty1, ty2)) {
58 printf("%s [%d,%d] y!= t1=%g (%g,%g) t2=%g (%g,%g)\n",
59 __FUNCTION__, (int)index, pt, tt1, tx1, ty1, tt2, tx2, ty2);
60 }
61 }
62 }
63 }
64 }
65}