blob: f05dbd634f22b192f9f0a3b9a840e60703130124 [file] [log] [blame]
caryclark@google.comc6825902012-02-03 22:07:47 +00001#include "CurveIntersection.h"
caryclark@google.com27accef2012-01-25 18:57:23 +00002#include "Intersection_Tests.h"
3#include "Intersections.h"
4#include "LineUtilities.h"
5#include "TestUtilities.h"
6
7struct lineCubic {
8 Cubic cubic;
9 _Line line;
10} lineCubicTests[] = {
11 {{{0, 0}, {0, 1}, {0, 1}, {1, 1}}, {{0, 1}, {1, 0}}}
12};
13
14size_t lineCubicTests_count = sizeof(lineCubicTests) / sizeof(lineCubicTests[0]);
15
16const int firstLineCubicIntersectionTest = 0;
17
18void 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.comc6825902012-02-03 22:07:47 +000033 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.com27accef2012-01-25 18:57:23 +000049 }
50 }
51 }
52 }
53}