blob: adf91bde86f4e5cf114b385e5f4af6fb84ff798c [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 "QuadraticIntersection_TestData.h"
5#include "TestUtilities.h"
caryclark@google.comb45a1b42012-05-18 20:50:33 +00006#include "SkTypes.h"
caryclark@google.com27accef2012-01-25 18:57:23 +00007
8const int firstQuadIntersectionTest = 9;
9
caryclark@google.comb45a1b42012-05-18 20:50:33 +000010static void standardTestCases() {
caryclark@google.com27accef2012-01-25 18:57:23 +000011 for (size_t index = firstQuadIntersectionTest; index < quadraticTests_count; ++index) {
12 const Quadratic& quad1 = quadraticTests[index][0];
13 const Quadratic& quad2 = quadraticTests[index][1];
14 Quadratic reduce1, reduce2;
15 int order1 = reduceOrder(quad1, reduce1);
16 int order2 = reduceOrder(quad2, reduce2);
17 if (order1 < 3) {
18 printf("[%d] quad1 order=%d\n", (int) index, order1);
19 }
20 if (order2 < 3) {
21 printf("[%d] quad2 order=%d\n", (int) index, order2);
22 }
23 if (order1 == 3 && order2 == 3) {
24 Intersections intersections;
caryclark@google.comc6825902012-02-03 22:07:47 +000025 intersect(reduce1, reduce2, intersections);
caryclark@google.com27accef2012-01-25 18:57:23 +000026 if (intersections.intersected()) {
27 for (int pt = 0; pt < intersections.used(); ++pt) {
28 double tt1 = intersections.fT[0][pt];
29 double tx1, ty1;
30 xy_at_t(quad1, tt1, tx1, ty1);
31 double tt2 = intersections.fT[1][pt];
32 double tx2, ty2;
33 xy_at_t(quad2, tt2, tx2, ty2);
34 if (!approximately_equal(tx1, tx2)) {
35 printf("%s [%d,%d] x!= t1=%g (%g,%g) t2=%g (%g,%g)\n",
36 __FUNCTION__, (int)index, pt, tt1, tx1, ty1, tt2, tx2, ty2);
37 }
38 if (!approximately_equal(ty1, ty2)) {
39 printf("%s [%d,%d] y!= t1=%g (%g,%g) t2=%g (%g,%g)\n",
40 __FUNCTION__, (int)index, pt, tt1, tx1, ty1, tt2, tx2, ty2);
41 }
42 }
43 }
44 }
45 }
46}
47
caryclark@google.comb45a1b42012-05-18 20:50:33 +000048static const Quadratic testSet[] = {
49 {{8, 8}, {10, 10}, {8, -10}},
50 {{8, 8}, {12, 12}, {14, 4}},
51 {{8, 8}, {9, 9}, {10, 8}}
52};
53
54const size_t testSetCount = sizeof(testSet) / sizeof(testSet[0]);
55
56static void oneOffTest() {
caryclark@google.comf25edfe2012-06-01 18:20:10 +000057 for (size_t outer = 0; outer < testSetCount - 1; ++outer) {
58 for (size_t inner = outer + 1; inner < testSetCount; ++inner) {
caryclark@google.comb45a1b42012-05-18 20:50:33 +000059 const Quadratic& quad1 = testSet[outer];
60 const Quadratic& quad2 = testSet[inner];
61 Intersections intersections;
62 intersect(quad1, quad2, intersections);
63 if (!intersections.intersected()) {
64 SkDebugf("%s no intersection!\n", __FUNCTION__);
65 }
66 for (int pt = 0; pt < intersections.used(); ++pt) {
67 double tt1 = intersections.fT[0][pt];
68 double tx1, ty1;
69 xy_at_t(quad1, tt1, tx1, ty1);
70 double tt2 = intersections.fT[1][pt];
71 double tx2, ty2;
72 xy_at_t(quad2, tt2, tx2, ty2);
73 if (!approximately_equal(tx1, tx2)) {
74 SkDebugf("%s [%d,%d] x!= t1=%g (%g,%g) t2=%g (%g,%g)\n",
75 __FUNCTION__, (int)index, pt, tt1, tx1, ty1, tt2, tx2, ty2);
76 SkASSERT(0);
77 }
78 if (!approximately_equal(ty1, ty2)) {
79 SkDebugf("%s [%d,%d] y!= t1=%g (%g,%g) t2=%g (%g,%g)\n",
80 __FUNCTION__, (int)index, pt, tt1, tx1, ty1, tt2, tx2, ty2);
81 SkASSERT(0);
82 }
83 SkDebugf("%s [%d][%d] t1=%1.9g (%1.9g, %1.9g) t2=%1.9g\n", __FUNCTION__,
84 outer, inner, tt1, tx1, tx2, tt2);
85 }
86 }
87 }
88}
89
90void QuadraticIntersection_Test() {
91 oneOffTest();
92 standardTestCases();
caryclark@google.coma3f05fa2012-06-01 17:44:28 +000093}