aboutsummaryrefslogtreecommitdiffhomepage
path: root/experimental/Intersection/CubicParameterization_Test.cpp
blob: cc095b60fda00cf81f6dda3e833aa977f7472805 (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
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
/*
 * Copyright 2012 Google Inc.
 *
 * Use of this source code is governed by a BSD-style license that can be
 * found in the LICENSE file.
 */
#include "QuadraticUtilities.h"
#include "CurveIntersection.h"
#include "Intersection_Tests.h"
#include "Parameterization_Test.h"
#include "TestUtilities.h"

const Quadratic quadratics[] = {
    {{0, 0}, {1, 0}, {1, 1}},
};

const size_t quadratics_count = sizeof(quadratics) / sizeof(quadratics[0]);

int firstCubicCoincidenceTest = 0;

void CubicCoincidence_Test() {
    // split large quadratic
    // upscale quadratics to cubics
    // compare original, parts, to see if the are coincident
    for (size_t index = firstCubicCoincidenceTest; index < quadratics_count; ++index) {
        const Quadratic& test = quadratics[index];
        QuadraticPair split;
        chop_at(test, split, 0.5);
        Quadratic midThird;
        sub_divide(test, 1.0/3, 2.0/3, midThird);
        Cubic whole, first, second, mid;
        quad_to_cubic(test, whole);
        quad_to_cubic(split.first(), first);
        quad_to_cubic(split.second(), second);
        quad_to_cubic(midThird, mid);
        if (!implicit_matches(whole, first)) {
            SkDebugf("%s-1 %d\n", __FUNCTION__, (int)index);
        }
        if (!implicit_matches(whole, second)) {
            SkDebugf("%s-2 %d\n", __FUNCTION__, (int)index);
        }
        if (!implicit_matches(mid, first)) {
            SkDebugf("%s-3 %d\n", __FUNCTION__, (int)index);
        }
        if (!implicit_matches(mid, second)) {
            SkDebugf("%s-4 %d\n", __FUNCTION__, (int)index);
        }
        if (!implicit_matches(first, second)) {
            SkDebugf("%s-5 %d\n", __FUNCTION__, (int)index);
        }
    }
}

// pairs of coincident cubics
// The on curve points of each cubic should be on both parameterized cubics.
const Cubic cubics[] = {
  {
    { 1,     -1},
    { 1.0/3,  1},
    {-1.0/3, -1},
    {-1,      1}
  },
  {
    {-1,     1},
    {-1.0/3, -1},
    { 1.0/3,  1},
    { 1,     -1}
  },
  {
    {0, 2},
    {0, 1},
    {1, 0},
    {2, 0}
  }, {
    {2, 0},
    {1, 0},
    {0, 1},
    {0, 2}
  },
  {
    {315.74799999999999, 312.83999999999997},
    {312.64400000000001, 318.13400000000001},
    {305.83600000000001, 319.90899999999999},
    {300.54199999999997, 316.80399999999997}
  }, {
    {317.12200000000001, 309.05000000000001},
    {316.11200000000002, 315.10199999999998},
    {310.38499999999999, 319.19},
    {304.33199999999999, 318.17899999999997}
  }
};

const size_t cubics_count = sizeof(cubics) / sizeof(cubics[0]);

int firstCubicParameterizationTest = 0;

void CubicParameterization_Test() {
    for (size_t index = firstCubicParameterizationTest; index < cubics_count; ++index) {
        for (size_t inner = 0; inner < 4; inner += 3) {
            if (!point_on_parameterized_curve(cubics[index], cubics[index][inner])) {
                    SkDebugf("%s [%zu,%zu] 1 parameterization failed\n",
                        __FUNCTION__, index, inner);
            }
            if (!point_on_parameterized_curve(cubics[index], cubics[index ^ 1][inner])) {
                    SkDebugf("%s [%zu,%zu] 2 parameterization failed\n",
                        __FUNCTION__, index, inner);
            }
        }
        if (!implicit_matches(cubics[index], cubics[index ^ 1])) {
            SkDebugf("%s %d\n", __FUNCTION__, (int)index);
        }
    }
}