caryclark@google.com | a5e5592 | 2013-05-07 18:51:31 +0000 | [diff] [blame] | 1 | /* |
| 2 | * Copyright 2013 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 | 8d0a524 | 2013-07-16 16:11:16 +0000 | [diff] [blame] | 7 | #include "PathOpsTestCommon.h" |
caryclark@google.com | a5e5592 | 2013-05-07 18:51:31 +0000 | [diff] [blame] | 8 | #include "SkIntersections.h" |
| 9 | #include "SkPathOpsCubic.h" |
| 10 | #include "SkPathOpsQuad.h" |
| 11 | #include "SkReduceOrder.h" |
| 12 | #include "Test.h" |
| 13 | |
| 14 | static struct lineCubic { |
| 15 | SkDCubic cubic; |
| 16 | SkDQuad quad; |
| 17 | int answerCount; |
| 18 | SkDPoint answers[2]; |
| 19 | } quadCubicTests[] = { |
skia.committer@gmail.com | b0a0589 | 2013-10-03 07:01:37 +0000 | [diff] [blame] | 20 | {{{{49, 47}, {49, 74.614250183105469}, {26.614250183105469, 97}, {-1, 97}}}, |
caryclark@google.com | 7eaa53d | 2013-10-02 14:49:34 +0000 | [diff] [blame] | 21 | {{{-8.659739592076221e-015, 96.991401672363281}, {20.065492630004883, 96.645187377929688}, |
| 22 | {34.355339050292969, 82.355339050292969}}}, 2, |
| 23 | {{34.355339050292969,82.355339050292969}, {34.306797674910243,82.403823585863449}}}, |
| 24 | |
skia.committer@gmail.com | 2b34fe0 | 2013-05-08 07:01:40 +0000 | [diff] [blame] | 25 | {{{{10,234}, {10,229.58172607421875}, {13.581720352172852,226}, {18,226}}}, |
caryclark@google.com | 7eaa53d | 2013-10-02 14:49:34 +0000 | [diff] [blame] | 26 | {{{18,226}, {14.686291694641113,226}, {12.342399597167969,228.3424072265625}}}, 1, |
| 27 | {{18,226}, {0,0}}}, |
skia.committer@gmail.com | 2b34fe0 | 2013-05-08 07:01:40 +0000 | [diff] [blame] | 28 | {{{{10,234}, {10,229.58172607421875}, {13.581720352172852,226}, {18,226}}}, |
caryclark@google.com | 7eaa53d | 2013-10-02 14:49:34 +0000 | [diff] [blame] | 29 | {{{12.342399597167969,228.3424072265625}, {10,230.68629455566406}, {10,234}}}, 1, |
| 30 | {{10,234}, {0,0}}}, |
caryclark@google.com | a5e5592 | 2013-05-07 18:51:31 +0000 | [diff] [blame] | 31 | }; |
| 32 | |
| 33 | static const size_t quadCubicTests_count = SK_ARRAY_COUNT(quadCubicTests); |
| 34 | |
| 35 | static void PathOpsCubicQuadIntersectionTest(skiatest::Reporter* reporter) { |
| 36 | for (size_t index = 0; index < quadCubicTests_count; ++index) { |
| 37 | int iIndex = static_cast<int>(index); |
| 38 | const SkDCubic& cubic = quadCubicTests[index].cubic; |
caryclark@google.com | 8d0a524 | 2013-07-16 16:11:16 +0000 | [diff] [blame] | 39 | SkASSERT(ValidCubic(cubic)); |
caryclark@google.com | a5e5592 | 2013-05-07 18:51:31 +0000 | [diff] [blame] | 40 | const SkDQuad& quad = quadCubicTests[index].quad; |
caryclark@google.com | 8d0a524 | 2013-07-16 16:11:16 +0000 | [diff] [blame] | 41 | SkASSERT(ValidQuad(quad)); |
caryclark@google.com | a5e5592 | 2013-05-07 18:51:31 +0000 | [diff] [blame] | 42 | SkReduceOrder reduce1; |
| 43 | SkReduceOrder reduce2; |
| 44 | int order1 = reduce1.reduce(cubic, SkReduceOrder::kNo_Quadratics, |
| 45 | SkReduceOrder::kFill_Style); |
| 46 | int order2 = reduce2.reduce(quad, SkReduceOrder::kFill_Style); |
| 47 | if (order1 != 4) { |
| 48 | SkDebugf("[%d] cubic order=%d\n", iIndex, order1); |
| 49 | REPORTER_ASSERT(reporter, 0); |
| 50 | } |
| 51 | if (order2 != 3) { |
| 52 | SkDebugf("[%d] quad order=%d\n", iIndex, order2); |
| 53 | REPORTER_ASSERT(reporter, 0); |
| 54 | } |
| 55 | SkIntersections i; |
| 56 | int roots = i.intersect(cubic, quad); |
| 57 | SkASSERT(roots == quadCubicTests[index].answerCount); |
| 58 | for (int pt = 0; pt < roots; ++pt) { |
| 59 | double tt1 = i[0][pt]; |
caryclark@google.com | 4fdbb22 | 2013-07-23 15:27:41 +0000 | [diff] [blame] | 60 | SkDPoint xy1 = cubic.ptAtT(tt1); |
caryclark@google.com | a5e5592 | 2013-05-07 18:51:31 +0000 | [diff] [blame] | 61 | double tt2 = i[1][pt]; |
caryclark@google.com | 4fdbb22 | 2013-07-23 15:27:41 +0000 | [diff] [blame] | 62 | SkDPoint xy2 = quad.ptAtT(tt2); |
caryclark@google.com | a5e5592 | 2013-05-07 18:51:31 +0000 | [diff] [blame] | 63 | if (!xy1.approximatelyEqual(xy2)) { |
| 64 | SkDebugf("%s [%d,%d] x!= t1=%g (%g,%g) t2=%g (%g,%g)\n", |
| 65 | __FUNCTION__, iIndex, pt, tt1, xy1.fX, xy1.fY, tt2, xy2.fX, xy2.fY); |
| 66 | } |
| 67 | REPORTER_ASSERT(reporter, xy1.approximatelyEqual(xy2)); |
| 68 | bool found = false; |
| 69 | for (int idx2 = 0; idx2 < quadCubicTests[index].answerCount; ++idx2) { |
| 70 | found |= quadCubicTests[index].answers[idx2].approximatelyEqual(xy1); |
| 71 | } |
| 72 | REPORTER_ASSERT(reporter, found); |
| 73 | } |
| 74 | reporter->bumpTestCount(); |
| 75 | } |
| 76 | } |
| 77 | |
| 78 | #include "TestClassDef.h" |
| 79 | DEFINE_TESTCLASS_SHORT(PathOpsCubicQuadIntersectionTest) |