blob: d7924634b2bb84b3fb97b4282a95b1af2e2bb726 [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 */
7#include "PathOpsTestCommon.h"
8#include "SkIntersections.h"
9#include "SkPathOpsConic.h"
10#include "SkPathOpsCubic.h"
11#include "SkReduceOrder.h"
12#include "Test.h"
13
14static struct cubicConic {
caryclarka35ab3e2016-10-20 08:32:18 -070015 CubicPts cubic;
16 ConicPts conic;
caryclark26ad22a2015-10-16 09:03:38 -070017} cubicConicTests[] = {
18 {{{{188.60000610351562, 2041.5999755859375}, {188.60000610351562, 2065.39990234375},
19 {208, 2084.800048828125}, {231.80000305175781, 2084.800048828125}}},
20 {{{{231.80000305175781, 2084.800048828125}, {188.60000610351562, 2084.800048828125},
21 {188.60000610351562, 2041.5999755859375}}}, 0.707107008f}},
22
23 {{{{231.80000305175781, 2084.800048828125}, {255.60000610351562, 2084.800048828125},
24 {275, 2065.39990234375}, {275, 2041.5999755859375}}},
25 {{{{275, 2041.5999755859375}, {275, 2084.800048828125},
26 {231.80000305175781, 2084.800048828125}}}, 0.707107008f}},
27};
28
29static const int cubicConicTests_count = (int) SK_ARRAY_COUNT(cubicConicTests);
30
31static void cubicConicIntersection(skiatest::Reporter* reporter, int index) {
caryclarka35ab3e2016-10-20 08:32:18 -070032 const CubicPts& cu = cubicConicTests[index].cubic;
33 SkDCubic cubic;
34 cubic.debugSet(cu.fPts);
caryclark26ad22a2015-10-16 09:03:38 -070035 SkASSERT(ValidCubic(cubic));
caryclarka35ab3e2016-10-20 08:32:18 -070036 const ConicPts& co = cubicConicTests[index].conic;
37 SkDConic conic;
38 conic.debugSet(co.fPts.fPts, co.fWeight);
caryclark26ad22a2015-10-16 09:03:38 -070039 SkASSERT(ValidConic(conic));
40 SkReduceOrder reduce1;
41 SkReduceOrder reduce2;
42 int order1 = reduce1.reduce(cubic, SkReduceOrder::kNo_Quadratics);
43 int order2 = reduce2.reduce(conic.fPts);
44 if (order1 != 4) {
45 SkDebugf("[%d] cubic order=%d\n", index, order1);
46 REPORTER_ASSERT(reporter, 0);
47 }
48 if (order2 != 3) {
49 SkDebugf("[%d] conic order=%d\n", index, order2);
50 REPORTER_ASSERT(reporter, 0);
51 }
52 SkIntersections i;
53 int roots = i.intersect(cubic, conic);
54 for (int pt = 0; pt < roots; ++pt) {
55 double tt1 = i[0][pt];
56 SkDPoint xy1 = cubic.ptAtT(tt1);
57 double tt2 = i[1][pt];
58 SkDPoint xy2 = conic.ptAtT(tt2);
59 if (!xy1.approximatelyEqual(xy2)) {
60 SkDebugf("%s [%d,%d] x!= t1=%g (%g,%g) t2=%g (%g,%g)\n",
61 __FUNCTION__, index, pt, tt1, xy1.fX, xy1.fY, tt2, xy2.fX, xy2.fY);
62 }
63 REPORTER_ASSERT(reporter, xy1.approximatelyEqual(xy2));
64 }
65 reporter->bumpTestCount();
66}
67
68DEF_TEST(PathOpsCubicConicIntersection, reporter) {
69 for (int index = 0; index < cubicConicTests_count; ++index) {
70 cubicConicIntersection(reporter, index);
71 reporter->bumpTestCount();
72 }
73}
74
75DEF_TEST(PathOpsCubicConicIntersectionOneOff, reporter) {
76 cubicConicIntersection(reporter, 1);
77}