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 | |
| 13 | static const SkDQuad testSet[] = { |
| 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) { |
| 22 | const SkDQuad& quad = testSet[index]; |
| 23 | SkReduceOrder reducer; |
caryclark@google.com | 927b702 | 2013-11-25 14:18:21 +0000 | [diff] [blame] | 24 | SkDEBUGCODE(int result = ) reducer.reduce(quad); |
caryclark@google.com | 4961201 | 2013-04-08 20:37:35 +0000 | [diff] [blame] | 25 | SkASSERT(result == 3); |
| 26 | } |
| 27 | } |
| 28 | |
| 29 | static void standardTestCases(skiatest::Reporter* reporter) { |
| 30 | size_t index; |
| 31 | SkReduceOrder reducer; |
| 32 | int order; |
| 33 | enum { |
| 34 | RunAll, |
| 35 | RunQuadraticLines, |
| 36 | RunQuadraticModLines, |
| 37 | RunNone |
| 38 | } run = RunAll; |
| 39 | int firstTestIndex = 0; |
| 40 | #if 0 |
| 41 | run = RunQuadraticLines; |
| 42 | firstTestIndex = 1; |
| 43 | #endif |
| 44 | int firstQuadraticLineTest = run == RunAll ? 0 : run == RunQuadraticLines ? firstTestIndex |
| 45 | : SK_MaxS32; |
| 46 | int firstQuadraticModLineTest = run == RunAll ? 0 : run == RunQuadraticModLines ? firstTestIndex |
| 47 | : SK_MaxS32; |
| 48 | |
| 49 | for (index = firstQuadraticLineTest; index < quadraticLines_count; ++index) { |
| 50 | const SkDQuad& quad = quadraticLines[index]; |
caryclark@google.com | 927b702 | 2013-11-25 14:18:21 +0000 | [diff] [blame] | 51 | order = reducer.reduce(quad); |
caryclark@google.com | 4961201 | 2013-04-08 20:37:35 +0000 | [diff] [blame] | 52 | if (order != 2) { |
bungeman@google.com | fab44db | 2013-10-11 18:50:45 +0000 | [diff] [blame] | 53 | SkDebugf("[%d] line quad order=%d\n", (int) index, order); |
caryclark@google.com | 4961201 | 2013-04-08 20:37:35 +0000 | [diff] [blame] | 54 | } |
| 55 | } |
| 56 | for (index = firstQuadraticModLineTest; index < quadraticModEpsilonLines_count; ++index) { |
| 57 | const SkDQuad& quad = quadraticModEpsilonLines[index]; |
caryclark@google.com | 927b702 | 2013-11-25 14:18:21 +0000 | [diff] [blame] | 58 | order = reducer.reduce(quad); |
caryclark@google.com | 4961201 | 2013-04-08 20:37:35 +0000 | [diff] [blame] | 59 | if (order != 3) { |
bungeman@google.com | fab44db | 2013-10-11 18:50:45 +0000 | [diff] [blame] | 60 | SkDebugf("[%d] line mod quad order=%d\n", (int) index, order); |
caryclark@google.com | 4961201 | 2013-04-08 20:37:35 +0000 | [diff] [blame] | 61 | } |
| 62 | } |
| 63 | } |
| 64 | |
tfarina@chromium.org | 78e7b4e | 2014-01-02 21:45:03 +0000 | [diff] [blame] | 65 | DEF_TEST(PathOpsReduceOrderQuad, reporter) { |
caryclark@google.com | 4961201 | 2013-04-08 20:37:35 +0000 | [diff] [blame] | 66 | oneOffTest(reporter); |
| 67 | standardTestCases(reporter); |
| 68 | } |