caryclark | 26ad22a | 2015-10-16 09:03:38 -0700 | [diff] [blame] | 1 | /* |
| 2 | * Copyright 2015 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 | */ |
Mike Klein | c0bd9f9 | 2019-04-23 12:05:21 -0500 | [diff] [blame] | 7 | #include "src/pathops/SkIntersections.h" |
| 8 | #include "src/pathops/SkPathOpsConic.h" |
| 9 | #include "src/pathops/SkPathOpsCubic.h" |
| 10 | #include "src/pathops/SkReduceOrder.h" |
| 11 | #include "tests/PathOpsTestCommon.h" |
| 12 | #include "tests/Test.h" |
caryclark | 26ad22a | 2015-10-16 09:03:38 -0700 | [diff] [blame] | 13 | |
| 14 | static struct cubicConic { |
caryclark | a35ab3e | 2016-10-20 08:32:18 -0700 | [diff] [blame] | 15 | CubicPts cubic; |
| 16 | ConicPts conic; |
caryclark | 26ad22a | 2015-10-16 09:03:38 -0700 | [diff] [blame] | 17 | } cubicConicTests[] = { |
Cary Clark | 74b4290 | 2018-03-09 07:38:47 -0500 | [diff] [blame] | 18 | #if 0 |
| 19 | // FIXME: this triggers an assert in bool SkTSect::extractCoincident() at |
| 20 | // SkOPASSERT(oppStartT < oppEndT); |
| 21 | // Throwing an error here breaks one test, but only in release. |
| 22 | // More work to be done to figure this out. |
Hal Canary | d499817 | 2018-07-11 11:31:34 -0400 | [diff] [blame] | 23 | {{{{2.1883804947719909e-05, 3.6366123822517693e-05 }, |
| 24 | {2.9145950975362211e-05, 2.9117207304807380e-05 }, |
| 25 | {2.9113532946212217e-05, 2.9173743314458989e-05 }, |
| 26 | {0.00000000000000000, 5.8282588724978268e-05 }}}, |
| 27 | {{{{0.00000000000000000, 5.8282581449020654e-05 }, |
| 28 | {0.00000000000000000, 5.8282563259126619e-05 }, |
Cary Clark | 74b4290 | 2018-03-09 07:38:47 -0500 | [diff] [blame] | 29 | {5.8282588724978268e-05, 0.00000000000000000 }}}, 53684.6563f}}, |
Hal Canary | d499817 | 2018-07-11 11:31:34 -0400 | [diff] [blame] | 30 | #endif |
Cary Clark | 74b4290 | 2018-03-09 07:38:47 -0500 | [diff] [blame] | 31 | |
caryclark | 26ad22a | 2015-10-16 09:03:38 -0700 | [diff] [blame] | 32 | {{{{188.60000610351562, 2041.5999755859375}, {188.60000610351562, 2065.39990234375}, |
| 33 | {208, 2084.800048828125}, {231.80000305175781, 2084.800048828125}}}, |
| 34 | {{{{231.80000305175781, 2084.800048828125}, {188.60000610351562, 2084.800048828125}, |
| 35 | {188.60000610351562, 2041.5999755859375}}}, 0.707107008f}}, |
| 36 | |
| 37 | {{{{231.80000305175781, 2084.800048828125}, {255.60000610351562, 2084.800048828125}, |
| 38 | {275, 2065.39990234375}, {275, 2041.5999755859375}}}, |
| 39 | {{{{275, 2041.5999755859375}, {275, 2084.800048828125}, |
| 40 | {231.80000305175781, 2084.800048828125}}}, 0.707107008f}}, |
| 41 | }; |
| 42 | |
| 43 | static const int cubicConicTests_count = (int) SK_ARRAY_COUNT(cubicConicTests); |
| 44 | |
| 45 | static void cubicConicIntersection(skiatest::Reporter* reporter, int index) { |
caryclark | a35ab3e | 2016-10-20 08:32:18 -0700 | [diff] [blame] | 46 | const CubicPts& cu = cubicConicTests[index].cubic; |
| 47 | SkDCubic cubic; |
| 48 | cubic.debugSet(cu.fPts); |
caryclark | 26ad22a | 2015-10-16 09:03:38 -0700 | [diff] [blame] | 49 | SkASSERT(ValidCubic(cubic)); |
caryclark | a35ab3e | 2016-10-20 08:32:18 -0700 | [diff] [blame] | 50 | const ConicPts& co = cubicConicTests[index].conic; |
| 51 | SkDConic conic; |
| 52 | conic.debugSet(co.fPts.fPts, co.fWeight); |
caryclark | 26ad22a | 2015-10-16 09:03:38 -0700 | [diff] [blame] | 53 | SkASSERT(ValidConic(conic)); |
| 54 | SkReduceOrder reduce1; |
| 55 | SkReduceOrder reduce2; |
| 56 | int order1 = reduce1.reduce(cubic, SkReduceOrder::kNo_Quadratics); |
| 57 | int order2 = reduce2.reduce(conic.fPts); |
| 58 | if (order1 != 4) { |
| 59 | SkDebugf("[%d] cubic order=%d\n", index, order1); |
| 60 | REPORTER_ASSERT(reporter, 0); |
| 61 | } |
| 62 | if (order2 != 3) { |
| 63 | SkDebugf("[%d] conic order=%d\n", index, order2); |
| 64 | REPORTER_ASSERT(reporter, 0); |
| 65 | } |
| 66 | SkIntersections i; |
| 67 | int roots = i.intersect(cubic, conic); |
| 68 | for (int pt = 0; pt < roots; ++pt) { |
| 69 | double tt1 = i[0][pt]; |
| 70 | SkDPoint xy1 = cubic.ptAtT(tt1); |
| 71 | double tt2 = i[1][pt]; |
| 72 | SkDPoint xy2 = conic.ptAtT(tt2); |
| 73 | if (!xy1.approximatelyEqual(xy2)) { |
| 74 | SkDebugf("%s [%d,%d] x!= t1=%g (%g,%g) t2=%g (%g,%g)\n", |
| 75 | __FUNCTION__, index, pt, tt1, xy1.fX, xy1.fY, tt2, xy2.fX, xy2.fY); |
| 76 | } |
| 77 | REPORTER_ASSERT(reporter, xy1.approximatelyEqual(xy2)); |
| 78 | } |
| 79 | reporter->bumpTestCount(); |
| 80 | } |
| 81 | |
| 82 | DEF_TEST(PathOpsCubicConicIntersection, reporter) { |
| 83 | for (int index = 0; index < cubicConicTests_count; ++index) { |
| 84 | cubicConicIntersection(reporter, index); |
| 85 | reporter->bumpTestCount(); |
| 86 | } |
| 87 | } |
| 88 | |
| 89 | DEF_TEST(PathOpsCubicConicIntersectionOneOff, reporter) { |
Cary Clark | 74b4290 | 2018-03-09 07:38:47 -0500 | [diff] [blame] | 90 | cubicConicIntersection(reporter, 0); |
caryclark | 26ad22a | 2015-10-16 09:03:38 -0700 | [diff] [blame] | 91 | } |