caryclark@google.com | 4961201 | 2013-04-08 20:37:35 +0000 | [diff] [blame] | 1 | /* |
| 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 | */ |
| 7 | #include "PathOpsQuadIntersectionTestData.h" |
| 8 | #include "SkIntersections.h" |
| 9 | #include "SkPathOpsRect.h" |
| 10 | #include "SkReduceOrder.h" |
| 11 | #include "Test.h" |
| 12 | |
caryclark | a35ab3e | 2016-10-20 08:32:18 -0700 | [diff] [blame] | 13 | static const QuadPts testSet[] = { |
caryclark@google.com | 4961201 | 2013-04-08 20:37:35 +0000 | [diff] [blame] | 14 | {{{1, 1}, {2, 2}, {1, 1.000003}}}, |
| 15 | {{{1, 0}, {2, 6}, {3, 0}}} |
| 16 | }; |
| 17 | |
caryclark@google.com | ad65a3e | 2013-04-15 19:13:59 +0000 | [diff] [blame] | 18 | static const size_t testSetCount = SK_ARRAY_COUNT(testSet); |
caryclark@google.com | 4961201 | 2013-04-08 20:37:35 +0000 | [diff] [blame] | 19 | |
| 20 | static void oneOffTest(skiatest::Reporter* reporter) { |
| 21 | for (size_t index = 0; index < testSetCount; ++index) { |
caryclark | a35ab3e | 2016-10-20 08:32:18 -0700 | [diff] [blame] | 22 | const QuadPts& q = testSet[index]; |
| 23 | SkDQuad quad; |
| 24 | quad.debugSet(q.fPts); |
caryclark@google.com | 4961201 | 2013-04-08 20:37:35 +0000 | [diff] [blame] | 25 | SkReduceOrder reducer; |
caryclark@google.com | 927b702 | 2013-11-25 14:18:21 +0000 | [diff] [blame] | 26 | SkDEBUGCODE(int result = ) reducer.reduce(quad); |
caryclark@google.com | 4961201 | 2013-04-08 20:37:35 +0000 | [diff] [blame] | 27 | SkASSERT(result == 3); |
| 28 | } |
| 29 | } |
| 30 | |
| 31 | static void standardTestCases(skiatest::Reporter* reporter) { |
| 32 | size_t index; |
| 33 | SkReduceOrder reducer; |
| 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 |
| 47 | : SK_MaxS32; |
| 48 | int firstQuadraticModLineTest = run == RunAll ? 0 : run == RunQuadraticModLines ? firstTestIndex |
| 49 | : SK_MaxS32; |
| 50 | |
| 51 | for (index = firstQuadraticLineTest; index < quadraticLines_count; ++index) { |
caryclark | a35ab3e | 2016-10-20 08:32:18 -0700 | [diff] [blame] | 52 | const QuadPts& q = quadraticLines[index]; |
| 53 | SkDQuad quad; |
| 54 | quad.debugSet(q.fPts); |
caryclark@google.com | 927b702 | 2013-11-25 14:18:21 +0000 | [diff] [blame] | 55 | order = reducer.reduce(quad); |
caryclark@google.com | 4961201 | 2013-04-08 20:37:35 +0000 | [diff] [blame] | 56 | if (order != 2) { |
bungeman@google.com | fab44db | 2013-10-11 18:50:45 +0000 | [diff] [blame] | 57 | SkDebugf("[%d] line quad order=%d\n", (int) index, order); |
caryclark@google.com | 4961201 | 2013-04-08 20:37:35 +0000 | [diff] [blame] | 58 | } |
| 59 | } |
| 60 | for (index = firstQuadraticModLineTest; index < quadraticModEpsilonLines_count; ++index) { |
caryclark | a35ab3e | 2016-10-20 08:32:18 -0700 | [diff] [blame] | 61 | const QuadPts& q = quadraticModEpsilonLines[index]; |
| 62 | SkDQuad quad; |
| 63 | quad.debugSet(q.fPts); |
caryclark@google.com | 927b702 | 2013-11-25 14:18:21 +0000 | [diff] [blame] | 64 | order = reducer.reduce(quad); |
caryclark | 65f5531 | 2014-11-13 06:58:52 -0800 | [diff] [blame] | 65 | if (order != 2 && order != 3) { // FIXME: data probably is not good |
bungeman@google.com | fab44db | 2013-10-11 18:50:45 +0000 | [diff] [blame] | 66 | SkDebugf("[%d] line mod quad order=%d\n", (int) index, order); |
caryclark@google.com | 4961201 | 2013-04-08 20:37:35 +0000 | [diff] [blame] | 67 | } |
| 68 | } |
| 69 | } |
| 70 | |
tfarina@chromium.org | 78e7b4e | 2014-01-02 21:45:03 +0000 | [diff] [blame] | 71 | DEF_TEST(PathOpsReduceOrderQuad, reporter) { |
caryclark@google.com | 4961201 | 2013-04-08 20:37:35 +0000 | [diff] [blame] | 72 | oneOffTest(reporter); |
| 73 | standardTestCases(reporter); |
| 74 | } |