blob: 3f2c622f12d6dadf0e86540d759e4383a2b77dd1 [file] [log] [blame]
caryclark@google.com27accef2012-01-25 18:57:23 +00001#include "CubicIntersection.h"
2#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) {
33 Intersections intersections;
34 intersectStart(reduce1, reduce2, intersections);
35 if (intersections.intersected()) {
36 for (int pt = 0; pt < intersections.used(); ++pt) {
37 double tt1 = intersections.fT[0][pt];
38 double tx1, ty1;
39 xy_at_t(cubic, tt1, tx1, ty1);
40 double tt2 = intersections.fT[1][pt];
41 double tx2, ty2;
42 xy_at_t(line, tt2, tx2, ty2);
43 if (!approximately_equal(tx1, tx2)) {
44 printf("%s [%d,%d] x!= t1=%g (%g,%g) t2=%g (%g,%g)\n",
45 __FUNCTION__, (int)index, pt, tt1, tx1, ty1, tt2, tx2, ty2);
46 }
47 if (!approximately_equal(ty1, ty2)) {
48 printf("%s [%d,%d] y!= t1=%g (%g,%g) t2=%g (%g,%g)\n",
49 __FUNCTION__, (int)index, pt, tt1, tx1, ty1, tt2, tx2, ty2);
50 }
51 }
52 }
53 }
54 }
55}