• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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  */
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 
14 static struct cubicConic {
15     CubicPts cubic;
16     ConicPts 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 
29 static const int cubicConicTests_count = (int) SK_ARRAY_COUNT(cubicConicTests);
30 
cubicConicIntersection(skiatest::Reporter * reporter,int index)31 static void cubicConicIntersection(skiatest::Reporter* reporter, int index) {
32     const CubicPts& cu = cubicConicTests[index].cubic;
33     SkDCubic cubic;
34     cubic.debugSet(cu.fPts);
35     SkASSERT(ValidCubic(cubic));
36     const ConicPts& co = cubicConicTests[index].conic;
37     SkDConic conic;
38     conic.debugSet(co.fPts.fPts, co.fWeight);
39     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 
DEF_TEST(PathOpsCubicConicIntersection,reporter)68 DEF_TEST(PathOpsCubicConicIntersection, reporter) {
69     for (int index = 0; index < cubicConicTests_count; ++index) {
70         cubicConicIntersection(reporter, index);
71         reporter->bumpTestCount();
72     }
73 }
74 
DEF_TEST(PathOpsCubicConicIntersectionOneOff,reporter)75 DEF_TEST(PathOpsCubicConicIntersectionOneOff, reporter) {
76     cubicConicIntersection(reporter, 1);
77 }
78