blob: 7551dc3df244281a98ec462f31a14db5bd8e8cd8 [file] [log] [blame]
caryclark@google.comc6825902012-02-03 22:07:47 +00001#include "CurveIntersection.h"
caryclark@google.com8dcf1142012-07-02 20:27:02 +00002#include "CurveUtilities.h"
caryclark@google.com27accef2012-01-25 18:57:23 +00003#include "Intersection_Tests.h"
4#include "Intersections.h"
caryclark@google.com27accef2012-01-25 18:57:23 +00005#include "TestUtilities.h"
6
7struct lineQuad {
8 Quadratic quad;
9 _Line line;
10} lineQuadTests[] = {
caryclark@google.comfa0588f2012-04-26 21:01:06 +000011 {{{2, 0}, {1, 1}, {2, 2}}, {{0, 0}, {0, 2}}},
12 {{{4, 0}, {0, 1}, {4, 2}}, {{3, 1}, {4, 1}}},
13 {{{0, 0}, {0, 1}, {1, 1}}, {{0, 1}, {1, 0}}},
caryclark@google.com27accef2012-01-25 18:57:23 +000014};
15
16size_t lineQuadTests_count = sizeof(lineQuadTests) / sizeof(lineQuadTests[0]);
17
18const int firstLineQuadIntersectionTest = 0;
19
20void LineQuadraticIntersection_Test() {
21 for (size_t index = firstLineQuadIntersectionTest; index < lineQuadTests_count; ++index) {
22 const Quadratic& quad = lineQuadTests[index].quad;
23 const _Line& line = lineQuadTests[index].line;
24 Quadratic reduce1;
25 _Line reduce2;
26 int order1 = reduceOrder(quad, reduce1);
27 int order2 = reduceOrder(line, reduce2);
28 if (order1 < 3) {
29 printf("[%d] quad order=%d\n", (int) index, order1);
30 }
31 if (order2 < 2) {
32 printf("[%d] line order=%d\n", (int) index, order2);
33 }
34 if (order1 == 3 && order2 == 2) {
35 Intersections intersections;
caryclark@google.comc6825902012-02-03 22:07:47 +000036 intersect(reduce1, reduce2, intersections);
caryclark@google.com27accef2012-01-25 18:57:23 +000037 if (intersections.intersected()) {
38 for (int pt = 0; pt < intersections.used(); ++pt) {
39 double tt1 = intersections.fT[0][pt];
40 double tx1, ty1;
41 xy_at_t(quad, tt1, tx1, ty1);
42 double tt2 = intersections.fT[1][pt];
43 double tx2, ty2;
44 xy_at_t(line, tt2, tx2, ty2);
45 if (!approximately_equal(tx1, tx2)) {
46 printf("%s [%d,%d] x!= t1=%g (%g,%g) t2=%g (%g,%g)\n",
47 __FUNCTION__, (int)index, pt, tt1, tx1, ty1, tt2, tx2, ty2);
48 }
49 if (!approximately_equal(ty1, ty2)) {
50 printf("%s [%d,%d] y!= t1=%g (%g,%g) t2=%g (%g,%g)\n",
51 __FUNCTION__, (int)index, pt, tt1, tx1, ty1, tt2, tx2, ty2);
52 }
53 }
54 }
55 }
56 }
57}