blob: 017a44ed77d60edc4c7569088b09ca2685295484 [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 lineQuad {
8 Quadratic quad;
9 _Line line;
10} lineQuadTests[] = {
11 {{{0, 0}, {0, 1}, {1, 1}}, {{0, 1}, {1, 0}}}
12};
13
14size_t lineQuadTests_count = sizeof(lineQuadTests) / sizeof(lineQuadTests[0]);
15
16const int firstLineQuadIntersectionTest = 0;
17
18void LineQuadraticIntersection_Test() {
19 for (size_t index = firstLineQuadIntersectionTest; index < lineQuadTests_count; ++index) {
20 const Quadratic& quad = lineQuadTests[index].quad;
21 const _Line& line = lineQuadTests[index].line;
22 Quadratic reduce1;
23 _Line reduce2;
24 int order1 = reduceOrder(quad, reduce1);
25 int order2 = reduceOrder(line, reduce2);
26 if (order1 < 3) {
27 printf("[%d] quad 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 == 3 && order2 == 2) {
33 Intersections intersections;
caryclark@google.comc6825902012-02-03 22:07:47 +000034 intersect(reduce1, reduce2, intersections);
caryclark@google.com27accef2012-01-25 18:57:23 +000035 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(quad, 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}