blob: 3f49b95267b82b4bdfd09539cb85faa335c6bdba [file] [log] [blame]
caryclark@google.com9e49fb62012-08-27 14:11:33 +00001/*
2 * Copyright 2012 Google Inc.
3 *
4 * Use of this source code is governed by a BSD-style license that can be
5 * found in the LICENSE file.
6 */
caryclark@google.comc6825902012-02-03 22:07:47 +00007#include "CurveIntersection.h"
caryclark@google.com27accef2012-01-25 18:57:23 +00008#include "Intersection_Tests.h"
9#include "QuadraticIntersection_TestData.h"
10#include "TestUtilities.h"
caryclark@google.comb45a1b42012-05-18 20:50:33 +000011#include "SkTypes.h"
caryclark@google.com27accef2012-01-25 18:57:23 +000012
caryclark@google.comb45a1b42012-05-18 20:50:33 +000013static const Quadratic testSet[] = {
14 {{1, 1}, {2, 2}, {1, 1.000003}},
15 {{1, 0}, {2, 6}, {3, 0}}
16};
17
18static const size_t testSetCount = sizeof(testSet) / sizeof(testSet[0]);
19
20
21static void oneOffTest() {
22 SkDebugf("%s FLT_EPSILON=%1.9g\n", __FUNCTION__, FLT_EPSILON);
caryclark@google.comf25edfe2012-06-01 18:20:10 +000023 for (size_t index = 0; index < testSetCount; ++index) {
caryclark@google.comb45a1b42012-05-18 20:50:33 +000024 const Quadratic& quad = testSet[index];
25 Quadratic reduce;
26 int order = reduceOrder(quad, reduce);
27 SkASSERT(order == 3);
28 }
29}
30
31static void standardTestCases() {
caryclark@google.com27accef2012-01-25 18:57:23 +000032 size_t index;
33 Quadratic reduce;
34 int order;
35 enum {
36 RunAll,
37 RunQuadraticLines,
38 RunQuadraticModLines,
39 RunNone
40 } run = RunAll;
41 int firstTestIndex = 0;
42#if 0
43 run = RunQuadraticLines;
44 firstTestIndex = 1;
45#endif
46 int firstQuadraticLineTest = run == RunAll ? 0 : run == RunQuadraticLines ? firstTestIndex : INT_MAX;
47 int firstQuadraticModLineTest = run == RunAll ? 0 : run == RunQuadraticModLines ? firstTestIndex : INT_MAX;
48
49 for (index = firstQuadraticLineTest; index < quadraticLines_count; ++index) {
50 const Quadratic& quad = quadraticLines[index];
51 order = reduceOrder(quad, reduce);
52 if (order != 2) {
53 printf("[%d] line quad order=%d\n", (int) index, order);
54 }
55 }
56 for (index = firstQuadraticModLineTest; index < quadraticModEpsilonLines_count; ++index) {
57 const Quadratic& quad = quadraticModEpsilonLines[index];
58 order = reduceOrder(quad, reduce);
59 if (order != 3) {
60 printf("[%d] line mod quad order=%d\n", (int) index, order);
61 }
62 }
63}
caryclark@google.comb45a1b42012-05-18 20:50:33 +000064
65void QuadraticReduceOrder_Test() {
66 oneOffTest();
67 standardTestCases();
68}