aboutsummaryrefslogtreecommitdiffhomepage
path: root/tests/PathOpsCubicConicIntersectionTest.cpp
blob: d7924634b2bb84b3fb97b4282a95b1af2e2bb726 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
/*
 * Copyright 2015 Google Inc.
 *
 * Use of this source code is governed by a BSD-style license that can be
 * found in the LICENSE file.
 */
#include "PathOpsTestCommon.h"
#include "SkIntersections.h"
#include "SkPathOpsConic.h"
#include "SkPathOpsCubic.h"
#include "SkReduceOrder.h"
#include "Test.h"

static struct cubicConic {
    CubicPts cubic;
    ConicPts conic;
} cubicConicTests[] = {
    {{{{188.60000610351562, 2041.5999755859375}, {188.60000610351562, 2065.39990234375},
        {208, 2084.800048828125}, {231.80000305175781, 2084.800048828125}}},
    {{{{231.80000305175781, 2084.800048828125}, {188.60000610351562, 2084.800048828125},
        {188.60000610351562, 2041.5999755859375}}}, 0.707107008f}},

    {{{{231.80000305175781, 2084.800048828125}, {255.60000610351562, 2084.800048828125},
        {275, 2065.39990234375}, {275, 2041.5999755859375}}},
    {{{{275, 2041.5999755859375}, {275, 2084.800048828125},
        {231.80000305175781, 2084.800048828125}}}, 0.707107008f}},
};

static const int cubicConicTests_count = (int) SK_ARRAY_COUNT(cubicConicTests);

static void cubicConicIntersection(skiatest::Reporter* reporter, int index) {
    const CubicPts& cu = cubicConicTests[index].cubic;
    SkDCubic cubic;
    cubic.debugSet(cu.fPts);
    SkASSERT(ValidCubic(cubic));
    const ConicPts& co = cubicConicTests[index].conic;
    SkDConic conic;
    conic.debugSet(co.fPts.fPts, co.fWeight);
    SkASSERT(ValidConic(conic));
    SkReduceOrder reduce1;
    SkReduceOrder reduce2;
    int order1 = reduce1.reduce(cubic, SkReduceOrder::kNo_Quadratics);
    int order2 = reduce2.reduce(conic.fPts);
    if (order1 != 4) {
        SkDebugf("[%d] cubic order=%d\n", index, order1);
        REPORTER_ASSERT(reporter, 0);
    }
    if (order2 != 3) {
        SkDebugf("[%d] conic order=%d\n", index, order2);
        REPORTER_ASSERT(reporter, 0);
    }
    SkIntersections i;
    int roots = i.intersect(cubic, conic);
    for (int pt = 0; pt < roots; ++pt) {
        double tt1 = i[0][pt];
        SkDPoint xy1 = cubic.ptAtT(tt1);
        double tt2 = i[1][pt];
        SkDPoint xy2 = conic.ptAtT(tt2);
        if (!xy1.approximatelyEqual(xy2)) {
            SkDebugf("%s [%d,%d] x!= t1=%g (%g,%g) t2=%g (%g,%g)\n",
                __FUNCTION__, index, pt, tt1, xy1.fX, xy1.fY, tt2, xy2.fX, xy2.fY);
        }
        REPORTER_ASSERT(reporter, xy1.approximatelyEqual(xy2));
    }
    reporter->bumpTestCount();
}

DEF_TEST(PathOpsCubicConicIntersection, reporter) {
    for (int index = 0; index < cubicConicTests_count; ++index) {
        cubicConicIntersection(reporter, index);
        reporter->bumpTestCount();
    }
}

DEF_TEST(PathOpsCubicConicIntersectionOneOff, reporter) {
    cubicConicIntersection(reporter, 1);
}