blob: fae1233a55823cc28bf63f22c2d33e4cf90189a9 [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 {
15 SkDCubic cubic;
16 SkDConic conic;
17} 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) {
32 const SkDCubic& cubic = cubicConicTests[index].cubic;
33 SkASSERT(ValidCubic(cubic));
34 const SkDConic& conic = cubicConicTests[index].conic;
35 SkASSERT(ValidConic(conic));
36 SkReduceOrder reduce1;
37 SkReduceOrder reduce2;
38 int order1 = reduce1.reduce(cubic, SkReduceOrder::kNo_Quadratics);
39 int order2 = reduce2.reduce(conic.fPts);
40 if (order1 != 4) {
41 SkDebugf("[%d] cubic order=%d\n", index, order1);
42 REPORTER_ASSERT(reporter, 0);
43 }
44 if (order2 != 3) {
45 SkDebugf("[%d] conic order=%d\n", index, order2);
46 REPORTER_ASSERT(reporter, 0);
47 }
48 SkIntersections i;
49 int roots = i.intersect(cubic, conic);
50 for (int pt = 0; pt < roots; ++pt) {
51 double tt1 = i[0][pt];
52 SkDPoint xy1 = cubic.ptAtT(tt1);
53 double tt2 = i[1][pt];
54 SkDPoint xy2 = conic.ptAtT(tt2);
55 if (!xy1.approximatelyEqual(xy2)) {
56 SkDebugf("%s [%d,%d] x!= t1=%g (%g,%g) t2=%g (%g,%g)\n",
57 __FUNCTION__, index, pt, tt1, xy1.fX, xy1.fY, tt2, xy2.fX, xy2.fY);
58 }
59 REPORTER_ASSERT(reporter, xy1.approximatelyEqual(xy2));
60 }
61 reporter->bumpTestCount();
62}
63
64DEF_TEST(PathOpsCubicConicIntersection, reporter) {
65 for (int index = 0; index < cubicConicTests_count; ++index) {
66 cubicConicIntersection(reporter, index);
67 reporter->bumpTestCount();
68 }
69}
70
71DEF_TEST(PathOpsCubicConicIntersectionOneOff, reporter) {
72 cubicConicIntersection(reporter, 1);
73}