blob: e9e8b4bc9297a8a35f1e7c887d0132f272f494f1 [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"
11
caryclark@google.comb45a1b42012-05-18 20:50:33 +000012static const Quadratic testSet[] = {
13 {{1, 1}, {2, 2}, {1, 1.000003}},
14 {{1, 0}, {2, 6}, {3, 0}}
15};
16
17static const size_t testSetCount = sizeof(testSet) / sizeof(testSet[0]);
18
19
20static void oneOffTest() {
21 SkDebugf("%s FLT_EPSILON=%1.9g\n", __FUNCTION__, FLT_EPSILON);
caryclark@google.comf25edfe2012-06-01 18:20:10 +000022 for (size_t index = 0; index < testSetCount; ++index) {
caryclark@google.comb45a1b42012-05-18 20:50:33 +000023 const Quadratic& quad = testSet[index];
24 Quadratic reduce;
caryclark@google.com1304bb22013-03-13 20:29:41 +000025 SkDEBUGCODE(int result = ) reduceOrder(quad, reduce, kReduceOrder_TreatAsFill);
26 SkASSERT(result == 3);
caryclark@google.comb45a1b42012-05-18 20:50:33 +000027 }
28}
29
30static void standardTestCases() {
caryclark@google.com27accef2012-01-25 18:57:23 +000031 size_t index;
32 Quadratic reduce;
33 int order;
34 enum {
35 RunAll,
36 RunQuadraticLines,
37 RunQuadraticModLines,
38 RunNone
39 } run = RunAll;
40 int firstTestIndex = 0;
41#if 0
42 run = RunQuadraticLines;
43 firstTestIndex = 1;
44#endif
caryclark@google.comaa358312013-01-29 20:28:49 +000045 int firstQuadraticLineTest = run == RunAll ? 0 : run == RunQuadraticLines ? firstTestIndex : SK_MaxS32;
46 int firstQuadraticModLineTest = run == RunAll ? 0 : run == RunQuadraticModLines ? firstTestIndex : SK_MaxS32;
caryclark@google.com27accef2012-01-25 18:57:23 +000047
48 for (index = firstQuadraticLineTest; index < quadraticLines_count; ++index) {
49 const Quadratic& quad = quadraticLines[index];
caryclark@google.com47d73da2013-02-17 01:41:25 +000050 order = reduceOrder(quad, reduce, kReduceOrder_TreatAsFill);
caryclark@google.com27accef2012-01-25 18:57:23 +000051 if (order != 2) {
52 printf("[%d] line quad order=%d\n", (int) index, order);
53 }
54 }
55 for (index = firstQuadraticModLineTest; index < quadraticModEpsilonLines_count; ++index) {
56 const Quadratic& quad = quadraticModEpsilonLines[index];
caryclark@google.com47d73da2013-02-17 01:41:25 +000057 order = reduceOrder(quad, reduce, kReduceOrder_TreatAsFill);
caryclark@google.com27accef2012-01-25 18:57:23 +000058 if (order != 3) {
59 printf("[%d] line mod quad order=%d\n", (int) index, order);
60 }
61 }
62}
caryclark@google.comb45a1b42012-05-18 20:50:33 +000063
64void QuadraticReduceOrder_Test() {
65 oneOffTest();
66 standardTestCases();
67}