blob: 18322c8e2a357ff20835ccbdad4645a964813327 [file] [log] [blame]
caryclark@google.com639df892012-01-10 21:46:10 +00001#include "CubicIntersection.h"
caryclark@google.com27accef2012-01-25 18:57:23 +00002#include "Intersection_Tests.h"
caryclark@google.com639df892012-01-10 21:46:10 +00003#include "TestUtilities.h"
4
5const Quadratic quadratics[] = {
6 {{0, 0}, {1, 0}, {1, 1}},
7};
8
9const size_t quadratics_count = sizeof(quadratics) / sizeof(quadratics[0]);
10
11int firstCubicCoincidenceTest = 0;
12
13void CubicCoincidence_Test() {
14 // split large quadratic
15 // upscale quadratics to cubics
16 // compare original, parts, to see if the are coincident
17 for (size_t index = firstCubicCoincidenceTest; index < quadratics_count; ++index) {
18 const Quadratic& test = quadratics[index];
19 QuadraticPair split;
20 chop_at(test, split, 0.5);
21 Quadratic midThird;
22 sub_divide(test, 1.0/3, 2.0/3, midThird);
23 Cubic whole, first, second, mid;
24 quad_to_cubic(test, whole);
25 quad_to_cubic(split.first(), first);
26 quad_to_cubic(split.second(), second);
27 quad_to_cubic(midThird, mid);
28 if (!implicit_matches(whole, first)) {
29 printf("%s-1 %d\n", __FUNCTION__, (int)index);
30 }
31 if (!implicit_matches(whole, second)) {
32 printf("%s-2 %d\n", __FUNCTION__, (int)index);
33 }
34 if (!implicit_matches(mid, first)) {
35 printf("%s-3 %d\n", __FUNCTION__, (int)index);
36 }
37 if (!implicit_matches(mid, second)) {
38 printf("%s-4 %d\n", __FUNCTION__, (int)index);
39 }
40 if (!implicit_matches(first, second)) {
41 printf("%s-5 %d\n", __FUNCTION__, (int)index);
42 }
43 }
44}
caryclark@google.com27accef2012-01-25 18:57:23 +000045
46// pairs of coincident cubics
47// The on curve points of each cubic should be on both parameterized cubics.
48const Cubic cubics[] = {
49 {
50 {1, -1},
51 {.333, 1},
52 {-.333, -1},
53 {-1, 1}
54 },
55 {
56 {-1, 1},
57 {-.333, -1},
58 {.333, 1},
59 {1, -1}
60 },
61 {
62 {0, 2},
63 {0, 1},
64 {1, 0},
65 {2, 0}
66 }, {
67 {2, 0},
68 {1, 0},
69 {0, 1},
70 {0, 2}
71 },
72 {
73 {315.74799999999999, 312.83999999999997},
74 {312.64400000000001, 318.13400000000001},
75 {305.83600000000001, 319.90899999999999},
76 {300.54199999999997, 316.80399999999997}
77 }, {
78 {317.12200000000001, 309.05000000000001},
79 {316.11200000000002, 315.10199999999998},
80 {310.38499999999999, 319.19},
81 {304.33199999999999, 318.17899999999997}
82 }
83};
84
85const size_t cubics_count = sizeof(cubics) / sizeof(cubics[0]);
86
87int firstCubicParameterizationTest = 0;
88
89void CubicParameterization_Test() {
90 for (size_t index = firstCubicParameterizationTest; index < cubics_count; ++index) {
91 for (size_t inner = 0; inner < 4; inner += 3) {
92 if (!point_on_parameterized_curve(cubics[index], cubics[index][inner])) {
93 printf("%s [%zu,%zu] 1 parameterization failed\n",
94 __FUNCTION__, index, inner);
95 }
96 if (!point_on_parameterized_curve(cubics[index], cubics[index ^ 1][inner])) {
97 printf("%s [%zu,%zu] 2 parameterization failed\n",
98 __FUNCTION__, index, inner);
99 }
100 }
101 }
102}