blob: 9f8034fa5e7e9bc8e1233ec6356391f0b8d61e66 [file] [log] [blame]
caryclark26ad22a2015-10-16 09:03:38 -07001/*
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 Kleinc0bd9f92019-04-23 12:05:21 -05007#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"
caryclark26ad22a2015-10-16 09:03:38 -070013
14static struct cubicConic {
caryclarka35ab3e2016-10-20 08:32:18 -070015 CubicPts cubic;
16 ConicPts conic;
caryclark26ad22a2015-10-16 09:03:38 -070017} cubicConicTests[] = {
Cary Clark74b42902018-03-09 07:38:47 -050018#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 Canaryd4998172018-07-11 11:31:34 -040023 {{{{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 Clark74b42902018-03-09 07:38:47 -050029 {5.8282588724978268e-05, 0.00000000000000000 }}}, 53684.6563f}},
Hal Canaryd4998172018-07-11 11:31:34 -040030#endif
Cary Clark74b42902018-03-09 07:38:47 -050031
caryclark26ad22a2015-10-16 09:03:38 -070032 {{{{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
43static const int cubicConicTests_count = (int) SK_ARRAY_COUNT(cubicConicTests);
44
45static void cubicConicIntersection(skiatest::Reporter* reporter, int index) {
caryclarka35ab3e2016-10-20 08:32:18 -070046 const CubicPts& cu = cubicConicTests[index].cubic;
47 SkDCubic cubic;
48 cubic.debugSet(cu.fPts);
caryclark26ad22a2015-10-16 09:03:38 -070049 SkASSERT(ValidCubic(cubic));
caryclarka35ab3e2016-10-20 08:32:18 -070050 const ConicPts& co = cubicConicTests[index].conic;
51 SkDConic conic;
52 conic.debugSet(co.fPts.fPts, co.fWeight);
caryclark26ad22a2015-10-16 09:03:38 -070053 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
82DEF_TEST(PathOpsCubicConicIntersection, reporter) {
83 for (int index = 0; index < cubicConicTests_count; ++index) {
84 cubicConicIntersection(reporter, index);
85 reporter->bumpTestCount();
86 }
87}
88
89DEF_TEST(PathOpsCubicConicIntersectionOneOff, reporter) {
Cary Clark74b42902018-03-09 07:38:47 -050090 cubicConicIntersection(reporter, 0);
caryclark26ad22a2015-10-16 09:03:38 -070091}