blob: b716cdb1a8764f16a70402b8e33611f5ca0808b3 [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 "QuadraticIntersection_TestData.h"
4#include "TestUtilities.h"
caryclark@google.comb45a1b42012-05-18 20:50:33 +00005#include "SkTypes.h"
caryclark@google.com27accef2012-01-25 18:57:23 +00006
caryclark@google.comb45a1b42012-05-18 20:50:33 +00007static const Quadratic testSet[] = {
8 {{1, 1}, {2, 2}, {1, 1.000003}},
9 {{1, 0}, {2, 6}, {3, 0}}
10};
11
12static const size_t testSetCount = sizeof(testSet) / sizeof(testSet[0]);
13
14
15static void oneOffTest() {
16 SkDebugf("%s FLT_EPSILON=%1.9g\n", __FUNCTION__, FLT_EPSILON);
17 for (int index = 0; index < testSetCount; ++index) {
18 const Quadratic& quad = testSet[index];
19 Quadratic reduce;
20 int order = reduceOrder(quad, reduce);
21 SkASSERT(order == 3);
22 }
23}
24
25static void standardTestCases() {
caryclark@google.com27accef2012-01-25 18:57:23 +000026 size_t index;
27 Quadratic reduce;
28 int order;
29 enum {
30 RunAll,
31 RunQuadraticLines,
32 RunQuadraticModLines,
33 RunNone
34 } run = RunAll;
35 int firstTestIndex = 0;
36#if 0
37 run = RunQuadraticLines;
38 firstTestIndex = 1;
39#endif
40 int firstQuadraticLineTest = run == RunAll ? 0 : run == RunQuadraticLines ? firstTestIndex : INT_MAX;
41 int firstQuadraticModLineTest = run == RunAll ? 0 : run == RunQuadraticModLines ? firstTestIndex : INT_MAX;
42
43 for (index = firstQuadraticLineTest; index < quadraticLines_count; ++index) {
44 const Quadratic& quad = quadraticLines[index];
45 order = reduceOrder(quad, reduce);
46 if (order != 2) {
47 printf("[%d] line quad order=%d\n", (int) index, order);
48 }
49 }
50 for (index = firstQuadraticModLineTest; index < quadraticModEpsilonLines_count; ++index) {
51 const Quadratic& quad = quadraticModEpsilonLines[index];
52 order = reduceOrder(quad, reduce);
53 if (order != 3) {
54 printf("[%d] line mod quad order=%d\n", (int) index, order);
55 }
56 }
57}
caryclark@google.comb45a1b42012-05-18 20:50:33 +000058
59void QuadraticReduceOrder_Test() {
60 oneOffTest();
61 standardTestCases();
62}