• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright 2012 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 "QuadraticUtilities.h"
8 #include "CurveIntersection.h"
9 #include "Intersection_Tests.h"
10 #include "Parameterization_Test.h"
11 #include "TestUtilities.h"
12 
13 const Quadratic quadratics[] = {
14     {{0, 0}, {1, 0}, {1, 1}},
15 };
16 
17 const size_t quadratics_count = sizeof(quadratics) / sizeof(quadratics[0]);
18 
19 int firstCubicCoincidenceTest = 0;
20 
CubicCoincidence_Test()21 void CubicCoincidence_Test() {
22     // split large quadratic
23     // upscale quadratics to cubics
24     // compare original, parts, to see if the are coincident
25     for (size_t index = firstCubicCoincidenceTest; index < quadratics_count; ++index) {
26         const Quadratic& test = quadratics[index];
27         QuadraticPair split;
28         chop_at(test, split, 0.5);
29         Quadratic midThird;
30         sub_divide(test, 1.0/3, 2.0/3, midThird);
31         Cubic whole, first, second, mid;
32         quad_to_cubic(test, whole);
33         quad_to_cubic(split.first(), first);
34         quad_to_cubic(split.second(), second);
35         quad_to_cubic(midThird, mid);
36         if (!implicit_matches(whole, first)) {
37             SkDebugf("%s-1 %d\n", __FUNCTION__, (int)index);
38         }
39         if (!implicit_matches(whole, second)) {
40             SkDebugf("%s-2 %d\n", __FUNCTION__, (int)index);
41         }
42         if (!implicit_matches(mid, first)) {
43             SkDebugf("%s-3 %d\n", __FUNCTION__, (int)index);
44         }
45         if (!implicit_matches(mid, second)) {
46             SkDebugf("%s-4 %d\n", __FUNCTION__, (int)index);
47         }
48         if (!implicit_matches(first, second)) {
49             SkDebugf("%s-5 %d\n", __FUNCTION__, (int)index);
50         }
51     }
52 }
53 
54 // pairs of coincident cubics
55 // The on curve points of each cubic should be on both parameterized cubics.
56 const Cubic cubics[] = {
57   {
58     { 1,     -1},
59     { 1.0/3,  1},
60     {-1.0/3, -1},
61     {-1,      1}
62   },
63   {
64     {-1,     1},
65     {-1.0/3, -1},
66     { 1.0/3,  1},
67     { 1,     -1}
68   },
69   {
70     {0, 2},
71     {0, 1},
72     {1, 0},
73     {2, 0}
74   }, {
75     {2, 0},
76     {1, 0},
77     {0, 1},
78     {0, 2}
79   },
80   {
81     {315.74799999999999, 312.83999999999997},
82     {312.64400000000001, 318.13400000000001},
83     {305.83600000000001, 319.90899999999999},
84     {300.54199999999997, 316.80399999999997}
85   }, {
86     {317.12200000000001, 309.05000000000001},
87     {316.11200000000002, 315.10199999999998},
88     {310.38499999999999, 319.19},
89     {304.33199999999999, 318.17899999999997}
90   }
91 };
92 
93 const size_t cubics_count = sizeof(cubics) / sizeof(cubics[0]);
94 
95 int firstCubicParameterizationTest = 0;
96 
CubicParameterization_Test()97 void CubicParameterization_Test() {
98     for (size_t index = firstCubicParameterizationTest; index < cubics_count; ++index) {
99         for (size_t inner = 0; inner < 4; inner += 3) {
100             if (!point_on_parameterized_curve(cubics[index], cubics[index][inner])) {
101                     SkDebugf("%s [%zu,%zu] 1 parameterization failed\n",
102                         __FUNCTION__, index, inner);
103             }
104             if (!point_on_parameterized_curve(cubics[index], cubics[index ^ 1][inner])) {
105                     SkDebugf("%s [%zu,%zu] 2 parameterization failed\n",
106                         __FUNCTION__, index, inner);
107             }
108         }
109         if (!implicit_matches(cubics[index], cubics[index ^ 1])) {
110             SkDebugf("%s %d\n", __FUNCTION__, (int)index);
111         }
112     }
113 }
114