caryclark@google.com | 9e49fb6 | 2012-08-27 14:11:33 +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 | */ |
caryclark@google.com | c682590 | 2012-02-03 22:07:47 +0000 | [diff] [blame] | 7 | #include "CurveIntersection.h" |
caryclark@google.com | 27accef | 2012-01-25 18:57:23 +0000 | [diff] [blame] | 8 | #include "Intersection_Tests.h" |
| 9 | #include "QuadraticIntersection_TestData.h" |
| 10 | #include "TestUtilities.h" |
| 11 | |
caryclark@google.com | b45a1b4 | 2012-05-18 20:50:33 +0000 | [diff] [blame] | 12 | static const Quadratic testSet[] = { |
| 13 | {{1, 1}, {2, 2}, {1, 1.000003}}, |
| 14 | {{1, 0}, {2, 6}, {3, 0}} |
| 15 | }; |
| 16 | |
| 17 | static const size_t testSetCount = sizeof(testSet) / sizeof(testSet[0]); |
| 18 | |
| 19 | |
| 20 | static void oneOffTest() { |
| 21 | SkDebugf("%s FLT_EPSILON=%1.9g\n", __FUNCTION__, FLT_EPSILON); |
caryclark@google.com | f25edfe | 2012-06-01 18:20:10 +0000 | [diff] [blame] | 22 | for (size_t index = 0; index < testSetCount; ++index) { |
caryclark@google.com | b45a1b4 | 2012-05-18 20:50:33 +0000 | [diff] [blame] | 23 | const Quadratic& quad = testSet[index]; |
| 24 | Quadratic reduce; |
caryclark@google.com | 1304bb2 | 2013-03-13 20:29:41 +0000 | [diff] [blame] | 25 | SkDEBUGCODE(int result = ) reduceOrder(quad, reduce, kReduceOrder_TreatAsFill); |
| 26 | SkASSERT(result == 3); |
caryclark@google.com | b45a1b4 | 2012-05-18 20:50:33 +0000 | [diff] [blame] | 27 | } |
| 28 | } |
| 29 | |
| 30 | static void standardTestCases() { |
caryclark@google.com | 27accef | 2012-01-25 18:57:23 +0000 | [diff] [blame] | 31 | 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.com | aa35831 | 2013-01-29 20:28:49 +0000 | [diff] [blame] | 45 | int firstQuadraticLineTest = run == RunAll ? 0 : run == RunQuadraticLines ? firstTestIndex : SK_MaxS32; |
| 46 | int firstQuadraticModLineTest = run == RunAll ? 0 : run == RunQuadraticModLines ? firstTestIndex : SK_MaxS32; |
caryclark@google.com | 27accef | 2012-01-25 18:57:23 +0000 | [diff] [blame] | 47 | |
| 48 | for (index = firstQuadraticLineTest; index < quadraticLines_count; ++index) { |
| 49 | const Quadratic& quad = quadraticLines[index]; |
caryclark@google.com | 47d73da | 2013-02-17 01:41:25 +0000 | [diff] [blame] | 50 | order = reduceOrder(quad, reduce, kReduceOrder_TreatAsFill); |
caryclark@google.com | 27accef | 2012-01-25 18:57:23 +0000 | [diff] [blame] | 51 | 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.com | 47d73da | 2013-02-17 01:41:25 +0000 | [diff] [blame] | 57 | order = reduceOrder(quad, reduce, kReduceOrder_TreatAsFill); |
caryclark@google.com | 27accef | 2012-01-25 18:57:23 +0000 | [diff] [blame] | 58 | if (order != 3) { |
| 59 | printf("[%d] line mod quad order=%d\n", (int) index, order); |
| 60 | } |
| 61 | } |
| 62 | } |
caryclark@google.com | b45a1b4 | 2012-05-18 20:50:33 +0000 | [diff] [blame] | 63 | |
| 64 | void QuadraticReduceOrder_Test() { |
| 65 | oneOffTest(); |
| 66 | standardTestCases(); |
| 67 | } |