blob: 005e77781cdbb1c7c64cd3d2e17201a6adb6213c [file] [log] [blame]
caryclark@google.comc6825902012-02-03 22:07:47 +00001#include "CurveIntersection.h"
caryclark@google.com639df892012-01-10 21:46:10 +00002#include "CubicIntersection_TestData.h"
caryclark@google.com27accef2012-01-25 18:57:23 +00003#include "Intersection_Tests.h"
caryclark@google.com639df892012-01-10 21:46:10 +00004#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) {
caryclark@google.com27accef2012-01-25 18:57:23 +000017 printf("%s [%d] cubic1 order=%d\n", __FUNCTION__, (int) index, order1);
18 continue;
caryclark@google.com639df892012-01-10 21:46:10 +000019 }
20 if (order2 < 4) {
caryclark@google.com27accef2012-01-25 18:57:23 +000021 printf("%s [%d] cubic2 order=%d\n", __FUNCTION__, (int) index, order2);
22 continue;
caryclark@google.com639df892012-01-10 21:46:10 +000023 }
caryclark@google.com27accef2012-01-25 18:57:23 +000024 if (implicit_matches(reduce1, reduce2)) {
25 printf("%s [%d] coincident\n", __FUNCTION__, (int) index);
26 continue;
27 }
28 Intersections tIntersections;
caryclark@google.comc6825902012-02-03 22:07:47 +000029 intersect(reduce1, reduce2, tIntersections);
caryclark@google.com27accef2012-01-25 18:57:23 +000030 if (!tIntersections.intersected()) {
31 printf("%s [%d] no intersection\n", __FUNCTION__, (int) index);
32 continue;
33 }
34 for (int pt = 0; pt < tIntersections.used(); ++pt) {
35 double tt1 = tIntersections.fT[0][pt];
36 double tx1, ty1;
37 xy_at_t(cubic1, tt1, tx1, ty1);
38 double tt2 = tIntersections.fT[1][pt];
39 double tx2, ty2;
40 xy_at_t(cubic2, tt2, tx2, ty2);
41 if (!approximately_equal(tx1, tx2)) {
42 printf("%s [%d,%d] x!= t1=%g (%g,%g) t2=%g (%g,%g)\n",
43 __FUNCTION__, (int)index, pt, tt1, tx1, ty1, tt2, tx2, ty2);
44 }
45 if (!approximately_equal(ty1, ty2)) {
46 printf("%s [%d,%d] y!= t1=%g (%g,%g) t2=%g (%g,%g)\n",
47 __FUNCTION__, (int)index, pt, tt1, tx1, ty1, tt2, tx2, ty2);
caryclark@google.com639df892012-01-10 21:46:10 +000048 }
49 }
50 }
51}